yuin / goldmark

:trophy: A markdown parser written in Go. Easy to extend, standard(CommonMark) compliant, well structured.
MIT License
3.68k stars 255 forks source link

Use non-numeric footnote anchor in id and href #92

Closed tv42 closed 4 years ago

tv42 commented 4 years ago

Please answer the following before submitting your issue:

  1. What version of goldmark are you using? : v1.1.21
  2. What version of Go are you using? : go1.13.6
  3. What operating system and processor architecture are you using? : linux/amd64
  4. What did you do? : Use footnotes like blah[^name] ... [^name]: more
  5. What did you expect to see? : HTML with id and href mentioning name, retain backwards compatibility with existing website using blackfriday.
  6. What did you see instead? : fn:1
  7. Did you confirm your output is different from CommonMark online demo or other official renderer correspond with an extension?: Footnotes are an extension so CommonMark does not apply. The linked to php-markdown "spec" doesn't even allow named footnotes. blackfriday did exactly what I wanted.
  8. (Feature request only): Why you can not implement it as an extension?: I can, but it seems like I'd end up copy-pasting at least FootnoteHTMLRenderer, and the way it uses private methods and registration it doesn't seem like I could easily wrap & extend it.

It seems like this would be a simple enhancement to current footnote extension. If n.Ref is not numeric, use it instead of n.Index.

tv42 commented 4 years ago

In #93 I just escaped funky inputs like RenderAttributes would have, but blackfriday actually has a better policy that I just couldn't implement as easily: a slugify function that converts non-alphanumerics to dashes, while ensuring no leading/trailing dashes and only one dash in a row. If you like the PR, I should add that before this goes live...

yuin commented 4 years ago

I do not care about compatilibity with blackfriday. Non-standard behavior should not be included as a built-in feature in goldmark because it is hard to implement certain non-standard feature that satisfies all users.

So it is preferable for me that we modify goldmark as you easily implement this feature as an extension. You can make this kind of PR?

tv42 commented 4 years ago

Non-standard behavior should not be included

By that argument, rip out the current footnote extension, as footnotes are not in CommonMark.

I'll make my code an independent extension and stop using whatever current footnote functionality exists. At this time at least, I believe nothing else is needed from goldmark; I was merely trying to avoid reimplementing/copy-pasting the existing footnote code.

yuin commented 4 years ago

Footnotes in goldmark is based on MarkdownExtra as I wrote in README.

sjml commented 4 years ago

@yuin I totally understand not wanting to add the functionality to the core of Goldmark. Would you prefer to see this as a separate extension, then? Or a configuration flag on the existing extension?

(Since there seems to be momentum over on this side, I'll close my #90 PR.)

yuin commented 4 years ago

@sjml I prefer to see this as a separate extension. And as I wrote above it is preferable for me modifying goldmark as you can easily implement this feature as a separate extension(e.g.: add some hook function options to the built-in footnotes extension).

sjml commented 4 years ago

@yuin That makes sense. I'll see what I can whip up. Would you consider adding such a separate extension to this repository, or would it need to be its own thing entirely?

yuin commented 4 years ago

@sjml It should be maintained in a separated repository.

stale[bot] commented 4 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

theory commented 4 years ago

@tv42 or @sjml Did either of you create an extension for this? Might be useful to link it from here so people can find it when the find this issue. Thanks!

sjml commented 4 years ago

I didn't because the Hugo maintainers didn't seem interested in using third-party plugins, so that ended up being a dead-end unless I wanted to always be maintaining my own branch of Hugo. :( The code I submitted in PR #90 could easily be used to make a separate plugin, though.

theory commented 4 years ago

Thanks @sjml. It's too bad, because it means my footnotes are broken in list pages. I asked about it in this post (which is how I was led to this ticket).

sjml commented 4 years ago

Yeah, I tried to see if there was any interest in it in this post but got no traction. I ultimately ended up moving away from Hugo entirely so I could have a little more flexibility (which I'm willing to trade speed for at my scale). But at this point we're off-topic of this issue. :)

tv42 commented 4 years ago

@theory I kinda gave up on it for now, too. I'll probably make the extension if & when I migrate out of Hugo again.