diff options
author | defanor <defanor@uberspace.net> | 2017-10-30 03:09:19 +0300 |
---|---|---|
committer | defanor <defanor@uberspace.net> | 2017-10-30 03:09:19 +0300 |
commit | b6f4091a1c2f6e39548a9228594a4f677855cd29 (patch) | |
tree | 38f6384d7ba7465acaf549a4623998be4f7fcd3c /Text | |
parent | 2489d6808500b0395546216a9c6a9f2785496f6f (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')
-rw-r--r-- | Text/Pandoc/Readers/Gopher.hs | 17 |
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 () |