summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo Hörnquist <hugo@lysator.liu.se>2022-10-30 20:27:08 +0100
committerHugo Hörnquist <hugo@lysator.liu.se>2022-10-30 21:53:41 +0100
commitade2280a73c85b481d3b14f6a6deb80a0c8645c1 (patch)
tree2826a06057b042cda05e9ef7bc45620b23b035e4
parentReplace ini parser. (diff)
downloadvimwiki-scripts-ade2280a73c85b481d3b14f6a6deb80a0c8645c1.tar.gz
vimwiki-scripts-ade2280a73c85b481d3b14f6a6deb80a0c8645c1.tar.xz
Ubuntu 20 compat.
-rw-r--r--hs/Config.hs3
-rw-r--r--hs/Data/Text/Compat.hs35
-rw-r--r--hs/Html.hs54
-rw-r--r--hs/Links.hs16
-rw-r--r--hs/Vimwiki/Man.hs20
-rw-r--r--hs/vimwiki.cabal3
6 files changed, 88 insertions, 43 deletions
diff --git a/hs/Config.hs b/hs/Config.hs
index a2ceaeb..565f77b 100644
--- a/hs/Config.hs
+++ b/hs/Config.hs
@@ -1,14 +1,13 @@
{-# LANGUAGE TemplateHaskell
, OverloadedStrings
, FlexibleInstances
- , ImportQualifiedPost
#-}
module Config where
import Control.Lens
import Data.Map (Map)
-import Data.Map qualified as M
+import qualified Data.Map as M
import Network.URI (URI, parseURI)
import Options.Applicative
import Data.Ini
diff --git a/hs/Data/Text/Compat.hs b/hs/Data/Text/Compat.hs
new file mode 100644
index 0000000..f07d60a
--- /dev/null
+++ b/hs/Data/Text/Compat.hs
@@ -0,0 +1,35 @@
+{-# LANGUAGE CPP
+ , FlexibleInstances
+ , TypeSynonymInstances #-}
+
+module Data.Text.Compat where
+
+import Data.Text (Text, pack, unpack)
+
+#if MIN_VERSION_pandoc_types(1, 17, 6)
+type PandocStr = Text
+#else
+type PandocStr = String
+#endif
+
+class PS a where
+ -- Convert from something to a pandoc string
+ conv :: a -> PandocStr
+ -- Convert from a pandoc string back into another string type
+ from :: PandocStr -> a
+
+#if MIN_VERSION_pandoc_types(1, 17, 6)
+instance PS Text where
+ conv = id
+ from = id
+instance PS String where
+ conv = pack
+ from = unpack
+#else
+instance PS Text where
+ conv = unpack
+ from = pack
+instance PS String where
+ conv = id
+ from = id
+#endif
diff --git a/hs/Html.hs b/hs/Html.hs
index ff8df89..f17c08e 100644
--- a/hs/Html.hs
+++ b/hs/Html.hs
@@ -1,6 +1,6 @@
{-# LANGUAGE OverloadedStrings
- , ImportQualifiedPost
, ScopedTypeVariables
+ , CPP
#-}
module Html
@@ -24,25 +24,25 @@ import Control.Monad.IO.Class (liftIO)
import Data.Default (def)
import Data.List (partition)
-import Data.Map qualified as M
+import qualified Data.Map as M
import Data.Map (Map)
import Data.Maybe (listToMaybe, fromMaybe, fromJust)
import Data.Set (Set)
-import Data.Set qualified as S
-import Data.Text (Text, unpack, pack)
-import Data.Text.IO qualified as T
+import qualified Data.Set as S
+import Data.Text (Text, pack)
+import qualified Data.Text.IO as T
import Data.Text.Lazy (toStrict)
+import Data.Text.Compat (PandocStr, conv, from)
import Network.URI hiding (query)
-import Network.URI.Lens
import System.Directory (copyFile, createDirectoryIfMissing)
import System.Environment.XDG.BaseDir (getUserConfigDir)
import Text.Blaze.Html5 (Html, toHtml, (!), textValue, docTypeHtml)
-import Text.Blaze.Html5 qualified as H
+import qualified Text.Blaze.Html5 as H
import Text.Blaze.Html5.Attributes (href, role, rel, content, name, charset)
-import Text.Blaze.Html5.Attributes qualified as A
+import qualified Text.Blaze.Html5.Attributes as A
import Text.Blaze.Html.Renderer.Text (renderHtml)
@@ -62,7 +62,11 @@ import Text.Pandoc
import Text.Pandoc.Shared (stringify)
import Text.Pandoc.Walk (Walkable (..), walk)
-import Text.Pandoc.Writers.Shared (toTableOfContents, lookupMetaString)
+import Text.Pandoc.Writers.Shared (
+#if MIN_VERSION_pandoc(2, 6, 0)
+ toTableOfContents,
+#endif
+ lookupMetaString)
import Files
@@ -81,10 +85,10 @@ isWikiFile = isFiletype "wiki"
-- - Tilde-expand paths from filenames
-mailRewriter :: String -> [Inline] -> URI -> ([Inline], Text)
-mailRewriter mu4eURL body uri = (body, pack $ mu4eURL <> "?id=" <> uriPath uri)
+mailRewriter :: String -> [Inline] -> URI -> ([Inline], PandocStr)
+mailRewriter mu4eURL body uri = (body, conv $ mu4eURL <> "?id=" <> uriPath uri)
-urlRewrites :: Configuration -> Map String ([Inline] -> URI -> ([Inline], Text))
+urlRewrites :: Configuration -> Map String ([Inline] -> URI -> ([Inline], PandocStr))
urlRewrites conf = M.fromList [ ("mail", mailRewriter $ (fromJust $ conf ^. output . mu4eURL))
-- , ("man", manRewriter $ (rewriters ! (fromJust $ conf ^. output . manProvider)))
-- TODO choose man implementation from
@@ -101,27 +105,27 @@ fixExtension url
resolveInterwiki :: Map String URI -> String -> URI -> String
resolveInterwiki wikilinks wikiname uri =
case M.lookup wikiname wikilinks of
- Just uri' -> show $ uri' & uriPathLens %~ (<> fixExtension (uriPath uri))
+ Just uri' -> show $ uri' { uriPath = uriPath uri' <> fixExtension (uriPath uri) }
Nothing -> error $ "Unknown Wiki name: " <> wikiname <> ""
rebuildLinks :: Configuration -> Inline -> Inline
rebuildLinks conf l@(Link attributes body (url, title@"wikilink"))
- = case parseURI . unpack $ url of
+ = case parseURI . from $ url of
Just uri -> case uriScheme uri of
('w':'n':'.':wikiname') -> let wikiname = init wikiname'
in Link attributes
- [ Str . pack . uriPath $ uri
- , Superscript [Str $ pack wikiname]]
- (pack $ resolveInterwiki (conf ^. wikis) wikiname uri, title)
+ [ Str . conv . uriPath $ uri
+ , Superscript [Str $ conv wikiname]]
+ (conv $ resolveInterwiki (conf ^. wikis) wikiname uri, title)
_ -> case M.lookup (init . uriScheme $ uri) (urlRewrites conf) of
Just proc -> (proc body uri) & (\(body, url) -> Link attributes body (url, title))
Nothing -> l
- Nothing -> case break (== '#') (unpack url) of
+ Nothing -> case break (== '#') (from url) of
("", '#':_) -> Link attributes body (url, title)
- (page, "") -> Link attributes body (pack $ fixExtension page, title)
- (page, '#':local) -> Link attributes body (pack $ fixExtension page <> "#" <> local, title)
+ (page, "") -> Link attributes body (conv $ fixExtension page, title)
+ (page, '#':local) -> Link attributes body (conv $ fixExtension page <> "#" <> local, title)
_ -> l
rebuildLinks _ l = l
@@ -205,7 +209,7 @@ allHeaders = query f
f _ = []
-headerContent :: Block -> Maybe Text
+headerContent :: Block -> Maybe PandocStr
headerContent (Header _ _ inlines) = Just $ stringify inlines
headerContent _ = Nothing
@@ -227,7 +231,11 @@ handlePart conf outdir backlinks wiki_root parts = do
pandoc <- handleSourceText conf text
let Pandoc meta blocks = pandoc
+#if MIN_VERSION_pandoc(2, 6, 0)
toc <- writeHtml5 def $ Pandoc meta $ [toTableOfContents def blocks]
+#else
+ let toc = mempty
+#endif
html <- writeHtml5 def pandoc
-- Since we (explicitly) don't reset the state between invocations
@@ -235,13 +243,13 @@ handlePart conf outdir backlinks wiki_root parts = do
-- before and after, and check if it is langer
-- log <- getsCommonState stLog
-- liftIO $ print meta
- let title :: Text = firstJust (pack $ takeBaseName item_path)
+ let title :: PandocStr = firstJust (conv $ takeBaseName item_path)
[ nullToMaybe $ lookupMetaString "title" meta
, headerContent =<< (listToMaybe $ allHeaders pandoc)
]
-- liftIO $ print log
- let htmlString = toStrict . renderHtml . htmlWrap conf (unpack title) parts bl toc $ html
+ let htmlString = toStrict . renderHtml . htmlWrap conf (from title) parts bl toc $ html
liftIO $ T.writeFile outTarget htmlString
diff --git a/hs/Links.hs b/hs/Links.hs
index cb8fd27..ecef78b 100644
--- a/hs/Links.hs
+++ b/hs/Links.hs
@@ -1,5 +1,4 @@
{-# LANGUAGE OverloadedStrings
- , ImportQualifiedPost
#-}
module Links
@@ -12,13 +11,14 @@ import Control.Monad.IO.Class (liftIO)
import Data.Default (def)
-import Data.Map qualified as M
+import qualified Data.Map as M
import Data.Set (Set)
-import Data.Set qualified as S
+import qualified Data.Set as S
import Data.Text (Text)
-import Data.Text.IO qualified as T
+import Data.Text.Compat (PandocStr, conv, from)
+import qualified Data.Text.IO as T
import System.FilePath (joinPath, (</>))
@@ -28,10 +28,10 @@ import Text.Pandoc.Walk (query)
-- Find all wikilinks in the given document
-extractLinks :: Pandoc -> [Text]
+extractLinks :: Pandoc -> [PandocStr]
extractLinks = query extractLink
- where extractLink :: Inline -> [Text]
- extractLink (Link _ _ (target, "wikilink")) = [target]
+ where extractLink :: Inline -> [PandocStr]
+ extractLink (Link _ _ (target, "wikilink")) = [conv target]
extractLink _ = []
@@ -43,7 +43,7 @@ findLinks wiki_root parts = do
pandoc <- readVimwiki def text
- return (item_path, extractLinks pandoc)
+ return (item_path, from <$> extractLinks pandoc)
-- let htmlString = toStrict . renderHtml $ html
-- liftIO $ T.writeFile outTarget htmlString
diff --git a/hs/Vimwiki/Man.hs b/hs/Vimwiki/Man.hs
index dde9028..35d6383 100644
--- a/hs/Vimwiki/Man.hs
+++ b/hs/Vimwiki/Man.hs
@@ -1,26 +1,28 @@
{-# LANGUAGE OverloadedStrings
- , ImportQualifiedPost
+ , CPP
#-}
module Vimwiki.Man where
import Data.Map (Map)
-import Data.Map qualified as M
+import qualified Data.Map as M
import Data.Maybe (fromMaybe)
import Data.String (IsString)
-import Data.Text hiding (tail)
import Network.URI
import Text.Pandoc (Inline (Str))
import Util (nullToMaybe)
+import Data.Text.Compat
-manRewriter :: (Text -> Maybe Text -> Maybe Text -> Text) -> [Inline] -> URI -> ([Inline], Text)
+manRewriter :: (PandocStr -> Maybe PandocStr -> Maybe PandocStr -> PandocStr)
+ -> [Inline] -> URI -> ([Inline], PandocStr)
manRewriter manImpl _ uri
- = ([Str $ path <> "(" <> (fromMaybe "?" section') <> ")"]
+ = ([Str . conv $ path <> "(" <> (fromMaybe "?" section') <> ")"]
, manImpl path section' language')
- where path :: Text
- path = pack $ uriPath uri
- section' = pack . tail <$> nullToMaybe (uriFragment uri)
- language' = pack . tail <$> nullToMaybe (uriQuery uri)
+ where path :: PandocStr
+ path = conv $ uriPath uri
+ section' = conv . tail <$> nullToMaybe (uriFragment uri)
+ language' = conv . tail <$> nullToMaybe (uriQuery uri)
+
archMan :: (Semigroup a, IsString a) => a -> Maybe a -> Maybe a -> a
archMan page section' language'
diff --git a/hs/vimwiki.cabal b/hs/vimwiki.cabal
index c52c479..f68194d 100644
--- a/hs/vimwiki.cabal
+++ b/hs/vimwiki.cabal
@@ -34,7 +34,8 @@ executable Main
Handlingar,
Vimwiki.Man,
System.Home,
- Util
+ Util,
+ Data.Text.Compat
build-depends:
base >= 4.8,
blaze-html >= 0.9,