summaryrefslogtreecommitdiff
path: root/Text/Pandoc
diff options
context:
space:
mode:
authordefanor <defanor@uberspace.net>2017-12-21 09:23:21 +0300
committerdefanor <defanor@uberspace.net>2017-12-21 09:23:21 +0300
commitb32900a7d426f06ee1bd2f69d8cf7899034f5470 (patch)
tree33496f0d50e87b286da038973cb294079da3dafc /Text/Pandoc
parentdbd5740dea0ad6119cbef2b3b1cccf1e865beaca (diff)
Retain position on redisplay, reload, etc
Based on line numbers that are attached to document blocks, not dependent on window/terminal width. Some bits can still be refined/refactored, but here's the initial support.
Diffstat (limited to 'Text/Pandoc')
-rw-r--r--Text/Pandoc/Readers/Gopher.hs12
-rw-r--r--Text/Pandoc/Readers/Plain.hs4
2 files changed, 8 insertions, 8 deletions
diff --git a/Text/Pandoc/Readers/Gopher.hs b/Text/Pandoc/Readers/Gopher.hs
index 4f90082..6b39d80 100644
--- a/Text/Pandoc/Readers/Gopher.hs
+++ b/Text/Pandoc/Readers/Gopher.hs
@@ -55,7 +55,7 @@ pInfo = do
_ <- manyTill unascii tab
_ <- manyTill unascii tab
_ <- many1 digit
- pure $ mkPrefix "" ++ lineToInlines info ++ [LineBreak]
+ pure $ mkPrefix "" ++ lineToInlines info
-- | A file\/link (i.e., any other than informational) directory
-- entry.
@@ -81,14 +81,14 @@ pLink = do
line = case t of
'3' -> prefix ++ lineToInlines name
_ -> [Link (name, [], []) (prefix ++ lineToInlines name) (uri, "")]
- pure $ line ++ [LineBreak]
+ pure $ line
-- | An erroneous directory entry. Still parsing it, since there is a
-- lot of broken directories out there -- but marking as an error.
pError :: Parser [Inline]
pError = do
line <- manyTill anyChar (lookAhead $ try pEOL)
- pure $ [Strong $ mkPrefix "error"] ++ lineToInlines line ++ [LineBreak]
+ pure $ [Strong $ mkPrefix "error"] ++ lineToInlines line
-- | Parses last line, with adjustments for what's used in the wild.
pLastLine :: Parser ()
@@ -102,8 +102,8 @@ pEOL = (endOfLine *> pure ())
<|> (tab >> char '+' >> manyTill anyChar endOfLine *> pure ())
-- | Parses a directory.
-pDirEntries :: Parser [Inline]
-pDirEntries = concat <$>
+pDirEntries :: Parser [[Inline]]
+pDirEntries =
manyTill (choice ([ try pInfo <?> "info entry"
, try pLink <?> "link entry"
, pError <?> "erroneous entry"])
@@ -115,4 +115,4 @@ readGopher :: PandocMonad m => T.Text -> m Pandoc
readGopher s =
case parse pDirEntries "directory entry" s of
Left err -> throwError $ PandocParseError $ show err
- Right r -> pure . Pandoc mempty . pure $ Plain r
+ Right r -> pure . Pandoc mempty . pure $ LineBlock r
diff --git a/Text/Pandoc/Readers/Plain.hs b/Text/Pandoc/Readers/Plain.hs
index 3e64b6b..a66b1cd 100644
--- a/Text/Pandoc/Readers/Plain.hs
+++ b/Text/Pandoc/Readers/Plain.hs
@@ -43,6 +43,6 @@ lineToInlines s = let (cur, next) = break (== ' ') s
-- | Reads plain text, always succeeding and producing a single
-- 'Plain' block.
readPlain :: PandocMonad m => T.Text -> m Pandoc
-readPlain = pure . Pandoc mempty . pure . Plain .
- concatMap (\l -> (lineToInlines $ T.unpack l) ++ [LineBreak])
+readPlain = pure . Pandoc mempty . pure . LineBlock
+ . map (\l -> (lineToInlines $ T.unpack l))
. T.lines . T.filter (/= '\r')