Skip to content

Commit

Permalink
better html checker
Browse files Browse the repository at this point in the history
  • Loading branch information
lyleschemmerling committed Nov 22, 2024
1 parent 966fd30 commit 8bd9ecd
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 58 deletions.
37 changes: 25 additions & 12 deletions astro/.remarkrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,39 @@ import remarkPresetLintRecommended from 'remark-preset-lint-recommended';
import { lintRule } from 'unified-lint-rule';
import { visitParents } from 'unist-util-visit-parents';

const checkIfHtml = (node, parents, file) => {
if (!node.position) return

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;

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

const noHtml = lintRule(
{
origin: 'remark-lint:no-html',
},

function (tree, file) {
//console.log(tree);
visitParents(tree, 'mdxJsxFlowElement', function (node, parents) {
if (!node.position) return

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;
checkIfHtml(node, parents, file);
})

file.message(`Unexpected HTML tag [${name}], use markdown instead`, {
ancestors: [...parents, node],
place: node.position
})
visitParents(tree, 'paragraph', function (node, parents) {
[...node.children].forEach((child) => {
if (child.type === 'mdxJsxTextElement') {
checkIfHtml(child, parents, file);
}
});
})
}
)
Expand Down
46 changes: 0 additions & 46 deletions astro/src/plugins/remark-lint-ban-html.js

This file was deleted.

0 comments on commit 8bd9ecd

Please sign in to comment.