mirror of
https://github.com/danielepintore/dotfiles.git
synced 2026-06-15 20:25:13 +02:00
Added pandoc filter to parse links in vimwiki
This commit is contained in:
6
.config/vimwiki/README.md
Normal file
6
.config/vimwiki/README.md
Normal file
@@ -0,0 +1,6 @@
|
||||
# How to compile the filter
|
||||
|
||||
In order to compile the filter you must type: `ghc -static --make filter.hs`. Keep in mind that you don't need to compile anything, because you can just make the `filter.hs` file executable via `chmod +x filter.hs` and then run it via:
|
||||
`pandoc -f markdown -t html --filter ./filter.hs -o index.html index.md`.
|
||||
|
||||
To do that remember also to add the shebang: `#!/usr/bin/env runhaskell`
|
||||
10
.config/vimwiki/delink.hs
Executable file
10
.config/vimwiki/delink.hs
Executable file
@@ -0,0 +1,10 @@
|
||||
#!/usr/bin/env runhaskell
|
||||
-- This haskell filter removes links from the document
|
||||
|
||||
import Text.Pandoc.JSON
|
||||
|
||||
main = toJSONFilter delink
|
||||
|
||||
delink :: Inline -> [Inline]
|
||||
delink (Link _ txt _) = txt
|
||||
delink x = [x]
|
||||
BIN
.config/vimwiki/linkParser
Executable file
BIN
.config/vimwiki/linkParser
Executable file
Binary file not shown.
18
.config/vimwiki/linkParser.hs
Executable file
18
.config/vimwiki/linkParser.hs
Executable file
@@ -0,0 +1,18 @@
|
||||
#!/usr/bin/env runhaskell
|
||||
-- This simple filter checks if the link contained is a valid url, if it isn't
|
||||
-- it adds a .html extenstion to the link (it's supposed to be a page in the wiki)
|
||||
|
||||
import Text.Pandoc.JSON
|
||||
import Text.Regex.TDFA ((=~))
|
||||
import Data.Text (pack, unpack)
|
||||
|
||||
main = toJSONFilter linkParser
|
||||
|
||||
linkParser :: Inline -> Inline
|
||||
linkParser (Link attr txt (url, title)) = Link attr txt (newUrl, title)
|
||||
where
|
||||
newUrl = if isValidURL (unpack url) then url else pack (unpack url ++ ".html")
|
||||
linkParser x = x
|
||||
|
||||
isValidURL :: String -> Bool
|
||||
isValidURL url = url =~ ("^((https?|ftp)://)*[a-zA-Z0-9]+(\\.[a-zA-Z0-9]+)+([/?].*)?$" :: String)
|
||||
Reference in New Issue
Block a user