gettalong / kramdown

kramdown is a fast, pure Ruby Markdown superset converter, using a strict syntax definition and supporting several common extensions.
http://kramdown.gettalong.org
Other
1.72k stars 271 forks source link

Add new option, `footnote_link_text` #774

Open BryceStevenWilley opened 1 year ago

BryceStevenWilley commented 1 year ago

footnote_link_text is a string that is directly inserted in front of the footnote number. It can also be a formatted string that the number is formatted into.

For example, if the string is "[footnote %s]", the footnote link will be "[footnote 1]".

It will determine it the option is a forat string by running it through sprintf; if the output is the same, then it's not a format string.

Also adds tests to make sure of the new output.

Fixes #692, and is a different attempt at #693.

gettalong commented 1 year ago

Thanks @BryceStevenWilley for the pull request!

What is the benefit of keeping the special case formatted_link_text == link_text? Wouldn't it be easier to omit that special case and make the default value '%s'.

BryceStevenWilley commented 1 year ago

What is the benefit of keeping the special case formatted_link_text == link_text?

It lets folks use footnote_link_text without using the printf formatting. If they don't use the formatting (when formatted link is the same as the link text), we'll add the number at the end, so the links will still read as distinct.

Making the default case %s is a good idea though! Makes the default behavior much clearer, and introduces people to the formatting feature. I can make that change soon, unless you want to make it yourself.

gettalong commented 1 year ago

Thanks for the feedback! So I would go with the solution of %s being the default value. This also means the option description needs to be updated and there should be a validation block making sure that %s appears in the option value.

BryceStevenWilley commented 1 year ago

So I would go with the solution of %s being the default value. This also means the option description needs to be updated and there should be a validation block making sure that %s appears in the option value.

This is in now! Let me know if you want it changed at all, I tried to match the surrounding validation blocks, but wasn't certain how well I did.