neurobin / mdx_wikilink_plus

A wikilink extension for Python Markdown
Other
16 stars 4 forks source link

Hyphens in the label are replaced with spaces #11

Closed nicbou closed 1 year ago

nicbou commented 1 year ago

This wikilink: Let's take the [[S-Bahn]]! is rendered as Let's take the <a href="/glossary/S-Bahn">S Bahn</a>. The hyphen is correctly preserved for the link, but replaced with a space in the label.

This is my config:

# config['wikilinks_base_url'] is "/glossary"
WikiLinkPlusExtension(dict(
    base_url=config.get('wikilinks_base_url', '') + '/',
    url_whitespace='%20',
    html_class=None,
    image_class=None,
))
nicbou commented 1 year ago

This line is the culprit: https://github.com/neurobin/mdx_wikilink_plus/blob/master/mdx_wikilink_plus/mdx_wikilink_plus.py#L148

However I dare not change it without understanding why it's there in the first place.

neurobin commented 1 year ago

that is the expected behavior. For example, [my-google-example] will become My Google Example. If you want to change it, then you will have to add another config parameter label_clean_re which defaults to r'[\s_-]+'

nicbou commented 1 year ago

Is this based on the behaviour of other Wikilink implementations? Otherwise it would make more sense to keep the labels as-is. This is the behaviour I see on Wikipedia, for example. The label should be transformed to a link, but not to a different label, right?

Feel free to close this as wontfix. Since my need is very simple ([[hello world]] > [hello world](/glossary/hello%20world)), I can also write my own implementation.

neurobin commented 1 year ago

[[hello world]] > [hello world](/glossary/hello%20world) this example will work as you expect it when you set the label_case config param to '';

nicbou commented 1 year ago

Unless there are hyphens in the label. I'm wondering if this behaviour is common to wikilink implementations or a mdx_wikilink_plus bug.

neurobin commented 1 year ago

that is the expected behavior. For example, [my-google-example] will become My Google Example. If you want to change it, then you will have to add another config parameter label_clean_re which defaults to r'[\s_-]+'

nicbou commented 1 year ago

Thanks for the clarification. In the end, the build_url parameter in the original wikilinks extension handled my use case pretty well.