git.iko.soy/typeable/pandoc
on master help sign in
Updated readers, writers and README for link attribute
commita010b83a7542d1324bde3d248c24faae9e681dbd authormb21 <mb21@users.noreply.github.com> dateSun 26 Jul 2015, 18:30 (11 years ago) parente44fc54
30 files changed+122−125
README+4−9 src/Text/Pandoc/Readers/CommonMark.hs+1−1 src/Text/Pandoc/Readers/DocBook.hs+2−1 src/Text/Pandoc/Readers/Docx.hs+2−2 src/Text/Pandoc/Readers/EPUB.hs+6−6 src/Text/Pandoc/Readers/HTML.hs+4−14 src/Text/Pandoc/Readers/RST.hs+1−1 src/Text/Pandoc/Shared.hs+2−2 src/Text/Pandoc/Writers/AsciiDoc.hs+1−1 src/Text/Pandoc/Writers/CommonMark.hs+1−1 src/Text/Pandoc/Writers/ConTeXt.hs+4−5 src/Text/Pandoc/Writers/Custom.hs+1−1 src/Text/Pandoc/Writers/Docbook.hs+16−12 src/Text/Pandoc/Writers/Docx.hs+2−2 src/Text/Pandoc/Writers/DokuWiki.hs+2−2 src/Text/Pandoc/Writers/EPUB.hs+3−3 src/Text/Pandoc/Writers/FB2.hs+2−2 src/Text/Pandoc/Writers/HTML.hs+12−11 src/Text/Pandoc/Writers/Haddock.hs+3−3 src/Text/Pandoc/Writers/ICML.hs+1−1 src/Text/Pandoc/Writers/LaTeX.hs+6−6 src/Text/Pandoc/Writers/Man.hs+3−3 src/Text/Pandoc/Writers/Markdown.hs+27−22 src/Text/Pandoc/Writers/MediaWiki.hs+1−1 src/Text/Pandoc/Writers/OpenDocument.hs+1−1 src/Text/Pandoc/Writers/Org.hs+1−1 src/Text/Pandoc/Writers/RST.hs+4−4 src/Text/Pandoc/Writers/RTF.hs+1−1 src/Text/Pandoc/Writers/Texinfo.hs+2−2 src/Text/Pandoc/Writers/Textile.hs+6−4
README+4−9
@@ -2644,7 +2644,7 @@ nonbreaking space after the image:
26442644
26452645#### Extension: `common_link_attributes` ####
26462646
2647−Attributes can be set on images:
2647+Attributes can be set on links and images:
26482648
26492649 An inline ![image](foo.jpg){#id .class width=30 height=20px}
26502650 and a reference ![image][ref] with attributes.
@@ -2666,7 +2666,7 @@ and `%`. There must not be any spaces between the number and the unit.
26662666For example:
26672667
26682668```
2669−![](file.jpg){width=50%}
2669+![](file.jpg){ width=50% }
26702670```
26712671
26722672- Dimensions are converted to inches for output in page-based formats like
@@ -2685,10 +2685,6 @@ For example:
26852685 is to look at the image resolution and the dpi metadata embedded in
26862686 the image file.
26872687
2688−Note that while attributes are also parsed on links, pandoc's internal
2689−document model provides nowhere to put them, so they are presently
2690−just ignored.
2691−
26922688
26932689Footnotes
26942690---------
@@ -2964,9 +2960,8 @@ letters are omitted.
29642960#### Extension: `link_attributes` ####
29652961
29662962Parses multimarkdown style key-value attributes on link
2967−and image references. (Since pandoc's internal document model
2968−provides nowhere to put these for links, they are presently just
2969−ignored, but they work for images.)
2963+and image references. This extension should not be confused with the
2964+[`common_link_attributes`](#extension-common_link_attributes) extension.
29702965
29712966 This is a reference ![image][ref] with multimarkdown attributes.
29722967
src/Text/Pandoc/Readers/CommonMark.hs+1−1
@@ -113,7 +113,7 @@ addInline (Node _ EMPH nodes) =
113113addInline (Node _ STRONG nodes) =
114114 (Strong (addInlines nodes) :)
115115addInline (Node _ (LINK url title) nodes) =
116− (Link (addInlines nodes) (unpack url, unpack title) :)
116+ (Link nullAttr (addInlines nodes) (unpack url, unpack title) :)
117117addInline (Node _ (IMAGE url title) nodes) =
118118 (Image nullAttr (addInlines nodes) (unpack url, unpack title) :)
119119addInline _ = id
src/Text/Pandoc/Readers/DocBook.hs+2−1
@@ -967,7 +967,8 @@ parseInline (Elem e) =
967967 Just h -> h
968968 _ -> ('#' : attrValue "linkend" e)
969969 let ils' = if ils == mempty then str href else ils
970− return $ link href "" ils'
970+ let attr = (attrValue "id" e, words $ attrValue "role" e, [])
971+ return $ linkWith href "" attr ils'
971972 "foreignphrase" -> emph <$> innerInlines
972973 "emphasis" -> case attrValue "role" e of
973974 "bold" -> strong <$> innerInlines
src/Text/Pandoc/Readers/Docx.hs+2−2
@@ -533,10 +533,10 @@ bodyPartToBlocks (OMathPara e) = do
533533
534534-- replace targets with generated anchors.
535535rewriteLink' :: Inline -> DocxContext Inline
536−rewriteLink' l@(Link ils ('#':target, title)) = do
536+rewriteLink' l@(Link attr ils ('#':target, title)) = do
537537 anchorMap <- gets docxAnchorMap
538538 return $ case M.lookup target anchorMap of
539− Just newTarget -> (Link ils ('#':newTarget, title))
539+ Just newTarget -> (Link attr ils ('#':newTarget, title))
540540 Nothing -> l
541541rewriteLink' il = return il
542542
src/Text/Pandoc/Readers/EPUB.hs+6−6
@@ -192,20 +192,20 @@ fixInlineIRs s (Span as v) =
192192 Span (fixAttrs s as) v
193193fixInlineIRs s (Code as code) =
194194 Code (fixAttrs s as) code
195−fixInlineIRs s (Link t ('#':url, tit)) =
196− Link t (addHash s url, tit)
195+fixInlineIRs s (Link attr t ('#':url, tit)) =
196+ Link attr t (addHash s url, tit)
197197fixInlineIRs _ v = v
198198
199199normalisePath :: Inline -> Inline
200−normalisePath (Link t (url, tit)) =
200+normalisePath (Link attr t (url, tit)) =
201201 let (path, uid) = span (/= '#') url in
202− Link t (takeFileName path ++ uid, tit)
202+ Link attr t (takeFileName path ++ uid, tit)
203203normalisePath s = s
204204
205205prependHash :: [String] -> Inline -> Inline
206−prependHash ps l@(Link is (url, tit))
206+prependHash ps l@(Link attr is (url, tit))
207207 | or [s `isPrefixOf` url | s <- ps] =
208− Link is ('#':url, tit)
208+ Link attr is ('#':url, tit)
209209 | otherwise = l
210210prependHash _ i = i
211211
src/Text/Pandoc/Readers/HTML.hs+4−14
@@ -576,16 +576,8 @@ pLineBreak = do
576576 return B.linebreak
577577
578578pLink :: TagParser Inlines
579−pLink = pRelLink <|> pAnchor
580−
581−pAnchor :: TagParser Inlines
582−pAnchor = try $ do
583− tag <- pSatisfy (tagOpenLit "a" (isJust . lookup "id"))
584− return $ B.spanWith (fromAttrib "id" tag , [], []) mempty
585−
586−pRelLink :: TagParser Inlines
587−pRelLink = try $ do
588− tag <- pSatisfy (tagOpenLit "a" (isJust . lookup "href"))
579+pLink = try $ do
580+ tag <- pSatisfy $ tagOpenLit "a" (const True)
589581 mbBaseHref <- baseHref <$> getState
590582 let url' = fromAttrib "href" tag
591583 let url = case (isURI url', mbBaseHref) of
@@ -593,11 +585,9 @@ pRelLink = try $ do
593585 _ -> url'
594586 let title = fromAttrib "title" tag
595587 let uid = fromAttrib "id" tag
596− let spanC = case uid of
597− [] -> id
598− s -> B.spanWith (s, [], [])
588+ let cls = words $ fromAttrib "class" tag
599589 lab <- trimInlines . mconcat <$> manyTill inline (pCloses "a")
600− return $ spanC $ B.link (escapeURI url) title lab
590+ return $ B.linkWith (escapeURI url) title (uid, cls, []) lab
601591
602592pImage :: TagParser Inlines
603593pImage = do
src/Text/Pandoc/Readers/RST.hs+1−1
@@ -814,7 +814,7 @@ substKey = try $ do
814814 -- use alt unless :alt: attribute on image:
815815 [Para [Image _ [Str "image"] (src,tit)]] ->
816816 return $ B.image src tit alt
817− [Para [Link [Image _ [Str "image"] (src,tit)] (src',tit')]] ->
817+ [Para [Link _ [Image _ [Str "image"] (src,tit)] (src',tit')]] ->
818818 return $ B.link src' tit' (B.image src tit alt)
819819 [Para ils] -> return $ B.fromList ils
820820 _ -> mzero
src/Text/Pandoc/Shared.hs+2−2
@@ -507,8 +507,8 @@ normalizeInlines (Note bs : ys) = Note (normalizeBlocks bs) :
507507 normalizeInlines ys
508508normalizeInlines (Quoted qt ils : ys) =
509509 Quoted qt (normalizeInlines ils) : normalizeInlines ys
510−normalizeInlines (Link ils t : ys) =
511− Link (normalizeInlines ils) t : normalizeInlines ys
510+normalizeInlines (Link attr ils t : ys) =
511+ Link attr (normalizeInlines ils) t : normalizeInlines ys
512512normalizeInlines (Image attr ils t : ys) =
513513 Image attr (normalizeInlines ils) t : normalizeInlines ys
514514normalizeInlines (Cite cs ils : ys) =
src/Text/Pandoc/Writers/AsciiDoc.hs+1−1
@@ -394,7 +394,7 @@ inlineToAsciiDoc _ (RawInline f s)
394394inlineToAsciiDoc _ (LineBreak) = return $ " +" <> cr
395395inlineToAsciiDoc _ Space = return space
396396inlineToAsciiDoc opts (Cite _ lst) = inlineListToAsciiDoc opts lst
397−inlineToAsciiDoc opts (Link txt (src, _tit)) = do
397+inlineToAsciiDoc opts (Link _ txt (src, _tit)) = do
398398-- relative: link:downloads/foo.zip[download foo.zip]
399399-- abs: http://google.cod[Google]
400400-- or my@email.com[email john]
src/Text/Pandoc/Writers/CommonMark.hs+1−1
@@ -153,7 +153,7 @@ inlineToNodes (SmallCaps xs) =
153153 ((node (INLINE_HTML (T.pack "<span style=\"font-variant:small-caps;\">")) []
154154 : inlinesToNodes xs ++
155155 [node (INLINE_HTML (T.pack "</span>")) []]) ++ )
156−inlineToNodes (Link ils (url,tit)) =
156+inlineToNodes (Link _ ils (url,tit)) =
157157 (node (LINK (T.pack url) (T.pack tit)) (inlinesToNodes ils) :)
158158inlineToNodes (Image _ ils (url,tit)) =
159159 (node (IMAGE (T.pack url) (T.pack tit)) (inlinesToNodes ils) :)
src/Text/Pandoc/Writers/ConTeXt.hs+4−5
@@ -303,7 +303,7 @@ inlineToConTeXt (RawInline _ _) = return empty
303303inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
304304inlineToConTeXt Space = return space
305305-- Handle HTML-like internal document references to sections
306−inlineToConTeXt (Link txt (('#' : ref), _)) = do
306+inlineToConTeXt (Link _ txt (('#' : ref), _)) = do
307307 opts <- gets stOptions
308308 contents <- inlineListToConTeXt txt
309309 let ref' = toLabel $ stringToConTeXt opts ref
@@ -311,7 +311,7 @@ inlineToConTeXt (Link txt (('#' : ref), _)) = do
311311 <> braces contents
312312 <> brackets (text ref')
313313
314−inlineToConTeXt (Link txt (src, _)) = do
314+inlineToConTeXt (Link _ txt (src, _)) = do
315315 let isAutolink = txt == [Str (unEscapeString src)]
316316 st <- get
317317 let next = stNextRef st
@@ -326,10 +326,9 @@ inlineToConTeXt (Link txt (src, _)) = do
326326 else brackets empty <> brackets contents)
327327 <> "\\from"
328328 <> brackets (text ref)
329−inlineToConTeXt (Image attr _ (src, _)) = do
329+inlineToConTeXt (Image attr@(_,cls,_) _ (src, _)) = do
330330 opts <- gets stOptions
331− let (_,cls,_) = attr
332− showDim dir = let d = text (show dir) <> "="
331+ let showDim dir = let d = text (show dir) <> "="
333332 in case (dimension dir attr) of
334333 Just (Pixel a) ->
335334 [d <> text (showInInch opts (Pixel a)) <> "in"]
src/Text/Pandoc/Writers/Custom.hs+1−1
@@ -309,7 +309,7 @@ inlineToCustom lua (RawInline format str) =
309309
310310inlineToCustom lua (LineBreak) = callfunc lua "LineBreak"
311311
312−inlineToCustom lua (Link txt (src,tit)) =
312+inlineToCustom lua (Link _ txt (src,tit)) =
313313 callfunc lua "Link" txt src tit
314314
315315inlineToCustom lua (Image _ alt (src,tit)) =
src/Text/Pandoc/Writers/Docbook.hs+16−12
@@ -153,16 +153,9 @@ listItemToDocbook opts item =
153153 inTagsIndented "listitem" $ blocksToDocbook opts $ map plainToPara item
154154
155155imageToDocbook :: WriterOptions -> Attr -> String -> Doc
156−imageToDocbook _ attr src = selfClosingTag "imagedata" $ ("fileref", src):ident
157− ++ roles ++ dims
156+imageToDocbook _ attr src = selfClosingTag "imagedata" $
157+ ("fileref", src) : idAndRole attr ++ dims
158158 where
159− (idStr,cls,_) = attr
160− ident = if null idStr
161− then []
162− else [("id", idStr)]
163− roles = if null cls
164− then []
165− else [("role", unwords cls)]
166159 dims = go Width "width" ++ go Height "depth"
167160 go dir dstr = case (dimension dir attr) of
168161 Just a -> [(dstr, show a)]
@@ -339,7 +332,7 @@ inlineToDocbook _ (RawInline f x) | f == "html" || f == "docbook" = text x
339332 | otherwise = empty
340333inlineToDocbook _ LineBreak = text "\n"
341334inlineToDocbook _ Space = space
342−inlineToDocbook opts (Link txt (src, _))
335+inlineToDocbook opts (Link attr txt (src, _))
343336 | Just email <- stripPrefix "mailto:" src =
344337 let emailLink = inTagsSimple "email" $ text $
345338 escapeStringForXML $ email
@@ -349,8 +342,8 @@ inlineToDocbook opts (Link txt (src, _))
349342 char '(' <> emailLink <> char ')'
350343 | otherwise =
351344 (if isPrefixOf "#" src
352− then inTags False "link" [("linkend", drop 1 src)]
353− else inTags False "ulink" [("url", src)]) $
345+ then inTags False "link" $ ("linkend", drop 1 src) : idAndRole attr
346+ else inTags False "ulink" $ ("url", src) : idAndRole attr ) $
354347 inlinesToDocbook opts txt
355348inlineToDocbook opts (Image attr _ (src, tit)) =
356349 let titleDoc = if null tit
@@ -365,3 +358,14 @@ inlineToDocbook opts (Note contents) =
365358isMathML :: HTMLMathMethod -> Bool
366359isMathML (MathML _) = True
367360isMathML _ = False
361+
362+idAndRole :: Attr -> [(String, String)]
363+idAndRole (id',cls,_) = ident ++ role
364+ where
365+ ident = if null id'
366+ then []
367+ else [("id", id')]
368+ role = if null cls
369+ then []
370+ else [("role", unwords cls)]
371+
src/Text/Pandoc/Writers/Docx.hs+2−2
@@ -1087,11 +1087,11 @@ inlineToOpenXML opts (Note bs) = do
10871087 [ mknode "w:rPr" [] footnoteStyle
10881088 , mknode "w:footnoteReference" [("w:id", notenum)] () ] ]
10891089-- internal link:
1090−inlineToOpenXML opts (Link txt ('#':xs,_)) = do
1090+inlineToOpenXML opts (Link _ txt ('#':xs,_)) = do
10911091 contents <- withTextPropM (rStyleM "Hyperlink") $ inlinesToOpenXML opts txt
10921092 return [ mknode "w:hyperlink" [("w:anchor",xs)] contents ]
10931093-- external link:
1094−inlineToOpenXML opts (Link txt (src,_)) = do
1094+inlineToOpenXML opts (Link _ txt (src,_)) = do
10951095 contents <- withTextPropM (rStyleM "Hyperlink") $ inlinesToOpenXML opts txt
10961096 extlinks <- gets stExternalLinks
10971097 id' <- case M.lookup src extlinks of
src/Text/Pandoc/Writers/DokuWiki.hs+2−2
@@ -464,13 +464,13 @@ inlineToDokuWiki _ (LineBreak) = return "\\\\\n"
464464
465465inlineToDokuWiki _ Space = return " "
466466
467−inlineToDokuWiki opts (Link txt (src, _)) = do
467+inlineToDokuWiki opts (Link _ txt (src, _)) = do
468468 label <- inlineListToDokuWiki opts txt
469469 case txt of
470470 [Str s] | "mailto:" `isPrefixOf` src -> return $ "<" ++ s ++ ">"
471471 | escapeURI s == src -> return src
472472 _ -> if isURI src
473− then return $ "[[" ++ src ++ "|" ++ label ++ "]]"
473+ then return $ "[[" ++ src ++ "|" ++ label ++ "]]"
474474 else return $ "[[" ++ src' ++ "|" ++ label ++ "]]"
475475 where src' = case src of
476476 '/':xs -> xs -- with leading / it's a
src/Text/Pandoc/Writers/EPUB.hs+3−3
@@ -457,10 +457,10 @@ writeEPUB opts doc@(Pandoc meta _) = do
457457 chapters' [1..]
458458
459459 let fixInternalReferences :: Inline -> Inline
460− fixInternalReferences (Link lab ('#':xs, tit)) =
460+ fixInternalReferences (Link attr lab ('#':xs, tit)) =
461461 case lookup xs reftable of
462− Just ys -> Link lab (ys, tit)
463− Nothing -> Link lab ('#':xs, tit)
462+ Just ys -> Link attr lab (ys, tit)
463+ Nothing -> Link attr lab ('#':xs, tit)
464464 fixInternalReferences x = x
465465
466466 -- internal reference IDs change when we chunk the file,
src/Text/Pandoc/Writers/FB2.hs+2−2
@@ -442,7 +442,7 @@ toXml Space = return [txt " "]
442442toXml LineBreak = return [el "empty-line" ()]
443443toXml (Math _ formula) = insertMath InlineImage formula
444444toXml (RawInline _ _) = return [] -- raw TeX and raw HTML are suppressed
445−toXml (Link text (url,ttl)) = do
445+toXml (Link _ text (url,ttl)) = do
446446 fns <- footnotes `liftM` get
447447 let n = 1 + length fns
448448 let ln_id = linkID n
@@ -572,7 +572,7 @@ plain Space = " "
572572plain LineBreak = "\n"
573573plain (Math _ s) = s
574574plain (RawInline _ s) = s
575−plain (Link text (url,_)) = concat (map plain text ++ [" <", url, ">"])
575+plain (Link _ text (url,_)) = concat (map plain text ++ [" <", url, ">"])
576576plain (Image _ alt _) = concat (map plain alt)
577577plain (Note _) = "" -- FIXME
578578
src/Text/Pandoc/Writers/HTML.hs+12−11
@@ -363,10 +363,10 @@ parseMailto s = do
363363 _ -> fail "not a mailto: URL"
364364
365365-- | Obfuscate a "mailto:" link.
366−obfuscateLink :: WriterOptions -> Html -> String -> Html
367−obfuscateLink opts txt s | writerEmailObfuscation opts == NoObfuscation =
368− H.a ! A.href (toValue s) $ txt
369−obfuscateLink opts (renderHtml -> txt) s =
366+obfuscateLink :: WriterOptions -> Attr -> Html -> String -> Html
367+obfuscateLink opts attr txt s | writerEmailObfuscation opts == NoObfuscation =
368+ addAttrs opts attr $ H.a ! A.href (toValue s) $ txt
369+obfuscateLink opts attr (renderHtml -> txt) s =
370370 let meth = writerEmailObfuscation opts
371371 s' = map toLower (take 7 s) ++ drop 7 s
372372 in case parseMailto s' of
@@ -392,7 +392,7 @@ obfuscateLink opts (renderHtml -> txt) s =
392392 linkText ++ "+'<\\/'+'a'+'>');\n// -->\n")) >>
393393 H.noscript (preEscapedString $ obfuscateString altText)
394394 _ -> error $ "Unknown obfuscation method: " ++ show meth
395− _ -> H.a ! A.href (toValue s) $ toHtml txt -- malformed email
395+ _ -> addAttrs opts attr $ H.a ! A.href (toValue s) $ toHtml txt -- malformed email
396396
397397-- | Obfuscate character as entity.
398398obfuscateChar :: Char -> String
@@ -808,10 +808,10 @@ inlineToHtml opts inline =
808808 _ -> return mempty
809809 | f == Format "html" -> return $ preEscapedString str
810810 | otherwise -> return mempty
811− (Link txt (s,_)) | "mailto:" `isPrefixOf` s -> do
811+ (Link attr txt (s,_)) | "mailto:" `isPrefixOf` s -> do
812812 linkText <- inlineListToHtml opts txt
813− return $ obfuscateLink opts linkText s
814− (Link txt (s,tit)) -> do
813+ return $ obfuscateLink opts attr linkText s
814+ (Link attr txt (s,tit)) -> do
815815 linkText <- inlineListToHtml opts txt
816816 let s' = case s of
817817 '#':xs | writerSlideVariant opts ==
@@ -821,9 +821,10 @@ inlineToHtml opts inline =
821821 let link' = if txt == [Str (unEscapeString s)]
822822 then link ! A.class_ "uri"
823823 else link
824+ let link'' = addAttrs opts attr link'
824825 return $ if null tit
825− then link'
826− else link' ! A.title (toValue tit)
826+ then link''
827+ else link'' ! A.title (toValue tit)
827828 (Image attr txt (s,tit)) | treatAsImage s -> do
828829 let alternate' = stringify txt
829830 let attributes = [A.src $ toValue s] ++
@@ -874,7 +875,7 @@ blockListToNote :: WriterOptions -> String -> [Block] -> State WriterState Html
874875blockListToNote opts ref blocks =
875876 -- If last block is Para or Plain, include the backlink at the end of
876877 -- that block. Otherwise, insert a new Plain block with the backlink.
877− let backlink = [Link [Str "↩"] ("#" ++ writerIdentifierPrefix opts ++ "fnref" ++ ref,[])]
878+ let backlink = [Link nullAttr [Str "↩"] ("#" ++ writerIdentifierPrefix opts ++ "fnref" ++ ref,[])]
878879 blocks' = if null blocks
879880 then []
880881 else let lastBlock = last blocks
src/Text/Pandoc/Writers/Haddock.hs+3−3
@@ -327,7 +327,7 @@ inlineToHaddock _ (RawInline f str)
327327inlineToHaddock _ (LineBreak) = return cr
328328inlineToHaddock _ Space = return space
329329inlineToHaddock opts (Cite _ lst) = inlineListToHaddock opts lst
330−inlineToHaddock opts (Link txt (src, _)) = do
330+inlineToHaddock opts (Link _ txt (src, _)) = do
331331 linktext <- inlineListToHaddock opts txt
332332 let useAuto = isURI src &&
333333 case txt of
@@ -335,8 +335,8 @@ inlineToHaddock opts (Link txt (src, _)) = do
335335 _ -> False
336336 return $ nowrap $ "<" <> text src <>
337337 (if useAuto then empty else space <> linktext) <> ">"
338−inlineToHaddock opts (Image _ alternate (source, tit)) = do
339− linkhaddock <- inlineToHaddock opts (Link alternate (source, tit))
338+inlineToHaddock opts (Image attr alternate (source, tit)) = do
339+ linkhaddock <- inlineToHaddock opts (Link attr alternate (source, tit))
340340 return $ "<" <> linkhaddock <> ">"
341341-- haddock doesn't have notes, but we can fake it:
342342inlineToHaddock opts (Note contents) = do
src/Text/Pandoc/Writers/ICML.hs+1−1
@@ -419,7 +419,7 @@ inlineToICML _ style (Math _ str) = charStyle style $ text $ escapeStringForXML
419419inlineToICML _ _ (RawInline f str)
420420 | f == Format "icml" = return $ text str
421421 | otherwise = return empty
422−inlineToICML opts style (Link lst (url, title)) = do
422+inlineToICML opts style (Link _ lst (url, title)) = do
423423 content <- inlinesToICML opts (linkName:style) lst
424424 state $ \st ->
425425 let ident = if null $ links st
src/Text/Pandoc/Writers/LaTeX.hs+6−6
@@ -99,8 +99,8 @@ pandocToLaTeX options (Pandoc meta blocks) = do
9999 _ -> blocks
100100 else blocks
101101 -- see if there are internal links
102− let isInternalLink (Link _ ('#':xs,_)) = [xs]
103− isInternalLink _ = []
102+ let isInternalLink (Link _ _ ('#':xs,_)) = [xs]
103+ isInternalLink _ = []
104104 modify $ \s -> s{ stInternalLinks = query isInternalLink blocks' }
105105 let template = writerTemplate options
106106 -- set stBook depending on documentclass
@@ -620,8 +620,8 @@ defListItemToLaTeX (term, defs) = do
620620 term' <- inlineListToLaTeX term
621621 -- put braces around term if it contains an internal link,
622622 -- since otherwise we get bad bracket interactions: \item[\hyperref[..]
623− let isInternalLink (Link _ ('#':_,_)) = True
624− isInternalLink _ = False
623+ let isInternalLink (Link _ _ ('#':_,_)) = True
624+ isInternalLink _ = False
625625 let term'' = if any isInternalLink term
626626 then braces term'
627627 else term'
@@ -828,11 +828,11 @@ inlineToLaTeX (RawInline f str)
828828 | otherwise = return empty
829829inlineToLaTeX (LineBreak) = return $ "\\\\" <> cr
830830inlineToLaTeX Space = return space
831−inlineToLaTeX (Link txt ('#':ident, _)) = do
831+inlineToLaTeX (Link _ txt ('#':ident, _)) = do
832832 contents <- inlineListToLaTeX txt
833833 lab <- toLabel ident
834834 return $ text "\\hyperref" <> brackets (text lab) <> braces contents
835−inlineToLaTeX (Link txt (src, _)) =
835+inlineToLaTeX (Link _ txt (src, _)) =
836836 case txt of
837837 [Str x] | escapeURI x == src -> -- autolink
838838 do modify $ \s -> s{ stUrl = True }
src/Text/Pandoc/Writers/Man.hs+3−3
@@ -342,7 +342,7 @@ inlineToMan _ (RawInline f str)
342342inlineToMan _ (LineBreak) = return $
343343 cr <> text ".PD 0" $$ text ".P" $$ text ".PD" <> cr
344344inlineToMan _ Space = return space
345−inlineToMan opts (Link txt (src, _)) = do
345+inlineToMan opts (Link _ txt (src, _)) = do
346346 linktext <- inlineListToMan opts txt
347347 let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
348348 return $ case txt of
@@ -350,12 +350,12 @@ inlineToMan opts (Link txt (src, _)) = do
350350 | escapeURI s == srcSuffix ->
351351 char '<' <> text srcSuffix <> char '>'
352352 _ -> linktext <> text " (" <> text src <> char ')'
353−inlineToMan opts (Image _ alternate (source, tit)) = do
353+inlineToMan opts (Image attr alternate (source, tit)) = do
354354 let txt = if (null alternate) || (alternate == [Str ""]) ||
355355 (alternate == [Str source]) -- to prevent autolinks
356356 then [Str "image"]
357357 else alternate
358− linkPart <- inlineToMan opts (Link txt (source, tit))
358+ linkPart <- inlineToMan opts (Link attr txt (source, tit))
359359 return $ char '[' <> text "IMAGE: " <> linkPart <> char ']'
360360inlineToMan _ (Note contents) = do
361361 -- add to notes in state
src/Text/Pandoc/Writers/Markdown.hs+27−22
@@ -55,7 +55,8 @@ import qualified Data.Vector as V
5555import qualified Data.Text as T
5656
5757type Notes = [[Block]]
58−type Refs = [([Inline], Target)]
58+type Ref = ([Inline], Target, Attr)
59+type Refs = [Ref]
5960data WriterState = WriterState { stNotes :: Notes
6061 , stRefs :: Refs
6162 , stRefShortcutable :: Bool
@@ -200,15 +201,16 @@ refsToMarkdown opts refs = mapM (keyToMarkdown opts) refs >>= return . vcat
200201
201202-- | Return markdown representation of a reference key.
202203keyToMarkdown :: WriterOptions
203− -> ([Inline], (String, String))
204+ -> Ref
204205 -> State WriterState Doc
205−keyToMarkdown opts (label, (src, tit)) = do
206+keyToMarkdown opts (label, (src, tit), attr) = do
206207 label' <- inlineListToMarkdown opts label
207208 let tit' = if null tit
208209 then empty
209210 else space <> "\"" <> text tit <> "\""
210211 return $ nest 2 $ hang 2
211212 ("[" <> label' <> "]:" <> space) (text src <> tit')
213+ <> linkAttributes opts attr
212214
213215-- | Return markdown representation of notes.
214216notesToMarkdown :: WriterOptions -> [[Block]] -> State WriterState Doc
@@ -280,6 +282,12 @@ attrsToMarkdown attribs = braces $ hsep [attribId, attribClasses, attribKeys]
280282 map (\(k,v) -> text k
281283 <> "=\"" <> text v <> "\"") ks
282284
285+linkAttributes :: WriterOptions -> Attr -> Doc
286+linkAttributes opts attr =
287+ if isEnabled Ext_common_link_attributes opts && attr /= nullAttr
288+ then attrsToMarkdown attr
289+ else empty
290+
283291-- | Ordered list start parser for use in Para below.
284292olMarker :: Parser [Char] ParserState Char
285293olMarker = do (start, style', delim) <- anyOrderedListMarker
@@ -665,21 +673,21 @@ blockListToMarkdown opts blocks =
665673
666674-- | Get reference for target; if none exists, create unique one and return.
667675-- Prefer label if possible; otherwise, generate a unique key.
668−getReference :: [Inline] -> Target -> State WriterState [Inline]
669−getReference label (src, tit) = do
676+getReference :: Attr -> [Inline] -> Target -> State WriterState [Inline]
677+getReference attr label target = do
670678 st <- get
671− case find ((== (src, tit)) . snd) (stRefs st) of
672− Just (ref, _) -> return ref
679+ case find (\(_,t,a) -> t == target && a == attr) (stRefs st) of
680+ Just (ref, _, _) -> return ref
673681 Nothing -> do
674− let label' = case find ((== label) . fst) (stRefs st) of
682+ let label' = case find (\(l,_,_) -> l == label) (stRefs st) of
675683 Just _ -> -- label is used; generate numerical label
676684 case find (\n -> notElem [Str (show n)]
677− (map fst (stRefs st)))
685+ (map (\(l,_,_) -> l) (stRefs st)))
678686 [1..(10000 :: Integer)] of
679687 Just x -> [Str (show x)]
680688 Nothing -> error "no unique label"
681689 Nothing -> label
682− modify (\s -> s{ stRefs = (label', (src,tit)) : stRefs st })
690+ modify (\s -> s{ stRefs = (label', target, attr) : stRefs st })
683691 return label'
684692
685693-- | Convert list of Pandoc inline elements to markdown.
@@ -689,10 +697,10 @@ inlineListToMarkdown opts lst = do
689697 go (if inlist then avoidBadWrapsInList lst else lst)
690698 where go [] = return empty
691699 go (i:is) = case i of
692− (Link _ _) -> case is of
700+ (Link _ _ _) -> case is of
693701 -- If a link is followed by another link or '[' we don't shortcut
694− (Link _ _):_ -> unshortcutable
695− Space:(Link _ _):_ -> unshortcutable
702+ (Link _ _ _):_ -> unshortcutable
703+ Space:(Link _ _ _):_ -> unshortcutable
696704 Space:(Str('[':_)):_ -> unshortcutable
697705 Space:(RawInline _ ('[':_)):_ -> unshortcutable
698706 Space:(Cite _ _):_ -> unshortcutable
@@ -883,7 +891,7 @@ inlineToMarkdown opts (Cite (c:cs) lst)
883891 return $ pdoc <+> r
884892 modekey SuppressAuthor = "-"
885893 modekey _ = ""
886−inlineToMarkdown opts (Link txt (src, tit)) = do
894+inlineToMarkdown opts (Link attr txt (src, tit)) = do
887895 plain <- gets stPlain
888896 linktext <- inlineListToMarkdown opts txt
889897 let linktitle = if null tit
@@ -898,7 +906,7 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
898906 shortcutable <- gets stRefShortcutable
899907 let useShortcutRefLinks = shortcutable &&
900908 isEnabled Ext_shortcut_reference_links opts
901− ref <- if useRefLinks then getReference txt (src, tit) else return []
909+ ref <- if useRefLinks then getReference attr txt (src, tit) else return []
902910 reftext <- inlineListToMarkdown opts ref
903911 return $ if useAuto
904912 then if plain
@@ -915,21 +923,18 @@ inlineToMarkdown opts (Link txt (src, tit)) = do
915923 else if plain
916924 then linktext
917925 else "[" <> linktext <> "](" <>
918− text src <> linktitle <> ")"
926+ text src <> linktitle <> ")" <>
927+ linkAttributes opts attr
919928inlineToMarkdown opts (Image attr alternate (source, tit)) = do
920929 plain <- gets stPlain
921930 let txt = if null alternate || alternate == [Str source]
922931 -- to prevent autolinks
923932 then [Str ""]
924933 else alternate
925− linkPart <- inlineToMarkdown opts (Link txt (source, tit))
934+ linkPart <- inlineToMarkdown opts (Link attr txt (source, tit))
926935 return $ if plain
927936 then "[" <> linkPart <> "]"
928− else "!" <> linkPart <>
929− if isEnabled Ext_common_link_attributes opts
930− && attr /= nullAttr
931− then attrsToMarkdown attr
932− else empty
937+ else "!" <> linkPart
933938inlineToMarkdown opts (Note contents) = do
934939 modify (\st -> st{ stNotes = contents : stNotes st })
935940 st <- get
src/Text/Pandoc/Writers/MediaWiki.hs+1−1
@@ -399,7 +399,7 @@ inlineToMediaWiki (LineBreak) = return "<br />\n"
399399
400400inlineToMediaWiki Space = return " "
401401
402−inlineToMediaWiki (Link txt (src, _)) = do
402+inlineToMediaWiki (Link _ txt (src, _)) = do
403403 label <- inlineListToMediaWiki txt
404404 case txt of
405405 [Str s] | isURI src && escapeURI s == src -> return src
src/Text/Pandoc/Writers/OpenDocument.hs+1−1
@@ -393,7 +393,7 @@ inlineToOpenDocument o ils
393393 | RawInline f s <- ils = if f == Format "opendocument"
394394 then return $ text s
395395 else return empty
396− | Link l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l
396+ | Link _ l (s,t) <- ils = mkLink s t <$> inlinesToOpenDocument o l
397397 | Image attr _ (s,t) <- ils = mkImg attr s t
398398 | Note l <- ils = mkNote l
399399 | otherwise = return empty
src/Text/Pandoc/Writers/Org.hs+1−1
@@ -276,7 +276,7 @@ inlineToOrg (RawInline f str) | f == "tex" || f == "latex" = return $ text str
276276inlineToOrg (RawInline _ _) = return empty
277277inlineToOrg (LineBreak) = return (text "\\\\" <> cr)
278278inlineToOrg Space = return space
279−inlineToOrg (Link txt (src, _)) = do
279+inlineToOrg (Link _ txt (src, _)) = do
280280 case txt of
281281 [Str x] | escapeURI x == src -> -- autolink
282282 do modify $ \s -> s{ stLinks = True }
src/Text/Pandoc/Writers/RST.hs+4−4
@@ -390,7 +390,7 @@ inlineListToRST lst =
390390 isComplex (Strikeout _) = True
391391 isComplex (Superscript _) = True
392392 isComplex (Subscript _) = True
393− isComplex (Link _ _) = True
393+ isComplex (Link _ _ _) = True
394394 isComplex (Image _ _ _) = True
395395 isComplex (Code _ _) = True
396396 isComplex (Math _ _) = True
@@ -442,17 +442,17 @@ inlineToRST (RawInline f x)
442442inlineToRST (LineBreak) = return cr -- there's no line break in RST (see Para)
443443inlineToRST Space = return space
444444-- autolink
445−inlineToRST (Link [Str str] (src, _))
445+inlineToRST (Link _ [Str str] (src, _))
446446 | isURI src &&
447447 if "mailto:" `isPrefixOf` src
448448 then src == escapeURI ("mailto:" ++ str)
449449 else src == escapeURI str = do
450450 let srcSuffix = fromMaybe src (stripPrefix "mailto:" src)
451451 return $ text srcSuffix
452−inlineToRST (Link [Image attr alt (imgsrc,imgtit)] (src, _tit)) = do
452+inlineToRST (Link _ [Image attr alt (imgsrc,imgtit)] (src, _tit)) = do
453453 label <- registerImage attr alt (imgsrc,imgtit) (Just src)
454454 return $ "|" <> label <> "|"
455−inlineToRST (Link txt (src, tit)) = do
455+inlineToRST (Link _ txt (src, tit)) = do
456456 useReferenceLinks <- get >>= return . writerReferenceLinks . stOptions
457457 linktext <- inlineListToRST $ normalizeSpaces txt
458458 if useReferenceLinks
src/Text/Pandoc/Writers/RTF.hs+1−1
@@ -350,7 +350,7 @@ inlineToRTF (RawInline f str)
350350 | otherwise = ""
351351inlineToRTF (LineBreak) = "\\line "
352352inlineToRTF Space = " "
353−inlineToRTF (Link text (src, _)) =
353+inlineToRTF (Link _ text (src, _)) =
354354 "{\\field{\\*\\fldinst{HYPERLINK \"" ++ (codeStringToRTF src) ++
355355 "\"}}{\\fldrslt{\\ul\n" ++ (inlineListToRTF text) ++ "\n}}}\n"
356356inlineToRTF (Image _ _ (source, _)) =
src/Text/Pandoc/Writers/Texinfo.hs+2−2
@@ -427,11 +427,11 @@ inlineToTexinfo (RawInline f str)
427427inlineToTexinfo (LineBreak) = return $ text "@*" <> cr
428428inlineToTexinfo Space = return space
429429
430−inlineToTexinfo (Link txt (src@('#':_), _)) = do
430+inlineToTexinfo (Link _ txt (src@('#':_), _)) = do
431431 contents <- escapeCommas $ inlineListToTexinfo txt
432432 return $ text "@ref" <>
433433 braces (text (stringToTexinfo src) <> text "," <> contents)
434−inlineToTexinfo (Link txt (src, _)) = do
434+inlineToTexinfo (Link _ txt (src, _)) = do
435435 case txt of
436436 [Str x] | escapeURI x == src -> -- autolink
437437 do return $ text $ "@url{" ++ x ++ "}"
src/Text/Pandoc/Writers/Textile.hs+6−4
@@ -426,23 +426,25 @@ inlineToTextile _ (LineBreak) = return "\n"
426426
427427inlineToTextile _ Space = return " "
428428
429−inlineToTextile opts (Link txt (src, _)) = do
429+inlineToTextile opts (Link (_, cls, _) txt (src, _)) = do
430+ let classes = if null cls
431+ then ""
432+ else "(" ++ unwords cls ++ ")"
430433 label <- case txt of
431434 [Code _ s]
432435 | s == src -> return "$"
433436 [Str s]
434437 | s == src -> return "$"
435438 _ -> inlineListToTextile opts txt
436− return $ "\"" ++ label ++ "\":" ++ src
439+ return $ "\"" ++ classes ++ label ++ "\":" ++ src
437440
438−inlineToTextile opts (Image attr alt (source, tit)) = do
441+inlineToTextile opts (Image attr@(_, cls, _) alt (source, tit)) = do
439442 alt' <- inlineListToTextile opts alt
440443 let txt = if null tit
441444 then if null alt'
442445 then ""
443446 else "(" ++ alt' ++ ")"
444447 else "(" ++ tit ++ ")"
445− (_, cls, _) = attr
446448 classes = if null cls
447449 then ""
448450 else "(" ++ unwords cls ++ ")"