Skip to content
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

Extending with custom tags #1373

Closed
ghost opened this issue Oct 31, 2018 · 15 comments
Closed

Extending with custom tags #1373

ghost opened this issue Oct 31, 2018 · 15 comments
Labels
category: docs Documentation changes

Comments

@ghost
Copy link

ghost commented Oct 31, 2018

I want to create custom "tags", like text alignment blocks, inline text color, etc.
Documentation is not very clear to me how to create totally new tags or tokens.

There are other examples?

@UziTech
Copy link
Member

UziTech commented Oct 31, 2018

you will have to modify the lexer and parser if you want to create your own tokens.

Example from the docs

This is not something that is done easily. There have been times where a fix in marked has created a bug in someones custom parser.

@ghost
Copy link
Author

ghost commented Nov 1, 2018

Maintainability is not a problem if I understand how the extension system exactly works.

Should be good to have a basic example of all steps (renderer, parser, lexer, etc) to create new inline and block tokens in the documentation.

Currently, I'm analyzing the source code to understand it, because the documentation seems incomplete to me.

@UziTech
Copy link
Member

UziTech commented Nov 1, 2018

The documentation is incomplete, but we are always accepting pull requests 😁

@ghost
Copy link
Author

ghost commented Nov 1, 2018

You're right, but my knowledge is too low/insufficient for this right now 😅

@styfle styfle added the question label Nov 1, 2018
@solugebefola
Copy link

Follow up question here...I have seen examples of how to modify the inlineLexer, but how to modify the main lexer with custom rules? I don't see how to add custom tokens without completely rewriting theLexer.prototype.tokens function?

@UziTech
Copy link
Member

UziTech commented Mar 11, 2019

@solugebefola Right now to modify the lexer you will need to rewrite Lexer.prototype.tokens. A PR would be nice to be able to modify the Lexer easier.

@solugebefola
Copy link

Was there a PR to add this feature? Or just closing b/c no activity?

@UziTech UziTech reopened this Dec 4, 2019
@UziTech
Copy link
Member

UziTech commented Dec 4, 2019

Sorry I was closing all of the NFE issues since they weren't going to result in a change in this repo. This issue should be listed as docs changes.

There have not been any PRs to address this.

@horacioh
Copy link

can the parser and lexer implement a similar api as the renderer to make them more extensable?

@UziTech
Copy link
Member

UziTech commented Feb 26, 2020

@horacioh that would be great if they did. PRs are always welcome. 😁

@calculuschild
Copy link
Contributor

calculuschild commented Mar 27, 2020

I might work on a PR for this. There are a couple of lexer elements I want to customize how tokens are generated (tables) but I can't without rewriting the whole function.

Sounds like it would be in line with the Marked architecture if I separate each lexer token into its own named item like it is in the renderer?

@UziTech
Copy link
Member

UziTech commented Mar 27, 2020

@calculuschild That would be great! Just make sure that creating separate functions doesn't slow it down too much. You can run npm run bench to run benchmark tests against marked and other markdown libraries.

I am also working on creating inline tokens before sending them to the parser in PR #1627

@calculuschild
Copy link
Contributor

@UziTech Alright, got an initial attempt at extending the Lexer.

@calculuschild
Copy link
Contributor

@UziTech does #2043 solve this?

@UziTech
Copy link
Member

UziTech commented Oct 4, 2021

Ya I think it does.

@UziTech UziTech closed this as completed Oct 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category: docs Documentation changes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants