Skip to content

Commit

Permalink
more better
Browse files Browse the repository at this point in the history
  • Loading branch information
lyleschemmerling committed Dec 13, 2024
1 parent 2a55557 commit 56f9992
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions astro/.remarkrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,40 @@ import remarkPresetLintRecommended from 'remark-preset-lint-recommended';
import { lintRule } from 'unified-lint-rule';
import { visitParents } from 'unist-util-visit-parents';

const htmlTagsWithMarkdownEquivalents = [
'h1', 'h2', 'h3', 'h4', 'h5', 'h6', // Headings
'p', // Paragraphs
'br', // Line Breaks
'strong', 'b', // Bold
'em', 'i', // Italic
'blockquote', // Blockquote
'ol', 'ul', 'li', // Lists
'code', // Inline Code
'pre', // Code Block
'hr', // Horizontal Rule
'a', // Links
'img' // Images
];
const checkIfHtml = (node, parents, file) => {
if (!node.position) return

// Is this html-ish?
if (/^[\t ]*<!--/.test(node.value)) return

const name = node.name;
// check if name starts with a capital letter
const isComponent = /^[A-Z]/.test(name);
if (isComponent) return;
// check if the tag has no markdown equivalent
const tagHasNoMarkdownEquivalent = !htmlTagsWithMarkdownEquivalents.includes(name);
if (isComponent || tagHasNoMarkdownEquivalent) return;

file.message(`Unexpected HTML tag [${name}], use markdown instead`, {
ancestors: [...parents, node],
place: node.position
})
});
}

// this is the lint rule definition
const noHtml = lintRule(
{
origin: 'remark-lint:no-html',
Expand Down

0 comments on commit 56f9992

Please sign in to comment.