Skip to content

Make the markdown parser able to generate anchors for headings #1032

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

Merged
merged 1 commit into from
Aug 4, 2015

Conversation

bobylito
Copy link

This pull request gives the user a configuration so that he can choose to let the markdown parser add an anchor in the headings. This feature is very useful if you want to point directly to specific parts of a tutorial generated with markdown (that's my current use case).

To use the feature : set the attribute anchorInHeadings in the markdown part of the configuration file. The default is set to false.

{
  "markdown" : {
    "idInHeadings" : true
  }
}

I would have added some tests, but there seems to be none existing so far for the markdown. If it is necessary, could you give a hand in making them?

Cheers.

@@ -105,6 +105,10 @@ function getParseFunction(parserName, conf) {
markedRenderer = new marked.Renderer();

markedRenderer.heading = function(text, level) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default, marked's heading renderer adds an id attribute to headings, so you could simplify things by doing this instead (note that I've changed the option's name as well):

if (!conf.idInHeadings) {
    markedRenderer.heading = function(text, level) {
        // code
    };
}

@hegemonic
Copy link
Contributor

See my comment above.

The plugin has tests here, but right now it's not possible to change the plugin's default settings in the test. That means you're off the hook for tests.

@bobylito
Copy link
Author

bobylito commented Jul 6, 2015

Thanks @hegemonic for having a look at this PR. Will make the changes ASAP!

@hegemonic
Copy link
Contributor

@bobylito Still working on this?

@bobylito
Copy link
Author

Thanks for the reminder, will make the changes right away :)

On Thu, Jul 30, 2015 at 12:36 AM Jeff Williams [email protected]
wrote:

@bobylito https://github.com/bobylito Still working on this?


Reply to this email directly or view it on GitHub
#1032 (comment).

@bobylito
Copy link
Author

Updated! :)

@hegemonic
Copy link
Contributor

@bobylito Sorry, but I'm not seeing the changes I requested.

It uses the following configuration key in the markdown
section : idInHeadings.
If set to true it will make the headings generated in the markdown have
id's like on github.
@bobylito
Copy link
Author

bobylito commented Aug 1, 2015

@hegemonic Sorry, wrong manipulations while amending my commit :/

hegemonic added a commit that referenced this pull request Aug 4, 2015
Make the markdown parser able to generate anchors for headings
@hegemonic hegemonic merged commit ff37609 into jsdoc:master Aug 4, 2015
@hegemonic
Copy link
Contributor

Merged to master. Thanks for making the changes!

@bobylito
Copy link
Author

bobylito commented Aug 5, 2015

Thanks for accepting this modification. Hope I can contribute more :)

On Wed, Aug 5, 2015 at 1:25 AM Jeff Williams [email protected]
wrote:

Merged to master. Thanks for making the changes!


Reply to this email directly or view it on GitHub
#1032 (comment).

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

Successfully merging this pull request may close these issues.

2 participants