git.iko.soy/typeable/pandoc
on master help sign in
ConTeXt writer: use span identifiers as reference anchors.
4417dacAlbert Krewinkel
src/Text/Pandoc/Writers/ConTeXt.hs+6−2
@@ -487,7 +487,7 @@ inlineToConTeXt (Note contents) = do
487 then literal "\\footnote{" <> nest 2 (chomp contents') <> char '}'
487 then literal "\\footnote{" <> nest 2 (chomp contents') <> char '}'
488 else literal "\\startbuffer " <> nest 2 (chomp contents') <>
488 else literal "\\startbuffer " <> nest 2 (chomp contents') <>
489 literal "\\stopbuffer\\footnote{\\getbuffer}"
489 literal "\\stopbuffer\\footnote{\\getbuffer}"
490−inlineToConTeXt (Span (_,_,kvs) ils) = do
490+inlineToConTeXt (Span (ident,_,kvs) ils) = do
491 mblang <- fromBCP47 (lookup "lang" kvs)
491 mblang <- fromBCP47 (lookup "lang" kvs)
492 let wrapDir txt = case lookup "dir" kvs of
492 let wrapDir txt = case lookup "dir" kvs of
493 Just "rtl" -> braces $ "\\righttoleft " <> txt
493 Just "rtl" -> braces $ "\\righttoleft " <> txt
@@ -497,7 +497,11 @@ inlineToConTeXt (Span (_,_,kvs) ils) = do
497 Just lng -> braces ("\\language" <>
497 Just lng -> braces ("\\language" <>
498 brackets (literal lng) <> txt)
498 brackets (literal lng) <> txt)
499 Nothing -> txt
499 Nothing -> txt
500+ addReference =
501+ if T.null ident
502+ then id
503+ else (("\\reference" <> brackets (literal ident) <> "{}") <>)
500− wrapLang . wrapDir <$> inlineListToConTeXt ils
504+ addReference . wrapLang . wrapDir <$> inlineListToConTeXt ils
501
505
502-- | Craft the section header, inserting the section reference, if supplied.
506-- | Craft the section header, inserting the section reference, if supplied.
503sectionHeader :: PandocMonad m
507sectionHeader :: PandocMonad m
test/Tests/Writers/ConTeXt.hs+3
@@ -43,6 +43,9 @@ tests =
43 [ testGroup "inline code"
43 [ testGroup "inline code"
44 [ "with '}'" =: code "}" =?> "\\mono{\\}}"
44 [ "with '}'" =: code "}" =?> "\\mono{\\}}"
45 , "without '}'" =: code "]" =?> "\\type{]}"
45 , "without '}'" =: code "]" =?> "\\type{]}"
46+ , "span with ID" =:
47+ spanWith ("city", [], []) "Berlin" =?>
48+ "\\reference[city]{}Berlin"
46 , testProperty "code property" $ \s -> null s || '\n' `elem` s ||
49 , testProperty "code property" $ \s -> null s || '\n' `elem` s ||
47 if '{' `elem` s || '}' `elem` s
50 if '{' `elem` s || '}' `elem` s
48 then context' (code $ pack s) == "\\mono{" ++
51 then context' (code $ pack s) == "\\mono{" ++