redimp / otterwiki

A minimalistic wiki powered by python, markdown and git.
https://otterwiki.com
MIT License
652 stars 29 forks source link

Conversion of wikilink format to markdown link format is too eager #144

Closed astroowen closed 1 month ago

astroowen commented 1 month ago

I'm running 2.6.1. Wikilinks are handled by the parser by converting them to the equivalent markdown link. But the parser is too eager and also performs this conversion inside code blocks (between backticks).

For example, in the markdown source I write

`[[Page]]` becomes [[Page]], `[[Page/Sub page]]` becomes [[Page/Sub page]]

But on the page I see

[Page](/Page) becomes Page, [Page/Sub page](/Page/Sub%20page) becomes Page/Sub page

Which is not what I wrote: the [[]] syntax becomes []() syntax. Then it's impossible to demonstrate the wikilink syntax. I expect the parsed markdown output to reflect verbatim what I put in code blocks.

Fortunately it looks (to me) like this parsing is not done by the mistune package but by these regexes in this plugin:

https://github.com/redimp/otterwiki/blob/67264121ab51b83b7e4164b49ba89cd380eae4c6/otterwiki/plugins.py#L46-L51

A naïve but fast way to fix this is just to modify the regexes to exclude strings starting with backticks. I'm not sure if there is some place in the rendering where code blocks are handled which could be modified to just not activate the plugin for that text - that would be a clearer solution, I think.

redimp commented 1 month ago

Hey @astroowen, thank you for reporting this issue.

Implementing this as a plugin (example) was not the best idea.

This should be dealt with in mistune as plugin in the renderer, where the order and hierachy of the parsed elements matters. I will take care of it this week.

redimp commented 1 month ago

After implementing the wikilink as mistune plugin and running the tests I was reminded why I chose this workaround .. Wikilinks inside of a table didn't work, e.g.

| name     | date       | link                 |
| -------- | ---------- | -------------------- |
| John     | 01/31/1996 | [[people/John]]      |
| Mary     | 10/08/2001 | [[Mary|people/Mary]] |

The [[Mary|people/Mary]] wikilink breaks the "Mary" row.

I even wrote a test for that ... 😅

https://github.com/redimp/otterwiki/blob/67264121ab51b83b7e4164b49ba89cd380eae4c6/tests/test_renderer.py#L116-L127

Will dig futher into this.

redimp commented 1 month ago

Fixed in v2.6.2.