diff --git a/package.json b/package.json index 52074d5..40bcce9 100644 --- a/package.json +++ b/package.json @@ -71,8 +71,9 @@ "eslint-plugin-simple-import-sort": "^10", "eslint-plugin-sort-keys-fix": "^1", "eslint-plugin-typescript-sort-keys": "^3", - "eslint-plugin-unicorn": "^48", + "eslint-plugin-unicorn": "^49", "eslint-plugin-unused-imports": "^3", + "gatsby-remark-find-replace": "^0.3.0", "postcss-less": "^6", "postcss-styled-syntax": "^0.5", "prettier-plugin-organize-imports": "^3", @@ -114,7 +115,8 @@ "stylelint-config-clean-order": "^5", "stylelint-config-recommended": "^13", "stylelint-less": "^2", - "stylelint-order": "^6" + "stylelint-order": "^6", + "unist-util-visit": "^5.0.0" }, "devDependencies": { "@commitlint/cli": "^18", diff --git a/src/remarklint/index.ts b/src/remarklint/index.ts index c60fe3d..997cbbb 100644 --- a/src/remarklint/index.ts +++ b/src/remarklint/index.ts @@ -1,6 +1,5 @@ -const replaceNBSP = (str: string) => { - return str.replaceAll(' ', ' '); -}; +import { remarkGfmHighlight } from './remarkGfmHighlight'; +import { replaceNBSP } from './remarkTextrPlugins'; export default { $schema: 'https://json.schemastore.org/remarkrc', @@ -9,6 +8,7 @@ export default { 'remark-frontmatter', 'remark-pangu', ['remark-textr', { plugins: [replaceNBSP] }], + remarkGfmHighlight, // ----- Plugin ----------------------------------------------------------- 'remark-sort-definitions', @@ -50,9 +50,11 @@ export default { ], settings: { bullet: '-', + emphasis: '*', fences: true, listItemIndent: 1, rule: '-', + strong: '*', tightDefinitions: true, }, }; diff --git a/src/remarklint/remarkGfmHighlight.ts b/src/remarklint/remarkGfmHighlight.ts new file mode 100644 index 0000000..7823533 --- /dev/null +++ b/src/remarklint/remarkGfmHighlight.ts @@ -0,0 +1,32 @@ +const gfmHighlight = [ + { from: 'Note', to: '[!NOTE]' }, + { from: 'Tip', to: '[!TIP]' }, + { from: 'Important', to: '[!IMPORTANT]' }, + { from: 'Warning', to: '[!WARNING]' }, + { from: 'Caution', to: '[!CAUTION]' }, +]; + +export function remarkGfmHighlight() { + return async (tree: any) => { + const { visit } = await import('unist-util-visit'); + visit(tree, 'blockquote', (node: any) => { + visit(node, 'strong', (subnode: any) => { + let value = ''; + + visit(subnode, 'text', (textnode: any) => { + if (['Note', 'Tip', 'Important', 'Warning', 'Caution'].includes(textnode.value)) { + for (const item of gfmHighlight) { + if (item.from === textnode.value) { + value = item.to; + } + } + } + if (value) { + subnode.type = 'text'; + subnode.value = value; + } + }); + }); + }); + }; +} diff --git a/src/remarklint/remarkTextrPlugins.ts b/src/remarklint/remarkTextrPlugins.ts new file mode 100644 index 0000000..a2da3f8 --- /dev/null +++ b/src/remarklint/remarkTextrPlugins.ts @@ -0,0 +1,3 @@ +export const replaceNBSP = (str: string) => { + return str.replaceAll(' ', ' '); +};