git.iko.soy/typeable/pandoc
on master help sign in
RST reader: reformatting (code line length).
commit5844af67b41606d6da15e14c9b7dd6cedb17321e authorJohn MacFarlane <jgm@berkeley.edu> dateTue 23 May 2017, 21:00 (9 years ago) parentc0c54b7
1 file changed+47−23
src/Text/Pandoc/Readers/RST.hs+47−23
src/Text/Pandoc/Readers/RST.hs+47−23
@@ -35,8 +35,8 @@ import Control.Monad (guard, liftM, mzero, when)
3535import Control.Monad.Identity (Identity(..))
3636import Control.Monad.Except (throwError)
3737import Data.Char (isHexDigit, isSpace, toLower, toUpper)
38−import Data.List (deleteFirstsBy, findIndex, intercalate, isInfixOf, isSuffixOf,
39− nub, sort, transpose, union)
38+import Data.List (deleteFirstsBy, findIndex, intercalate, isInfixOf,
39+ isSuffixOf, nub, sort, transpose, union)
4040import qualified Data.Map as M
4141import Data.Maybe (fromMaybe, isJust)
4242import Data.Monoid ((<>))
@@ -131,7 +131,10 @@ metaFromDefList ds meta = adjustAuthors $ foldr f meta ds
131131 adjustAuthors (Meta metamap) = Meta $ M.adjust splitAuthors "author"
132132 $ M.adjust toPlain "date"
133133 $ M.adjust toPlain "title"
134− $ M.mapKeys (\k -> if k == "authors" then "author" else k)
134+ $ M.mapKeys (\k ->
135+ if k == "authors"
136+ then "author"
137+ else k)
135138 $ metamap
136139 toPlain (MetaBlocks [Para xs]) = MetaInlines xs
137140 toPlain x = x
@@ -595,10 +598,14 @@ listItem start = try $ do
595598 parsed <- parseFromString parseBlocks $ concat (first:rest) ++ "\n"
596599 updateState (\st -> st {stateParserContext = oldContext})
597600 return $ case B.toList parsed of
598− [Para xs] -> B.singleton $ Plain xs
599− [Para xs, BulletList ys] -> B.fromList [Plain xs, BulletList ys]
600− [Para xs, OrderedList s ys] -> B.fromList [Plain xs, OrderedList s ys]
601− [Para xs, DefinitionList ys] -> B.fromList [Plain xs, DefinitionList ys]
601+ [Para xs] ->
602+ B.singleton $ Plain xs
603+ [Para xs, BulletList ys] ->
604+ B.fromList [Plain xs, BulletList ys]
605+ [Para xs, OrderedList s ys] ->
606+ B.fromList [Plain xs, OrderedList s ys]
607+ [Para xs, DefinitionList ys] ->
608+ B.fromList [Plain xs, DefinitionList ys]
602609 _ -> parsed
603610
604611orderedList :: PandocMonad m => RSTParser m Blocks
@@ -726,7 +733,8 @@ directive' = do
726733 "figure" -> do
727734 (caption, legend) <- parseFromString extractCaption body'
728735 let src = escapeURI $ trim top
729− return $ B.para (B.imageWith (imgAttr "figclass") src "fig:" caption) <> legend
736+ return $ B.para (B.imageWith (imgAttr "figclass") src "fig:"
737+ caption) <> legend
730738 "image" -> do
731739 let src = escapeURI $ trim top
732740 let alt = B.str $ maybe "image" trim $ lookup "alt" fields
@@ -737,7 +745,8 @@ directive' = do
737745 $ B.imageWith attr src "" alt
738746 Nothing -> B.imageWith attr src "" alt
739747 "class" -> do
740− let attrs = ("", (splitBy isSpace $ trim top), map (\(k,v) -> (k, trimr v)) fields)
748+ let attrs = ("", (splitBy isSpace $ trim top),
749+ map (\(k,v) -> (k, trimr v)) fields)
741750 -- directive content or the first immediately following element
742751 children <- case body of
743752 "" -> block
@@ -764,20 +773,27 @@ tableDirective top _fields body = do
764773
765774
766775-- TODO: :stub-columns:.
767−-- Only the first row becomes the header even if header-rows: > 1, since Pandoc doesn't support a table with multiple header rows.
768−-- We don't need to parse :align: as it represents the whole table align.
769−listTableDirective :: PandocMonad m => String -> [(String, String)] -> String -> RSTParser m Blocks
776+-- Only the first row becomes the header even if header-rows: > 1,
777+-- since Pandoc doesn't support a table with multiple header rows.
778+-- We don't need to parse :align: as it represents the whole table align.
779+listTableDirective :: PandocMonad m
780+ => String -> [(String, String)] -> String
781+ -> RSTParser m Blocks
770782listTableDirective top fields body = do
771783 bs <- parseFromString parseBlocks body
772784 title <- parseFromString (trimInlines . mconcat <$> many inline) top
773785 let rows = takeRows $ B.toList bs
774− headerRowsNum = fromMaybe (0 :: Int) $ lookup "header-rows" fields >>= safeRead
786+ headerRowsNum = fromMaybe (0 :: Int) $
787+ lookup "header-rows" fields >>= safeRead
775788 (headerRow,bodyRows,numOfCols) = case rows of
776− x:xs -> if headerRowsNum > 0 then (x, xs, length x) else ([], rows, length x)
789+ x:xs -> if headerRowsNum > 0
790+ then (x, xs, length x)
791+ else ([], rows, length x)
777792 _ -> ([],[],0)
778793 widths = case trim <$> lookup "widths" fields of
779794 Just "auto" -> replicate numOfCols 0
780− Just specs -> normWidths $ map (fromMaybe (0 :: Double) . safeRead) $ splitBy (`elem` (" ," :: String)) specs
795+ Just specs -> normWidths $ map (fromMaybe (0 :: Double) . safeRead) $
796+ splitBy (`elem` (" ," :: String)) specs
781797 _ -> replicate numOfCols 0
782798 return $ B.table title
783799 (zip (replicate numOfCols AlignDefault) widths)
@@ -792,7 +808,8 @@ listTableDirective top fields body = do
792808-- TODO:
793809-- - Only supports :format: fields with a single format for :raw: roles,
794810-- change Text.Pandoc.Definition.Format to fix
795−addNewRole :: PandocMonad m => String -> [(String, String)] -> RSTParser m Blocks
811+addNewRole :: PandocMonad m
812+ => String -> [(String, String)] -> RSTParser m Blocks
796813addNewRole roleString fields = do
797814 pos <- getPosition
798815 (role, parentRole) <- parseFromString inheritedRole roleString
@@ -822,7 +839,8 @@ addNewRole roleString fields = do
822839 SkippedContent ":format: [because parent of role is not :raw:]" pos
823840 _ -> logMessage $ SkippedContent (":" ++ key ++ ":") pos
824841 when (parentRole == "raw" && countKeys "format" > 1) $
825− logMessage $ SkippedContent ":format: [after first in definition of role]"
842+ logMessage $ SkippedContent
843+ ":format: [after first in definition of role]"
826844 pos
827845 when (parentRole == "code" && countKeys "language" > 1) $
828846 logMessage $ SkippedContent
@@ -837,7 +855,8 @@ addNewRole roleString fields = do
837855 where
838856 countKeys k = length . filter (== k) . map fst $ fields
839857 inheritedRole =
840− (,) <$> roleName <*> ((char '(' *> roleName <* char ')') <|> pure "span")
858+ (,) <$> roleName <*> ((char '(' *> roleName <* char ')')
859+ <|> pure "span")
841860
842861
843862-- Can contain character codes as decimal numbers or
@@ -1014,7 +1033,8 @@ substKey = try $ do
10141033 [Para ils] -> return $ B.fromList ils
10151034 _ -> mzero
10161035 let key = toKey $ stripFirstAndLast ref
1017− updateState $ \s -> s{ stateSubstitutions = M.insert key il $ stateSubstitutions s }
1036+ updateState $ \s -> s{ stateSubstitutions =
1037+ M.insert key il $ stateSubstitutions s }
10181038
10191039anonymousKey :: Monad m => RSTParser m ()
10201040anonymousKey = try $ do
@@ -1023,7 +1043,8 @@ anonymousKey = try $ do
10231043 pos <- getPosition
10241044 let key = toKey $ "_" ++ printf "%09d" (sourceLine pos)
10251045 --TODO: parse width, height, class and name attributes
1026− updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $ stateKeys s }
1046+ updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
1047+ stateKeys s }
10271048
10281049stripTicks :: String -> String
10291050stripTicks = reverse . stripTick . reverse . stripTick
@@ -1038,7 +1059,8 @@ regularKey = try $ do
10381059 src <- targetURI
10391060 let key = toKey $ stripTicks ref
10401061 --TODO: parse width, height, class and name attributes
1041− updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $ stateKeys s }
1062+ updateState $ \s -> s { stateKeys = M.insert key ((src,""), nullAttr) $
1063+ stateKeys s }
10421064
10431065headerBlock :: PandocMonad m => RSTParser m [Char]
10441066headerBlock = do
@@ -1243,7 +1265,8 @@ interpretedRole = try $ do
12431265 (role, contents) <- roleBefore <|> roleAfter
12441266 renderRole contents Nothing role nullAttr
12451267
1246−renderRole :: PandocMonad m => String -> Maybe String -> String -> Attr -> RSTParser m Inlines
1268+renderRole :: PandocMonad m
1269+ => String -> Maybe String -> String -> Attr -> RSTParser m Inlines
12471270renderRole contents fmt role attr = case role of
12481271 "sup" -> return $ B.superscript $ B.str contents
12491272 "superscript" -> return $ B.superscript $ B.str contents
@@ -1376,7 +1399,8 @@ referenceLink = try $ do
13761399 (k:_) -> return k
13771400 ((src,tit), attr) <- lookupKey [] key
13781401 -- if anonymous link, remove key so it won't be used again
1379− when (isAnonKey key) $ updateState $ \s -> s{ stateKeys = M.delete key keyTable }
1402+ when (isAnonKey key) $ updateState $ \s ->
1403+ s{ stateKeys = M.delete key keyTable }
13801404 return $ B.linkWith attr src tit label'
13811405
13821406-- We keep a list of oldkeys so we can detect lookup loops.