@@ -34,8 +34,8 @@ module Text.Pandoc.Readers.Org.Blocks
36import Text.Pandoc.Readers.Org.BlockStarts
36import Text.Pandoc.Readers.Org.BlockStarts
37−import Text.Pandoc.Readers.Org.ExportSettings ( exportSettings )
38import Text.Pandoc.Readers.Org.Inlines
37import Text.Pandoc.Readers.Org.Inlines
38+import Text.Pandoc.Readers.Org.Meta ( metaLine )
39import Text.Pandoc.Readers.Org.ParserState
39import Text.Pandoc.Readers.Org.ParserState
40import Text.Pandoc.Readers.Org.Parsing
40import Text.Pandoc.Readers.Org.Parsing
41import Text.Pandoc.Readers.Org.Shared
41import Text.Pandoc.Readers.Org.Shared
@@ -52,9 +52,7 @@ import Text.Pandoc.Shared ( compactify', compactify'DL )
52import Control.Monad ( foldM, guard, mzero, void )
52import Control.Monad ( foldM, guard, mzero, void )
53import Data.Char ( isSpace, toLower, toUpper)
53import Data.Char ( isSpace, toLower, toUpper)
54import Data.List ( foldl', intersperse, isPrefixOf )
54import Data.List ( foldl', intersperse, isPrefixOf )
55−import qualified Data.Map as M
56import Data.Maybe ( fromMaybe, isNothing )
55import Data.Maybe ( fromMaybe, isNothing )
57−import Network.HTTP ( urlEncode )
60-- Org headers
58-- Org headers
@@ -631,67 +629,9 @@ exampleCode = B.codeBlockWith ("", ["example"], [])
631specialLine :: OrgParser (F Blocks)
629specialLine :: OrgParser (F Blocks)
632specialLine = fmap return . try $ metaLine <|> commentLine
630specialLine = fmap return . try $ metaLine <|> commentLine
634−-- The order, in which blocks are tried, makes sure that we're not looking at
635−-- the beginning of a block, so we don't need to check for it
636−metaLine :: OrgParser Blocks
637−metaLine = mempty <$ metaLineStart <* (optionLine <|> declarationLine)
639commentLine :: OrgParser Blocks
632commentLine :: OrgParser Blocks
640commentLine = commentLineStart *> anyLine *> pure mempty
633commentLine = commentLineStart *> anyLine *> pure mempty
642−declarationLine :: OrgParser ()
643−declarationLine = try $ do
645− value <- metaInlines
646− updateState $ \st ->
647− let meta' = B.setMeta key <$> value <*> pure nullMeta
648− in st { orgStateMeta = orgStateMeta st <> meta' }
650−metaInlines :: OrgParser (F MetaValue)
651−metaInlines = fmap (MetaInlines . B.toList) <$> inlinesTillNewline
653−metaKey :: OrgParser String
654−metaKey = map toLower <$> many1 (noneOf ": \n\r")
658−optionLine :: OrgParser ()
659−optionLine = try $ do
662− "link" -> parseLinkFormat >>= uncurry addLinkFormat
663− "options" -> exportSettings
666−addLinkFormat :: String
667− -> (String -> String)
669−addLinkFormat key formatter = updateState $ \s ->
670− let fs = orgStateLinkFormatters s
671− in s{ orgStateLinkFormatters = M.insert key formatter fs }
673−parseLinkFormat :: OrgParser ((String, String -> String))
674−parseLinkFormat = try $ do
675− linkType <- (:) <$> letter <*> many (alphaNum <|> oneOf "-_") <* skipSpaces
676− linkSubst <- parseFormat
677− return (linkType, linkSubst)
679−-- | An ad-hoc, single-argument-only implementation of a printf-style format
681−parseFormat :: OrgParser (String -> String)
682−parseFormat = try $ do
683− replacePlain <|> replaceUrl <|> justAppend
685− -- inefficient, but who cares
686− replacePlain = try $ (\x -> concat . flip intersperse x)
687− <$> sequence [tillSpecifier 's', rest]
688− replaceUrl = try $ (\x -> concat . flip intersperse x . urlEncode)
689− <$> sequence [tillSpecifier 'h', rest]
690− justAppend = try $ (++) <$> rest
692− rest = manyTill anyChar (eof <|> () <$ oneOf "\n\r")
693− tillSpecifier c = manyTill (noneOf "\n\r") (try $ string ('%':c:""))
@@ -868,9 +808,6 @@ paraOrPlain = try $ do
868 *> return (B.para <$> ils))
808 *> return (B.para <$> ils))
869 <|> (return (B.plain <$> ils))
809 <|> (return (B.plain <$> ils))
871−inlinesTillNewline :: OrgParser (F Inlines)
872−inlinesTillNewline = trimInlinesF . mconcat <$> manyTill inline newline
876-- list blocks
813-- list blocks