git.iko.soy/typeable/pandoc
on master help sign in
Markdown writer: re-use functions from Inline

Instead of duplicating linkAttributes and attrsToMarkdown, let’s just use those from the Inline module.

commitc6f8c38c49e9579bf0bc0c91131bb206f0617e6b authorJan Tojnar <jtojnar@gmail.com> dateSat 5 Jun 2021, 16:31 (5 years ago) parent17a2f4c
2 files changed+4−29
src/Text/Pandoc/Writers/Markdown.hs+1−28 src/Text/Pandoc/Writers/Markdown/Inline.hs+3−1
src/Text/Pandoc/Writers/Markdown.hs+1−28
@@ -43,7 +43,7 @@ import Text.Pandoc.Templates (renderTemplate)
4343import Text.DocTemplates (Val(..), Context(..), FromContext(..))
4444import Text.Pandoc.Walk
4545import Text.Pandoc.Writers.HTML (writeHtml5String)
46−import Text.Pandoc.Writers.Markdown.Inline (inlineListToMarkdown)
46+import Text.Pandoc.Writers.Markdown.Inline (inlineListToMarkdown, linkAttributes, attrsToMarkdown)
4747import Text.Pandoc.Writers.Markdown.Types (MarkdownVariant(..),
4848 WriterState(..),
4949 WriterEnv(..),
@@ -257,39 +257,12 @@ noteToMarkdown opts num blocks = do
257257 then hang (writerTabStop opts) (marker <> spacer) contents
258258 else marker <> spacer <> contents
259259
260−attrsToMarkdown :: Attr -> Doc Text
261−attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
262− where attribId = case attribs of
263− ("",_,_) -> empty
264− (i,_,_) -> "#" <> escAttr i
265− attribClasses = case attribs of
266− (_,[],_) -> empty
267− (_,cs,_) -> hsep $
268− map (escAttr . ("."<>))
269− cs
270− attribKeys = case attribs of
271− (_,_,[]) -> empty
272− (_,_,ks) -> hsep $
273− map (\(k,v) -> escAttr k
274− <> "=\"" <>
275− escAttr v <> "\"") ks
276− escAttr = mconcat . map escAttrChar . T.unpack
277− escAttrChar '"' = literal "\\\""
278− escAttrChar '\\' = literal "\\\\"
279− escAttrChar c = literal $ T.singleton c
280−
281260-- | (Code) blocks with a single class can just use it standalone,
282261-- no need to bother with curly braces.
283262classOrAttrsToMarkdown :: Attr -> Doc Text
284263classOrAttrsToMarkdown ("",[cls],_) = literal cls
285264classOrAttrsToMarkdown attrs = attrsToMarkdown attrs
286265
287−linkAttributes :: WriterOptions -> Attr -> Doc Text
288−linkAttributes opts attr =
289− if isEnabled Ext_link_attributes opts && attr /= nullAttr
290− then attrsToMarkdown attr
291− else empty
292−
293266-- | Ordered list start parser for use in Para below.
294267olMarker :: Parser Text ParserState ()
295268olMarker = do (start, style', delim) <- anyOrderedListMarker
src/Text/Pandoc/Writers/Markdown/Inline.hs+3−1
@@ -11,7 +11,9 @@
1111 Portability : portable
1212-}
1313module Text.Pandoc.Writers.Markdown.Inline (
14− inlineListToMarkdown
14+ inlineListToMarkdown,
15+ linkAttributes,
16+ attrsToMarkdown
1517 ) where
1618import Control.Monad.Reader
1719import Control.Monad.State.Strict