-
I'm building an extension that may have cross-line content, for example replace any
After I made an extension, I got this error in second case:
The extension's core logic is: const demoConstruct = { name: "demo", tokenize: demoTokenize };
// 123: {
// 125: }
export const demos = { text: { 123: demoConstruct } };
function demoTokenize(effects, ok, nok) {
return start;
function start(code) {
effects.enter("demo");
effects.consume(code);
return inside;
}
function inside(code) {
if (code === 125) {
effects.consume(code);
effects.exit("demo");
return ok;
}
if (code === null) {
return nok;
}
effects.consume(code);
return inside;
}
} I wonder what's happened in this case? I want to handle line break correctly, what should I do? I've read some other extensions (for example extension math) but can't find what is the crucial point. Hopefully someone can help me. Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
Hi! First off, I don‘t understand your replace value, why would anyone want What you are making looks a bit like the example from the readme. I hope you saw that. When you see that, you might also see that it’s included in further exercises. And, earlier, that it’s mentioned that Looking at its source code, you will see that line endings are in a separate token: https://github.com/micromark/micromark-extension-mdx-expression/blob/9f7875c314ea0b4603331aa46595af83594f9163/packages/micromark-factory-mdx-expression/dev/index.js#L142-L147.
This is important for markdown, because other things can exist here. Take for example:
That indentation, those block quote markers, have to go somewhere. That can only work if regular characters and line endings are in separate tokens. |
Beta Was this translation helpful? Give feedback.
Hi!
First off, I don‘t understand your replace value, why would anyone want
__demo__
to appear in a document?What you are making looks a bit like the example from the readme. I hope you saw that. When you see that, you might also see that it’s included in further exercises. And, earlier, that it’s mentioned that
micromark-extension-mdx-expression
is similar but more advanced, already: https://github.com/micromark/micromark-extension-mdx-expression.Looking at its source code, you will see that line endings are in a separate token: https://github.com/micromark/micromark-extension-mdx-expression/blob/9f7875c314ea0b4603331aa46595af83594f9163/packages/micromark-factory-mdx-expression/dev/ind…