git.iko.soy/typeable/pandoc
on master help sign in
ConTeXt writer: Improved autolinks.
093229dJohn MacFarlane
src/Text/Pandoc/Writers/ConTeXt.hs+5−11
@@ -35,7 +35,7 @@ import Text.Pandoc.Writers.Shared
35import Text.Pandoc.Options
35import Text.Pandoc.Options
36import Text.Pandoc.Walk (query)
36import Text.Pandoc.Walk (query)
37import Text.Printf ( printf )
37import Text.Printf ( printf )
38−import Data.List ( intercalate, isPrefixOf )
38+import Data.List ( intercalate )
39import Control.Monad.State
39import Control.Monad.State
40import Text.Pandoc.Pretty
40import Text.Pandoc.Pretty
41import Text.Pandoc.Templates ( renderTemplate' )
41import Text.Pandoc.Templates ( renderTemplate' )
@@ -283,14 +283,6 @@ inlineToConTeXt (RawInline "tex" str) = return $ text str
283inlineToConTeXt (RawInline _ _) = return empty
283inlineToConTeXt (RawInline _ _) = return empty
284inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
284inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
285inlineToConTeXt Space = return space
285inlineToConTeXt Space = return space
286−-- autolink
287−inlineToConTeXt (Link [Str str] (src, tit))
288− | if "mailto:" `isPrefixOf` src
289− then src == escapeURI ("mailto:" ++ str)
290− else src == escapeURI str =
291− inlineToConTeXt (Link
292− [RawInline "context" "\\hyphenatedurl{", Str str, RawInline "context" "}"]
293− (src, tit))
294-- Handle HTML-like internal document references to sections
286-- Handle HTML-like internal document references to sections
295inlineToConTeXt (Link txt (('#' : ref), _)) = do
287inlineToConTeXt (Link txt (('#' : ref), _)) = do
296 opts <- gets stOptions
288 opts <- gets stOptions
@@ -305,6 +297,7 @@ inlineToConTeXt (Link txt (('#' : ref), _)) = do
305 <> brackets (text ref)
297 <> brackets (text ref)
306
298
307inlineToConTeXt (Link txt (src, _)) = do
299inlineToConTeXt (Link txt (src, _)) = do
300+ let isAutolink = txt == [Str src]
308 st <- get
301 st <- get
309 let next = stNextRef st
302 let next = stNextRef st
310 put $ st {stNextRef = next + 1}
303 put $ st {stNextRef = next + 1}
@@ -313,8 +306,9 @@ inlineToConTeXt (Link txt (src, _)) = do
313 return $ "\\useURL"
306 return $ "\\useURL"
314 <> brackets (text ref)
307 <> brackets (text ref)
315 <> brackets (text $ escapeStringUsing [('#',"\\#"),('%',"\\%")] src)
308 <> brackets (text $ escapeStringUsing [('#',"\\#"),('%',"\\%")] src)
309+ <> (if isAutolink
310+ then empty
316− <> brackets empty
311+ else brackets empty <> brackets label)
317− <> brackets label
318 <> "\\from"
312 <> "\\from"
319 <> brackets (text ref)
313 <> brackets (text ref)
320inlineToConTeXt (Image _ (src, _)) = do
314inlineToConTeXt (Image _ (src, _)) = do
tests/writer.context+4−6
@@ -813,24 +813,22 @@ braces]\from[url26].
813
813
814\subsection[autolinks]{Autolinks}
814\subsection[autolinks]{Autolinks}
815
815
816−With an ampersand:
817−\useURL[url27][http://example.com/?foo=1&bar=2][][\hyphenatedurl{http://example.com/?foo=1&bar=2}]\from[url27]
816+With an ampersand: \useURL[url27][http://example.com/?foo=1&bar=2]\from[url27]
818
817
819\startitemize[packed]
818\startitemize[packed]
820\item
819\item
821 In a list?
820 In a list?
822\item
821\item
823− \useURL[url28][http://example.com/][][\hyphenatedurl{http://example.com/}]\from[url28]
822+ \useURL[url28][http://example.com/]\from[url28]
824\item
823\item
825 It should.
824 It should.
826\stopitemize
825\stopitemize
827
826
828An e-mail address:
827An e-mail address:
829−\useURL[url29][mailto:nobody@nowhere.net][][\hyphenatedurl{nobody@nowhere.net}]\from[url29]
828+\useURL[url29][mailto:nobody@nowhere.net][][nobody@nowhere.net]\from[url29]
830
829
831\startblockquote
830\startblockquote
832−Blockquoted:
833−\useURL[url30][http://example.com/][][\hyphenatedurl{http://example.com/}]\from[url30]
831+Blockquoted: \useURL[url30][http://example.com/]\from[url30]
834\stopblockquote
832\stopblockquote
835
833
836Auto-links should not occur here: \type{<http://example.com/>}
834Auto-links should not occur here: \type{<http://example.com/>}