|
3 | 3 |
|
4 | 4 | local patterns = require("modules/patterns") |
5 | 5 |
|
6 | | -kTblCap = "tbl-cap" |
7 | | -kTblSubCap = "tbl-subcap" |
8 | | - |
9 | | -function table_captions() |
10 | | - return { |
| 6 | +function table_captions() |
| 7 | + local kTblCap = "tbl-cap" |
| 8 | + local kTblSubCap = "tbl-subcap" |
| 9 | + return { |
11 | 10 | Div = function(el) |
12 | 11 | if tcontains(el.attr.classes, "cell") then |
13 | 12 | -- extract table attributes |
14 | | - local tblCap = extractTblCapAttrib(el,kTblCap) |
| 13 | + local tblCap = extractTblCapAttrib(el, kTblCap) |
15 | 14 | local tblSubCap = extractTblCapAttrib(el, kTblSubCap, true) |
16 | | - if hasTableRef(el) or tblCap then |
17 | | - local tables = countTables(el) |
18 | | - if tables > 0 then |
19 | | - |
20 | | - -- apply captions and labels if we have a tbl-cap or tbl-subcap |
21 | | - if tblCap or tblSubCap then |
22 | | - |
23 | | - -- special case: knitr::kable will generate a \begin{tablular} without |
24 | | - -- a \begin{table} wrapper -- put the wrapper in here if need be |
25 | | - if _quarto.format.isLatexOutput() then |
26 | | - el = _quarto.ast.walk(el, { |
27 | | - RawBlock = function(raw) |
28 | | - if _quarto.format.isRawLatex(raw) then |
29 | | - local tabular_match = _quarto.modules.patterns.match_all_in_table(_quarto.patterns.latexTabularPattern) |
30 | | - local table_match = _quarto.modules.patterns.match_all_in_table(_quarto.patterns.latexTablePattern) |
31 | | - if tabular_match(raw.text) and not table_match(raw.text) then |
32 | | - raw.text = raw.text:gsub( |
33 | | - _quarto.modules.patterns.combine_patterns(_quarto.patterns.latexTabularPattern), |
34 | | - "\\begin{table}\n\\centering\n%1%2%3\n\\end{table}\n", |
35 | | - 1) |
36 | | - return raw |
37 | | - end |
38 | | - end |
39 | | - end |
40 | | - }) |
41 | | - end |
42 | | - |
43 | | - -- compute all captions and labels |
44 | | - local label = el.attr.identifier |
45 | | - local mainCaption, tblCaptions, mainLabel, tblLabels = table_captionsAndLabels( |
46 | | - label, |
47 | | - tables, |
48 | | - tblCap, |
49 | | - tblSubCap |
50 | | - ) |
51 | | - -- apply captions and label |
52 | | - el.attr.identifier = mainLabel |
53 | | - if mainCaption then |
54 | | - el.content:insert(pandoc.Para(mainCaption)) |
55 | | - end |
56 | | - if #tblCaptions > 0 then |
57 | | - el = applyTableCaptions(el, tblCaptions, tblLabels) |
| 15 | + if not (tblCap or hasTableRef(el)) then |
| 16 | + return |
| 17 | + end |
| 18 | + if not (tblCap or tblSubCap) then |
| 19 | + return |
| 20 | + end |
| 21 | + local tables = countTables(el) |
| 22 | + if tables <= 0 then |
| 23 | + return |
| 24 | + end |
| 25 | + |
| 26 | + -- special case: knitr::kable will generate a \begin{tabular} without |
| 27 | + -- a \begin{table} wrapper -- put the wrapper in here if need be |
| 28 | + if _quarto.format.isLatexOutput() then |
| 29 | + el = _quarto.ast.walk(el, { |
| 30 | + RawBlock = function(raw) |
| 31 | + if _quarto.format.isRawLatex(raw) then |
| 32 | + local tabular_match = _quarto.modules.patterns.match_all_in_table(_quarto.patterns.latexTabularPattern) |
| 33 | + local table_match = _quarto.modules.patterns.match_all_in_table(_quarto.patterns.latexTablePattern) |
| 34 | + if tabular_match(raw.text) and not table_match(raw.text) then |
| 35 | + raw.text = raw.text:gsub( |
| 36 | + _quarto.modules.patterns.combine_patterns(_quarto.patterns.latexTabularPattern), |
| 37 | + "\\begin{table}\n\\centering\n%1%2%3\n\\end{table}\n", |
| 38 | + 1) |
| 39 | + return raw |
| 40 | + end |
58 | 41 | end |
59 | | - return el |
60 | 42 | end |
61 | | - end |
| 43 | + }) |
| 44 | + end |
| 45 | + |
| 46 | + -- compute all captions and labels |
| 47 | + local label = el.attr.identifier |
| 48 | + local mainCaption, tblCaptions, mainLabel, tblLabels = table_captionsAndLabels( |
| 49 | + label, |
| 50 | + tables, |
| 51 | + tblCap, |
| 52 | + tblSubCap |
| 53 | + ) |
| 54 | + -- apply captions and label |
| 55 | + el.attr.identifier = mainLabel |
| 56 | + if mainCaption then |
| 57 | + el.content:insert(pandoc.Para(mainCaption)) |
| 58 | + end |
| 59 | + if #tblCaptions > 0 then |
| 60 | + el = applyTableCaptions(el, tblCaptions, tblLabels) |
62 | 61 | end |
| 62 | + return el |
63 | 63 | end |
64 | | - |
65 | | - |
66 | 64 | end |
67 | 65 | } |
68 | 66 |
|
@@ -138,7 +136,7 @@ function applyTableCaptions(el, tblCaptions, tblLabels) |
138 | 136 | cap:extend(tblCaptions[idx]) |
139 | 137 | cap:insert(pandoc.Space()) |
140 | 138 | end |
141 | | - if #tblLabels[idx] > 0 then |
| 139 | + if #tblLabels[idx] > 0 and tblLabels[idx]:match("^tbl%-") then |
142 | 140 | cap:insert(pandoc.Str("{#" .. tblLabels[idx] .. "}")) |
143 | 141 | end |
144 | 142 | idx = idx + 1 |
|
0 commit comments