From d4c8cc303713ee8f70b9ff9c7d5250debff3e8d9 Mon Sep 17 00:00:00 2001 From: Evan Silberman Date: Thu, 6 Feb 2025 15:42:08 -0800 Subject: [PATCH] Track wikilinks with a class instead of the title The use of title="wikilink" in HTML output likely traces back to Pandoc's hijacking of the title attribute for this purpose back when Pandoc links didn't have Attrs. A coordinated change in Pandoc moves this more appropriately into a class. --- .../src/Commonmark/Extensions/Wikilinks.hs | 2 +- .../test/wikilinks_title_after_pipe.md | 10 +++++----- .../test/wikilinks_title_before_pipe.md | 10 +++++----- commonmark-pandoc/src/Commonmark/Pandoc.hs | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/commonmark-extensions/src/Commonmark/Extensions/Wikilinks.hs b/commonmark-extensions/src/Commonmark/Extensions/Wikilinks.hs index a17b711..01f64aa 100644 --- a/commonmark-extensions/src/Commonmark/Extensions/Wikilinks.hs +++ b/commonmark-extensions/src/Commonmark/Extensions/Wikilinks.hs @@ -23,7 +23,7 @@ class HasWikilinks il where wikilink :: Text -> il -> il instance Rangeable (Html a) => HasWikilinks (Html a) where - wikilink url il = link url "wikilink" il + wikilink url il = addAttribute ("class", "wikilink") $ link url "" il instance (HasWikilinks il, Semigroup il, Monoid il) => HasWikilinks (WithSourceMap il) where diff --git a/commonmark-extensions/test/wikilinks_title_after_pipe.md b/commonmark-extensions/test/wikilinks_title_after_pipe.md index efa783c..bc4186b 100644 --- a/commonmark-extensions/test/wikilinks_title_after_pipe.md +++ b/commonmark-extensions/test/wikilinks_title_after_pipe.md @@ -10,25 +10,25 @@ With this version of wikilinks, the title comes after the pipe. ```````````````````````````````` example [[https://example.org]] . -

https://example.org

+

https://example.org

```````````````````````````````` ```````````````````````````````` example [[https://example.org|title]] . -

title

+

title

```````````````````````````````` ```````````````````````````````` example [[Name of page]] . -

Name of page

+

Name of page

```````````````````````````````` ```````````````````````````````` example [[Name of page|Title]] . -

Title

+

Title

```````````````````````````````` HTML entities are recognized both in the name of page and in the link title. @@ -36,5 +36,5 @@ HTML entities are recognized both in the name of page and in the link title. ```````````````````````````````` example [[Geschütztes Leerzeichen|Über  ]] . -

Über  

+

Über  

```````````````````````````````` diff --git a/commonmark-extensions/test/wikilinks_title_before_pipe.md b/commonmark-extensions/test/wikilinks_title_before_pipe.md index 40e036f..cba385c 100644 --- a/commonmark-extensions/test/wikilinks_title_before_pipe.md +++ b/commonmark-extensions/test/wikilinks_title_before_pipe.md @@ -10,25 +10,25 @@ With this version of wikilinks, the title comes before the pipe. ```````````````````````````````` example [[https://example.org]] . -

https://example.org

+

https://example.org

```````````````````````````````` ```````````````````````````````` example [[title|https://example.org]] . -

title

+

title

```````````````````````````````` ```````````````````````````````` example [[Name of page]] . -

Name of page

+

Name of page

```````````````````````````````` ```````````````````````````````` example [[Title|Name of page]] . -

Title

+

Title

```````````````````````````````` Regular links should still work! @@ -44,5 +44,5 @@ HTML entities are recognized both in the name of page and in the link title. ```````````````````````````````` example [[Über  |Geschütztes Leerzeichen]] . -

Über  

+

Über  

```````````````````````````````` diff --git a/commonmark-pandoc/src/Commonmark/Pandoc.hs b/commonmark-pandoc/src/Commonmark/Pandoc.hs index dddac2b..a3eb108 100644 --- a/commonmark-pandoc/src/Commonmark/Pandoc.hs +++ b/commonmark-pandoc/src/Commonmark/Pandoc.hs @@ -120,7 +120,7 @@ instance HasEmoji (Cm b B.Inlines) where $ B.text t instance HasWikilinks (Cm b B.Inlines) where - wikilink t il = Cm $ B.link t "wikilink" $ unCm il + wikilink t il = Cm $ B.linkWith (mempty, ["wikilink"], mempty) t "" $ unCm il instance HasPipeTable (Cm a B.Inlines) (Cm a B.Blocks) where pipeTable aligns headerCells rows =