git.iko.soy/typeable/pandoc
on master help sign in
Added --inline-links option to force links in HTML to be parsed
31c030efiddlosopher
@@ -241,6 +241,9 @@ preserved, rather than converted to spaces (the default).
241`--strict` specifies that strict markdown syntax is to be used, without
241`--strict` specifies that strict markdown syntax is to be used, without
242pandoc's usual extensions and variants (described below).
242pandoc's usual extensions and variants (described below).
243
243
244+`--inline-links` causes links in HTML to be parsed as inline links, rather
245+than reference links.
246+
244`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
247`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
245codes and LaTeX environments that it can't translate as raw HTML or
248codes and LaTeX environments that it can't translate as raw HTML or
246LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
249LaTeX. Raw HTML can be printed in markdown, reStructuredText, HTML,
man/man1/html2markdown.1+2
@@ -32,6 +32,8 @@ Write output to \fIFILE\fR instead of STDOUT.
32.B \-\-strict
32.B \-\-strict
33Use strict markdown syntax, with no extensions or variants.
33Use strict markdown syntax, with no extensions or variants.
34.TP
34.TP
35+.B \-\-inline\-links
36+Parse links in HTML as inline links, rather than reference links.
35.TP
37.TP
36.B \-R, \-\-parse-raw
38.B \-R, \-\-parse-raw
37Parse untranslatable HTML codes as raw HTML.
39Parse untranslatable HTML codes as raw HTML.
man/man1/pandoc.1+3
@@ -105,6 +105,9 @@ Specify tab stop (default is 4).
105.B \-\-strict
105.B \-\-strict
106Use strict markdown syntax, with no extensions or variants.
106Use strict markdown syntax, with no extensions or variants.
107.TP
107.TP
108+.B \-\-inline\-links
109+Parse links in HTML as inline links, rather than reference links.
110+.TP
108.B \-R, \-\-parse-raw
111.B \-R, \-\-parse-raw
109Parse untranslatable HTML codes and LaTeX environments as raw HTML
112Parse untranslatable HTML codes and LaTeX environments as raw HTML
110or LaTeX, instead of ignoring them.
113or LaTeX, instead of ignoring them.
src/Main.hs+15−6
@@ -118,6 +118,7 @@ data Opt = Opt
118 , optDumpArgs :: Bool -- ^ Output command-line arguments
118 , optDumpArgs :: Bool -- ^ Output command-line arguments
119 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
119 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
120 , optStrict :: Bool -- ^ Use strict markdown syntax
120 , optStrict :: Bool -- ^ Use strict markdown syntax
121+ , optInlineLinks :: Bool -- ^ Use inline links in parsing HTML
121 }
122 }
122
123
123-- | Defaults for command-line options.
124-- | Defaults for command-line options.
@@ -143,6 +144,7 @@ defaultOpts = Opt
143 , optDumpArgs = False
144 , optDumpArgs = False
144 , optIgnoreArgs = False
145 , optIgnoreArgs = False
145 , optStrict = False
146 , optStrict = False
147+ , optInlineLinks = False
146 }
148 }
147
149
148-- | A list of functions, each transforming the options data structure
150-- | A list of functions, each transforming the options data structure
@@ -188,6 +190,11 @@ options =
188 (\opt -> return opt { optStrict = True } ))
190 (\opt -> return opt { optStrict = True } ))
189 "" -- "Use strict markdown syntax with no extensions"
191 "" -- "Use strict markdown syntax with no extensions"
190
192
193+ , Option "" ["inline-links"]
194+ (NoArg
195+ (\opt -> return opt { optInlineLinks = True } ))
196+ "" -- "Use inline links in parsing HTML"
197+
191 , Option "R" ["parse-raw"]
198 , Option "R" ["parse-raw"]
192 (NoArg
199 (NoArg
193 (\opt -> return opt { optParseRaw = True }))
200 (\opt -> return opt { optParseRaw = True }))
@@ -398,6 +405,7 @@ main = do
398 , optDumpArgs = dumpArgs
405 , optDumpArgs = dumpArgs
399 , optIgnoreArgs = ignoreArgs
406 , optIgnoreArgs = ignoreArgs
400 , optStrict = strict
407 , optStrict = strict
408+ , optInlineLinks = inlineLinks
401 } = opts
409 } = opts
402
410
403 if dumpArgs
411 if dumpArgs
@@ -440,12 +448,13 @@ main = do
440 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
448 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
441 let filter = tabFilter . addBlank . removeCRs
449 let filter = tabFilter . addBlank . removeCRs
442 let startParserState =
450 let startParserState =
443− defaultParserState { stateParseRaw = parseRaw,
451+ defaultParserState { stateParseRaw = parseRaw,
444− stateTabStop = tabStop,
452+ stateTabStop = tabStop,
445− stateStandalone = standalone && (not strict),
453+ stateStandalone = standalone && (not strict),
446− stateSmart = smart || writerName' == "latex",
454+ stateSmart = smart || writerName' == "latex",
447− stateColumns = columns,
455+ stateColumns = columns,
448− stateStrict = strict }
456+ stateStrict = strict,
457+ stateInlineLinks = inlineLinks }
449 let csslink = if (css == "")
458 let csslink = if (css == "")
450 then ""
459 then ""
451 else "<link rel=\"stylesheet\" href=\"" ++ css ++
460 else "<link rel=\"stylesheet\" href=\"" ++ css ++
src/Text/Pandoc/Readers/HTML.hs+6−3
@@ -449,15 +449,18 @@ extractAttribute name ((attrName, contents):rest) =
449 then Just (decodeEntities contents)
449 then Just (decodeEntities contents)
450 else extractAttribute name rest
450 else extractAttribute name rest
451
451
452−link = try (do
452+link = try $ do
453 (tag, attributes) <- htmlTag "a"
453 (tag, attributes) <- htmlTag "a"
454 url <- case (extractAttribute "href" attributes) of
454 url <- case (extractAttribute "href" attributes) of
455 Just url -> do {return url}
455 Just url -> do {return url}
456 Nothing -> fail "no href"
456 Nothing -> fail "no href"
457 let title = fromMaybe "" (extractAttribute "title" attributes)
457 let title = fromMaybe "" (extractAttribute "title" attributes)
458 label <- inlinesTilEnd "a"
458 label <- inlinesTilEnd "a"
459+ state <- getState
460+ ref <- if stateInlineLinks state
461+ then return (Src url title)
459− ref <- generateReference url title
462+ else generateReference url title
460− return (Link (normalizeSpaces label) ref))
463+ return $ Link (normalizeSpaces label) ref
461
464
462image = try (do
465image = try (do
463 (tag, attributes) <- htmlTag "img"
466 (tag, attributes) <- htmlTag "img"
src/Text/Pandoc/Shared.hs+2
@@ -133,6 +133,7 @@ data ParserState = ParserState
133 stateSmart :: Bool, -- ^ Use smart typography
133 stateSmart :: Bool, -- ^ Use smart typography
134 stateColumns :: Int, -- ^ Number of columns in
134 stateColumns :: Int, -- ^ Number of columns in
135 -- terminal (used for tables)
135 -- terminal (used for tables)
136+ stateInlineLinks :: Bool, -- ^ Parse html links as inline
136 stateHeaderTable :: [HeaderType] -- ^ List of header types used,
137 stateHeaderTable :: [HeaderType] -- ^ List of header types used,
137 -- in what order (rst only)
138 -- in what order (rst only)
138 }
139 }
@@ -155,6 +156,7 @@ defaultParserState =
155 stateStrict = False,
156 stateStrict = False,
156 stateSmart = False,
157 stateSmart = False,
157 stateColumns = 80,
158 stateColumns = 80,
159+ stateInlineLinks = False,
158 stateHeaderTable = [] }
160 stateHeaderTable = [] }
159
161
160-- | Indent string as a block.
162-- | Indent string as a block.