@@ -1066,8 +1066,6 @@ inline = (mempty <$ comment)
1066inlines :: PandocMonad m => LP m Inlines
1066inlines :: PandocMonad m => LP m Inlines
1067inlines = mconcat <$> many inline
1067inlines = mconcat <$> many inline
1069−-- PREVIOUSLY HAD (notFollowedBy (char '}') *> inline)
1071-- block elements:
1069-- block elements:
1073paragraph :: PandocMonad m => LP m Blocks
1071paragraph :: PandocMonad m => LP m Blocks
@@ -1200,7 +1198,7 @@ blockCommands = M.fromList $
1200 , ("rule", skipopts *> tok *> tok *> pure horizontalRule)
1198 , ("rule", skipopts *> tok *> tok *> pure horizontalRule)
1201-- , ("item", skipopts *> looseItem)
1199-- , ("item", skipopts *> looseItem)
1202-- , ("documentclass", skipopts *> braced *> preamble)
1200-- , ("documentclass", skipopts *> braced *> preamble)
1203−-- , ("centerline", (para . trimInlines) <$> (skipopts *> tok))
1201+ , ("centerline", (para . trimInlines) <$> (skipopts *> tok))
1204-- , ("caption", skipopts *> setCaption)
1202-- , ("caption", skipopts *> setCaption)
1205-- , ("bibliography", mempty <$ (skipopts *> braced >>=
1203-- , ("bibliography", mempty <$ (skipopts *> braced >>=
1206-- addMeta "bibliography" . splitBibs))
1204-- addMeta "bibliography" . splitBibs))
@@ -1245,331 +1243,6 @@ blocks :: PandocMonad m => LP m Blocks
1245blocks = mconcat <$> many block
1243blocks = mconcat <$> many block
1248−-- -- | Parse LaTeX from string and return 'Pandoc' document.
1249−-- readLaTeX :: PandocMonad m
1250−-- => ReaderOptions -- ^ Reader options
1251−-- -> Text -- ^ String to parse (assumes @'\n'@ line endings)
1253−-- readLaTeX opts ltx = do
1254−-- parsed <- readWithM parseLaTeX def{ stateOptions = opts }
1255−-- (unpack (crFilter ltx))
1257−-- Right result -> return result
1258−-- Left e -> throwError e
1261−-- parseLaTeX :: PandocMonad m => LP m Pandoc
1266−-- let meta = stateMeta st
1267−-- let doc' = doc bs
1268−-- let headerLevel (Header n _ _) = [n]
1269−-- headerLevel _ = []
1270−-- let bottomLevel = minimumDef 1 $ query headerLevel doc'
1271−-- let adjustHeaders m (Header n attr ils) = Header (n+m) attr ils
1272−-- adjustHeaders _ x = x
1273−-- let (Pandoc _ bs') =
1274−-- -- handle the case where you have \part or \chapter
1275−-- (if bottomLevel < 1
1276−-- then walk (adjustHeaders (1 - bottomLevel))
1278−-- return $ Pandoc meta bs'
1280−-- anyControlSeq :: PandocMonad m => LP m String
1281−-- anyControlSeq = do
1283−-- next <- option '\n' anyChar
1285−-- '\n' -> return ""
1286−-- c | isLetter c -> (c:) <$> (many letter <* optional sp)
1287−-- | otherwise -> return [c]
1289−-- controlSeq :: PandocMonad m => String -> LP m String
1290−-- controlSeq name = try $ do
1294−-- [c] | not (isLetter c) -> string [c]
1295−-- cs -> string cs <* notFollowedBy letter <* optional sp
1298−-- dimenarg :: PandocMonad m => LP m String
1299−-- dimenarg = try $ do
1300−-- ch <- option "" $ string "="
1301−-- num <- many1 digit
1302−-- dim <- oneOfStrings ["pt","pc","in","bp","cm","mm","dd","cc","sp"]
1303−-- return $ ch ++ num ++ dim
1305−-- sp :: PandocMonad m => LP m ()
1306−-- sp = whitespace <|> endline
1308−-- whitespace :: PandocMonad m => LP m ()
1309−-- whitespace = skipMany1 $ satisfy (\c -> c == ' ' || c == '\t')
1311−-- endline :: PandocMonad m => LP m ()
1312−-- endline = try (newline >> lookAhead anyChar >> notFollowedBy blankline)
1314−-- isLowerHex :: Char -> Bool
1315−-- isLowerHex x = x >= '0' && x <= '9' || x >= 'a' && x <= 'f'
1317−-- primEscape :: PandocMonad m => LP m Char
1318−-- primEscape = try $ do
1320−-- c <- satisfy (\x -> x >= '\0' && x <= '\128')
1321−-- d <- if isLowerHex c
1322−-- then option "" $ count 1 (satisfy isLowerHex)
1325−-- then case ord c of
1326−-- x | x >= 64 && x <= 127 -> return $ chr (x - 64)
1327−-- | otherwise -> return $ chr (x + 64)
1328−-- else return $ chr $ read ('0':'x':c:d)
1330−-- comment :: PandocMonad m => LP m ()
1333−-- skipMany (satisfy (/='\n'))
1337−-- bgroup :: PandocMonad m => LP m ()
1338−-- bgroup = try $ do
1339−-- skipMany (spaceChar <|> try (newline <* notFollowedBy blankline))
1341−-- <|> () <$ controlSeq "bgroup"
1342−-- <|> () <$ controlSeq "begingroup"
1344−-- egroup :: PandocMonad m => LP m ()
1345−-- egroup = () <$ char '}'
1346−-- <|> () <$ controlSeq "egroup"
1347−-- <|> () <$ controlSeq "endgroup"
1349−-- grouped :: PandocMonad m => Monoid a => LP m a -> LP m a
1350−-- grouped parser = try $ do
1352−-- -- first we check for an inner 'grouped', because
1353−-- -- {{a,b}} should be parsed the same as {a,b}
1354−-- try (grouped parser <* egroup)
1355−-- <|> (mconcat <$> manyTill parser egroup)
1357−-- braced :: PandocMonad m => LP m String
1358−-- braced = grouped chunk
1360−-- many1 (satisfy (\c -> c /= '\\' && c /= '}' && c /= '{'))
1361−-- <|> try (string "\\}")
1362−-- <|> try (string "\\{")
1363−-- <|> try (string "\\\\")
1364−-- <|> ((\x -> "{" ++ x ++ "}") <$> braced)
1365−-- <|> count 1 anyChar
1367−-- bracketed :: PandocMonad m => Monoid a => LP m a -> LP m a
1368−-- bracketed parser = try $ char '[' *> (mconcat <$> manyTill parser (char ']'))
1370−-- mathDisplay :: PandocMonad m => LP m String -> LP m Inlines
1371−-- mathDisplay p = displayMath <$> (try p >>= applyMacros' . trim)
1373−-- mathInline :: PandocMonad m => LP m String -> LP m Inlines
1374−-- mathInline p = math <$> (try p >>= applyMacros')
1376−-- mathChars :: PandocMonad m => LP m String
1378−-- concat <$> many (escapedChar
1379−-- <|> (snd <$> withRaw braced)
1380−-- <|> many1 (satisfy isOrdChar))
1381−-- where escapedChar = try $ do char '\\'
1384−-- isOrdChar '$' = False
1385−-- isOrdChar '{' = False
1386−-- isOrdChar '}' = False
1387−-- isOrdChar '\\' = False
1388−-- isOrdChar _ = True
1390−-- inline :: PandocMonad m => LP m Inlines
1391−-- inline = (mempty <$ comment)
1392−-- <|> (space <$ whitespace)
1393−-- <|> (softbreak <$ endline)
1395−-- <|> inlineCommand
1396−-- <|> inlineEnvironment
1398−-- <|> (char '-' *> option (str "-")
1399−-- (char '-' *> option (str "–") (str "—" <$ char '-')))
1402−-- <|> (str "”" <$ try (string "''"))
1403−-- <|> (str "”" <$ char '”')
1404−-- <|> (str "’" <$ char '\'')
1405−-- <|> (str "’" <$ char '’')
1406−-- <|> (str "\160" <$ char '~')
1407−-- <|> mathDisplay (string "$$" *> mathChars <* string "$$")
1408−-- <|> mathInline (char '$' *> mathChars <* char '$')
1409−-- <|> (guardEnabled Ext_literate_haskell *> char '|' *> doLHSverb)
1410−-- <|> (str . (:[]) <$> primEscape)
1411−-- <|> (do res <- oneOf "#&~^'`\"[]"
1412−-- pos <- getPosition
1413−-- report $ ParsingUnescaped [res] pos
1414−-- return $ str [res])
1416−-- inlines :: PandocMonad m => LP m Inlines
1417−-- inlines = mconcat <$> many (notFollowedBy (char '}') *> inline)
1419−-- inlineGroup :: PandocMonad m => LP m Inlines
1421−-- ils <- grouped inline
1423−-- then return mempty
1424−-- else return $ spanWith nullAttr ils
1425−-- -- we need the span so we can detitlecase bibtex entries;
1426−-- -- we need to know when something is {C}apitalized
1428−-- block :: PandocMonad m => LP m Blocks
1429−-- block = (mempty <$ comment)
1430−-- <|> (mempty <$ ((spaceChar <|> newline) *> spaces))
1436−-- <|> grouped block
1438−-- blocks :: PandocMonad m => LP m Blocks
1439−-- blocks = mconcat <$> many block
1441−-- getRawCommand :: PandocMonad m => String -> LP m String
1442−-- getRawCommand name' = do
1443−-- rawargs <- withRaw (many (try (optional sp *> opt)) *>
1444−-- option "" (try (optional sp *> dimenarg)) *>
1446−-- return $ '\\' : name' ++ snd rawargs
1448−-- lookupListDefault :: (Ord k) => v -> [k] -> M.Map k v -> v
1449−-- lookupListDefault d = (fromMaybe d .) . lookupList
1451−-- lookupList l m = msum $ map (`M.lookup` m) l
1453−-- blockCommand :: PandocMonad m => LP m Blocks
1454−-- blockCommand = try $ do
1455−-- name <- anyControlSeq
1456−-- guard $ name /= "begin" && name /= "end"
1457−-- star <- option "" (string "*" <* optional sp)
1458−-- let name' = name ++ star
1460−-- rawcommand <- getRawCommand name'
1461−-- transformed <- applyMacros' rawcommand
1462−-- guard $ transformed /= rawcommand
1463−-- notFollowedBy $ parseFromString' inlines transformed
1464−-- parseFromString' blocks transformed
1465−-- lookupListDefault raw [name',name] blockCommands
1467−-- inBrackets :: Inlines -> Inlines
1468−-- inBrackets x = str "[" <> x <> str "]"
1470−-- -- eat an optional argument and one or more arguments in braces
1471−-- ignoreInlines :: PandocMonad m => Text -> (Text, LP m Inlines)
1472−-- ignoreInlines name = (name, p)
1474−-- p = do oa <- optargs
1475−-- let rawCommand = '\\':name ++ oa
1476−-- let doraw = guardRaw >> return (rawInline "latex" rawCommand)
1477−-- doraw <|> ignore rawCommand
1479−-- guardRaw :: PandocMonad m => LP m ()
1480−-- guardRaw = getOption readerExtensions >>= guard . extensionEnabled Ext_raw_tex
1482−-- optargs :: PandocMonad m => LP m String
1483−-- optargs = snd <$> withRaw (skipopts *> skipMany (try $ optional sp *> braced))
1485−-- ignore :: (Monoid a, PandocMonad m) => String -> ParserT s u m a
1487−-- pos <- getPosition
1488−-- report $ SkippedContent raw pos
1491−-- ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
1492−-- ignoreBlocks name = (name, p)
1494−-- p = do oa <- optargs
1495−-- let rawCommand = '\\':name ++ oa
1496−-- let doraw = guardRaw >> return (rawBlock "latex" rawCommand)
1497−-- doraw <|> ignore rawCommand
1499−-- blockCommands :: PandocMonad m => M.Map String (LP m Blocks)
1500−-- blockCommands = M.fromList $
1501−-- [ ("par", mempty <$ skipopts)
1502−-- , ("parbox", braced >> grouped blocks)
1503−-- , ("title", mempty <$ (skipopts *>
1504−-- (grouped inline >>= addMeta "title")
1505−-- <|> (grouped block >>= addMeta "title")))
1506−-- , ("subtitle", mempty <$ (skipopts *> tok >>= addMeta "subtitle"))
1507−-- , ("author", mempty <$ (skipopts *> authors))
1508−-- -- -- in letter class, temp. store address & sig as title, author
1509−-- , ("address", mempty <$ (skipopts *> tok >>= addMeta "address"))
1510−-- , ("signature", mempty <$ (skipopts *> authors))
1511−-- , ("date", mempty <$ (skipopts *> tok >>= addMeta "date"))
1512−-- -- Koma-script metadata commands
1513−-- , ("dedication", mempty <$ (skipopts *> tok >>= addMeta "dedication"))
1515−-- , ("part", section nullAttr (-1))
1516−-- , ("part*", section nullAttr (-1))
1517−-- , ("chapter", section nullAttr 0)
1518−-- , ("chapter*", section ("",["unnumbered"],[]) 0)
1519−-- , ("section", section nullAttr 1)
1520−-- , ("section*", section ("",["unnumbered"],[]) 1)
1521−-- , ("subsection", section nullAttr 2)
1522−-- , ("subsection*", section ("",["unnumbered"],[]) 2)
1523−-- , ("subsubsection", section nullAttr 3)
1524−-- , ("subsubsection*", section ("",["unnumbered"],[]) 3)
1525−-- , ("paragraph", section nullAttr 4)
1526−-- , ("paragraph*", section ("",["unnumbered"],[]) 4)
1527−-- , ("subparagraph", section nullAttr 5)
1528−-- , ("subparagraph*", section ("",["unnumbered"],[]) 5)
1530−-- , ("frametitle", section nullAttr 3)
1531−-- , ("framesubtitle", section nullAttr 4)
1533−-- , ("opening", (para . trimInlines) <$> (skipopts *> tok))
1534−-- , ("closing", skipopts *> closing)
1536−-- , ("hrule", pure horizontalRule)
1537−-- , ("strut", pure mempty)
1538−-- , ("rule", skipopts *> tok *> tok *> pure horizontalRule)
1539−-- , ("item", skipopts *> looseItem)
1540−-- , ("documentclass", skipopts *> braced *> preamble)
1541−-- , ("centerline", (para . trimInlines) <$> (skipopts *> tok))
1542−-- , ("caption", skipopts *> setCaption)
1543−-- , ("bibliography", mempty <$ (skipopts *> braced >>=
1544−-- addMeta "bibliography" . splitBibs))
1545−-- , ("addbibresource", mempty <$ (skipopts *> braced >>=
1546−-- addMeta "bibliography" . splitBibs))
1548−-- , ("lstinputlisting", inputListing)
1549−-- , ("graphicspath", graphicsPath)
1551−-- , ("hypertarget", braced >> grouped block)
1552−-- ] ++ map ignoreBlocks
1553−-- -- these commands will be ignored unless --parse-raw is specified,
1554−-- -- in which case they will appear as raw latex blocks
1555−-- [ "newcommand", "renewcommand", "newenvironment", "renewenvironment"
1556−-- -- newcommand, etc. should be parsed by macro, but we need this
1557−-- -- here so these aren't parsed as inline commands to ignore
1558−-- , "special", "pdfannot", "pdfstringdef"
1559−-- , "bibliographystyle"
1560−-- , "maketitle", "makeindex", "makeglossary"
1561−-- , "addcontentsline", "addtocontents", "addtocounter"
1562−-- -- \ignore{} is used conventionally in literate haskell for definitions
1563−-- -- that are to be processed by the compiler but not printed.
1566−-- , "markboth", "markright", "markleft"
1567−-- , "hspace", "vspace"
1573-- graphicsPath :: PandocMonad m => LP m Blocks
1246-- graphicsPath :: PandocMonad m => LP m Blocks
1574-- graphicsPath = do
1247-- graphicsPath = do
1575-- ps <- bgroup *> (manyTill braced egroup)
1248-- ps <- bgroup *> (manyTill braced egroup)
@@ -1598,75 +1271,6 @@ blocks = mconcat <$> many block
1598-- resetCaption :: PandocMonad m => LP m ()
1271-- resetCaption :: PandocMonad m => LP m ()
1599-- resetCaption = updateState $ \st -> st{ stateCaption = Nothing }
1272-- resetCaption = updateState $ \st -> st{ stateCaption = Nothing }
1601−-- authors :: PandocMonad m => LP m ()
1602−-- authors = try $ do
1604−-- let oneAuthor = mconcat <$>
1605−-- many1 (notFollowedBy' (controlSeq "and") >>
1606−-- (inline <|> mempty <$ blockCommand))
1607−-- -- skip e.g. \vspace{10pt}
1608−-- auths <- sepBy oneAuthor (controlSeq "and")
1610−-- addMeta "author" (map trimInlines auths)
1612−-- section :: PandocMonad m => Attr -> Int -> LP m Blocks
1613−-- section (ident, classes, kvs) lvl = do
1615−-- contents <- grouped inline
1616−-- lab <- option ident $ try (spaces' >> controlSeq "label" >> spaces' >> braced)
1617−-- attr' <- registerHeader (lab, classes, kvs) contents
1618−-- return $ headerWith attr' lvl contents
1620−-- inlineCommand :: PandocMonad m => LP m Inlines
1621−-- inlineCommand = try $ do
1622−-- (name, raw') <- withRaw anyControlSeq
1623−-- guard $ name /= "begin" && name /= "end"
1624−-- star <- option "" (string "*")
1625−-- let name' = name ++ star
1627−-- guard $ not (isBlockCommand name)
1628−-- rawargs <- withRaw
1629−-- (skipangles *> skipopts *> option "" dimenarg *> many braced)
1630−-- let rawcommand = raw' ++ star ++ snd rawargs
1631−-- transformed <- applyMacros' rawcommand
1632−-- exts <- getOption readerExtensions
1633−-- if transformed /= rawcommand
1634−-- then parseFromString' inlines transformed
1635−-- else if extensionEnabled Ext_raw_tex exts
1636−-- then return $ rawInline "latex" rawcommand
1637−-- else ignore rawcommand
1638−-- (lookupListDefault raw [name',name] inlineCommands <*
1639−-- optional (try (string "{}")))
1641−-- rawInlineOr :: PandocMonad m => String -> LP m Inlines -> LP m Inlines
1642−-- rawInlineOr name' fallback = do
1643−-- parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions
1645−-- then rawInline "latex" <$> getRawCommand name'
1648−-- isBlockCommand :: String -> Bool
1649−-- isBlockCommand s = s `M.member` (blockCommands :: M.Map String (LP PandocPure Blocks))
1652−-- inlineEnvironments :: PandocMonad m => M.Map String (LP m Inlines)
1653−-- inlineEnvironments = M.fromList
1654−-- [ ("displaymath", mathEnvWith id Nothing "displaymath")
1655−-- , ("math", math <$> mathEnv "math")
1656−-- , ("equation", mathEnvWith id Nothing "equation")
1657−-- , ("equation*", mathEnvWith id Nothing "equation*")
1658−-- , ("gather", mathEnvWith id (Just "gathered") "gather")
1659−-- , ("gather*", mathEnvWith id (Just "gathered") "gather*")
1660−-- , ("multline", mathEnvWith id (Just "gathered") "multline")
1661−-- , ("multline*", mathEnvWith id (Just "gathered") "multline*")
1662−-- , ("eqnarray", mathEnvWith id (Just "aligned") "eqnarray")
1663−-- , ("eqnarray*", mathEnvWith id (Just "aligned") "eqnarray*")
1664−-- , ("align", mathEnvWith id (Just "aligned") "align")
1665−-- , ("align*", mathEnvWith id (Just "aligned") "align*")
1666−-- , ("alignat", mathEnvWith id (Just "aligned") "alignat")
1667−-- , ("alignat*", mathEnvWith id (Just "aligned") "alignat*")
1670-- mkImage :: PandocMonad m => [(String, String)] -> String -> LP m Inlines
1274-- mkImage :: PandocMonad m => [(String, String)] -> String -> LP m Inlines
1671-- mkImage options src = do
1275-- mkImage options src = do
1672-- let replaceTextwidth (k,v) = case numUnit v of
1276-- let replaceTextwidth (k,v) = case numUnit v of
@@ -1701,236 +1305,6 @@ blocks = mconcat <$> many block
1701-- emptyOr160 unit,
1305-- emptyOr160 unit,
1704−-- accent :: (Char -> String) -> Inlines -> LP m Inlines
1706−-- case toList ils of
1707−-- (Str (x:xs) : ys) -> return $ fromList (Str (f x ++ xs) : ys)
1711−-- grave :: Char -> String
1724−-- acute :: Char -> String
1751−-- circ :: Char -> String
1778−-- tilde :: Char -> String
1791−-- umlaut :: Char -> String
1804−-- hungarumlaut :: Char -> String
1805−-- hungarumlaut 'A' = "A̋"
1806−-- hungarumlaut 'E' = "E̋"
1807−-- hungarumlaut 'I' = "I̋"
1808−-- hungarumlaut 'O' = "Ő"
1809−-- hungarumlaut 'U' = "Ű"
1810−-- hungarumlaut 'Y' = "ӳ"
1811−-- hungarumlaut 'a' = "a̋"
1812−-- hungarumlaut 'e' = "e̋"
1813−-- hungarumlaut 'i' = "i̋"
1814−-- hungarumlaut 'o' = "ő"
1815−-- hungarumlaut 'u' = "ű"
1816−-- hungarumlaut 'y' = "ӳ"
1817−-- hungarumlaut c = [c]
1819−-- dot :: Char -> String
1831−-- macron :: Char -> String
1844−-- cedilla :: Char -> String
1845−-- cedilla 'c' = "ç"
1846−-- cedilla 'C' = "Ç"
1847−-- cedilla 's' = "ş"
1848−-- cedilla 'S' = "Ş"
1849−-- cedilla 't' = "ţ"
1850−-- cedilla 'T' = "Ţ"
1851−-- cedilla 'e' = "ȩ"
1852−-- cedilla 'E' = "Ȩ"
1853−-- cedilla 'h' = "ḩ"
1854−-- cedilla 'H' = "Ḩ"
1855−-- cedilla 'o' = "o̧"
1856−-- cedilla 'O' = "O̧"
1859−-- hacek :: Char -> String
1895−-- breve :: Char -> String
1910−-- tok :: PandocMonad m => LP m Inlines
1911−-- tok = try $ grouped inline <|> inlineCommand <|> str <$> count 1 inlineChar
1913−-- opt :: PandocMonad m => LP m Inlines
1914−-- opt = bracketed inline
1916−-- rawopt :: PandocMonad m => LP m String
1918−-- contents <- bracketed (many1 (noneOf "[]") <|> try (string "\\]") <|>
1919−-- try (string "\\[") <|> rawopt)
1921−-- return $ "[" ++ contents ++ "]"
1923−-- skipopts :: PandocMonad m => LP m ()
1924−-- skipopts = skipMany rawopt
1926−-- -- opts in angle brackets are used in beamer
1927−-- rawangle :: PandocMonad m => LP m ()
1928−-- rawangle = try $ do
1930−-- skipMany (noneOf ">")
1934-- skipangles :: PandocMonad m => LP m ()
1308-- skipangles :: PandocMonad m => LP m ()
1935-- skipangles = skipMany rawangle
1309-- skipangles = skipMany rawangle
@@ -1988,21 +1362,6 @@ blocks = mconcat <$> many block
1993−-- keyval :: PandocMonad m => LP m (String, String)
1994−-- keyval = try $ do
1995−-- key <- many1 alphaNum
1996−-- val <- option "" $ char '=' >> braced <|> (many1 (alphaNum <|> oneOf ".:-|\\"))
1997−-- skipMany spaceChar
1998−-- optional (char ',')
1999−-- skipMany spaceChar
2000−-- return (key, val)
2003−-- keyvals :: PandocMonad m => LP m [(String, String)]
2004−-- keyvals = try $ char '[' *> manyTill keyval (char ']')
2006-- alltt :: PandocMonad m => String -> LP m Blocks
1365-- alltt :: PandocMonad m => String -> LP m Blocks
2007-- alltt t = walk strToCode <$> parseFromString' blocks
1366-- alltt t = walk strToCode <$> parseFromString' blocks
2008-- (substitute " " "\\ " $ substitute "%" "\\%" $
1367-- (substitute " " "\\ " $ substitute "%" "\\%" $