git.iko.soy/typeable/pandoc
on master help sign in
Clean up BibTeX parsing.

Previously there was a messy code path that gave strange results in some cases, not passing through raw tex but trying to extract a string content. This was an artefact of trying to handle some special bibtex-specific commands in the BibTeX reader. Now we just handle these in the LaTeX reader and simplify parsing in the BibTeX reader. This does mean that more raw tex will be passed through (and currently this is not sensitive to the `raw_tex` extension; this should be fixed). Closes #7049.

commit98c2a52b4ee6c833c0a2f2652386cec024e377eb authorJohn MacFarlane <jgm@berkeley.edu> dateTue 26 Jan 2021, 22:45 (6 years ago) parent12bc662
4 files changed+25−37
src/Text/Pandoc/Citeproc/BibTeX.hs+1−32 src/Text/Pandoc/Readers/LaTeX.hs+18 test/command/biblatex-cotton.md+3−3 test/command/biblatex-murray.md+3−2
src/Text/Pandoc/Citeproc/BibTeX.hs+1−32
@@ -750,41 +750,10 @@ blocksToInlines bs =
750750 _ -> B.fromList $ Walk.query (:[]) bs
751751
752752adjustSpans :: Lang -> Inline -> Inline
753−adjustSpans lang (RawInline (Format "latex") s)
754− | s == "\\hyphen" || s == "\\hyphen " = Str "-"
755− | otherwise = parseRawLaTeX lang s
753+adjustSpans lang (Span ("",[],[("bibstring",s)]) _) = Str $ resolveKey' lang s
756754adjustSpans _ SoftBreak = Space
757755adjustSpans _ x = x
758756
759−parseRawLaTeX :: Lang -> Text -> Inline
760−parseRawLaTeX lang t@(T.stripPrefix "\\" -> Just xs) =
761− case parseLaTeX lang contents of
762− Right [Para ys] -> f command ys
763− Right [Plain ys] -> f command ys
764− Right [] -> f command []
765− _ -> RawInline (Format "latex") t
766− where (command', contents') = T.break (\c -> c =='{' || c =='\\') xs
767− command = T.strip command'
768− contents = T.drop 1 $ T.dropEnd 1 contents'
769− f "mkbibquote" ils = Span nullAttr [Quoted DoubleQuote ils]
770− f "mkbibemph" ils = Span nullAttr [Emph ils]
771− f "mkbibitalic" ils = Span nullAttr [Emph ils]
772− f "mkbibbold" ils = Span nullAttr [Strong ils]
773− f "mkbibparens" ils = Span nullAttr $
774− [Str "("] ++ ils ++ [Str ")"]
775− f "mkbibbrackets" ils = Span nullAttr $
776− [Str "["] ++ ils ++ [Str "]"]
777− -- ... both should be nestable & should work in year fields
778− f "autocap" ils = Span nullAttr ils
779− -- TODO: should work in year fields
780− f "textnormal" ils = Span ("",["nodecor"],[]) ils
781− f "bibstring" [Str s] = Str $ resolveKey' lang s
782− f "adddot" [] = Str "."
783− f "adddotspace" [] = Span nullAttr [Str ".", Space]
784− f "addabbrvspace" [] = Space
785− f _ ils = Span nullAttr ils
786−parseRawLaTeX _ t = RawInline (Format "latex") t
787−
788757latex' :: Text -> Bib [Block]
789758latex' t = do
790759 lang <- gets localeLang
src/Text/Pandoc/Readers/LaTeX.hs+18
@@ -940,6 +940,24 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
940940 , ("uline", underline <$> tok)
941941 -- plain tex stuff that should just be passed through as raw tex
942942 , ("ifdim", ifdim)
943+ -- bibtex
944+ , ("mkbibquote", spanWith nullAttr . doubleQuoted <$> tok)
945+ , ("mkbibemph", spanWith nullAttr . emph <$> tok)
946+ , ("mkbibitalic", spanWith nullAttr . emph <$> tok)
947+ , ("mkbibbold", spanWith nullAttr . strong <$> tok)
948+ , ("mkbibparens",
949+ spanWith nullAttr . (\x -> str "(" <> x <> str ")") <$> tok)
950+ , ("mkbibbrackets",
951+ spanWith nullAttr . (\x -> str "[" <> x <> str "]") <$> tok)
952+ , ("autocap", spanWith nullAttr <$> tok)
953+ , ("textnormal", spanWith ("",["nodecor"],[]) <$> tok)
954+ , ("bibstring",
955+ (\x -> spanWith ("",[],[("bibstring",x)]) (str x)) . untokenize
956+ <$> braced)
957+ , ("adddot", pure (str "."))
958+ , ("adddotspace", pure (spanWith nullAttr (str "." <> space)))
959+ , ("addabbrvspace", pure space)
960+ , ("hyphen", pure (str "-"))
943961 ]
944962
945963accent :: PandocMonad m => Char -> Maybe Char -> LP m Inlines
test/command/biblatex-cotton.md+3−3
@@ -43,9 +43,9 @@ Cotton, F. A., Wilkinson, G., Murillio, C. A., & Bochmann, M. (1999).
4343---
4444nocite: "[@*]"
4545references:
46−- annote: A book entry with author authors and an edition field. By
47− default, long author and editor lists are automatically truncated.
48− This is configurable
46+- annote: A book entry with `\arabic{author}`{=latex} authors and an
47+ edition field. By default, long author and editor lists are
48+ automatically truncated. This is configurable
4949 author:
5050 - family: Cotton
5151 given: Frank Albert
test/command/biblatex-murray.md+3−2
@@ -55,8 +55,9 @@ properties as a function of core size. *Langmuir*, *14*(1), 17–30.
5555---
5656nocite: "[@*]"
5757references:
58−- annote: An article entry with author authors. By default, long author
59− and editor lists are automatically truncated. This is configurable
58+- annote: An article entry with `\arabic{author}`{=latex} authors. By
59+ default, long author and editor lists are automatically truncated.
60+ This is configurable
6061 author:
6162 - family: Hostetler
6263 given: Michael J.