git.iko.soy/typeable/pandoc
on master help sign in
Vimwiki reader: improve handling of internal links.

1) Don't append `.html` 2) Add `wikilink` title This mirrors behavior of other wiki readers. Generally the `.html` extension is not wanted. It may be important for output to HTML in certain circumstances, but it can always be added using a filter that matches on links with title `wikilink`. Note that if you have a workflow that uses pandoc to convert vimwiki to readable HTML pages, you may need to add such a filter to reproduce current behavior. Here is a filter that does the job: ```lua function Link(el) if el.title == 'wikilink' then el.target = el.target .. ".html" end return el end ``` Save this as `fixlinks.lua` and use with `--lua-filter fixlinks.lua`. Closes #5414.

commit4f572ddf6941b8fb0ad7a5835216c708998444f0 authorJohn MacFarlane <jgm@berkeley.edu> dateFri 5 Apr 2019, 10:04 (8 years ago) parentba7898b
2 files changed+20−13
src/Text/Pandoc/Readers/Vimwiki.hs+12−5 test/vimwiki-reader.native+8−8
src/Text/Pandoc/Readers/Vimwiki.hs+12−5
@@ -74,7 +74,8 @@ import Text.Pandoc.Parsing (ParserState, ParserT, blanklines, emailAddress,
7474 many1Till, orderedListMarker, readWithM,
7575 registerHeader, spaceChar, stateMeta,
7676 stateOptions, uri)
77−import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast)
77+import Text.Pandoc.Shared (crFilter, splitBy, stringify, stripFirstAndLast,
78+ isURI)
7879import Text.Parsec.Char (alphaNum, anyChar, char, newline, noneOf, oneOf, space,
7980 spaces, string)
8081import Text.Parsec.Combinator (between, choice, count, eof, lookAhead, many1,
@@ -544,11 +545,17 @@ link = try $ do
544545 False -> do
545546 manyTill anyChar (string "]]")
546547-- not using try here because [[hell]o]] is not rendered as a link in vimwiki
547− return $ B.link (procLink contents) "" (B.str contents)
548+ let tit = if isURI contents
549+ then ""
550+ else "wikilink"
551+ return $ B.link (procLink contents) tit (B.str contents)
548552 True -> do
549553 url <- manyTill anyChar $ char '|'
550554 lab <- mconcat <$> manyTill inline (string "]]")
551− return $ B.link (procLink url) "" lab
555+ let tit = if isURI url
556+ then ""
557+ else "wikilink"
558+ return $ B.link (procLink url) tit lab
552559
553560image :: PandocMonad m => VwParser m Inlines
554561image = try $ do
@@ -580,13 +587,13 @@ images k
580587procLink' :: String -> String
581588procLink' s
582589 | 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
584591 | or ((`isPrefixOf` s) <$> [ "http:", "https:", "ftp:", "file:", "mailto:",
585592 "news:", "telnet:" ])
586593 = s
587594 | s == "" = ""
588595 | last s == '/' = s
589− | otherwise = s ++ ".html"
596+ | otherwise = s
590597
591598procLink :: String -> String
592599procLink 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
6262,Para [Link ("",[],[]) [Str "email",Space,Str "me"] ("mailto:info@example.org","")]
6363,Para [Link ("",[],[]) [Str "mailto:hello@bye.com"] ("mailto:hello@bye.com","")]
6464,Header 2 ("internal links",[],[]) [Str "internal",Space,Str "links"]
65−,Para [Link ("",[],[]) [Str "This is a link"] ("This is a link.html","")]
66−,Para [Link ("",[],[]) [Str "Description",Space,Str "of",Space,Str "the",Space,Str "link"] ("This is a link source.html","")]
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/","")]
68−,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "tag",Space,Str "anchors"] ("#tag-one","")]
69−,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "header",Space,Str "anchors"] ("#block quotes","")]
70−,Para [Link ("",[],[]) [Str "try",Space,Str "me",Space,Str "to",Space,Str "test",Space,Str "strong",Space,Str "anchors"] ("#strong","")]
71−,Para [Link ("",[],[]) [Str "Tasks",Space,Str "for",Space,Str "tomorrow"] ("Todo List.html#Tomorrow","")]
72−,Para [Link ("",[],[]) [Str "diary:2017-05-01"] ("diary/2017-05-01.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","wikilink")]
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","wikilink")]
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","wikilink")]
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","wikilink")]
7373,Para [Link ("",[],[]) [Str "Important",Space,Str "Data"] ("file:../assets/data.csv","")]
7474,Header 3 ("links with thumbnails",[],[]) [Str "links",Space,Str "with",Space,Str "thumbnails"]
7575,Para [Link ("",[],[]) [Image ("",[],[]) [Str ""] ("./movie.jpg","")] ("http://www.google.com","")]