comrak icon indicating copy to clipboard operation
comrak copied to clipboard

Add support for wikilinks format

Open digitalmoksha opened this issue 9 months ago • 1 comments

Add extensions to support both styles of wikilinks

  • [[display text|target page]] [GitHub style]
  • [[target page|display text]] [regular wiki link]

most likely with wikilinks_title_before_pipe and wikilinks_title_after_pipe extension names.

Inspired by commonmark-hs

digitalmoksha avatar May 09 '24 22:05 digitalmoksha

Command Mean [ms] Min [ms] Max [ms] Relative
./bench.sh ./comrak-036be5f 320.0 ± 3.0 314.4 326.9 2.87 ± 0.03
./bench.sh ./comrak-main 319.8 ± 5.9 317.5 347.5 2.87 ± 0.06
./bench.sh ./pulldown-cmark 111.4 ± 0.8 109.6 113.6 1.00
./bench.sh ./cmark-gfm 118.3 ± 1.4 117.1 124.1 1.06 ± 0.02
./bench.sh ./markdown-it 483.0 ± 3.8 479.2 492.4 4.34 ± 0.05

Run on Thu May 9 23:01:12 UTC 2024

github-actions[bot] avatar May 09 '24 23:05 github-actions[bot]

This works, but I hooked it before the normal bracket link processing cause it turned out to be much easier/cleaner, but I now realize it bypasses the normal inline processing of the link text. And I kinda think the link text should behave the same between the two. Which means emphasis, etc, would get properly handled in the link text, as it does for normal markdown links.

But maybe that's not expected in wikilinks. It doesn't work that way in commonmark-hs

cabal run exes -- -x wikilinks_title_before_pipe

[[_abc_|def]]

yields

<p><a href="def" title="wikilink">_abc_</a></p>

digitalmoksha avatar May 12 '24 16:05 digitalmoksha

Hmm, I need to spin up a wiki on GitHub and see what their behavior is.

~~EDIT: which would require me to upgrade :-(~~

digitalmoksha avatar May 12 '24 16:05 digitalmoksha

GH doesn't support markdown in the link text either. In fact GH doesn't recognize [[_abc_|def]] as a valid wikilink, which I think might be a bug.

So I would say the approach right now is good enough.

Still need to fix a failing spec.

digitalmoksha avatar May 12 '24 19:05 digitalmoksha

@kivikakk I think this is ready to go. Mind taking a look at it when you have some time?

digitalmoksha avatar May 12 '24 20:05 digitalmoksha

Will be running cargo +nightly fuzz run quadratic -j 6 all night

digitalmoksha avatar May 14 '24 01:05 digitalmoksha

==85446== libFuzzer: run interrupted; exiting
stat::number_of_executed_units: 64005
stat::average_exec_per_sec:     243
stat::new_units_added:          3258
stat::slowest_unit_time_sec:    0
stat::peak_rss_mb:              550
INFO: exiting: 18432 time: 135145s

digitalmoksha avatar May 15 '24 15:05 digitalmoksha

I think this is tightened up now. Even added a test to show how it works and doesn't work in pipe tables. Which is how it currently works in commonmark-hs, GitHub, and GitLab.

digitalmoksha avatar May 16 '24 01:05 digitalmoksha

This looks great. I've made a small adjustment in b769ee4 such that the Text node within the wikilink has the sourcepos of the component that produced the actual text (i.e. the label part if one exists, otherwise the URL). This all looks good to me — thank you! 🎉

kivikakk avatar May 16 '24 10:05 kivikakk

the Text node within the wikilink has the sourcepos of the component that produced the actual text

Good call, thanks!

digitalmoksha avatar May 16 '24 13:05 digitalmoksha