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

Typographic elements in heading are excluded from the automatically generated heading IDs #46

Closed
sungchang-ha opened this issue Nov 30, 2019 · 9 comments
Labels

Comments

@sungchang-ha
Copy link

@sungchang-ha sungchang-ha commented Nov 30, 2019

Hello,

For background and related discussion, please see the following post in Hugo forum.

https://discourse.gohugo.io/t/difference-in-auto-generated-heading-anchor-names-between-previous-versions-and-v0-60-x/22076

Please answer the following before submitting your issue:

  1. What version of goldmark are you using? : 1.1.8 (included in Hugo 0.60.1)
  2. What version of Go are you using? : 1.11.2 (but shouldn't matter as the test is done with pre-built Hugo)
  3. What operating system and processor architecture are you using? : macOS 10.13.6, Intel Core i5
  4. What did you do? : Upgrade Hugo from 0.54.0 to 0.60.1 to check the basic functionality
  5. What did you expect to see? : Non-alphanumeric typhographic elements (hyphen, period, underscore, etc.) in heading are transformed into hyphen in the auto heading IDs (e.g. for heading "Command-Gen-Instance" and "v1.0.0 (Apr 21, 2019)", the results are command-gen-instance and v1-0-0-apr-21-2019)
  6. What did you see instead? : Non-alphanumeric typhographic elements in heading are excluded from the auto heading IDs (e.g. for the example above, the results are commandgeninstance and v100-april-21-2019)

Many thanks for your work with Goldmark.

@sungchang-ha sungchang-ha changed the title Hyphens in heading are excluded from the automatically generated heading IDs Typographic elements in heading are excluded from the automatically generated heading IDs Dec 1, 2019
@kaushalmodi

This comment has been minimized.

Copy link

@kaushalmodi kaushalmodi commented Dec 1, 2019

I have this in my ox-hugo project that exports Org mode files to Hugo (Blackfriday/Goldmark) compatible Markdown files.. this function auto generates slugs or anchors for headings in a post: https://github.com/kaushalmodi/ox-hugo/blob/4c0ae850518c45e010a3d7253e78087c098b2fca/ox-hugo.el#L1816

You don't need to know lisp to read that code. But if you read the doc string of that function, can Goldmark adapt something like that?

@yuin

This comment has been minimized.

Copy link
Owner

@yuin yuin commented Dec 1, 2019

@sungchang-ha @kaushalmodi
This is not a bug, just that's it. There are no standards about the auto header id generation(or the slug generation).

If I follow ox-hugo spec, others may say "goldmark generates header ids that does not suit my preference".

So it may be better that users can add your own auto generation logic by options.

@yuin yuin added the enhancement label Dec 1, 2019
@kaushalmodi

This comment has been minimized.

Copy link

@kaushalmodi kaushalmodi commented Dec 1, 2019

@yuin

If I follow ox-hugo spec, others may say "goldmark generates header ids that does not suit my preference".

The ox-hugo function was just for reference.

If you look at this discussion on Hugo Discourse:

For example, the ID for heading CLI_INIT v1.0.0 (Apr-21-2019) becomes cli-init-v1-0-0-apr-21-2019 by v0.59.1, whereas cliinit-v100-april212019 by 0.60.1.

may be there can be some agreement on which is more readable:

  • cli-init-v1-0-0-apr-21-2019
  • cliinit-v100-april212019

At the very least, can one or more consecutive spaces and other non alphanumeric chars be replaced with a single hyphen?

@yuin

This comment has been minimized.

Copy link
Owner

@yuin yuin commented Dec 1, 2019

@kaushalmodi
goldmark is a standalone markdown library, not dedicated for the Hugo. So I don’t give a special treatment for Hugo.

@kaushalmodi

This comment has been minimized.

Copy link

@kaushalmodi kaushalmodi commented Dec 1, 2019

@yuin Seems like my reply came across in a wrong way. My suggestion has nothing to do with Hugo. I am just suggesting to introduce more hyphens to separate the words in the anchors so that they are more readable.

But this is your pet project so I cannot push any further. I hope that you provide a hook or something so that Hugo can customize the anchor generation logic.

Thanks for working on this better Markdown parser and your replies in these issue threads.

@yuin

This comment has been minimized.

Copy link
Owner

@yuin yuin commented Dec 1, 2019

@kaushalmodi Thanks for your suggestion, I'll add an option that allow you to change the auto heading id generation logic. I'm not sure about readability of heading ids, I'm thinking about the proposal.

Anyway, I'm Japanese(using CJK characters), so auto generated heading ids are ususally just a meaningless strings :(
So I did not think about readability of the auto generated heading ids.

@yuin yuin closed this in 68dcec6 Dec 2, 2019
@yuin

This comment has been minimized.

Copy link
Owner

@yuin yuin commented Dec 2, 2019

@kaushalmodi @sungchang-ha I've tweaked logics and added an WithIDs option. See here for usage.

@sungchang-ha

This comment has been minimized.

Copy link
Author

@sungchang-ha sungchang-ha commented Dec 2, 2019

@kaushalmodi Thanks for the follow-up discussion on this.
@yuin Thank you for dealing with the issue. As you can imagine, the change of heading ID naming rule requires replacing all the pre-existing anchors to the new ones -- which could be dozens to several hundreds or more depending on the scale of a project -- as well as adapting to the new rule. We'll check the changed implementation.

@kaushalmodi

This comment has been minimized.

Copy link

@kaushalmodi kaushalmodi commented Dec 2, 2019

/cc @bep so that he can review the commit ( 68dcec6 ) fixing this issue; probably a custom WithIDs will need to be passed from Hugo side?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.