-
-
Notifications
You must be signed in to change notification settings - Fork 357
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make it easier for plugins to add tokenizers to the parser #42
Comments
Sorry for the late response. I’ve been busy launching, and handling the public interest, associated with alex. Regarding mentions, you should take a look at how mdast-github implements them. However, that just adds links. I think that’s good. With mdast-html#1 I’m thinking of adding support for a new property on nodes which sets their content. Could you give some examples of what input you would like to transform to what output? |
I'm having also some challenges using mdast for the very same reason. I do not use I do not understand how to extend the current markdown grammar (to support mentions for instance) or whether mdast is suited for that. My use case is to do something like this: return mdast
.use(mentionGrammar)
.use(hashtagGrammar)
.parse(this.text, {position: false}); Let me know if I can help in any way. |
@masylum Thanks for your interest! First of all, the code you posted will not run the plug-ins: Regarding to your question, and this issue in general, I recommend you investigate how How the parser parses is currently, as you noticed, not documented. In the (nearby?) future I plan on rewriting the used system (related: GH-75, GH-82) to remove the need for regular expressions and only depend on tokeniser functions. In the future your use-case should be easier to accomplish, but as it’s going to change, I don’t currently plan on providing a very in-depth guide to modify the parser. |
I understand. I guess I could just transform the AST looking for text nodes and try to generate newer nodes. Since I want to get a prototype sooner than later I'm playing with https://github.com/markdown-it/markdown-it at the moment. I will keep an eye on the project though. |
Have been trying to extend the parser in order to wrap hashtags (let say twitter format). But getting this error
where
|
You should return a node if you find something. Something like |
@wooorm Thanks. That was the issue I think. Although I am getting wired duplicated html string at the end! |
Looking here and here it seems like I need to have intimate knowledge of the how the parser works in order to define regular expressions to tokenize. The use case is detecting and linking URLs (auto-linking) and @mentions. Some of the URLs I'd like to turn into special node types – such as "twitter", which another plugin could render as HTML for an embedded tweet.
Ideally I could write a plugin that only has to specify a regular expression, a function which returns the node, and some rules about scope (for example, I wouldn't want to create a link for a URL that is already inside a link).
The text was updated successfully, but these errors were encountered: