summaryrefslogtreecommitdiff
path: root/Text/Pandoc
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-10-30 03:09:19 +0300
committerdefanor <defanor@uberspace.net>2017-10-30 03:09:19 +0300
commitb6f4091a1c2f6e39548a9228594a4f677855cd29 (patch)
tree38f6384d7ba7465acaf549a4623998be4f7fcd3c /Text/Pandoc
parent2489d6808500b0395546216a9c6a9f2785496f6f (diff)
Prefix Gopher directory entries with item types
Similar to what lynx is doing, since that's quite handy to see.
Diffstat (limited to 'Text/Pandoc')
-rw-r--r--Text/Pandoc/Readers/Gopher.hs17
1 files changed, 15 insertions, 2 deletions
diff --git a/Text/Pandoc/Readers/Gopher.hs b/Text/Pandoc/Readers/Gopher.hs
index 3909e3d..de346f5 100644
--- a/Text/Pandoc/Readers/Gopher.hs
+++ b/Text/Pandoc/Readers/Gopher.hs
@@ -23,6 +23,10 @@ import Text.Pandoc.Readers.Plain
unascii :: Parser Char
unascii = noneOf ['\t', '\n', '\r', '\0']
+-- | Creates a type prefix for directory entries.
+mkPrefix :: String -> [Inline]
+mkPrefix s = replicate (6 - length s) Space ++ [Str s, Space]
+
-- | An informational directory entry.
pInfo :: Parser [Inline]
pInfo = do
@@ -31,7 +35,7 @@ pInfo = do
_ <- manyTill unascii tab
_ <- manyTill unascii tab
_ <- many1 digit
- pure $ lineToInlines info ++ [LineBreak]
+ pure $ mkPrefix "" ++ lineToInlines info ++ [LineBreak]
-- | A file\/link (i.e., any other than informational) directory
-- entry.
@@ -43,7 +47,16 @@ pLink = do
host <- manyTill unascii tab
port <- many1 digit
let uri = concat ["gopher://", host, ":", port, "/", [t], selector]
- pure [Link (name, [], []) (lineToInlines name) (uri, ""), LineBreak]
+ prefix = mkPrefix $ case t of
+ '0' -> "(text)"
+ '1' -> "(dir)"
+ 'h' -> "(html)"
+ '9' -> "(bin)"
+ 'I' -> "(img)"
+ 's' -> "(snd)"
+ '7' -> "(srch)"
+ _ -> "(?)"
+ pure [Link (name, [], []) (prefix ++ lineToInlines name) (uri, ""), LineBreak]
-- | Parses last line, with adjustments for what's used in the wild.
pLastLine :: Parser ()