11--- Replaces plain quotation marks with typographic ones.
2- --
2+ --
33-- # SYNOPSIS
4- --
4+ --
55-- pandoc --lua-filter pandoc-quotes.lua
6- --
7- --
6+ --
7+ --
88-- # DESCRIPTION
9- --
9+ --
1010-- pandoc-quotes.lua is a filter for pandoc that replaces non-typographic
1111-- quotation marks with typographic ones for languages other than American
1212-- English.
13- --
13+ --
1414-- You can define which typographic quotation marks to replace plain ones with
1515-- by setting either a document's quot-marks, quot-lang, or lang
1616-- metadata field. If none of these is set, pandoc-quotes.lua does nothing.
17- --
17+ --
1818-- You can add your own mapping of a language to quotation marks or override
1919-- the default ones by setting quot-marks-by-lang.
20- --
20+ --
2121-- ## quot-marks
22- --
22+ --
2323-- A list of four strings, where the first item lists the primary left
2424-- quotation mark, the second the primary right quotation mark, the third
2525-- the secondary left quotation mark, and the fourth the secondary right
2626-- quotation mark.
27- --
27+ --
2828-- For example:
29- --
29+ --
3030-- ```yaml
3131-- ---
3232-- quot-marks:
3636-- - '
3737-- ...
3838-- ```
39- --
39+ --
4040-- You always have to set all four.
41- --
41+ --
4242-- If each quotation mark consists of one character only,
4343-- you can write the whole list as a simple string.
44- --
44+ --
4545-- For example:
46- --
46+ --
4747-- ```yaml
4848-- ---
4949-- quot-marks: ""''
5050-- ...
5151-- ```
52- --
52+ --
5353-- If quot-marks is set, the other fields are ignored.
54- --
55- --
54+ --
55+ --
5656-- # quotation-lang
57- --
57+ --
5858-- An RFC 5646-like code for the language the quotation marks of
5959-- which shall be used (e.g., "pt-BR", "es").
60- --
60+ --
6161-- For example:
62- --
62+ --
6363-- ```yaml
6464-- ---
6565-- quot-lang: de-AT
6666-- ...
6767-- ```
68- --
68+ --
6969-- Note: Only the language and the country tags of RFC 5646 are supported.
70- -- For example, "it-CH" (i.e., Italian as spoken in Switzerland) is fine,
71- -- but "it-756" (also Italian as spoken in Switzerland) will return the
70+ -- For example, "it-CH" (i.e., Italian as spoken in Switzerland) is fine,
71+ -- but "it-756" (also Italian as spoken in Switzerland) will return the
7272-- quotation marks for "it" (i.e., Italian as spoken in general).
73- --
73+ --
7474-- If quot-marks is set, quot-lang is ignored.
75- --
76- --
75+ --
76+ --
7777-- # lang
78- --
78+ --
7979-- The format of lang is the same as for quot-lang. If quot-marks
80- -- or quot-lang is set, lang is ignored.
81- --
80+ -- or quot-lang is set, lang is ignored.
81+ --
8282-- For example:
83- --
83+ --
8484-- ```yaml
8585-- ---
8686-- lang: de-AT
8787-- ...
8888-- ```
89- --
90- --
89+ --
90+ --
9191-- # ADDING LANGUAGES
92- --
92+ --
9393-- You can add quotation marks for unsupported languages, or override the
9494-- defaults, by setting the metadata field quot-marks-by-lang to a maping
9595-- of RFC 5646-like language codes (e.g., "pt-BR", "es") to lists of quotation
9696-- marks, which are given in the same format as for the quot-marks
9797-- metadata field.
98- --
98+ --
9999-- For example:
100- --
100+ --
101101-- ```yaml
102102-- ---
103103-- quot-marks-by-lang:
104104-- abc-XYZ: ""''
105105-- lang: abc-XYZ
106106-- ...
107107-- ```
108- --
109- --
108+ --
109+ --
110110-- # CAVEATS
111- --
111+ --
112112-- pandoc represents documents as abstract syntax trees internally, and
113113-- quotations are nodes in that tree. However, pandoc-quotes.lua replaces
114114-- those nodes with their content, adding proper quotation marks. That is,
115115-- pandoc-quotes.lua pushes quotations from the syntax of a document's
116- -- representation into its semantics. That being so, you should not
116+ -- representation into its semantics. That being so, you should not
117117-- use pandoc-quotes.lua with output formats that represent quotes
118118-- syntactically (e.g., HTML, LaTeX, ConTexT). Moroever, filters running after
119119-- pandoc-quotes won't recognise quotes. So, it should be the last or
120120-- one of the last filters you apply.
121- --
121+ --
122122-- Support for quotation marks of different languages is certainly incomplete
123123-- and likely erroneous. See <https://github.com/odkr/pandoc-quotes.lua> if
124124-- you'd like to help with this.
125- --
125+ --
126126-- pandoc-quotes.lua is Unicode-agnostic.
127- --
128- --
127+ --
128+ --
129129-- # SEE ALSO
130- --
130+ --
131131-- pandoc(1)
132132--
133133--
@@ -197,10 +197,10 @@ if PATH_SEP == '\\' then EOL = '\r\n'
197197
198198
199199--- A list of mappings from RFC 5646-ish language codes to quotation marks.
200- --
200+ --
201201-- I have adopted the list below from:
202202-- <https://en.wikipedia.org/w/index.php?title=Quotation_mark&oldid=836731669>
203- --
203+ --
204204-- I tried to come up with reasonable defaults for secondary quotes for
205205-- language that, according to the Wikipedia, don't have any.
206206--
@@ -218,13 +218,14 @@ if PATH_SEP == '\\' then EOL = '\r\n'
218218-- are going to use them anyway. And they should get a reasonable result,
219219-- not a runtime error.
220220--
221- -- The order in which languages are listed is meaningless. If you define
221+ -- The order in which languages are listed is meaningless. If you define
222222-- variants for a language that is spoken in different countries, also
223223-- define a 'default' for the language alone, without the country tag.
224224QUOT_MARKS_BY_LANG = {
225- bo = {' 「' , ' 」' , ' 『' , ' 』' },
226225 bs = {' ”' , ' ”' , ' ’' , ' ’' },
227- cn = {' 「' , ' 」' , ' 『' , ' 』' },
226+ bo = {' 「' , ' 」' , ' 『' , ' 』' },
227+ bs = {' ”' , ' ”' , ' ’' , ' ’' },
228+ cn = {' 「' , ' 」' , ' 『' , ' 』' },
228229 cs = {' „' , ' “' , ' ‚' , ' ‘' },
229230 cy = {' ‘' , ' ’' , ' “' , ' ”' },
230231 da = {' »' , ' «' , ' ›' , ' ‹' },
364365 --
365366 -- @tparam pandoc.MetaValue The content of a metadata field.
366367 -- Must be either of type pandoc.MetaInlines or pandoc.MetaList.
367- -- @treturn [1] {pandoc.Str,pandoc.Str,pandoc.Str,pandoc.Str}
368- -- A table of quotation marks
368+ -- @treturn [1] {pandoc.Str,pandoc.Str,pandoc.Str,pandoc.Str}
369+ -- A table of quotation marks
369370 -- @treturn [2] `nil` if an error occurred.
370371 -- @treturn [2] string An error message.
371372 function get_quotation_marks (meta )
391392
392393do
393394 local stringify = pandoc .utils .stringify
394-
395+
395396 -- Holds the quotation marks for the language of the document.
396397 -- Common to `configure` and `insert_quot_marks`.
397398 local QUOT_MARKS = nil
407408 if meta [' quot-marks-by-lang' ] then
408409 for k , v in pairs (meta [' quot-marks-by-lang' ]) do
409410 local quot_marks , err = get_quotation_marks (v )
410- if not quot_marks then
411+ if not quot_marks then
411412 warn (' metadata field "quot-marks-by-lang": lang "%s": %s.' ,
412- k , err )
413+ k , err )
413414 return
414415 end
415416 QUOT_MARKS_BY_LANG [k ] = quot_marks
418419 if meta [' quot-marks' ] then
419420 local err
420421 quot_marks , err = get_quotation_marks (meta [' quot-marks' ])
421- if not quot_marks then
422+ if not quot_marks then
422423 warn (' metadata field "quot-marks": %s.' , err )
423424 return
424425 end
440441 if quot_marks then break end
441442 end
442443 end
443- if quot_marks then QUOT_MARKS = map (pandoc .Str , quot_marks )
444+ if quot_marks then QUOT_MARKS = map (pandoc .Str , quot_marks )
444445 elseif lang then warn (' %s: unknown language.' , lang ) end
445446 end
446447
449450 local insert = table.insert
450451 --- Replaces quoted elements with quoted text.
451452 --
452- -- Uses the quotation marks stored in `QUOT_MARKS`,
453+ -- Uses the quotation marks stored in `QUOT_MARKS`,
453454 -- which it shares with `configure`.
454455 --
455456 -- @tparam pandoc.Quoted quoted A quoted element.
0 commit comments