git.iko.soy/typeable/pandoc
on master help sign in
ConTeXt writer: use span identifiers as reference anchors.

Closes: #7246

commit4417dacc440e269c5a4db1d67b52da9e0fe05561 authorAlbert Krewinkel <albert@zeitkraut.de> dateMon 17 May 2021, 13:00 (5 years ago) parentd3ca486
2 files changed+9−2
src/Text/Pandoc/Writers/ConTeXt.hs+6−2 test/Tests/Writers/ConTeXt.hs+3
src/Text/Pandoc/Writers/ConTeXt.hs+6−2
@@ -487,7 +487,7 @@ inlineToConTeXt (Note contents) = do
487487 then literal "\\footnote{" <> nest 2 (chomp contents') <> char '}'
488488 else literal "\\startbuffer " <> nest 2 (chomp contents') <>
489489 literal "\\stopbuffer\\footnote{\\getbuffer}"
490−inlineToConTeXt (Span (_,_,kvs) ils) = do
490+inlineToConTeXt (Span (ident,_,kvs) ils) = do
491491 mblang <- fromBCP47 (lookup "lang" kvs)
492492 let wrapDir txt = case lookup "dir" kvs of
493493 Just "rtl" -> braces $ "\\righttoleft " <> txt
@@ -497,7 +497,11 @@ inlineToConTeXt (Span (_,_,kvs) ils) = do
497497 Just lng -> braces ("\\language" <>
498498 brackets (literal lng) <> txt)
499499 Nothing -> txt
500− wrapLang . wrapDir <$> inlineListToConTeXt ils
500+ addReference =
501+ if T.null ident
502+ then id
503+ else (("\\reference" <> brackets (literal ident) <> "{}") <>)
504+ addReference . wrapLang . wrapDir <$> inlineListToConTeXt ils
501505
502506-- | Craft the section header, inserting the section reference, if supplied.
503507sectionHeader :: PandocMonad m
test/Tests/Writers/ConTeXt.hs+3
@@ -43,6 +43,9 @@ tests =
4343 [ testGroup "inline code"
4444 [ "with '}'" =: code "}" =?> "\\mono{\\}}"
4545 , "without '}'" =: code "]" =?> "\\type{]}"
46+ , "span with ID" =:
47+ spanWith ("city", [], []) "Berlin" =?>
48+ "\\reference[city]{}Berlin"
4649 , testProperty "code property" $ \s -> null s || '\n' `elem` s ||
4750 if '{' `elem` s || '}' `elem` s
4851 then context' (code $ pack s) == "\\mono{" ++