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

How does one extend built-in parsers/tokenizers? #410

Open
ghost opened this issue Jul 22, 2021 · 0 comments
Open

How does one extend built-in parsers/tokenizers? #410

ghost opened this issue Jul 22, 2021 · 0 comments

Comments

@ghost
Copy link

ghost commented Jul 22, 2021

For example:

const linksidx = md.inline.ruler.__find__('links')
const oldlinks = md.inline.ruler.__rules__[linksidx].fn
const links = function (state, startLine, endLine, silent) {
    console.log(state)
    const ret = oldlinks(state, silent)
    if (!ret) return false

    console.log(state) /* This just returns the cumulative
        state object, without the ability to modify the
        particular link instance that was just captured. */
    return true
}
md.inline.ruler.at("links", links)

But to add custom attributes, one would need to import all the dependencies in lib/rules_inline/links.js and basically copy/paste the function, but the lib dir does not come with the node package. Also, this API seems to be a roundabout way to override or extend parser rules. Is there a better way?

Example case: add dimensions to images with a custom extension:

[alt text](https://example.com/image.jpg)[500x300]

I guess I will have to add it to the ALT text like:

[@500x300,alt text here](https://example.com/image.jpg)

but this use case could apply to any custom token such as a heading, URL, even a table with attributes, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

0 participants