diff options
author | John MacFarlane <jgm@berkeley.edu> | 2015-05-26 17:14:42 -0700 |
---|---|---|
committer | John MacFarlane <jgm@berkeley.edu> | 2015-05-26 17:14:42 -0700 |
commit | 24bfc8274e3b5eec3904e8a41f63183a23c56918 (patch) | |
tree | e88f32e82e1cbe5e5df0dd44654f821f7d48b6ee /src | |
parent | fe66122b61f446aca112eeefcd090e33bf1a8f0c (diff) | |
parent | b61355cecd39b84109160cb925af95469a9e01dd (diff) | |
download | pandoc-24bfc8274e3b5eec3904e8a41f63183a23c56918.tar.gz |
Merge pull request #2170 from tarleb/org-generalize-result-block
Org generalize result block
Diffstat (limited to 'src')
-rw-r--r-- | src/Text/Pandoc/Readers/Org.hs | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/Text/Pandoc/Readers/Org.hs b/src/Text/Pandoc/Readers/Org.hs index 65b8d972c..980f63504 100644 --- a/src/Text/Pandoc/Readers/Org.hs +++ b/src/Text/Pandoc/Readers/Org.hs @@ -180,19 +180,6 @@ recordAnchorId :: String -> OrgParser () recordAnchorId i = updateState $ \s -> s{ orgStateAnchorIds = i : (orgStateAnchorIds s) } -addBlockAttribute :: String -> String -> OrgParser () -addBlockAttribute key val = updateState $ \s -> - let attrs = orgStateBlockAttributes s - in s{ orgStateBlockAttributes = M.insert key val attrs } - -lookupBlockAttribute :: String -> OrgParser (Maybe String) -lookupBlockAttribute key = - M.lookup key . orgStateBlockAttributes <$> getState - -resetBlockAttributes :: OrgParser () -resetBlockAttributes = updateState $ \s -> - s{ orgStateBlockAttributes = orgStateBlockAttributes def } - updateLastForbiddenCharPos :: OrgParser () updateLastForbiddenCharPos = getPosition >>= \p -> updateState $ \s -> s{ orgStateLastForbiddenCharPos = Just p} @@ -320,9 +307,18 @@ block = choice [ mempty <$ blanklines , paraOrPlain ] <?> "block" +-- +-- Block Attributes +-- + +-- | Parse optional block attributes (like #+TITLE or #+NAME) optionalAttributes :: OrgParser (F Blocks) -> OrgParser (F Blocks) optionalAttributes parser = try $ resetBlockAttributes *> parseBlockAttributes *> parser + where + resetBlockAttributes :: OrgParser () + resetBlockAttributes = updateState $ \s -> + s{ orgStateBlockAttributes = orgStateBlockAttributes def } parseBlockAttributes :: OrgParser () parseBlockAttributes = do @@ -347,6 +343,15 @@ lookupInlinesAttr attr = try $ do (fmap Just . parseFromString parseInlines) val +addBlockAttribute :: String -> String -> OrgParser () +addBlockAttribute key val = updateState $ \s -> + let attrs = orgStateBlockAttributes s + in s{ orgStateBlockAttributes = M.insert key val attrs } + +lookupBlockAttribute :: String -> OrgParser (Maybe String) +lookupBlockAttribute key = + M.lookup key . orgStateBlockAttributes <$> getState + -- -- Org Blocks (#+BEGIN_... / #+END_...) @@ -402,11 +407,11 @@ exportsResults :: [(String, String)] -> Bool exportsResults attrs = ("rundoc-exports", "results") `elem` attrs || ("rundoc-exports", "both") `elem` attrs -followingResultsBlock :: OrgParser (Maybe String) +followingResultsBlock :: OrgParser (Maybe (F Blocks)) followingResultsBlock = optionMaybe (try $ blanklines *> stringAnyCase "#+RESULTS:" *> blankline - *> (unlines <$> many1 exampleLine)) + *> block) codeBlock :: BlockProperties -> OrgParser (F Blocks) codeBlock blkProp = do @@ -421,7 +426,7 @@ codeBlock blkProp = do labelledBlck <- maybe (pure codeBlck) (labelDiv codeBlck) <$> lookupInlinesAttr "caption" - let resultBlck = pure $ maybe mempty (exampleCode) resultsContent + let resultBlck = fromMaybe mempty resultsContent return $ (if includeCode then labelledBlck else mempty) <> (if includeResults then resultBlck else mempty) where |