1. On parse phase, replace content by random number and store it in `env`.
2. Do async processing over collected data.
3. Render content and replace those random numbers with text
(or replace first, then render).
3. Render content and replace those random numbers with text; or replace first, then render.
Or you can render html, then parse it to DOM (or
[cheerio](https://github.com/cheeriojs/cheerio) AST) and apply transformations
in more convenient way.
Alternatively, you can render HTML, then parse it to DOM, or
[cheerio](https://github.com/cheeriojs/cheerio) AST, and apply transformations
in a more convenient way.
#### How to replace part of text token with link?
Righ sequence is to split text to several tokens and add link tokens between.
Result will be: `text` + `link_open` + `text` + `link_close` + `text`.
The right sequence is to split text to several tokens and add link tokens in between.
The result will be: `text` + `link_open` + `text` + `link_close` + `text`.
See implementations of [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js) & [emoji](https://github.com/markdown-it/markdown-it-emoji/blob/master/lib/replace.js) - those do text token splits.
See implementations of [linkify](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_core/linkify.js) and [emoji](https://github.com/markdown-it/markdown-it-emoji/blob/master/lib/replace.js) - those do text token splits.
__Note.__ Don't try to replace text with html markup! That's not secure.
__Note.__ Don't try to replace text with HTML markup! That's not secure.
#### Why my inline rule is not executed?
The inline parser skips pieces of texts for the best speed. It stops only on [a small set of chars](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_inline/text.js), which can be tokens. We did not made this list extendable, also for performance reasons.
The inline parser skips pieces of texts to optimize speed. It stops only on [a small set of chars](https://github.com/markdown-it/markdown-it/blob/master/lib/rules_inline/text.js), which can be tokens. We did not made this list extensible for performance reasons too.
If you are absolutely sure that something important is missing there - create a
ticket and we will consider adding new charcodes.
ticket and we will consider adding it as a new charcode.
#### Why do you reject some useful things?
We do a markdown parser. It should keep "markdown spirit". Other things should
be kept separate (in plugins, for example). We have no clear criteria, sorry.
Probably, you will find [CommonMark forum](http://talk.commonmark.org/) useful to read to understand us better.
We do a markdown parser. It should keep the "markdown spirit". Other things should
be kept separate, in plugins, for example. We have no clear criteria, sorry.
Probably, you will find [CommonMark forum](http://talk.commonmark.org/) a useful read to understand us better.
Of cause, if you find architecture of this parser interesting for another type
of markup - you are welcome to reuse it in another project.
Of course, if you find the architecture of this parser interesting for another type
of markup, you are welcome to reuse it in another project.