Markdown writer: re-use functions from Inline

Instead of duplicating linkAttributes and attrsToMarkdown, let’s just use those from the Inline module.
This commit is contained in:
Jan Tojnar 2021-06-05 16:31:12 +02:00 committed by John MacFarlane
parent 17a2f4c49d
commit c6f8c38c49
2 changed files with 4 additions and 29 deletions

View file

@ -43,7 +43,7 @@ import Text.Pandoc.Templates (renderTemplate)
import Text.DocTemplates (Val(..), Context(..), FromContext(..))
import Text.Pandoc.Walk
import Text.Pandoc.Writers.HTML (writeHtml5String)
import Text.Pandoc.Writers.Markdown.Inline (inlineListToMarkdown)
import Text.Pandoc.Writers.Markdown.Inline (inlineListToMarkdown, linkAttributes, attrsToMarkdown)
import Text.Pandoc.Writers.Markdown.Types (MarkdownVariant(..),
WriterState(..),
WriterEnv(..),
@ -257,39 +257,12 @@ noteToMarkdown opts num blocks = do
then hang (writerTabStop opts) (marker <> spacer) contents
else marker <> spacer <> contents
attrsToMarkdown :: Attr -> Doc Text
attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
where attribId = case attribs of
("",_,_) -> empty
(i,_,_) -> "#" <> escAttr i
attribClasses = case attribs of
(_,[],_) -> empty
(_,cs,_) -> hsep $
map (escAttr . ("."<>))
cs
attribKeys = case attribs of
(_,_,[]) -> empty
(_,_,ks) -> hsep $
map (\(k,v) -> escAttr k
<> "=\"" <>
escAttr v <> "\"") ks
escAttr = mconcat . map escAttrChar . T.unpack
escAttrChar '"' = literal "\\\""
escAttrChar '\\' = literal "\\\\"
escAttrChar c = literal $ T.singleton c
-- | (Code) blocks with a single class can just use it standalone,
-- no need to bother with curly braces.
classOrAttrsToMarkdown :: Attr -> Doc Text
classOrAttrsToMarkdown ("",[cls],_) = literal cls
classOrAttrsToMarkdown attrs = attrsToMarkdown attrs
linkAttributes :: WriterOptions -> Attr -> Doc Text
linkAttributes opts attr =
if isEnabled Ext_link_attributes opts && attr /= nullAttr
then attrsToMarkdown attr
else empty
-- | Ordered list start parser for use in Para below.
olMarker :: Parser Text ParserState ()
olMarker = do (start, style', delim) <- anyOrderedListMarker

View file

@ -11,7 +11,9 @@
Portability : portable
-}
module Text.Pandoc.Writers.Markdown.Inline (
inlineListToMarkdown
inlineListToMarkdown,
linkAttributes,
attrsToMarkdown
) where
import Control.Monad.Reader
import Control.Monad.State.Strict