git.iko.soy/typeable/pandoc
on master help sign in
Added --inline-links option to force links in HTML to be parsed

as inline links, rather than reference links. (Addresses Issue #4.) git-svn-id: https://pandoc.googlecode.com/svn/trunk@554 788f1e2b-df1e-0410-8736-df70ead52e1b

commit31c030e3a55c3bc9d4a606e9658dd30a9aa1c938 authorfiddlosopher <fiddlosopher@788f1e2b-df1e-0410-8736-df70ead52e1b> dateSat 3 Mar 2007, 18:19 (20 years ago) parentf99cedd
6 files changed+31−9
README+3 man/man1/html2markdown.1+2 man/man1/pandoc.1+3 src/Main.hs+15−6 src/Text/Pandoc/Readers/HTML.hs+6−3 src/Text/Pandoc/Shared.hs+2
README+3
@@ -241,6 +241,9 @@ preserved, rather than converted to spaces (the default).
241241`--strict` specifies that strict markdown syntax is to be used, without
242242pandoc's usual extensions and variants (described below).
243243
244+`--inline-links` causes links in HTML to be parsed as inline links, rather
245+than reference links.
246+
244247`-R` or `--parse-raw` causes the HTML and LaTeX readers to parse HTML
245248codes and LaTeX environments that it can't translate as raw HTML or
246249LaTeX. 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.
3232.B \-\-strict
3333Use strict markdown syntax, with no extensions or variants.
3434.TP
35+.B \-\-inline\-links
36+Parse links in HTML as inline links, rather than reference links.
3537.TP
3638.B \-R, \-\-parse-raw
3739Parse untranslatable HTML codes as raw HTML.
man/man1/pandoc.1+3
@@ -105,6 +105,9 @@ Specify tab stop (default is 4).
105105.B \-\-strict
106106Use strict markdown syntax, with no extensions or variants.
107107.TP
108+.B \-\-inline\-links
109+Parse links in HTML as inline links, rather than reference links.
110+.TP
108111.B \-R, \-\-parse-raw
109112Parse untranslatable HTML codes and LaTeX environments as raw HTML
110113or LaTeX, instead of ignoring them.
src/Main.hs+15−6
@@ -118,6 +118,7 @@ data Opt = Opt
118118 , optDumpArgs :: Bool -- ^ Output command-line arguments
119119 , optIgnoreArgs :: Bool -- ^ Ignore command-line arguments
120120 , optStrict :: Bool -- ^ Use strict markdown syntax
121+ , optInlineLinks :: Bool -- ^ Use inline links in parsing HTML
121122 }
122123
123124-- | Defaults for command-line options.
@@ -143,6 +144,7 @@ defaultOpts = Opt
143144 , optDumpArgs = False
144145 , optIgnoreArgs = False
145146 , optStrict = False
147+ , optInlineLinks = False
146148 }
147149
148150-- | A list of functions, each transforming the options data structure
@@ -188,6 +190,11 @@ options =
188190 (\opt -> return opt { optStrict = True } ))
189191 "" -- "Use strict markdown syntax with no extensions"
190192
193+ , Option "" ["inline-links"]
194+ (NoArg
195+ (\opt -> return opt { optInlineLinks = True } ))
196+ "" -- "Use inline links in parsing HTML"
197+
191198 , Option "R" ["parse-raw"]
192199 (NoArg
193200 (\opt -> return opt { optParseRaw = True }))
@@ -398,6 +405,7 @@ main = do
398405 , optDumpArgs = dumpArgs
399406 , optIgnoreArgs = ignoreArgs
400407 , optStrict = strict
408+ , optInlineLinks = inlineLinks
401409 } = opts
402410
403411 if dumpArgs
@@ -440,12 +448,13 @@ main = do
440448 let removeCRs str = filter (/= '\r') str -- remove DOS-style line endings
441449 let filter = tabFilter . addBlank . removeCRs
442450 let startParserState =
443− defaultParserState { stateParseRaw = parseRaw,
444− stateTabStop = tabStop,
445− stateStandalone = standalone && (not strict),
446− stateSmart = smart || writerName' == "latex",
447− stateColumns = columns,
448− stateStrict = strict }
451+ defaultParserState { stateParseRaw = parseRaw,
452+ stateTabStop = tabStop,
453+ stateStandalone = standalone && (not strict),
454+ stateSmart = smart || writerName' == "latex",
455+ stateColumns = columns,
456+ stateStrict = strict,
457+ stateInlineLinks = inlineLinks }
449458 let csslink = if (css == "")
450459 then ""
451460 else "<link rel=\"stylesheet\" href=\"" ++ css ++
src/Text/Pandoc/Readers/HTML.hs+6−3
@@ -449,15 +449,18 @@ extractAttribute name ((attrName, contents):rest) =
449449 then Just (decodeEntities contents)
450450 else extractAttribute name rest
451451
452−link = try (do
452+link = try $ do
453453 (tag, attributes) <- htmlTag "a"
454454 url <- case (extractAttribute "href" attributes) of
455455 Just url -> do {return url}
456456 Nothing -> fail "no href"
457457 let title = fromMaybe "" (extractAttribute "title" attributes)
458458 label <- inlinesTilEnd "a"
459− ref <- generateReference url title
460− return (Link (normalizeSpaces label) ref))
459+ state <- getState
460+ ref <- if stateInlineLinks state
461+ then return (Src url title)
462+ else generateReference url title
463+ return $ Link (normalizeSpaces label) ref
461464
462465image = try (do
463466 (tag, attributes) <- htmlTag "img"
src/Text/Pandoc/Shared.hs+2
@@ -133,6 +133,7 @@ data ParserState = ParserState
133133 stateSmart :: Bool, -- ^ Use smart typography
134134 stateColumns :: Int, -- ^ Number of columns in
135135 -- terminal (used for tables)
136+ stateInlineLinks :: Bool, -- ^ Parse html links as inline
136137 stateHeaderTable :: [HeaderType] -- ^ List of header types used,
137138 -- in what order (rst only)
138139 }
@@ -155,6 +156,7 @@ defaultParserState =
155156 stateStrict = False,
156157 stateSmart = False,
157158 stateColumns = 80,
159+ stateInlineLinks = False,
158160 stateHeaderTable = [] }
159161
160162-- | Indent string as a block.