@@ -34,14 +34,14 @@ import qualified Data.Set as Set
3434import Data.Text (Text)
3535import qualified Data.Text as T
3636import System.FilePath (addExtension, replaceExtension, takeExtension)
37−import Text.Pandoc.BCP47 (Lang (..), renderLang)
38−import Text.Pandoc.Builder
37+import Text.Pandoc.BCP47 (renderLang)
38+import Text.Pandoc.Builder as B
3939import Text.Pandoc.Class.PandocPure (PandocPure)
4040import Text.Pandoc.Class.PandocMonad (PandocMonad (..), getResourcePath,
41− readFileFromDirs, report, setResourcePath,
42− translateTerm)
41+ readFileFromDirs, report,
42+ setResourcePath)
4343import Text.Pandoc.Error (PandocError (PandocParseError, PandocParsecError))
44−import Text.Pandoc.Highlighting (fromListingsLanguage, languagesByExtension)
44+import Text.Pandoc.Highlighting (languagesByExtension)
4545import Text.Pandoc.ImageSize (numUnit, showFl)
4646import Text.Pandoc.Logging
4747import Text.Pandoc.Options
@@ -49,7 +49,6 @@ import Text.Pandoc.Parsing hiding (blankline, many, mathDisplay, mathInline,
4949 optional, space, spaces, withRaw, (<|>))
5050import Text.Pandoc.Readers.LaTeX.Types (Tok (..), TokType (..))
5151import Text.Pandoc.Readers.LaTeX.Parsing
52−import Text.Pandoc.Readers.LaTeX.Accent (accentCommands)
5352import Text.Pandoc.Readers.LaTeX.Citation (citationCommands, cites)
5453import Text.Pandoc.Readers.LaTeX.Math (dollarsMath, inlineEnvironments,
5554 inlineEnvironment,
@@ -58,13 +57,18 @@ import Text.Pandoc.Readers.LaTeX.Math (dollarsMath, inlineEnvironments,
5857 theoremEnvironment)
5958import Text.Pandoc.Readers.LaTeX.Table (tableEnvironments)
6059import Text.Pandoc.Readers.LaTeX.Macro (macroDef)
61−import Text.Pandoc.Readers.LaTeX.Lang (polyglossiaLangToBCP47,
60+import Text.Pandoc.Readers.LaTeX.Lang (inlineLanguageCommands,
61+ enquoteCommands,
6262 babelLangToBCP47, setDefaultLanguage)
6363import Text.Pandoc.Readers.LaTeX.SIunitx (siunitxCommands)
64+import Text.Pandoc.Readers.LaTeX.Inline (acronymCommands, refCommands,
65+ nameCommands, charCommands,
66+ accentCommands,
67+ biblatexInlineCommands,
68+ verbCommands, rawInlineOr,
69+ listingsLanguage)
6470import Text.Pandoc.Shared
65−import qualified Text.Pandoc.Translations as Translations
6671import Text.Pandoc.Walk
67−import qualified Text.Pandoc.Builder as B
6872import Safe
6973
7074-- for debugging:
@@ -290,18 +294,6 @@ quoted' f starter ender = do
290294lit :: Text -> LP m Inlines
291295lit = pure . str
292296
293−enquote :: PandocMonad m => Bool -> Maybe Text -> LP m Inlines
294−enquote starred mblang = do
295− skipopts
296− let lang = mblang >>= babelLangToBCP47
297− let langspan = case lang of
298− Nothing -> id
299− Just l -> spanWith ("",[],[("lang", renderLang l)])
300− quoteContext <- sQuoteContext <$> getState
301− if starred || quoteContext == InDoubleQuote
302− then singleQuoted . langspan <$> withQuoteContext InSingleQuote tok
303− else doubleQuoted . langspan <$> withQuoteContext InDoubleQuote tok
304−
305297blockquote :: PandocMonad m => Bool -> Maybe Text -> LP m Blocks
306298blockquote cvariant mblang = do
307299 citepar <- if cvariant
@@ -317,76 +309,6 @@ blockquote cvariant mblang = do
317309 optional $ symbolIn (".:;?!" :: [Char]) -- currently ignored
318310 return $ blockQuote . langdiv $ (bs <> citepar)
319311
320−doAcronym :: PandocMonad m => Text -> LP m Inlines
321−doAcronym form = do
322− acro <- braced
323− return . mconcat $ [spanWith ("",[],[("acronym-label", untokenize acro),
324− ("acronym-form", "singular+" <> form)])
325− $ str $ untokenize acro]
326−
327−doAcronymPlural :: PandocMonad m => Text -> LP m Inlines
328−doAcronymPlural form = do
329− acro <- braced
330− plural <- lit "s"
331− return . mconcat $ [spanWith ("",[],[("acronym-label", untokenize acro),
332− ("acronym-form", "plural+" <> form)]) $
333− mconcat [str $ untokenize acro, plural]]
334−
335−doverb :: PandocMonad m => LP m Inlines
336−doverb = do
337− Tok _ Symbol t <- anySymbol
338− marker <- case T.uncons t of
339− Just (c, ts) | T.null ts -> return c
340− _ -> mzero
341− withVerbatimMode $
342− code . untokenize <$>
343− manyTill (notFollowedBy newlineTok >> verbTok marker) (symbol marker)
344−
345−verbTok :: PandocMonad m => Char -> LP m Tok
346−verbTok stopchar = do
347− t@(Tok pos toktype txt) <- anyTok
348− case T.findIndex (== stopchar) txt of
349− Nothing -> return t
350− Just i -> do
351− let (t1, t2) = T.splitAt i txt
352− inp <- getInput
353− setInput $ Tok (incSourceColumn pos i) Symbol (T.singleton stopchar)
354− : totoks (incSourceColumn pos (i + 1)) (T.drop 1 t2) ++ inp
355− return $ Tok pos toktype t1
356−
357−listingsLanguage :: [(Text, Text)] -> Maybe Text
358−listingsLanguage opts =
359− case lookup "language" opts of
360− Nothing -> Nothing
361− Just l -> fromListingsLanguage l `mplus` Just l
362−
363−dolstinline :: PandocMonad m => LP m Inlines
364−dolstinline = do
365− options <- option [] keyvals
366− let classes = maybeToList $ listingsLanguage options
367− doinlinecode classes
368−
369−domintinline :: PandocMonad m => LP m Inlines
370−domintinline = do
371− skipopts
372− cls <- untokenize <$> braced
373− doinlinecode [cls]
374−
375−doinlinecode :: PandocMonad m => [Text] -> LP m Inlines
376−doinlinecode classes = do
377− Tok _ Symbol t <- anySymbol
378− marker <- case T.uncons t of
379− Just (c, ts) | T.null ts -> return c
380− _ -> mzero
381− let stopchar = if marker == '{' then '}' else marker
382− withVerbatimMode $
383− codeWith ("",classes,[]) . T.map nlToSpace . untokenize <$>
384− manyTill (verbTok stopchar) (symbol stopchar)
385−
386−nlToSpace :: Char -> Char
387−nlToSpace '\n' = ' '
388−nlToSpace x = x
389−
390312inlineCommand' :: PandocMonad m => LP m Inlines
391313inlineCommand' = try $ do
392314 Tok _ (CtrlSeq name) cmd <- anyControlSeq
@@ -405,9 +327,6 @@ inlineCommand' = try $ do
405327tok :: PandocMonad m => LP m Inlines
406328tok = tokWith inline
407329
408−inBrackets :: Inlines -> Inlines
409−inBrackets x = str "[" <> x <> str "]"
410−
411330unescapeURL :: Text -> Text
412331unescapeURL = T.concat . go . T.splitOn "\\"
413332 where
@@ -420,234 +339,104 @@ unescapeURL = T.concat . go . T.splitOn "\\"
420339 | otherwise = "\\" <> t
421340
422341inlineCommands :: PandocMonad m => M.Map Text (LP m Inlines)
423−inlineCommands =
424− M.union inlineLanguageCommands $
425− M.union (accentCommands tok) $
426− M.union (citationCommands inline) $
427− M.union (siunitxCommands tok) $
428− M.fromList
429− [ ("emph", extractSpaces emph <$> tok)
430− , ("textit", extractSpaces emph <$> tok)
431− , ("textsl", extractSpaces emph <$> tok)
432− , ("textsc", extractSpaces smallcaps <$> tok)
433− , ("textsf", extractSpaces (spanWith ("",["sans-serif"],[])) <$> tok)
434− , ("textmd", extractSpaces (spanWith ("",["medium"],[])) <$> tok)
435− , ("textrm", extractSpaces (spanWith ("",["roman"],[])) <$> tok)
436− , ("textup", extractSpaces (spanWith ("",["upright"],[])) <$> tok)
437− , ("texttt", ttfamily)
438− , ("sout", extractSpaces strikeout <$> tok)
439− , ("alert", skipopts >> spanWith ("",["alert"],[]) <$> tok) -- beamer
440− , ("lq", return (str "‘"))
441− , ("rq", return (str "’"))
442− , ("textquoteleft", return (str "‘"))
443− , ("textquoteright", return (str "’"))
444− , ("textquotedblleft", return (str "“"))
445− , ("textquotedblright", return (str "”"))
446− , ("textsuperscript", extractSpaces superscript <$> tok)
447− , ("textsubscript", extractSpaces subscript <$> tok)
448− , ("textbackslash", lit "\\")
449− , ("backslash", lit "\\")
450− , ("slash", lit "/")
451− , ("textbf", extractSpaces strong <$> tok)
452− , ("textnormal", extractSpaces (spanWith ("",["nodecor"],[])) <$> tok)
453− , ("underline", underline <$> tok)
454− , ("ldots", lit "…")
455− , ("vdots", lit "\8942")
456− , ("dots", lit "…")
457− , ("mdots", lit "…")
458− , ("sim", lit "~")
459− , ("sep", lit ",")
460− , ("label", rawInlineOr "label" dolabel)
461− , ("ref", rawInlineOr "ref" $ doref "ref")
462− , ("cref", rawInlineOr "cref" $ doref "ref") -- from cleveref.sty
463− , ("vref", rawInlineOr "vref" $ doref "ref+page") -- from varioref.sty
464− , ("eqref", rawInlineOr "eqref" $ doref "eqref") -- from amsmath.sty
465− , ("mbox", rawInlineOr "mbox" $ processHBox <$> tok)
466− , ("hbox", rawInlineOr "hbox" $ processHBox <$> tok)
467− , ("lettrine", rawInlineOr "lettrine" lettrine)
468− , ("(", mathInline . untokenize <$> manyTill anyTok (controlSeq ")"))
469− , ("[", mathDisplay . untokenize <$> manyTill anyTok (controlSeq "]"))
470− , ("ensuremath", mathInline . untokenize <$> braced)
471− , ("texorpdfstring", const <$> tok <*> tok)
472− , ("P", lit "¶")
473− , ("S", lit "§")
474− , ("$", lit "$")
475− , ("%", lit "%")
476− , ("&", lit "&")
477− , ("#", lit "#")
478− , ("_", lit "_")
479− , ("{", lit "{")
480− , ("}", lit "}")
481− , ("qed", lit "\a0\x25FB")
482− -- old TeX commands
483− , ("em", extractSpaces emph <$> inlines)
484− , ("it", extractSpaces emph <$> inlines)
485− , ("sl", extractSpaces emph <$> inlines)
486− , ("bf", extractSpaces strong <$> inlines)
487− , ("tt", code . stringify . toList <$> inlines)
488− , ("rm", inlines)
489− , ("itshape", extractSpaces emph <$> inlines)
490− , ("slshape", extractSpaces emph <$> inlines)
491− , ("scshape", extractSpaces smallcaps <$> inlines)
492− , ("bfseries", extractSpaces strong <$> inlines)
493− , ("MakeUppercase", makeUppercase <$> tok)
494− , ("MakeTextUppercase", makeUppercase <$> tok) -- textcase
495− , ("uppercase", makeUppercase <$> tok)
496− , ("MakeLowercase", makeLowercase <$> tok)
497− , ("MakeTextLowercase", makeLowercase <$> tok)
498− , ("lowercase", makeLowercase <$> tok)
499− , ("/", pure mempty) -- italic correction
500− , ("\\", linebreak <$ (do inTableCell <- sInTableCell <$> getState
501− guard $ not inTableCell
502− optional rawopt
503− spaces))
504− , (",", lit "\8198")
505− , ("@", pure mempty)
506− , (" ", lit "\160")
507− , ("ps", pure $ str "PS." <> space)
508− , ("TeX", lit "TeX")
509− , ("LaTeX", lit "LaTeX")
510− , ("bar", lit "|")
511− , ("textless", lit "<")
512− , ("textgreater", lit ">")
513− , ("thanks", skipopts >> note <$> grouped block)
514− , ("footnote", skipopts >> note <$> grouped block)
515− , ("passthrough", tok) -- \passthrough macro used by latex writer
516− -- for listings
517− , ("verb", doverb)
518− , ("lstinline", dolstinline)
519− , ("mintinline", domintinline)
520− , ("Verb", doverb)
521− , ("url", (\url -> link url "" (str url)) . unescapeURL . untokenize <$>
522− bracedUrl)
523− , ("nolinkurl", code . unescapeURL . untokenize <$> bracedUrl)
524− , ("href", do url <- bracedUrl
525− sp
526− link (unescapeURL $ untokenize url) "" <$> tok)
527− , ("includegraphics", do options <- option [] keyvals
528− src <- braced
529− mkImage options . unescapeURL . removeDoubleQuotes $
530− untokenize src)
531− , ("enquote*", enquote True Nothing)
532− , ("enquote", enquote False Nothing)
533− -- foreignquote is supposed to use native quote marks
534− , ("foreignquote*", braced >>= enquote True . Just . untokenize)
535− , ("foreignquote", braced >>= enquote False . Just . untokenize)
536− -- hypehnquote uses regular quotes
537− , ("hyphenquote*", braced >>= enquote True . Just . untokenize)
538− , ("hyphenquote", braced >>= enquote False . Just . untokenize)
539− , ("figurename", doTerm Translations.Figure)
540− , ("prefacename", doTerm Translations.Preface)
541− , ("refname", doTerm Translations.References)
542− , ("bibname", doTerm Translations.Bibliography)
543− , ("chaptername", doTerm Translations.Chapter)
544− , ("partname", doTerm Translations.Part)
545− , ("contentsname", doTerm Translations.Contents)
546− , ("listfigurename", doTerm Translations.ListOfFigures)
547− , ("listtablename", doTerm Translations.ListOfTables)
548− , ("indexname", doTerm Translations.Index)
549− , ("abstractname", doTerm Translations.Abstract)
550− , ("tablename", doTerm Translations.Table)
551− , ("enclname", doTerm Translations.Encl)
552− , ("ccname", doTerm Translations.Cc)
553− , ("headtoname", doTerm Translations.To)
554− , ("pagename", doTerm Translations.Page)
555− , ("seename", doTerm Translations.See)
556− , ("seealsoname", doTerm Translations.SeeAlso)
557− , ("proofname", doTerm Translations.Proof)
558− , ("glossaryname", doTerm Translations.Glossary)
559− , ("lstlistingname", doTerm Translations.Listing)
560− , ("hyperlink", hyperlink)
561− , ("hypertarget", hypertargetInline)
562− -- glossaries package
563− , ("gls", doAcronym "short")
564− , ("Gls", doAcronym "short")
565− , ("glsdesc", doAcronym "long")
566− , ("Glsdesc", doAcronym "long")
567− , ("GLSdesc", doAcronym "long")
568− , ("acrlong", doAcronym "long")
569− , ("Acrlong", doAcronym "long")
570− , ("acrfull", doAcronym "full")
571− , ("Acrfull", doAcronym "full")
572− , ("acrshort", doAcronym "abbrv")
573− , ("Acrshort", doAcronym "abbrv")
574− , ("glspl", doAcronymPlural "short")
575− , ("Glspl", doAcronymPlural "short")
576− , ("glsdescplural", doAcronymPlural "long")
577− , ("Glsdescplural", doAcronymPlural "long")
578− , ("GLSdescplural", doAcronymPlural "long")
579− -- acronyms package
580− , ("ac", doAcronym "short")
581− , ("acf", doAcronym "full")
582− , ("acs", doAcronym "abbrv")
583− , ("acl", doAcronym "long")
584− , ("acp", doAcronymPlural "short")
585− , ("acfp", doAcronymPlural "full")
586− , ("acsp", doAcronymPlural "abbrv")
587− , ("aclp", doAcronymPlural "long")
588− , ("Ac", doAcronym "short")
589− , ("Acf", doAcronym "full")
590− , ("Acs", doAcronym "abbrv")
591− , ("Acl", doAcronym "long")
592− , ("Acp", doAcronymPlural "short")
593− , ("Acfp", doAcronymPlural "full")
594− , ("Acsp", doAcronymPlural "abbrv")
595− , ("Aclp", doAcronymPlural "long")
596− -- hyphenat
597− , ("bshyp", lit "\\\173")
598− , ("fshyp", lit "/\173")
599− , ("dothyp", lit ".\173")
600− , ("colonhyp", lit ":\173")
601− , ("hyp", lit "-")
602− , ("nohyphens", tok)
603− , ("textnhtt", ttfamily)
604− , ("nhttfamily", ttfamily)
605− -- LaTeX colors
606− , ("textcolor", coloredInline "color")
607− , ("colorbox", coloredInline "background-color")
608− -- fontawesome
609− , ("faCheck", lit "\10003")
610− , ("faClose", lit "\10007")
611− -- xspace
612− , ("xspace", doxspace)
613− -- etoolbox
614− , ("ifstrequal", ifstrequal)
615− , ("newtoggle", braced >>= newToggle)
616− , ("toggletrue", braced >>= setToggle True)
617− , ("togglefalse", braced >>= setToggle False)
618− , ("iftoggle", try $ ifToggle >> inline)
619− -- biblatex misc
620− , ("RN", romanNumeralUpper)
621− , ("Rn", romanNumeralLower)
622− -- babel
623− , ("foreignlanguage", foreignlanguage)
624− -- include
625− , ("input", rawInlineOr "input" $ include "input")
626− -- soul package
627− , ("ul", underline <$> tok)
628− -- ulem package
629− , ("uline", underline <$> tok)
630− -- plain tex stuff that should just be passed through as raw tex
631− , ("ifdim", ifdim)
632− -- bibtex
633− , ("mkbibquote", spanWith nullAttr . doubleQuoted <$> tok)
634− , ("mkbibemph", spanWith nullAttr . emph <$> tok)
635− , ("mkbibitalic", spanWith nullAttr . emph <$> tok)
636− , ("mkbibbold", spanWith nullAttr . strong <$> tok)
637− , ("mkbibparens",
638− spanWith nullAttr . (\x -> str "(" <> x <> str ")") <$> tok)
639− , ("mkbibbrackets",
640− spanWith nullAttr . (\x -> str "[" <> x <> str "]") <$> tok)
641− , ("autocap", spanWith nullAttr <$> tok)
642− , ("textnormal", spanWith ("",["nodecor"],[]) <$> tok)
643− , ("bibstring",
644− (\x -> spanWith ("",[],[("bibstring",x)]) (str x)) . untokenize
645− <$> braced)
646− , ("adddot", pure (str "."))
647− , ("adddotspace", pure (spanWith nullAttr (str "." <> space)))
648− , ("addabbrvspace", pure space)
649− , ("hyphen", pure (str "-"))
650− ]
342+inlineCommands = M.unions
343+ [ accentCommands tok
344+ , citationCommands inline
345+ , siunitxCommands tok
346+ , acronymCommands
347+ , refCommands
348+ , nameCommands
349+ , verbCommands
350+ , charCommands
351+ , enquoteCommands tok
352+ , inlineLanguageCommands tok
353+ , biblatexInlineCommands tok
354+ , rest ]
355+ where
356+ rest = M.fromList
357+ [ ("emph", extractSpaces emph <$> tok)
358+ , ("textit", extractSpaces emph <$> tok)
359+ , ("textsl", extractSpaces emph <$> tok)
360+ , ("textsc", extractSpaces smallcaps <$> tok)
361+ , ("textsf", extractSpaces (spanWith ("",["sans-serif"],[])) <$> tok)
362+ , ("textmd", extractSpaces (spanWith ("",["medium"],[])) <$> tok)
363+ , ("textrm", extractSpaces (spanWith ("",["roman"],[])) <$> tok)
364+ , ("textup", extractSpaces (spanWith ("",["upright"],[])) <$> tok)
365+ , ("texttt", ttfamily)
366+ , ("sout", extractSpaces strikeout <$> tok)
367+ , ("alert", skipopts >> spanWith ("",["alert"],[]) <$> tok) -- beamer
368+ , ("textsuperscript", extractSpaces superscript <$> tok)
369+ , ("textsubscript", extractSpaces subscript <$> tok)
370+ , ("textbf", extractSpaces strong <$> tok)
371+ , ("textnormal", extractSpaces (spanWith ("",["nodecor"],[])) <$> tok)
372+ , ("underline", underline <$> tok)
373+ , ("mbox", rawInlineOr "mbox" $ processHBox <$> tok)
374+ , ("hbox", rawInlineOr "hbox" $ processHBox <$> tok)
375+ , ("lettrine", rawInlineOr "lettrine" lettrine)
376+ , ("(", mathInline . untokenize <$> manyTill anyTok (controlSeq ")"))
377+ , ("[", mathDisplay . untokenize <$> manyTill anyTok (controlSeq "]"))
378+ , ("ensuremath", mathInline . untokenize <$> braced)
379+ , ("texorpdfstring", const <$> tok <*> tok)
380+ -- old TeX commands
381+ , ("em", extractSpaces emph <$> inlines)
382+ , ("it", extractSpaces emph <$> inlines)
383+ , ("sl", extractSpaces emph <$> inlines)
384+ , ("bf", extractSpaces strong <$> inlines)
385+ , ("tt", code . stringify . toList <$> inlines)
386+ , ("rm", inlines)
387+ , ("itshape", extractSpaces emph <$> inlines)
388+ , ("slshape", extractSpaces emph <$> inlines)
389+ , ("scshape", extractSpaces smallcaps <$> inlines)
390+ , ("bfseries", extractSpaces strong <$> inlines)
391+ , ("MakeUppercase", makeUppercase <$> tok)
392+ , ("MakeTextUppercase", makeUppercase <$> tok) -- textcase
393+ , ("uppercase", makeUppercase <$> tok)
394+ , ("MakeLowercase", makeLowercase <$> tok)
395+ , ("MakeTextLowercase", makeLowercase <$> tok)
396+ , ("lowercase", makeLowercase <$> tok)
397+ , ("thanks", skipopts >> note <$> grouped block)
398+ , ("footnote", skipopts >> note <$> grouped block)
399+ , ("passthrough", tok) -- \passthrough macro used by latex writer
400+ -- for listings
401+ , ("includegraphics", do options <- option [] keyvals
402+ src <- braced
403+ mkImage options .
404+ unescapeURL .
405+ removeDoubleQuotes $ untokenize src)
406+ -- hyperref
407+ , ("url", (\url -> link url "" (str url)) . unescapeURL . untokenize <$>
408+ bracedUrl)
409+ , ("nolinkurl", code . unescapeURL . untokenize <$> bracedUrl)
410+ , ("href", do url <- bracedUrl
411+ sp
412+ link (unescapeURL $ untokenize url) "" <$> tok)
413+ , ("hyperlink", hyperlink)
414+ , ("hyperref", hyperref)
415+ , ("hypertarget", hypertargetInline)
416+ -- hyphenat
417+ , ("nohyphens", tok)
418+ , ("textnhtt", ttfamily)
419+ , ("nhttfamily", ttfamily)
420+ -- LaTeX colors
421+ , ("textcolor", coloredInline "color")
422+ , ("colorbox", coloredInline "background-color")
423+ -- xspace
424+ , ("xspace", doxspace)
425+ -- etoolbox
426+ , ("ifstrequal", ifstrequal)
427+ , ("newtoggle", braced >>= newToggle)
428+ , ("toggletrue", braced >>= setToggle True)
429+ , ("togglefalse", braced >>= setToggle False)
430+ , ("iftoggle", try $ ifToggle >> inline)
431+ -- include
432+ , ("input", rawInlineOr "input" $ include "input")
433+ -- soul package
434+ , ("ul", underline <$> tok)
435+ -- ulem package
436+ , ("uline", underline <$> tok)
437+ -- plain tex stuff that should just be passed through as raw tex
438+ , ("ifdim", ifdim)
439+ ]
651440
652441lettrine :: PandocMonad m => LP m Inlines
653442lettrine = do
@@ -671,32 +460,18 @@ alterStr :: (Text -> Text) -> Inline -> Inline
671460alterStr f (Str xs) = Str (f xs)
672461alterStr _ x = x
673462
674−foreignlanguage :: PandocMonad m => LP m Inlines
675−foreignlanguage = do
676− babelLang <- untokenize <$> braced
677− case babelLangToBCP47 babelLang of
678− Just lang -> spanWith ("", [], [("lang", renderLang lang)]) <$> tok
679− _ -> tok
680−
681−inlineLanguageCommands :: PandocMonad m => M.Map Text (LP m Inlines)
682−inlineLanguageCommands = M.fromList $ mk <$> M.toList polyglossiaLangToBCP47
683− where
684− mk (polyglossia, bcp47Func) =
685− ("text" <> polyglossia, inlineLanguage bcp47Func)
686−
687−inlineLanguage :: PandocMonad m => (Text -> Lang) -> LP m Inlines
688−inlineLanguage bcp47Func = do
689− o <- option "" $ T.filter (\c -> c /= '[' && c /= ']')
690− <$> rawopt
691− let lang = renderLang $ bcp47Func o
692− extractSpaces (spanWith ("", [], [("lang", lang)])) <$> tok
693−
694463hyperlink :: PandocMonad m => LP m Inlines
695464hyperlink = try $ do
696465 src <- untokenize <$> braced
697466 lab <- tok
698467 return $ link ("#" <> src) "" lab
699468
469+hyperref :: PandocMonad m => LP m Inlines
470+hyperref = try $ do
471+ url <- (("#" <>) . untokenize <$> try (sp *> bracketedToks <* sp))
472+ <|> untokenize <$> (bracedUrl <* bracedUrl <* bracedUrl)
473+ link url "" <$> tok
474+
700475hypertargetBlock :: PandocMonad m => LP m Blocks
701476hypertargetBlock = try $ do
702477 ref <- untokenize <$> braced
@@ -711,31 +486,6 @@ hypertargetInline = try $ do
711486 ils <- grouped inline
712487 return $ spanWith (ref, [], []) ils
713488
714−romanNumeralUpper :: (PandocMonad m) => LP m Inlines
715−romanNumeralUpper =
716− str . toRomanNumeral <$> romanNumeralArg
717−
718−romanNumeralLower :: (PandocMonad m) => LP m Inlines
719−romanNumeralLower =
720− str . T.toLower . toRomanNumeral <$> romanNumeralArg
721−
722−romanNumeralArg :: (PandocMonad m) => LP m Int
723−romanNumeralArg = spaces *> (parser <|> inBraces)
724− where
725− inBraces = do
726− symbol '{'
727− spaces
728− res <- parser
729− spaces
730− symbol '}'
731− return res
732− parser = do
733− s <- untokenize <$> many1 (satisfyTok isWordTok)
734− let (digits, rest) = T.span isDigit s
735− unless (T.null rest) $
736− Prelude.fail "Non-digits in argument to \\Rn or \\RN"
737− safeRead digits
738−
739489newToggle :: (Monoid a, PandocMonad m) => [Tok] -> LP m a
740490newToggle name = do
741491 updateState $ \st ->
@@ -766,9 +516,6 @@ ifToggle = do
766516 report $ UndefinedToggle name' pos
767517 return ()
768518
769−doTerm :: PandocMonad m => Translations.Term -> LP m Inlines
770−doTerm term = str <$> translateTerm term
771−
772519ifstrequal :: (PandocMonad m, Monoid a) => LP m a
773520ifstrequal = do
774521 str1 <- tok
@@ -789,13 +536,6 @@ coloredInline stylename = do
789536ttfamily :: PandocMonad m => LP m Inlines
790537ttfamily = code . stringify . toList <$> tok
791538
792−rawInlineOr :: PandocMonad m => Text -> LP m Inlines -> LP m Inlines
793−rawInlineOr name' fallback = do
794− parseRaw <- extensionEnabled Ext_raw_tex <$> getOption readerExtensions
795− if parseRaw
796− then rawInline "latex" <$> getRawCommand name' ("\\" <> name')
797− else fallback
798−
799539processHBox :: Inlines -> Inlines
800540processHBox = walk convert
801541 where
@@ -846,25 +586,6 @@ treatAsInline = Set.fromList
846586 , "pagebreak"
847587 ]
848588
849−dolabel :: PandocMonad m => LP m Inlines
850−dolabel = do
851− v <- braced
852− let refstr = untokenize v
853− updateState $ \st ->
854− st{ sLastLabel = Just refstr }
855− return $ spanWith (refstr,[],[("label", refstr)])
856− $ inBrackets $ str $ untokenize v
857−
858−doref :: PandocMonad m => Text -> LP m Inlines
859−doref cls = do
860− v <- braced
861− let refstr = untokenize v
862− return $ linkWith ("",[],[ ("reference-type", cls)
863− , ("reference", refstr)])
864− ("#" <> refstr)
865− ""
866− (inBrackets $ str refstr)
867−
868589lookupListDefault :: (Ord k) => v -> [k] -> M.Map k v -> v
869590lookupListDefault d = (fromMaybe d .) . lookupList
870591 where lookupList l m = msum $ map (`M.lookup` m) l