Skip to content

Commit

Permalink
fix: unexpected transformation of colon symbol (#1962)
Browse files Browse the repository at this point in the history
Co-authored-by: liangjun.chen <liangjun.chen@yunqutech.com>
  • Loading branch information
DBSDs and liangjun.chen committed Dec 7, 2023
1 parent 3753b1b commit d87114e
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/loaders/markdown/transformer/fixtures/embed/embed.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,9 @@
second line

third line

type:null

:::success
这是一条成功信息
:::
4 changes: 3 additions & 1 deletion src/loaders/markdown/transformer/fixtures/embed/expect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { IMdTransformerResult } from '../..';

export default (ret: IMdTransformerResult) => {
expect(ret.content).toEqual(
'<><div className="markdown"><h3 id="this-is-indexmd"><a aria-hidden="true" tabIndex="-1" href="#this-is-indexmd"><span className="icon icon-link" /></a>{"This is index.md"}</h3><h3 id="this-is-embedmd"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[0].value}</p><p>{$$contentTexts[1].value}</p><h3 id="this-is-embedmd-1"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-1"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><h3 id="this-is-embedmd-2"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-2"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[2].value}</p><h3 id="this-is-embedmd-3"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-3"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[3].value}</p><p>{$$contentTexts[4].value}</p><h3 id="this-is-embedmd-4"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-4"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[5].value}</p><p>{$$contentTexts[6].value}</p></div></>',
'<><div className="markdown"><h3 id="this-is-indexmd"><a aria-hidden="true" tabIndex="-1" href="#this-is-indexmd"><span className="icon icon-link" /></a>{"This is index.md"}</h3><h3 id="this-is-embedmd"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[0].value}</p><p>{$$contentTexts[1].value}</p><p>{$$contentTexts[2].value}</p></div><Container type="success"><p>{$$contentTexts[3].value}</p></Container><div className="markdown"><h3 id="this-is-embedmd-1"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-1"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><h3 id="this-is-embedmd-2"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-2"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[4].value}</p><h3 id="this-is-embedmd-3"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-3"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[5].value}</p><p>{$$contentTexts[6].value}</p><p>{$$contentTexts[7].value}</p></div><Container type="success"><p>{$$contentTexts[8].value}</p></Container><div className="markdown"><h3 id="this-is-embedmd-4"><a aria-hidden="true" tabIndex="-1" href="#this-is-embedmd-4"><span className="icon icon-link" /></a>{"This is embed.md"}</h3><p>{$$contentTexts[9].value}</p><p>{$$contentTexts[10].value}</p><p>{$$contentTexts[11].value}</p></div><Container type="success"><p>{$$contentTexts[12].value}</p></Container></>',
);

expect(ret.meta.texts?.[2].value).toEqual('type:null');
};
2 changes: 2 additions & 0 deletions src/loaders/markdown/transformer/remarkEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { winPath } from 'umi/plugin-utils';
import type { FrozenProcessor, Transformer } from 'unified';
import url from 'url';
import type { IMdTransformerOptions } from '.';
import remarkContainer from './remarkContainer';

const EMBED_OPEN_TAG = '<embed ';
const EMBED_CLOSE_TAG = '</embed>';
Expand Down Expand Up @@ -150,6 +151,7 @@ export default function remarkEmbed(
// because directive & gfm is affect on micromark core parser rather than ast
// and if they are not applied, the embed ast will be wrong
.use(remarkDirective)
.use(remarkContainer)
.use(remarkGfm)
// for update relative src path
.use(remarkReplaceSrc, {
Expand Down

0 comments on commit d87114e

Please sign in to comment.