git.iko.soy/typeable/pandoc
on master help sign in
Add quotes properly in markdown YAML metadata fields.

This fixes a bug, which caused the writer to look at the LAST rather than the FIRST character in determining whether quotes were needed. So we got spurious quotes in some cases and didn't get necessary quotes in others. Closes #7245. Updated a number of test cases accordingly.

commit547bc2cdf83b8be926de55521674c0e8fab12db5 authorJohn MacFarlane <jgm@berkeley.edu> dateSun 25 Apr 2021, 10:31 (6 years ago) parent7f4850c
9 files changed+16−17
src/Text/Pandoc/Writers/Markdown.hs+5−6 test/command/1279.md+1−1 test/command/biblatex-inproceedings.md+1−1 test/command/biblatex-jaffe.md+2−2 test/command/biblatex-moraux.md+1−1 test/command/biblatex-quotes.md+1−1 test/command/biblatex-spiegelberg.md+2−2 test/command/biblatex-test-case-conversion.md+2−2 test/command/biblatex-textnormal.md+1−1
src/Text/Pandoc/Writers/Markdown.hs+5−6
@@ -26,7 +26,7 @@ import Data.Default
2626import Data.List (intersperse, sortOn, transpose)
2727import Data.List.NonEmpty (nonEmpty, NonEmpty(..))
2828import qualified Data.Map as M
29−import Data.Maybe (fromMaybe, mapMaybe)
29+import Data.Maybe (fromMaybe, mapMaybe, isNothing)
3030import qualified Data.Set as Set
3131import Data.Text (Text)
3232import qualified Data.Text as T
@@ -142,18 +142,17 @@ valToYaml (SimpleVal x)
142142 | otherwise =
143143 if hasNewlines x
144144 then hang 0 ("|" <> cr) x
145− else if fst $ foldr needsDoubleQuotes (False, True) x
145+ else if isNothing $ foldM needsDoubleQuotes True x
146146 then "\"" <> fmap escapeInDoubleQuotes x <> "\""
147147 else x
148148 where
149− needsDoubleQuotes t (positive, isFirst)
149+ needsDoubleQuotes isFirst t
150150 = if T.any isBadAnywhere t ||
151151 (isFirst && T.any isYamlPunct (T.take 1 t))
152− then (True, False)
153− else (positive, False)
152+ then Nothing
153+ else Just False
154154 isBadAnywhere '#' = True
155155 isBadAnywhere ':' = True
156− isBadAnywhere '`' = False
157156 isBadAnywhere _ = False
158157 hasNewlines NewLine = True
159158 hasNewlines BlankLines{} = True
test/command/1279.md+1−1
@@ -9,7 +9,7 @@ title: My Article
99[^1]: Dept. of This and That
1010^D
1111---
12−author: "John Doe[^1]"
12+author: John Doe[^1]
1313date: 2014
1414title: My Article
1515---
test/command/biblatex-inproceedings.md+1−1
@@ -63,7 +63,7 @@ references:
6363 publisher-place: Cambridge
6464 title: "Le *De Anima* dans la tradition grècque: Quelques aspects de
6565 l'interpretation du traité, de Theophraste à Themistius"
66− title-short: *De Anima* dans la tradition grècque
66+ title-short: "*De Anima* dans la tradition grècque"
6767 type: paper-conference
6868- author:
6969 - family: Salam
test/command/biblatex-jaffe.md+2−2
@@ -72,8 +72,8 @@ references:
7272 language: la
7373 number-of-volumes: 2
7474 publisher-place: Leipzig
75− title: "Regesta Pontificum Romanorum ab condita ecclesia ad annum post
76− Christum natum [mcxcviii]{.smallcaps}"
75+ title: Regesta Pontificum Romanorum ab condita ecclesia ad annum post
76+ Christum natum [mcxcviii]{.smallcaps}
7777 title-short: Regesta Pontificum Romanorum
7878 type: book
7979---
test/command/biblatex-moraux.md+1−1
@@ -86,7 +86,7 @@ references:
8686 publisher-place: Cambridge
8787 title: "Le *De Anima* dans la tradition grècque: Quelques aspects de
8888 l'interpretation du traité, de Theophraste à Themistius"
89− title-short: *De Anima* dans la tradition grècque
89+ title-short: "*De Anima* dans la tradition grècque"
9090 type: paper-conference
9191---
9292
test/command/biblatex-quotes.md+1−1
@@ -36,7 +36,7 @@ references:
3636 language: en-US
3737 publisher: Princeton University Press
3838 publisher-place: Princeton
39− title: "Aristotle's \"De Motu Animalium\""
39+ title: Aristotle's "De Motu Animalium"
4040 type: book
4141---
4242
test/command/biblatex-spiegelberg.md+2−2
@@ -63,8 +63,8 @@ references:
6363 issued: 1969
6464 language: de-DE
6565 page: 189-216
66− title: "Intention" und "Intentionalität" in der Scholastik, bei
67− Brentano und Husserl
66+ title: "\"Intention\" und \"Intentionalität\" in der Scholastik, bei
67+ Brentano und Husserl"
6868 title-short: Intention und Intentionalität
6969 type: article-journal
7070 volume: 29
test/command/biblatex-test-case-conversion.md+2−2
@@ -63,9 +63,9 @@ references:
6363 id: item1
6464 issued: 2013
6565 language: en-US
66− title: "A title, in English, with a Proper Name and an ACRONYM and a
66+ title: A title, in English, with a Proper Name and an ACRONYM and a
6767 [camelCase]{.nocase} word and some units, 400 [nm]{.nocase},
68− 3 [cm]{.nocase}, and a quote, *Alea [iacta est]{.nocase}*"
68+ 3 [cm]{.nocase}, and a quote, *Alea [iacta est]{.nocase}*
6969 type: article-journal
7070---
7171
test/command/biblatex-textnormal.md+1−1
@@ -9,7 +9,7 @@
99nocite: "[@*]"
1010references:
1111- id: item1
12− title: "The title [of this book]{.nodecor}"
12+ title: The title [of this book]{.nodecor}
1313 type: book
1414---
1515