git.iko.soy/typeable/pandoc
on master help sign in
Org reader: preserve targets of spurious links
acf9328Albert Krewinkel
src/Text/Pandoc/Readers/Org/Inlines.hs+4−5
@@ -477,17 +477,17 @@ linkToInlinesF linkStr =
477
477
478internalLink :: Text -> Inlines -> F Inlines
478internalLink :: Text -> Inlines -> F Inlines
479internalLink link title = do
479internalLink link title = do
480− anchorB <- (link `elem`) <$> asksF orgStateAnchorIds
480+ ids <- asksF orgStateAnchorIds
481− if anchorB
481+ if link `elem` ids
482 then return $ B.link ("#" <> link) "" title
482 then return $ B.link ("#" <> link) "" title
483+ else let attr' = ("", ["spurious-link"] , [("target", link)])
483− else return $ B.emph title
484+ in return $ B.spanWith attr' (B.emph title)
484
485
485-- | Parse an anchor like @<<anchor-id>>@ and return an empty span with
486-- | Parse an anchor like @<<anchor-id>>@ and return an empty span with
486-- @anchor-id@ set as id. Legal anchors in org-mode are defined through
487-- @anchor-id@ set as id. Legal anchors in org-mode are defined through
487-- @org-target-regexp@, which is fairly liberal. Since no link is created if
488-- @org-target-regexp@, which is fairly liberal. Since no link is created if
488-- @anchor-id@ contains spaces, we are more restrictive in what is accepted as
489-- @anchor-id@ contains spaces, we are more restrictive in what is accepted as
489-- an anchor.
490-- an anchor.
490−
491anchor :: PandocMonad m => OrgParser m (F Inlines)
491anchor :: PandocMonad m => OrgParser m (F Inlines)
492anchor = try $ do
492anchor = try $ do
493 anchorId <- parseAnchor
493 anchorId <- parseAnchor
@@ -501,7 +501,6 @@ anchor = try $ do
501
501
502-- | Replace every char but [a-zA-Z0-9_.-:] with a hyphen '-'. This mirrors
502-- | Replace every char but [a-zA-Z0-9_.-:] with a hyphen '-'. This mirrors
503-- the org function @org-export-solidify-link-text@.
503-- the org function @org-export-solidify-link-text@.
504−
505solidify :: Text -> Text
504solidify :: Text -> Text
506solidify = T.map replaceSpecialChar
505solidify = T.map replaceSpecialChar
507 where replaceSpecialChar c
506 where replaceSpecialChar c
test/Tests/Readers/Org/Meta.hs+4−2
@@ -270,7 +270,8 @@ tests =
270
270
271 , "Search links are read as emph" =:
271 , "Search links are read as emph" =:
272 "[[Wally][Where's Wally?]]" =?>
272 "[[Wally][Where's Wally?]]" =?>
273+ para (spanWith ("", ["spurious-link"], [("target", "Wally")])
273− para (emph $ "Where's" <> space <> "Wally?")
274+ (emph $ "Where's" <> space <> "Wally?"))
274
275
275 , "Link to nonexistent anchor" =:
276 , "Link to nonexistent anchor" =:
276 T.unlines [ "<<link-here>> Target."
277 T.unlines [ "<<link-here>> Target."
@@ -278,5 +279,6 @@ tests =
278 , "[[link$here][See here!]]"
279 , "[[link$here][See here!]]"
279 ] =?>
280 ] =?>
280 (para (spanWith ("link-here", [], []) mempty <> "Target.") <>
281 (para (spanWith ("link-here", [], []) mempty <> "Target.") <>
282+ para (spanWith ("", ["spurious-link"], [("target", "link$here")])
281− para (emph ("See" <> space <> "here!")))
283+ (emph ("See" <> space <> "here!"))))
282 ]
284 ]