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

Access to the render function from a custom highlight function #456

Closed
simondean opened this issue May 4, 2018 · 2 comments
Closed

Access to the render function from a custom highlight function #456

simondean opened this issue May 4, 2018 · 2 comments

Comments

@simondean
Copy link

Hi. I've trying to use markdown-it together with the https://www.npmjs.com/package/markdown-it-attrs extension.

I'm passing a custom highlight function to markdown-it to generate custom code block HTML

var md = markdownIt({
        linkify: true, html: true,
        highlight: function (str, lang) {
            if (highlightJs.getLanguage(lang)) {
                try {
                    return '<pre class="highlight lang-' + lang + '"><code>' +
                        highlightJs.highlight(lang, str, true).value +
                        '</code></pre>';
                } catch (__) { }
            }

            return '<pre class="highlight"><code>' + md.utils.escapeHtml(str) + '</code></pre>';
        }
    })
    .use(markdownItAttrs);

The problem I'm facing is that there's no way to access markdown-it's slf.renderAttrs(token) from within a custom highlight function. Because I can't access slf.renderAttrs(token), there's no way for to take advantage of the rendering that the https://www.npmjs.com/package/markdown-it-attrs extension provides.

I can think of a couple of ways of solving this:

  • markdown-it passes the slf object as a new third argument when it calls a custom highlight function.
  • markdown-it makes either slf or slf.renderAttrs(token) available on this when it calls a custom highlight function.

I've created some custom code for this issue here:

@puzrin
Copy link
Member

puzrin commented May 4, 2018

IMHO this request is too specific. You can override fenced renderer as you wish if default features are not enougth.

@puzrin puzrin closed this as completed May 4, 2018
@simondean
Copy link
Author

Thanks for the feedback @puzrin. I'll raise an issue on issue tracker for the extension https://github.com/arve0/markdown-it-attrs

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

2 participants