diff --git a/.config/vimwiki/README.md b/.config/vimwiki/README.md new file mode 100644 index 0000000..7405ac0 --- /dev/null +++ b/.config/vimwiki/README.md @@ -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` diff --git a/.config/vimwiki/delink.hs b/.config/vimwiki/delink.hs new file mode 100755 index 0000000..9e0f2c6 --- /dev/null +++ b/.config/vimwiki/delink.hs @@ -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] diff --git a/.config/vimwiki/linkParser b/.config/vimwiki/linkParser new file mode 100755 index 0000000..5303941 Binary files /dev/null and b/.config/vimwiki/linkParser differ diff --git a/.config/vimwiki/linkParser.hs b/.config/vimwiki/linkParser.hs new file mode 100755 index 0000000..0fc1400 --- /dev/null +++ b/.config/vimwiki/linkParser.hs @@ -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)