diff options
| author | John MacFarlane <[email protected]> | 2022-08-27 17:30:17 -0700 |
|---|---|---|
| committer | John MacFarlane <[email protected]> | 2022-08-27 17:30:17 -0700 |
| commit | 1d92024bcb14c976d4ad6daa079b296c54c2bafb (patch) | |
| tree | b730e3c3547a22eaf5034220ddd680807440dcaa /src/Text | |
| parent | eadcb4f97e4dcc370fe9c7979d48809a39906d50 (diff) | |
HTML, Markdown writers: filter out empty class attributes.
These should not be generated by any pandoc readers, but they
might be produced programatically. Technically that's a misuse
of the AST, but since the expectation that the classes are
nonempty strigs is not encoded in the types, it can happen. This patch
limits the damage if it does, preventing invalid markdown attributes
like `{.}` from being written.
Cloess #8251.
Diffstat (limited to 'src/Text')
| -rw-r--r-- | src/Text/Pandoc/Writers/HTML.hs | 3 | ||||
| -rw-r--r-- | src/Text/Pandoc/Writers/Markdown/Inline.hs | 4 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/Text/Pandoc/Writers/HTML.hs b/src/Text/Pandoc/Writers/HTML.hs index 0610351d0..010815d00 100644 --- a/src/Text/Pandoc/Writers/HTML.hs +++ b/src/Text/Pandoc/Writers/HTML.hs @@ -679,9 +679,10 @@ attrsToHtml :: PandocMonad m => WriterOptions -> Attr -> StateT WriterState m [Attribute] attrsToHtml opts (id',classes',keyvals) = do attrs <- toAttrs keyvals + let classes'' = filter (not . T.null) classes' return $ [prefixedId opts id' | not (T.null id')] ++ - [A.class_ (toValue $ T.unwords classes') | not (null classes')] ++ attrs + [A.class_ (toValue $ T.unwords classes'') | not (null classes'')] ++ attrs imgAttrsToHtml :: PandocMonad m => WriterOptions -> Attr -> StateT WriterState m [Attribute] diff --git a/src/Text/Pandoc/Writers/Markdown/Inline.hs b/src/Text/Pandoc/Writers/Markdown/Inline.hs index 4e98530b1..d9e4cebb3 100644 --- a/src/Text/Pandoc/Writers/Markdown/Inline.hs +++ b/src/Text/Pandoc/Writers/Markdown/Inline.hs @@ -117,8 +117,8 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys] attribClasses = case attribs of (_,[],_) -> empty (_,cs,_) -> hsep $ - map (escAttr . ("."<>)) - cs + map (escAttr . ("."<>)) $ + filter (not . T.null) cs attribKeys = case attribs of (_,_,[]) -> empty (_,_,ks) -> hsep $ |
