"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Text/Pandoc/Readers/Org/Blocks.hs" between
pandoc-2.11.1.1.tar.gz and pandoc-2.11.2.tar.gz

About: Pandoc converts files from one markup format into another.

Blocks.hs  (pandoc-2.11.1.1):Blocks.hs  (pandoc-2.11.2)
skipping to change at line 112 skipping to change at line 112
attrFromBlockAttributes BlockAttributes{..} = attrFromBlockAttributes BlockAttributes{..} =
let let
ident = fromMaybe mempty $ lookup "id" blockAttrKeyValues ident = fromMaybe mempty $ lookup "id" blockAttrKeyValues
classes = maybe [] T.words $ lookup "class" blockAttrKeyValues classes = maybe [] T.words $ lookup "class" blockAttrKeyValues
kv = filter ((`notElem` ["id", "class"]) . fst) blockAttrKeyValues kv = filter ((`notElem` ["id", "class"]) . fst) blockAttrKeyValues
in (ident, classes, kv) in (ident, classes, kv)
stringyMetaAttribute :: Monad m => OrgParser m (Text, Text) stringyMetaAttribute :: Monad m => OrgParser m (Text, Text)
stringyMetaAttribute = try $ do stringyMetaAttribute = try $ do
metaLineStart metaLineStart
attrName <- T.toUpper <$> many1TillChar nonspaceChar (char ':') attrName <- T.toLower <$> many1TillChar nonspaceChar (char ':')
skipSpaces skipSpaces
attrValue <- anyLine <|> ("" <$ newline) attrValue <- anyLine <|> ("" <$ newline)
return (attrName, attrValue) return (attrName, attrValue)
-- | Parse a set of block attributes. Block attributes are given through -- | Parse a set of block attributes. Block attributes are given through
-- lines like @#+caption: block caption@ or @#+attr_html: :width 20@.
-- Parsing will fail if any line contains an attribute different from -- Parsing will fail if any line contains an attribute different from
-- those attributes known to work on blocks. -- those attributes known to work on blocks.
blockAttributes :: PandocMonad m => OrgParser m BlockAttributes blockAttributes :: PandocMonad m => OrgParser m BlockAttributes
blockAttributes = try $ do blockAttributes = try $ do
kv <- many stringyMetaAttribute kv <- many stringyMetaAttribute
guard $ all (isBlockAttr . fst) kv guard $ all (isBlockAttr . fst) kv
let caption = foldl' (appendValues "CAPTION") Nothing kv let caption = foldl' (appendValues "caption") Nothing kv
let kvAttrs = foldl' (appendValues "ATTR_HTML") Nothing kv let kvAttrs = foldl' (appendValues "attr_html") Nothing kv
let name = lookup "NAME" kv let name = lookup "name" kv
let label = lookup "LABEL" kv let label = lookup "label" kv
caption' <- traverse (parseFromString inlines . (<> "\n")) caption caption' <- traverse (parseFromString inlines . (<> "\n")) caption
kvAttrs' <- parseFromString keyValues . (<> "\n") $ fromMaybe mempty kvAttrs kvAttrs' <- parseFromString keyValues . (<> "\n") $ fromMaybe mempty kvAttrs
return BlockAttributes return BlockAttributes
{ blockAttrName = name { blockAttrName = name
, blockAttrLabel = label , blockAttrLabel = label
, blockAttrCaption = caption' , blockAttrCaption = caption'
, blockAttrKeyValues = kvAttrs' , blockAttrKeyValues = kvAttrs'
} }
where where
isBlockAttr :: Text -> Bool isBlockAttr :: Text -> Bool
isBlockAttr = flip elem isBlockAttr = flip elem
[ "NAME", "LABEL", "CAPTION" [ "name", "label", "caption"
, "ATTR_HTML", "ATTR_LATEX" , "attr_html", "attr_latex"
, "RESULTS" , "results"
] ]
appendValues :: Text -> Maybe Text -> (Text, Text) -> Maybe Text appendValues :: Text -> Maybe Text -> (Text, Text) -> Maybe Text
appendValues attrName accValue (key, value) = appendValues attrName accValue (key, value) =
if key /= attrName if key /= attrName
then accValue then accValue
else case accValue of else case accValue of
Just acc -> Just $ acc <> " " <> value Just acc -> Just $ acc <> " " <> value
Nothing -> Just value Nothing -> Just value
skipping to change at line 170 skipping to change at line 170
value :: Monad m => OrgParser m Text value :: Monad m => OrgParser m Text
value = skipSpaces *> manyTillChar anyChar endOfValue value = skipSpaces *> manyTillChar anyChar endOfValue
endOfValue :: Monad m => OrgParser m () endOfValue :: Monad m => OrgParser m ()
endOfValue = endOfValue =
lookAhead $ (() <$ try (many1 spaceChar <* key)) lookAhead $ (() <$ try (many1 spaceChar <* key))
<|> () <$ newline <|> () <$ newline
-- --
-- Org Blocks (#+begin_... / #+end_...)
-- --
-- | Read an org-mode block delimited by #+begin_type and #+end_type.
orgBlock :: PandocMonad m => OrgParser m (F Blocks) orgBlock :: PandocMonad m => OrgParser m (F Blocks)
orgBlock = try $ do orgBlock = try $ do
blockAttrs <- blockAttributes blockAttrs <- blockAttributes
blkType <- blockHeaderStart blkType <- blockHeaderStart
($ blkType) $ ($ blkType) $
case T.toLower blkType of case T.toLower blkType of
"export" -> exportBlock "export" -> exportBlock
"comment" -> rawBlockLines (const mempty) "comment" -> rawBlockLines (const mempty)
"html" -> rawBlockLines (return . B.rawBlock (lowercase blkType)) "html" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
"latex" -> rawBlockLines (return . B.rawBlock (lowercase blkType)) "latex" -> rawBlockLines (return . B.rawBlock (lowercase blkType))
 End of changes. 6 change blocks. 
8 lines changed or deleted 11 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)