1
1
--- Replaces plain quotation marks with typographic ones.
2
- --
2
+ --
3
3
-- # SYNOPSIS
4
- --
4
+ --
5
5
-- pandoc --lua-filter pandoc-quotes.lua
6
- --
7
- --
6
+ --
7
+ --
8
8
-- # DESCRIPTION
9
- --
9
+ --
10
10
-- pandoc-quotes.lua is a filter for pandoc that replaces non-typographic
11
11
-- quotation marks with typographic ones for languages other than American
12
12
-- English.
13
- --
13
+ --
14
14
-- You can define which typographic quotation marks to replace plain ones with
15
15
-- by setting either a document's quot-marks, quot-lang, or lang
16
16
-- metadata field. If none of these is set, pandoc-quotes.lua does nothing.
17
- --
17
+ --
18
18
-- You can add your own mapping of a language to quotation marks or override
19
19
-- the default ones by setting quot-marks-by-lang.
20
- --
20
+ --
21
21
-- ## quot-marks
22
- --
22
+ --
23
23
-- A list of four strings, where the first item lists the primary left
24
24
-- quotation mark, the second the primary right quotation mark, the third
25
25
-- the secondary left quotation mark, and the fourth the secondary right
26
26
-- quotation mark.
27
- --
27
+ --
28
28
-- For example:
29
- --
29
+ --
30
30
-- ```yaml
31
31
-- ---
32
32
-- quot-marks:
36
36
-- - '
37
37
-- ...
38
38
-- ```
39
- --
39
+ --
40
40
-- You always have to set all four.
41
- --
41
+ --
42
42
-- If each quotation mark consists of one character only,
43
43
-- you can write the whole list as a simple string.
44
- --
44
+ --
45
45
-- For example:
46
- --
46
+ --
47
47
-- ```yaml
48
48
-- ---
49
49
-- quot-marks: ""''
50
50
-- ...
51
51
-- ```
52
- --
52
+ --
53
53
-- If quot-marks is set, the other fields are ignored.
54
- --
55
- --
54
+ --
55
+ --
56
56
-- # quotation-lang
57
- --
57
+ --
58
58
-- An RFC 5646-like code for the language the quotation marks of
59
59
-- which shall be used (e.g., "pt-BR", "es").
60
- --
60
+ --
61
61
-- For example:
62
- --
62
+ --
63
63
-- ```yaml
64
64
-- ---
65
65
-- quot-lang: de-AT
66
66
-- ...
67
67
-- ```
68
- --
68
+ --
69
69
-- 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
72
72
-- quotation marks for "it" (i.e., Italian as spoken in general).
73
- --
73
+ --
74
74
-- If quot-marks is set, quot-lang is ignored.
75
- --
76
- --
75
+ --
76
+ --
77
77
-- # lang
78
- --
78
+ --
79
79
-- 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
+ --
82
82
-- For example:
83
- --
83
+ --
84
84
-- ```yaml
85
85
-- ---
86
86
-- lang: de-AT
87
87
-- ...
88
88
-- ```
89
- --
90
- --
89
+ --
90
+ --
91
91
-- # ADDING LANGUAGES
92
- --
92
+ --
93
93
-- You can add quotation marks for unsupported languages, or override the
94
94
-- defaults, by setting the metadata field quot-marks-by-lang to a maping
95
95
-- of RFC 5646-like language codes (e.g., "pt-BR", "es") to lists of quotation
96
96
-- marks, which are given in the same format as for the quot-marks
97
97
-- metadata field.
98
- --
98
+ --
99
99
-- For example:
100
- --
100
+ --
101
101
-- ```yaml
102
102
-- ---
103
103
-- quot-marks-by-lang:
104
104
-- abc-XYZ: ""''
105
105
-- lang: abc-XYZ
106
106
-- ...
107
107
-- ```
108
- --
109
- --
108
+ --
109
+ --
110
110
-- # CAVEATS
111
- --
111
+ --
112
112
-- pandoc represents documents as abstract syntax trees internally, and
113
113
-- quotations are nodes in that tree. However, pandoc-quotes.lua replaces
114
114
-- those nodes with their content, adding proper quotation marks. That is,
115
115
-- 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
117
117
-- use pandoc-quotes.lua with output formats that represent quotes
118
118
-- syntactically (e.g., HTML, LaTeX, ConTexT). Moroever, filters running after
119
119
-- pandoc-quotes won't recognise quotes. So, it should be the last or
120
120
-- one of the last filters you apply.
121
- --
121
+ --
122
122
-- Support for quotation marks of different languages is certainly incomplete
123
123
-- and likely erroneous. See <https://github.com/odkr/pandoc-quotes.lua> if
124
124
-- you'd like to help with this.
125
- --
125
+ --
126
126
-- pandoc-quotes.lua is Unicode-agnostic.
127
- --
128
- --
127
+ --
128
+ --
129
129
-- # SEE ALSO
130
- --
130
+ --
131
131
-- pandoc(1)
132
132
--
133
133
--
@@ -197,10 +197,10 @@ if PATH_SEP == '\\' then EOL = '\r\n'
197
197
198
198
199
199
--- A list of mappings from RFC 5646-ish language codes to quotation marks.
200
- --
200
+ --
201
201
-- I have adopted the list below from:
202
202
-- <https://en.wikipedia.org/w/index.php?title=Quotation_mark&oldid=836731669>
203
- --
203
+ --
204
204
-- I tried to come up with reasonable defaults for secondary quotes for
205
205
-- language that, according to the Wikipedia, don't have any.
206
206
--
@@ -218,13 +218,14 @@ if PATH_SEP == '\\' then EOL = '\r\n'
218
218
-- are going to use them anyway. And they should get a reasonable result,
219
219
-- not a runtime error.
220
220
--
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
222
222
-- variants for a language that is spoken in different countries, also
223
223
-- define a 'default' for the language alone, without the country tag.
224
224
QUOT_MARKS_BY_LANG = {
225
- bo = {' 「' , ' 」' , ' 『' , ' 』' },
226
225
bs = {' ”' , ' ”' , ' ’' , ' ’' },
227
- cn = {' 「' , ' 」' , ' 『' , ' 』' },
226
+ bo = {' 「' , ' 」' , ' 『' , ' 』' },
227
+ bs = {' ”' , ' ”' , ' ’' , ' ’' },
228
+ cn = {' 「' , ' 」' , ' 『' , ' 』' },
228
229
cs = {' „' , ' “' , ' ‚' , ' ‘' },
229
230
cy = {' ‘' , ' ’' , ' “' , ' ”' },
230
231
da = {' »' , ' «' , ' ›' , ' ‹' },
364
365
--
365
366
-- @tparam pandoc.MetaValue The content of a metadata field.
366
367
-- 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
369
370
-- @treturn [2] `nil` if an error occurred.
370
371
-- @treturn [2] string An error message.
371
372
function get_quotation_marks (meta )
391
392
392
393
do
393
394
local stringify = pandoc .utils .stringify
394
-
395
+
395
396
-- Holds the quotation marks for the language of the document.
396
397
-- Common to `configure` and `insert_quot_marks`.
397
398
local QUOT_MARKS = nil
407
408
if meta [' quot-marks-by-lang' ] then
408
409
for k , v in pairs (meta [' quot-marks-by-lang' ]) do
409
410
local quot_marks , err = get_quotation_marks (v )
410
- if not quot_marks then
411
+ if not quot_marks then
411
412
warn (' metadata field "quot-marks-by-lang": lang "%s": %s.' ,
412
- k , err )
413
+ k , err )
413
414
return
414
415
end
415
416
QUOT_MARKS_BY_LANG [k ] = quot_marks
418
419
if meta [' quot-marks' ] then
419
420
local err
420
421
quot_marks , err = get_quotation_marks (meta [' quot-marks' ])
421
- if not quot_marks then
422
+ if not quot_marks then
422
423
warn (' metadata field "quot-marks": %s.' , err )
423
424
return
424
425
end
440
441
if quot_marks then break end
441
442
end
442
443
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 )
444
445
elseif lang then warn (' %s: unknown language.' , lang ) end
445
446
end
446
447
449
450
local insert = table.insert
450
451
--- Replaces quoted elements with quoted text.
451
452
--
452
- -- Uses the quotation marks stored in `QUOT_MARKS`,
453
+ -- Uses the quotation marks stored in `QUOT_MARKS`,
453
454
-- which it shares with `configure`.
454
455
--
455
456
-- @tparam pandoc.Quoted quoted A quoted element.
0 commit comments