Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

URL in LaTeX and ConTeXt #504

Closed
wants to merge 10 commits into from

2 participants

@bscottm

Make URL hyphenation work in LaTeX and ConTeXt writers. Again.

-- Note: it looks like a lot of commits to pull, but the actual files changed are 2. Some of the commits are just me synchronizing with your repo.

bscottm and others added some commits
@bscottm bscottm ConTeXt_url_hyphenation
Deeply scan through the [Inline] associated with a Link and ensure that
all URLs are hyphenated using SYB primitives.
d67a57e
@bscottm bscottm Merge branch 'master' of https://github.com/jgm/pandoc 11c77f4
@bscottm bscottm context_internal_links_110906a
Add the ability to refer to internal links to the ConTeXt writer, just
like the HTML writer can. The 'hierarchicalize' function generates
unique names for sections, which can be used for references in ConTeXt,
just as they can be in HTML.

The ConTeXt writer adds these unique identifiers to each \section and
does special processing of the Link target to see if it starts with a
'#' (hash symbol), which is the tip-off that the link is an internal
link.
ca0eebd
@bscottm bscottm author_meta_110907a
Generate HTML meta in a sensible way, permitting the template 'author'
variable to retain its HTML formatting.
ff34783
@bscottm bscottm latex_writer_enhancements_110908
- Like the ConTeXt writer, arrange for proper URL/URI hyphenation to
  prevent overfull hboxes.
- Embed \hyperdef's and \labels so that pdflatex internal links to
  sections work, just like HTML and ConTeXt.
c6e64fb
Scott Michel Merge branch 'master' of https://github.com/jgm/pandoc f68dc1c
Scott Michel Merge branch 'master' of https://github.com/jgm/pandoc 87c1c04
@bscottm bscottm Merge https://github.com/jgm/pandoc
Conflicts:
	README
	src/Text/Pandoc/Writers/ConTeXt.hs
	src/Text/Pandoc/Writers/HTML.hs
	src/Text/Pandoc/Writers/LaTeX.hs
9ac8496
@bscottm bscottm url_hyphenation_again
Make URL hyphenation work in ConTeXt and LaTeX, again.
4560e8e
@bscottm bscottm Sync with master, again. Sigh. fe2f573
@jgm
Owner
jgm commented

Please rebase your changes against the current master branch and give me a new pull request, so I can easily see exactly what is changing, without all the merge complications.

@bscottm

Not sure what exactly you're seeing, but I see two files changed in the "Diff" button. Reckon I could pare down the commit list.

@bscottm

Closing -- sync with current jgm/pandoc master, re-request pull with slimmed down commit list.

@bscottm bscottm closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 1, 2011
  1. @bscottm

    ConTeXt_url_hyphenation

    bscottm authored
    Deeply scan through the [Inline] associated with a Link and ensure that
    all URLs are hyphenated using SYB primitives.
Commits on Sep 6, 2011
  1. @bscottm
Commits on Sep 7, 2011
  1. @bscottm

    context_internal_links_110906a

    bscottm authored
    Add the ability to refer to internal links to the ConTeXt writer, just
    like the HTML writer can. The 'hierarchicalize' function generates
    unique names for sections, which can be used for references in ConTeXt,
    just as they can be in HTML.
    
    The ConTeXt writer adds these unique identifiers to each \section and
    does special processing of the Link target to see if it starts with a
    '#' (hash symbol), which is the tip-off that the link is an internal
    link.
  2. @bscottm

    author_meta_110907a

    bscottm authored
    Generate HTML meta in a sensible way, permitting the template 'author'
    variable to retain its HTML formatting.
Commits on Sep 8, 2011
  1. @bscottm

    latex_writer_enhancements_110908

    bscottm authored
    - Like the ConTeXt writer, arrange for proper URL/URI hyphenation to
      prevent overfull hboxes.
    - Embed \hyperdef's and \labels so that pdflatex internal links to
      sections work, just like HTML and ConTeXt.
Commits on Dec 20, 2011
  1. Merge branch 'master' of https://github.com/jgm/pandoc

    Scott Michel authored
  2. Merge branch 'master' of https://github.com/jgm/pandoc

    Scott Michel authored
