git.iko.soy/typeable/pandoc
on master help sign in
Vimwiki reader: improve handling of internal links.
4f572ddJohn MacFarlane
src/Text/Pandoc/Readers/Vimwiki.hs+12−5
@@ -74,7 +74,8 @@ import Text.Pandoc.Parsing (ParserState, ParserT, blanklines, emailAddress,
74 many1Till, orderedListMarker, readWithM,
74 many1Till, orderedListMarker, readWithM,
75 registerHeader, spaceChar, stateMeta,
75 registerHeader, spaceChar, stateMeta,
76 stateOptions, uri)
76 stateOptions, uri)
77−import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast)
77+import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast,
78+ isURI)
78import Text.Parsec.Char (alphaNum, anyChar, char, newline, noneOf, oneOf, space,
79import Text.Parsec.Char (alphaNum, anyChar, char, newline, noneOf, oneOf, space,
79 spaces, string)
80 spaces, string)
80import Text.Parsec.Combinator (between, choice, count, eof, lookAhead, many1,
81import Text.Parsec.Combinator (between, choice, count, eof, lookAhead, many1,
@@ -544,11 +545,17 @@ link = try $ do
544 False -> do
545 False -> do
545 manyTill anyChar (string "]]")
546 manyTill anyChar (string "]]")
546-- not using try here because [[hell]o]] is not rendered as a link in vimwiki
547-- not using try here because [[hell]o]] is not rendered as a link in vimwiki
548+ let tit = if isURI contents
549+ then ""
550+ else "wikilink"
547− return $ B.link (procLink contents) "" (B.str contents)
551+ return $ B.link (procLink contents) tit (B.str contents)
548 True -> do
552 True -> do
549 url <- manyTill anyChar $ char '|'
553 url <- manyTill anyChar $ char '|'
550 lab <- mconcat <$> manyTill inline (string "]]")
554 lab <- mconcat <$> manyTill inline (string "]]")
555+ let tit = if isURI url
556+ then ""
557+ else "wikilink"
551− return $ B.link (procLink url) "" lab
558+ return $ B.link (procLink url) tit lab
552
559
553image :: PandocMonad m => VwParser m Inlines
560image :: PandocMonad m => VwParser m Inlines
554image = try $ do
561image = try $ do
@@ -580,13 +587,13 @@ images k
580procLink' :: String -> String
587procLink' :: String -> String
581procLink' s
588procLink' s
582 | take 6 s == "local:" = "file" ++ drop 5 s
589 | take 6 s == "local:" = "file" ++ drop 5 s
583− | take 6 s == "diary:" = "diary/" ++ drop 6 s ++ ".html"
590+ | take 6 s == "diary:" = "diary/" ++ drop 6 s
584 | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
591 | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
585 "news:", "telnet:" ])
592 "news:", "telnet:" ])
586 = s
593 = s
587 | s == "" = ""
594 | s == "" = ""
588 | last s == '/' = s
595 | last s == '/' = s
589− | otherwise = s ++ ".html"
596+ | otherwise = s
590
597
591procLink :: String -> String
598procLink :: String -> String
592procLink s = procLink' x ++ y
599procLink s = procLink' x ++ y
test/vimwiki-reader.native+8−8
@@ -62,14 +62,14 @@ Pandoc (Meta {unMeta = fromList [("date",MetaInlines [Str "2017-05-01"]),("title
62,Para [Link ("",[],[]) [Str "email",Space,Str "me"] ("mailto:info@example.org","")]
62,Para [Link ("",[],[]) [Str "email",Space,Str "me"] ("mailto:info@example.org","")]
63,Para [Link ("",[],[]) [Str "mailto:hello@bye.com"] ("mailto:hello@bye.com","")]
63,Para [Link ("",[],[]) [Str "mailto:hello@bye.com"] ("mailto:hello@bye.com","")]
64,Header 2 ("internal links",[],[]) [Str "internal",Space,Str "links"]
64,Header 2 ("internal links",[],[]) [Str "internal",Space,Str "links"]
65−,Para [Link ("",[],[]) [Str "This is a link"] ("This is a link.html","")]
65+,Para [Link ("",[],[]) [Str "This is a link"] ("This is a link","wikilink")]
66−,Para [Link ("",[],[]) [Str "Description",Space,Str "of",Space,Str "the",Space,Str "link"] ("This is a link source.html","")]
66+,Para [Link ("",[],[]) [Str "Description",Space,Str "of",Space,Str "the",Space,Str "link"] ("This is a link source","wikilink")]
67−,Para [Link ("",[],[]) [Str "projects/Important Project 1"] ("projects/Important Project 1.html",""),SoftBreak,Link ("",[],[]) [Str "../index"] ("../index.html",""),SoftBreak,Link ("",[],[]) [Str "Other",Space,Str "files"] ("a subdirectory/","")]
67+,Para [Link ("",[],[]) [Str "projects/Important Project 1"] ("projects/Important Project 1","wikilink"),SoftBreak,Link ("",[],[]) [Str "../index"] ("../index","wikilink"),SoftBreak,Link ("",[],[]) [Str "Other",Space,Str "files"] ("a subdirectory/","wikilink")]
68−,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "tag",Space,Str "anchors"] ("#tag-one","")]
68+,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "tag",Space,Str "anchors"] ("#tag-one","wikilink")]
69−,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "header",Space,Str "anchors"] ("#block quotes","")]
69+,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "header",Space,Str "anchors"] ("#block quotes","wikilink")]
70−,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "strong",Space,Str "anchors"] ("#strong","")]
70+,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "strong",Space,Str "anchors"] ("#strong","wikilink")]
71−,Para [Link ("",[],[]) [Str "Tasks",Space,Str "for",Space,Str "tomorrow"] ("Todo List.html#Tomorrow","")]
71+,Para [Link ("",[],[]) [Str "Tasks",Space,Str "for",Space,Str "tomorrow"] ("Todo List#Tomorrow","wikilink")]
72−,Para [Link ("",[],[]) [Str "diary:2017-05-01"] ("diary/2017-05-01.html","")]
72+,Para [Link ("",[],[]) [Str "diary:2017-05-01"] ("diary/2017-05-01","wikilink")]
73,Para [Link ("",[],[]) [Str "Important",Space,Str "Data"] ("file:../assets/data.csv","")]
73,Para [Link ("",[],[]) [Str "Important",Space,Str "Data"] ("file:../assets/data.csv","")]
74,Header 3 ("links with thumbnails",[],[]) [Str "links",Space,Str "with",Space,Str "thumbnails"]
74,Header 3 ("links with thumbnails",[],[]) [Str "links",Space,Str "with",Space,Str "thumbnails"]
75,Para [Link ("",[],[]) [Image ("",[],[]) [Str ""] ("./movie.jpg","")] ("http://www.google.com","")]
75,Para [Link ("",[],[]) [Image ("",[],[]) [Str ""] ("./movie.jpg","")] ("http://www.google.com","")]