diff --git a/scripts/build.ts b/scripts/build.ts index f7c60e9..2cf1173 100644 --- a/scripts/build.ts +++ b/scripts/build.ts @@ -18,6 +18,7 @@ await esbuild.build({ format: 'esm', external: ['prettier'], minify: !!Deno.env.get('CI'), + target: 'node18', }) await Deno.writeTextFile( diff --git a/src/index.ts b/src/index.ts index 96e6a20..f88e264 100644 --- a/src/index.ts +++ b/src/index.ts @@ -21,6 +21,11 @@ const plugin: Plugin = { embed: (path: AstPath>, options) => { const { node } = path + if (node.type === 'word' && (node.value.at(0) === '{' || node.value.at(-1) === '}')) { + // attr (FIXME: do better parsing) + return node.value + } + if ((node.type !== 'jsx' && node.type !== 'liquidNode') || node.value.includes('\uFFFF')) { return md.printers.mdast.embed(path, options) } @@ -47,6 +52,7 @@ const plugin: Plugin = { return node.value // skip formatting something went wrong + // markdown in vue // return formatted.split('\uFFFF')[0]?.replace(/^\s{2}/gm, '') } }, diff --git a/tests/index.test.ts b/tests/index.test.ts index 0b7faf5..0fa9546 100644 --- a/tests/index.test.ts +++ b/tests/index.test.ts @@ -69,6 +69,21 @@ comment + +## 10 + +- export \`foo()\` (some long text here, this should not be treated as es export statement) + +## 11 + +\`\`\`md +Link to pure.html +\`\`\` + +## 12 + +attrs {target="_self" #id} +attrs {target="_self"} ` const expected = ` @@ -160,6 +175,21 @@ comment + +## 10 + +- export \`foo()\` (some long text here, this should not be treated as es export statement) + +## 11 + +\`\`\`md +Link to pure.html +\`\`\` + +## 12 + +attrs {target="_self" #id} +attrs {target="_self"} `.trimStart() const result = await prettier.format(code, {