Commits on Apr 30, 2012
  1. @bscottm

    Merge https://github.com/jgm/pandoc

    bscottm authored
    Conflicts:
    	README
    	src/Text/Pandoc/Writers/ConTeXt.hs
    	src/Text/Pandoc/Writers/HTML.hs
    	src/Text/Pandoc/Writers/LaTeX.hs
Commits on May 1, 2012
  1. @bscottm

    url_hyphenation_again

    bscottm authored
    Make URL hyphenation work in ConTeXt and LaTeX, again.
  2. @bscottm

    Sync with master, again. Sigh.

    bscottm authored
This page is out of date. Refresh to see the latest.
View
25 src/Text/Pandoc/Writers/ConTeXt.hs
@@ -31,7 +31,7 @@ Conversion of 'Pandoc' format into ConTeXt.
module Text.Pandoc.Writers.ConTeXt ( writeConTeXt ) where
import Text.Pandoc.Definition
import Text.Pandoc.Shared
-import Text.Pandoc.Generic (queryWith)
+import Text.Pandoc.Generic (queryWith, bottomUp)
import Text.Printf ( printf )
import Data.List ( intercalate )
import Control.Monad.State
@@ -274,9 +274,7 @@ inlineToConTeXt (RawInline _ _) = return empty
inlineToConTeXt (LineBreak) = return $ text "\\crlf" <> cr
inlineToConTeXt Space = return space
-- autolink
-inlineToConTeXt (Link [Code _ str] (src, tit)) = inlineToConTeXt (Link
- [RawInline "context" "\\hyphenatedurl{", Str str, RawInline "context" "}"]
- (src, tit))
+inlineToConTeXt (Link [Code _ str] (src, tit)) = inlineToConTeXt (Link [Str str] (src, tit))
-- Handle HTML-like internal document references to sections
inlineToConTeXt (Link txt (('#' : ref), _)) = do
opts <- gets stOptions
@@ -295,10 +293,11 @@ inlineToConTeXt (Link txt (src, _)) = do
let next = stNextRef st
put $ st {stNextRef = next + 1}
let ref = "url" ++ show next
- label <- inlineListToConTeXt txt
+ -- Intentionally collapse adjacent Str objects in txt, apply URL hyphenation
+ label <- inlineListToConTeXt $ bottomUp hyphenateURL (normalize txt)
return $ "\\useURL"
<> brackets (text ref)
- <> brackets (text $ escapeStringUsing [('#',"\\#"),('%',"\\%")] src)
+ <> brackets ((text . escapedURL) src)
<> brackets empty
<> brackets label
<> "\\from"
@@ -339,3 +338,17 @@ sectionHeader ident hdrLevel lst = do
then "\\chapter{" <> contents <> "}"
else contents <> blankline
+-- | Convert absolute URLs/URIs to ConTeXt raw inlines so that they are hyphenated.
+hyphenateURL :: Inline
+ -> Inline
+hyphenateURL x =
+ case x of
+ (Str str) -> if isURI str
+ then (RawInline "context" ("\\hyphenatedurl{" ++ (escapedURL str) ++ "}"))
+ else x
+ _otherwise -> x
+
+-- | Escape characters in a URL so that TeX doesn't complain.
+escapedURL :: String
+ -> String
+escapedURL = escapeStringUsing [('#',"\\#"),('%',"\\%")]
View
4 src/Text/Pandoc/Writers/LaTeX.hs
@@ -582,8 +582,8 @@ inlineToLaTeX (Link txt (src, _)) =
return $ text $ "\\url{" ++ x ++ "}"
_ -> do contents <- inlineListToLaTeX txt
src' <- stringToLaTeX True src
- return $ text ("\\href{" ++ src' ++ "}{") <>
- contents <> char '}'
+ return $ text ("\\href{" ++ src' ++ "}{\\url{") <>
+ contents <> char '}' <> char '}'
inlineToLaTeX (Image _ (source, _)) = do
modify $ \s -> s{ stGraphics = True }
let source' = if isAbsoluteURI source
Something went wrong with that request. Please try again.