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 to change markdown parser #882

Closed
qazzyl opened this issue Jul 12, 2019 · 10 comments
Closed

How to change markdown parser #882

qazzyl opened this issue Jul 12, 2019 · 10 comments

Comments

@qazzyl
Copy link

qazzyl commented Jul 12, 2019

Feature request

Can I change parser from marked to markdown-it. I really need the footnote features.

@berot3
Copy link

berot3 commented Jul 26, 2019

@rcarmo
Copy link

rcarmo commented Aug 19, 2019

I’m interested in using Remarkable instead, so I’m chiming in here in case this becomes a build option.

@berot3
Copy link

berot3 commented Aug 21, 2019

I am with you, remarkable would be fine too!

@berot3
Copy link

berot3 commented Aug 29, 2019

Maybe there is already some kind of way? I need a clever guy to figure it out! :)

Because in this comment #144 (comment) @QingWei-Li states that...

markdown-it size is very big. I do not think it's a big problem. But you can custom markdown parser by markdown option https://docsify.js.org/#/markdown

I'm not sure what he means by "markdown-it size is very big"...

As it states on the markdown-docs:

window.$docsify = {
  markdown: function(marked, renderer) {
    // ...

    return marked
  }
}

so maybe we can say this instead?:

markdown: function(mardown-it, renderer) {
    // ...

    return markdown-it
  }

@varadpoddar
Copy link

It's doable using custom plugins.
For example :

\\ Script files added before calling window.$docsify.
\\ Markdown-it V10.0
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/10.0.0/markdown-it.min.js" integrity_no="sha256-YASERpEeN8gRNr/Fy4Km34WGFqIq1h6HkJMAQnVHlhk=" crossorigin="anonymous"></script>
\\ Markdown-It-Attrs for Markdown-it
<script src="https://wzrd.in/standalone/markdown-it-attrs@latest" charset="utf-8"></script>

Now within your window.$docsify you can create a custom plugin to do the markdown for you.

window.$docsify = {
            plugins:[
            function (hook,vm) {
                hook.beforeEach(function (html) {
                    var md = window.markdownit();

                    md.use(markdownItAttrs, {
                        // optional, these are default options
                        leftDelimiter: '{',
                        rightDelimiter: '}',
                        allowedAttributes: []  // empty array = all attributes are allowed
                    });
                    return md.render(html);
                });
            }
            ]
        };

This would let you render the doc using markdown-it & since there would be no other markdown left, the other renderer would leave it alone. However, there could be performance implications. (Redundency)

@auspham
Copy link

auspham commented Oct 19, 2019

@varadpoddar your solution doesn't render footnote, plus the todo check list seems to be broken, is there any thing i have to add on?

@varadpoddar
Copy link

varadpoddar commented Oct 19, 2019

@rockmanvnx6

The footnotes and task lists functionality is a part of markdown's extended syntax.

You should add these corresponding packages for markdown-it. (If you choose to use markdown-it).

PS : If you are a web developer, you should test these plugins out using browsify's CDN.

Example Code :

\\ Script files added before calling window.$docsify.

\\ Markdown-it V10.0
<script src="https://cdnjs.cloudflare.com/ajax/libs/markdown-it/10.0.0/markdown-it.min.js" integrity="sha256-YASERpEeN8gRNr/Fy4Km34WGFqIq1h6HkJMAQnVHlhk=" crossorigin="anonymous"></script>

\\ Markdown-It-Attrs for Markdown-it
<script src="https://wzrd.in/standalone/markdown-it-attrs@latest" charset="utf-8"></script>

\\ Markdown-It-Footnote for Markdown-it
<script src="https://wzrd.in/standalone/markdown-it-footnote@latest" charset="utf-8"></script>

\\ Markdown-It-Task-List for Markdown-it
<script src="https://wzrd.in/standalone/markdown-it-task-list@latest" charset="utf-8"></script>

\\ Docsify

<script>
        window.$docsify = {
            plugins:[
            function (hook,vm) {
                hook.beforeEach(function (html) {
                    var md = window.markdownit();

                    md.use(markdownItAttrs, {
                        // optional, these are default options
                        leftDelimiter: '{',
                        rightDelimiter: '}',
                        allowedAttributes: []  // empty array = all attributes are allowed
                    }).use(markdownitFootnote).use(markdownItTaskList);
                    return md.render(html);
                });
            }
            ]
        };
</script>

@auspham
Copy link

auspham commented Oct 20, 2019

@varadpoddar thank you, for the script to work, I've to modify a bit:

        function (hook,vm) {
                hook.beforeEach(function (html) {
                    var md = window.markdownit();

                    md.use(window.markdownItAttrs, {
                        // optional, these are default options
                        leftDelimiter: '{',
                        rightDelimiter: '}',
                        allowedAttributes: []  // empty array = all attributes are allowed
                    }).use(window.markdownItFootnote)
                    .use(markdownItTaskList.default);
                    return md.render(html);
                });
        },

@varadpoddar
Copy link

@QingWei-Li Can I add the above workaround in the current docs in the form of a PR?
I believe this can also help close the issue.

@anikethsaha
Copy link
Member

You cant change the parser

It is in our roadmap for using a new pluggable parser for v5.
#823 (comment)

Closing this as it will be considered if required.
Please comment below if you want to add any more

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

6 participants