git.iko.soy/typeable/pandoc
on master help sign in
Removed --parse-raw and readerParseRaw.

These were confusing. Now we rely on the +raw_tex or +raw_html extension with latex or html input. Thus, instead of --parse-raw -f latex we use -f latex+raw_tex and instead of --parse-raw -f html we use -f html+raw_html

commit47a16065c44eb5028ca9b9e86993fe880ef2a37d authorJohn MacFarlane <jgm@berkeley.edu> dateMon 6 Feb 2017, 23:33 (10 years ago) parentd1c16c4
12 files changed+66−59
MANUAL.txt−11 src/Text/Pandoc.hs+1 src/Text/Pandoc/App.hs+14−19 src/Text/Pandoc/Options.hs−2 src/Text/Pandoc/Readers/EPUB.hs+2−1 src/Text/Pandoc/Readers/HTML.hs+7−7 src/Text/Pandoc/Readers/LaTeX.hs+12−7 src/Text/Pandoc/Readers/Markdown.hs−4 src/Text/Pandoc/Readers/Org/Inlines.hs+2−1 src/Text/Pandoc/Readers/Textile.hs−6 test/Tests/Old.hs+1−1 test/command/parse-raw.md+27
MANUAL.txt−11
@@ -391,17 +391,6 @@ General options
391391Reader options
392392--------------
393393
394−`-R`, `--parse-raw`
395−
396−: Parse untranslatable HTML codes and LaTeX environments as raw HTML
397− or LaTeX, instead of ignoring them. Affects only HTML and LaTeX
398− input. Raw HTML can be printed in Markdown, reStructuredText, Emacs Org
399− mode, HTML, Slidy, Slideous, DZSlides, reveal.js, and S5 output; raw LaTeX
400− can be printed in Markdown, reStructuredText, Emacs Org mode, LaTeX, and
401− ConTeXt output. The default is for the readers to omit untranslatable
402− HTML codes and LaTeX environments. (The LaTeX reader does pass through
403− untranslatable LaTeX *commands*, even if `-R` is not specified.)
404−
405394`--base-header-level=`*NUMBER*
406395
407396: Specify the base level for headers (defaults to 1).
src/Text/Pandoc.hs+1
@@ -336,6 +336,7 @@ getDefaultExtensions "context" = extensionsFromList
336336getDefaultExtensions "textile" = extensionsFromList
337337 [Ext_old_dashes,
338338 Ext_smart,
339+ Ext_raw_html,
339340 Ext_auto_identifiers]
340341getDefaultExtensions _ = extensionsFromList
341342 [Ext_auto_identifiers]
src/Text/Pandoc/App.hs+14−19
@@ -90,7 +90,7 @@ parseOptions options' defaults = do
9090 let (actions, args, unrecognizedOpts, errors) =
9191 getOpt' Permute options' rawArgs
9292
93− let unknownOptionErrors = foldr handelUnrecognizedOption [] unrecognizedOpts
93+ let unknownOptionErrors = foldr handleUnrecognizedOption [] unrecognizedOpts
9494
9595 unless (null errors && null unknownOptionErrors) $
9696 err 2 $ concat errors ++ unlines unknownOptionErrors ++
@@ -273,7 +273,6 @@ convertWithOpts opts = do
273273 _ -> Nothing
274274
275275 let readerOpts = def{ readerStandalone = standalone
276− , readerParseRaw = optParseRaw opts
277276 , readerColumns = optColumns opts
278277 , readerTabStop = optTabStop opts
279278 , readerIndentedCodeClasses = optIndentedCodeClasses opts
@@ -463,7 +462,6 @@ data Opt = Opt
463462 , optStandalone :: Bool -- ^ Include header, footer
464463 , optReader :: Maybe String -- ^ Reader format
465464 , optWriter :: Maybe String -- ^ Writer format
466− , optParseRaw :: Bool -- ^ Parse unconvertable HTML and TeX
467465 , optTableOfContents :: Bool -- ^ Include table of contents
468466 , optBaseHeaderLevel :: Int -- ^ Base header level
469467 , optTemplate :: Maybe FilePath -- ^ Custom template
@@ -529,7 +527,6 @@ defaultOpts = Opt
529527 , optStandalone = False
530528 , optReader = Nothing
531529 , optWriter = Nothing
532− , optParseRaw = False
533530 , optTableOfContents = False
534531 , optBaseHeaderLevel = 1
535532 , optTemplate = Nothing
@@ -777,11 +774,6 @@ options =
777774 "DIRECTORY") -- "Directory containing pandoc data files."
778775 ""
779776
780− , Option "R" ["parse-raw"]
781− (NoArg
782− (\opt -> return opt { optParseRaw = True }))
783− "" -- "Parse untranslatable HTML codes and LaTeX environments as raw"
784−
785777 , Option "" ["base-header-level"]
786778 (ReqArg
787779 (\arg opt ->
@@ -1403,22 +1395,25 @@ compileInfo =
14031395 "\nCompiled with pandoc-types " ++ VERSION_pandoc_types ++ ", texmath " ++
14041396 VERSION_texmath ++ ", skylighting " ++ VERSION_skylighting
14051397
1406−handelUnrecognizedOption :: String -> [String] -> [String]
1407−handelUnrecognizedOption "--smart" =
1408− (("--smart has been removed. Use +smart or -smart extension instead.\n" ++
1398+handleUnrecognizedOption :: String -> [String] -> [String]
1399+handleUnrecognizedOption "--smart" =
1400+ (("--smart/-S has been removed. Use +smart or -smart extension instead.\n" ++
14091401 "For example: pandoc -f markdown+smart -t markdown-smart.") :)
1410−handelUnrecognizedOption "-S" = handelUnrecognizedOption "--smart"
1411−handelUnrecognizedOption "--old-dashes" =
1402+handleUnrecognizedOption "-S" = handleUnrecognizedOption "--smart"
1403+handleUnrecognizedOption "--old-dashes" =
14121404 ("--old-dashes has been removed. Use +old_dashes extension instead." :)
1413−handelUnrecognizedOption "--no-wrap" =
1405+handleUnrecognizedOption "--no-wrap" =
14141406 ("--no-wrap has been removed. Use --wrap=none instead." :)
1415−handelUnrecognizedOption "--chapters" =
1407+handleUnrecognizedOption "--chapters" =
14161408 ("--chapters has been removed. Use --top-level-division=chapter instead." :)
1417−handelUnrecognizedOption "--reference-docx" =
1409+handleUnrecognizedOption "--reference-docx" =
14181410 ("--reference-docx has been removed. Use --reference-doc instead." :)
1419−handelUnrecognizedOption "--reference-odt" =
1411+handleUnrecognizedOption "--reference-odt" =
14201412 ("--reference-odt has been removed. Use --reference-doc instead." :)
1421−handelUnrecognizedOption x =
1413+handleUnrecognizedOption "--parse-raw" =
1414+ (("--parse-raw/-R has been removed. Use +raw_html or +raw_tex extension.\n") :)
1415+handleUnrecognizedOption "-R" = handleUnrecognizedOption "--parse-raw"
1416+handleUnrecognizedOption x =
14221417 (("Unknown option " ++ x ++ ".") :)
14231418
14241419uppercaseFirstLetter :: String -> String
src/Text/Pandoc/Options.hs−2
@@ -55,7 +55,6 @@ import GHC.Generics (Generic)
5555data ReaderOptions = ReaderOptions{
5656 readerExtensions :: Extensions -- ^ Syntax extensions
5757 , readerStandalone :: Bool -- ^ Standalone document with header
58− , readerParseRaw :: Bool -- ^ Parse raw HTML, LaTeX
5958 , readerColumns :: Int -- ^ Number of columns in terminal
6059 , readerTabStop :: Int -- ^ Tab stop
6160 , readerApplyMacros :: Bool -- ^ Apply macros to TeX math
@@ -69,7 +68,6 @@ instance Default ReaderOptions
6968 where def = ReaderOptions{
7069 readerExtensions = emptyExtensions
7170 , readerStandalone = False
72− , readerParseRaw = False
7371 , readerColumns = 80
7472 , readerTabStop = 4
7573 , readerApplyMacros = True
src/Text/Pandoc/Readers/EPUB.hs+2−1
@@ -13,6 +13,7 @@ import Text.Pandoc.Definition hiding (Attr)
1313import Text.Pandoc.Readers.HTML (readHtml)
1414import Text.Pandoc.Walk (walk, query)
1515import Text.Pandoc.Options ( ReaderOptions(..), Verbosity(..))
16+import Text.Pandoc.Extensions (enableExtension, Extension(Ext_raw_html))
1617import Text.Pandoc.Shared (escapeURI, collapseFilePath, addMetaField)
1718import Network.URI (unEscapeString)
1819import Text.Pandoc.MediaBag (MediaBag, insertMedia)
@@ -66,7 +67,7 @@ archiveToEPUB os archive = do
6667 P.setMediaBag $ fetchImages (M.elems items) root archive ast
6768 return ast
6869 where
69− os' = os {readerParseRaw = True}
70+ os' = os {readerExtensions = enableExtension Ext_raw_html (readerExtensions os)}
7071 parseSpineElem :: PandocMonad m => FilePath -> (FilePath, MimeType) -> m Pandoc
7172 parseSpineElem (normalise -> r) (normalise -> path, mime) = do
7273 report DEBUG ("parseSpineElem called with path " ++ show path)
src/Text/Pandoc/Readers/HTML.hs+7−7
@@ -45,9 +45,9 @@ import qualified Text.Pandoc.Builder as B
4545import Text.Pandoc.Builder (Blocks, Inlines, trimInlines, HasMeta(..))
4646import Text.Pandoc.Shared ( extractSpaces, renderTags', addMetaField
4747 , escapeURI, safeRead )
48−import Text.Pandoc.Options (ReaderOptions(readerParseRaw),
49− Verbosity(..), Extension (Ext_epub_html_exts,
50− Ext_native_divs, Ext_native_spans))
48+import Text.Pandoc.Options (ReaderOptions(readerExtensions), extensionEnabled,
49+ Verbosity(..), Extension (Ext_epub_html_exts,
50+ Ext_raw_html, Ext_native_divs, Ext_native_spans))
5151import Text.Pandoc.Parsing hiding ((<|>))
5252import Text.Pandoc.Walk
5353import qualified Data.Map as M
@@ -367,8 +367,8 @@ pDiv = try $ do
367367pRawHtmlBlock :: PandocMonad m => TagParser m Blocks
368368pRawHtmlBlock = do
369369 raw <- pHtmlBlock "script" <|> pHtmlBlock "style" <|> pRawTag
370− parseRaw <- getOption readerParseRaw
371− if parseRaw && not (null raw)
370+ exts <- getOption readerExtensions
371+ if extensionEnabled Ext_raw_html exts && not (null raw)
372372 then return $ B.rawBlock "html" raw
373373 else return mempty
374374
@@ -690,8 +690,8 @@ pRawHtmlInline = do
690690 <|> if inplain
691691 then pSatisfy (not . isBlockTag)
692692 else pSatisfy isInlineTag
693− parseRaw <- getOption readerParseRaw
694− if parseRaw
693+ exts <- getOption readerExtensions
694+ if extensionEnabled Ext_raw_html exts
695695 then return $ B.rawInline "html" $ renderTags' [result]
696696 else return mempty
697697
src/Text/Pandoc/Readers/LaTeX.hs+12−7
@@ -303,14 +303,18 @@ ignoreInlines name = (name, doraw <|> (mempty <$ optargs))
303303 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
304304 contseq = '\\':name
305305 doraw = (rawInline "latex" . (contseq ++) . snd) <$>
306− (getOption readerParseRaw >>= guard >> withRaw optargs)
306+ (do exts <- getOption readerExtensions
307+ guard $ extensionEnabled Ext_raw_tex exts
308+ withRaw optargs)
307309
308310ignoreBlocks :: PandocMonad m => String -> (String, LP m Blocks)
309311ignoreBlocks name = (name, doraw <|> (mempty <$ optargs))
310312 where optargs = skipopts *> skipMany (try $ optional sp *> braced)
311313 contseq = '\\':name
312314 doraw = (rawBlock "latex" . (contseq ++) . snd) <$>
313− (getOption readerParseRaw >>= guard >> withRaw optargs)
315+ (do exts <- getOption readerExtensions
316+ guard $ extensionEnabled Ext_raw_tex exts
317+ withRaw optargs)
314318
315319blockCommands :: PandocMonad m => M.Map String (LP m Blocks)
316320blockCommands = M.fromList $
@@ -423,7 +427,7 @@ inlineCommand = try $ do
423427 name <- anyControlSeq
424428 guard $ name /= "begin" && name /= "end"
425429 guard $ not $ isBlockCommand name
426− parseRaw <- getOption readerParseRaw
430+ exts <- getOption readerExtensions
427431 star <- option "" (string "*")
428432 let name' = name ++ star
429433 let raw = do
@@ -433,7 +437,7 @@ inlineCommand = try $ do
433437 transformed <- applyMacros' rawcommand
434438 if transformed /= rawcommand
435439 then parseFromString inlines transformed
436− else if parseRaw
440+ else if extensionEnabled Ext_raw_tex exts
437441 then return $ rawInline "latex" rawcommand
438442 else return mempty
439443 (lookupListDefault mzero [name',name] inlineCommands <*
@@ -441,7 +445,8 @@ inlineCommand = try $ do
441445 <|> raw
442446
443447unlessParseRaw :: PandocMonad m => LP m ()
444−unlessParseRaw = getOption readerParseRaw >>= guard . not
448+unlessParseRaw = getOption readerExtensions >>=
449+ guard . not . extensionEnabled Ext_raw_tex
445450
446451isBlockCommand :: String -> Bool
447452isBlockCommand s = s `M.member` (blockCommands :: M.Map String (LP PandocPure Blocks))
@@ -923,10 +928,10 @@ inlineEnvironment = try $ do
923928
924929rawEnv :: PandocMonad m => String -> LP m Blocks
925930rawEnv name = do
926− parseRaw <- getOption readerParseRaw
931+ exts <- getOption readerExtensions
927932 rawOptions <- mconcat <$> many rawopt
928933 let addBegin x = "\\begin{" ++ name ++ "}" ++ rawOptions ++ x
929− if parseRaw
934+ if extensionEnabled Ext_raw_tex exts
930935 then (rawBlock "latex" . addBegin) <$>
931936 (withRaw (env name blocks) >>= applyMacros' . snd)
932937 else env name blocks
src/Text/Pandoc/Readers/Markdown.hs−4
@@ -359,10 +359,6 @@ kvPair allowEmpty = try $ do
359359
360360parseMarkdown :: PandocMonad m => MarkdownParser m Pandoc
361361parseMarkdown = do
362− -- markdown allows raw HTML
363− updateState $ \state -> state { stateOptions =
364− let oldOpts = stateOptions state in
365− oldOpts{ readerParseRaw = True } }
366362 optional titleBlock
367363 blocks <- parseBlocks
368364 st <- getState
src/Text/Pandoc/Readers/Org/Inlines.hs+2−1
@@ -806,7 +806,8 @@ inlineLaTeX = try $ do
806806 where clean = dropWhileEnd (`elem` ("{}" :: String)) . drop 1
807807
808808 state :: ParserState
809− state = def{ stateOptions = def{ readerParseRaw = True }}
809+ state = def{ stateOptions = def{ readerExtensions =
810+ enableExtension Ext_raw_tex (readerExtensions def) } }
810811
811812 texMathToPandoc :: String -> Maybe [Inline]
812813 texMathToPandoc cs = (maybeRight $ readTeX cs) >>= writePandoc DisplayInline
src/Text/Pandoc/Readers/Textile.hs−6
@@ -85,12 +85,6 @@ readTextile opts s = do
8585-- | Generate a Pandoc ADT from a textile document
8686parseTextile :: PandocMonad m => ParserT [Char] ParserState m Pandoc
8787parseTextile = do
88− -- textile allows raw HTML and does smart punctuation by default,
89− -- but we do not enable smart punctuation unless it is explicitly
90− -- asked for, for better conversion to other light markup formats
91− oldOpts <- stateOptions `fmap` getState
92− updateState $ \state -> state{ stateOptions =
93− oldOpts{ readerParseRaw = True } }
9488 many blankline
9589 startPos <- getPosition
9690 -- go through once just to get list of reference keys and notes
test/Tests/Old.hs+1−1
@@ -46,7 +46,7 @@ tests = [ testGroup "markdown"
4646 , testGroup "latex"
4747 [ testGroup "writer" (writerTests "latex" ++ lhsWriterTests "latex")
4848 , testGroup "reader"
49− [ test "basic" ["-r", "latex", "-w", "native", "-s", "-R"]
49+ [ test "basic" ["-r", "latex+raw_tex", "-w", "native", "-s"]
5050 "latex-reader.latex" "latex-reader.native"
5151 , lhsReaderTest "latex+lhs"
5252 ]
test/command/parse-raw.mdnew file+27
@@ -0,0 +1,27 @@
1+```
2+% pandoc -f latex+raw_tex -t markdown
3+\emph{Hi \foo{there}}
4+^D
5+*Hi \foo{there}*
6+```
7+
8+```
9+% pandoc -f latex -t markdown
10+\emph{Hi \foo{there}}
11+^D
12+*Hi*
13+```
14+
15+```
16+% pandoc -f html+raw_html -t markdown
17+<em>Hi <blink>there</blink></em>
18+^D
19+*Hi <blink>there</blink>*
20+```
21+
22+```
23+% pandoc -f html -t markdown
24+<em>Hi <blink>there</blink></em>
25+^D
26+*Hi there*
27+```