@ -82,6 +82,26 @@ Where to search more details about tokens:
- [Live demo](https://markdown-it.github.io/) - type your text ant click `debug` tab.
- [Live demo](https://markdown-it.github.io/) - type your text ant click `debug` tab.
## Rules
Rules are functions, doing "magick" with parser `state` objects. Each rule is
registered in one of chain with unique name.
Rules are managed by names via [Ruler](https://markdown-it.github.io/markdown-it/#Ruler) instances and `enable` / `disable` methods in [MarkdownIt](https://markdown-it.github.io/markdown-it/#MarkdownIt).
You can note, that some rules have "validation mode" - in this mode rule does not
modify token stream, and only search end of token. It's one of important design principle - token stream is "write only" on block & inline parse stages.
Parser is designed to keep rules independent. You can safely disable any, or
add new one. There are no universal recipes how to create new rules - design of
distributed state machines with good data isolation is tricky business. But you
can investigate existing rules & plugins to see possible approaches.
Also, in complex cases you can try to ask for help in tracker. Condition is very
simple - it should be clear from your ticket, that you studied docs, sources,
and tryed to do something yourself. We never reject with help to real developpers.
## Parse process
## Parse process
This was mentioned in [Data flow](#data-flow), but let's repeat sequence again:
This was mentioned in [Data flow](#data-flow), but let's repeat sequence again:
or [rules](https://github.com/markdown-it/markdown-it/tree/master/lib),
or [rules](https://github.com/markdown-it/markdown-it/tree/master/lib),
doing something similar. It can me more simple to modify existing code,
doing something similar. It can me more simple to modify existing code,
instead of writing from scratch.
instead of writing from scratch.
@ -61,6 +62,24 @@ in more convenient way.
Righ sequence is to split text to several tokens and add link tokens between.
Righ sequence is to split text to several tokens and add link tokens between.
Result will be: `text` + `link_open` + `text` + `link_close` + `text`.
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 similar things.
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.
__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?
Inline parser skips porsion of texts for the best speed. It stops only on [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.
If you are absolutely sure, that something important is missed there - create a
ticket and we will add new charcodes.
#### Why do you reject to accept some useful things?
We do 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 useful to read [CommonMark forum](http://talk.commonmark.org/) 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.