aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEvan Silberman <[email protected]>2025-02-06 14:39:17 -0800
committerJohn MacFarlane <[email protected]>2025-02-07 14:04:12 -0800
commit97b36ecb7703b434ed4325cc128402a9eb32418d (patch)
treefe83694506972b24015a79e226565c1edf62e653 /src
parentcb8f7645b5ca894e0a840953185b839302817fa6 (diff)
Track wikilinks with a class instead of a title
Once upon a time the only metadata element for links in Pandoc's AST was a title, and it was hijacked to track certain links as having originated in the wikilink syntax. Now we have Attrs and we can use a class to handle wikilinks instead. Requires coordinated changes to commonmark-hs.
Diffstat (limited to 'src')
-rw-r--r--src/Text/Pandoc/Readers/Markdown.hs3
-rw-r--r--src/Text/Pandoc/Readers/MediaWiki.hs2
-rw-r--r--src/Text/Pandoc/Readers/Vimwiki.hs23
-rw-r--r--src/Text/Pandoc/Writers/Markdown/Inline.hs2
4 files changed, 10 insertions, 20 deletions
diff --git a/src/Text/Pandoc/Readers/Markdown.hs b/src/Text/Pandoc/Readers/Markdown.hs
index 3d4c5da45..a0fd682df 100644
--- a/src/Text/Pandoc/Readers/Markdown.hs
+++ b/src/Text/Pandoc/Readers/Markdown.hs
@@ -1859,6 +1859,7 @@ wikilink :: PandocMonad m
=> (Attr -> Text -> Text -> Inlines -> Inlines)
-> MarkdownParser m (F Inlines)
wikilink constructor = do
+ let attr = (mempty, ["wikilink"], mempty)
titleAfter <-
(True <$ guardEnabled Ext_wikilinks_title_after_pipe) <|>
(False <$ guardEnabled Ext_wikilinks_title_before_pipe)
@@ -1871,7 +1872,7 @@ wikilink constructor = do
| titleAfter -> (T.drop 1 after, before)
| otherwise -> (before, T.drop 1 after)
guard $ T.all (`notElem` ['\n','\r','\f','\t']) url
- return . pure . constructor nullAttr url "wikilink" $
+ return . pure . constructor attr url "" $
B.text $ fromEntities title
link :: PandocMonad m => MarkdownParser m (F Inlines)
diff --git a/src/Text/Pandoc/Readers/MediaWiki.hs b/src/Text/Pandoc/Readers/MediaWiki.hs
index e7d6ea4cb..b7460b82e 100644
--- a/src/Text/Pandoc/Readers/MediaWiki.hs
+++ b/src/Text/Pandoc/Readers/MediaWiki.hs
@@ -667,7 +667,7 @@ internalLink = try $ do
sym "]]"
-- see #8525:
linktrail <- B.text <$> manyChar (satisfy (\c -> isLetter c && not (isCJK c)))
- let link = B.link (addUnderscores pagename) "wikilink" (label <> linktrail)
+ let link = B.linkWith (mempty, ["wikilink"], mempty) (addUnderscores pagename) (stringify label) (label <> linktrail)
if "Category:" `T.isPrefixOf` pagename
then do
updateState $ \st -> st{ mwCategoryLinks = link : mwCategoryLinks st }
diff --git a/src/Text/Pandoc/Readers/Vimwiki.hs b/src/Text/Pandoc/Readers/Vimwiki.hs
index e8be03c28..818f5b601 100644
--- a/src/Text/Pandoc/Readers/Vimwiki.hs
+++ b/src/Text/Pandoc/Readers/Vimwiki.hs
@@ -56,15 +56,7 @@ import Data.Text (Text)
import qualified Data.Text as T
import Safe (lastMay)
import Text.Pandoc.Builder (Blocks, Inlines, fromList, toList, trimInlines)
-import qualified Text.Pandoc.Builder as B (blockQuote, bulletList, code,
- codeBlockWith, definitionList,
- displayMath, divWith, emph,
- headerWith, horizontalRule, image,
- imageWith, link, math, orderedList,
- para, plain, setMeta, simpleTable,
- softbreak, space, spanWith, str,
- strikeout, strong, subscript,
- superscript)
+import qualified Text.Pandoc.Builder as B
import Text.Pandoc.Class.PandocMonad (PandocMonad (..))
import Text.Pandoc.Definition (Attr, Block (BulletList, OrderedList),
Inline (Space), ListNumberDelim (..),
@@ -555,17 +547,14 @@ link = try $ do
then do
url <- manyTillChar anyChar $ char '|'
lab <- mconcat <$> manyTill inline (string "]]")
- let tit = if isURI url
- then ""
- else "wikilink"
- return $ B.link (procLink url) tit lab
+ return $ B.linkWith (attr url) (procLink url) "" lab
else do
manyTill anyChar (string "]]")
-- not using try here because [[hell]o]] is not rendered as a link in vimwiki
- let tit = if isURI contents
- then ""
- else "wikilink"
- return $ B.link (procLink contents) tit (B.str contents)
+ return $ B.linkWith (attr contents) (procLink contents) "" (B.str contents)
+ where
+ attr t | isURI t = B.nullAttr
+ | otherwise = (mempty, ["wikilink"], mempty)
image :: PandocMonad m => VwParser m Inlines
image = try $ do
diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs
index 948932fc5..da04e4b5e 100644
--- a/src/Text/Pandoc/Writers/Markdown/Inline.hs
+++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs
@@ -649,7 +649,7 @@ inlineToMarkdown opts lnk@(Link attr@(ident,classes,kvs) txt (src, tit)) = do
case txt of
[Str s] | escapeURI s == srcSuffix -> True
_ -> False
- let useWikilink = tit == "wikilink" &&
+ let useWikilink = "wikilink" `elem` classes &&
(isEnabled Ext_wikilinks_title_after_pipe opts ||
isEnabled Ext_wikilinks_title_before_pipe opts)
let useRefLinks = writerReferenceLinks opts && not useAuto