git.iko.soy/typeable/pandoc
on master help sign in
ConTeXt writer: Improved autolinks.

Closes #1270.

commit093229dc35506bff88f4edc6f2ae5316d621f8ff authorJohn MacFarlane <jgm@berkeley.edu> dateWed 30 Apr 2014, 08:58 (13 years ago) parent7f86f95
2 files changed+9−17
src/Text/Pandoc/Writers/ConTeXt.hs+5−11 tests/writer.context+4−6
src/Text/Pandoc/Writers/ConTeXt.hs+5−11
@@ -35,7 +35,7 @@ import Text.Pandoc.Writers.Shared
3535import Text.Pandoc.Options
3636import Text.Pandoc.Walk (query)
3737import Text.Printf ( printf )
38−import Data.List ( intercalate, isPrefixOf )
38+import Data.List ( intercalate )
3939import Control.Monad.State
4040import Text.Pandoc.Pretty
4141import Text.Pandoc.Templates ( renderTemplate' )
@@ -283,14 +283,6 @@ inlineToConTeXt (RawInline "tex" str) = return $ text str
283283inlineToConTeXt (RawInline _ _) = return empty
284284inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
285285inlineToConTeXt 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))
294286-- Handle HTML-like internal document references to sections
295287inlineToConTeXt (Link txt (('#' : ref), _)) = do
296288 opts <- gets stOptions
@@ -305,6 +297,7 @@ inlineToConTeXt (Link txt (('#' : ref), _)) = do
305297 <> brackets (text ref)
306298
307299inlineToConTeXt (Link txt (src, _)) = do
300+ let isAutolink = txt == [Str src]
308301 st <- get
309302 let next = stNextRef st
310303 put $ st {stNextRef = next + 1}
@@ -313,8 +306,9 @@ inlineToConTeXt (Link txt (src, _)) = do
313306 return $ "\\useURL"
314307 <> brackets (text ref)
315308 <> brackets (text $ escapeStringUsing [('#',"\\#"),('%',"\\%")] src)
316− <> brackets empty
317− <> brackets label
309+ <> (if isAutolink
310+ then empty
311+ else brackets empty <> brackets label)
318312 <> "\\from"
319313 <> brackets (text ref)
320314inlineToConTeXt (Image _ (src, _)) = do
tests/writer.context+4−6
@@ -813,24 +813,22 @@ braces]\from[url26].
813813
814814\subsection[autolinks]{Autolinks}
815815
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]
818817
819818\startitemize[packed]
820819\item
821820 In a list?
822821\item
823− \useURL[url28][http://example.com/][][\hyphenatedurl{http://example.com/}]\from[url28]
822+ \useURL[url28][http://example.com/]\from[url28]
824823\item
825824 It should.
826825\stopitemize
827826
828827An 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]
830829
831830\startblockquote
832−Blockquoted:
833−\useURL[url30][http://example.com/][][\hyphenatedurl{http://example.com/}]\from[url30]
831+Blockquoted: \useURL[url30][http://example.com/]\from[url30]
834832\stopblockquote
835833
836834Auto-links should not occur here: \type{<http://example.com/>}