aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2018-08-21 17:39:27 -0700
committerJohn MacFarlane <jgm@berkeley.edu>2018-08-21 17:39:27 -0700
commita733068ebf4b9dea2769c5698a4d46e6e5918bf1 (patch)
treeb1394729229209e82cf168f0f414f68c8379e5db
parentfb3295cb9e54260b5395afde669aa2a14334592b (diff)
downloadpandoc-a733068ebf4b9dea2769c5698a4d46e6e5918bf1.tar.gz
LaTeX reader: support enquote*, foreignquote, hypphenquote...
from csquotes. See #4848. Still TBD: blockquote, blockcquote, foreignblockquote.
-rw-r--r--src/Text/Pandoc/Readers/LaTeX.hs30
-rw-r--r--test/command/4848.md58
2 files changed, 82 insertions, 6 deletions
diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 2f16738ac..cd21179df 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -975,13 +975,22 @@ quoted' f starter ender = do
cs -> cs)
else lit startchs
-enquote :: PandocMonad m => LP m Inlines
-enquote = do
+enquote :: PandocMonad m => Bool -> Maybe Text -> LP m Inlines
+enquote starred mblang = do
skipopts
+ let lang = (T.unpack <$> mblang) >>= babelLangToBCP47
+ let langspan = case lang of
+ Nothing -> id
+ Just l -> spanWith ("",[],[("lang", renderLang l)])
quoteContext <- sQuoteContext <$> getState
- if quoteContext == InDoubleQuote
- then singleQuoted <$> withQuoteContext InSingleQuote tok
- else doubleQuoted <$> withQuoteContext InDoubleQuote tok
+ if starred || quoteContext == InDoubleQuote
+ then singleQuoted . langspan <$> withQuoteContext InSingleQuote tok
+ else doubleQuoted . langspan <$> withQuoteContext InDoubleQuote tok
+
+blockquote :: PandocMonad m => LP m Blocks
+blockquote = do
+ bs <- grouped block
+ return $ blockQuote bs
doAcronym :: PandocMonad m => String -> LP m Inlines
doAcronym form = do
@@ -1769,7 +1778,14 @@ inlineCommands = M.union inlineLanguageCommands $ M.fromList
src <- unescapeURL . T.unpack .
removeDoubleQuotes . untokenize <$> braced
mkImage options src)
- , ("enquote", enquote)
+ , ("enquote*", enquote True Nothing)
+ , ("enquote", enquote False Nothing)
+ -- foreignquote is supposed to use native quote marks
+ , ("foreignquote*", braced >>= enquote True . Just . untokenize)
+ , ("foreignquote", braced >>= enquote False . Just . untokenize)
+ -- hypehnquote uses regular quotes
+ , ("hyphenquote*", braced >>= enquote True . Just . untokenize)
+ , ("hyphenquote", braced >>= enquote False . Just . untokenize)
, ("figurename", doTerm Translations.Figure)
, ("prefacename", doTerm Translations.Preface)
, ("refname", doTerm Translations.References)
@@ -2524,6 +2540,8 @@ blockCommands = M.fromList
-- LaTeX colors
, ("textcolor", coloredBlock "color")
, ("colorbox", coloredBlock "background-color")
+ -- csquotse
+ , ("blockquote", blockquote)
-- include
, ("include", include "include")
, ("input", include "input")
diff --git a/test/command/4848.md b/test/command/4848.md
new file mode 100644
index 000000000..287bd9d33
--- /dev/null
+++ b/test/command/4848.md
@@ -0,0 +1,58 @@
+```
+% pandoc -f latex -t native
+\enquote*{hi}
+^D
+[Para [Quoted SingleQuote [Str "hi"]]]
+```
+
+```
+% pandoc -f latex -t native
+\foreignquote{italian}{hi}
+^D
+[Para [Quoted DoubleQuote [Span ("",[],[("lang","it")]) [Str "hi"]]]]
+```
+
+```
+% pandoc -f latex -t native
+\hyphenquote*{italian}{hi}
+^D
+[Para [Quoted SingleQuote [Span ("",[],[("lang","it")]) [Str "hi"]]]]
+```
+
+```
+% pandoc -f latex -t native
+Lorem ipsum
+\blockquote{dolor sit amet}
+consectetuer.
+^D
+[Para [Str "Lorem",Space,Str "ipsum"]
+,BlockQuote
+ [Para [Str "dolor",Space,Str "sit",Space,Str "amet"]]
+,Para [Str "consectetuer."]]
+```
+
+```
+% pandoc -f latex -t native
+Lorem ipsum
+\blockcquote[198]{Knu86}{dolor sit amet}
+consectetuer.
+^D
+[Para [Str "Lorem",Space,Str "ipsum"]
+,BlockQuote
+ [Para [Str "dolor",Space,Str "sit",Space,Str "amet",Space,Cite [Citation {citationId = "Knu86", citationPrefix = [], citationSuffix = [Str "198"], citationMode = NormalCitation, citationNoteNum = 0, citationHash = 0}] [RawInline (Format "latex") "\\cite[198]{Knu86}"]]]
+,Para [Str "consectetuer."]]
+```
+
+```
+% pandoc -f latex -t native
+Lorem ipsum
+\foreignblockquote{italian}{dolor sit amet}
+consectetuer.
+^D
+[Para [Str "Lorem",Space,Str "ipsum"]
+,Div ("",[],[("lang","it")])
+ [BlockQuote
+ [Para [Str "dolor",Space,Str "sit",Space,Str "amet"]]]
+,Para [Str "consectetuer."]]
+```
+