Skip to content

Commit 22efcb0

Browse files
committed
support table dividers
1 parent 5a0e11e commit 22efcb0

File tree

4 files changed

+84
-62
lines changed

4 files changed

+84
-62
lines changed

build.sh

Lines changed: 4 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -388,65 +388,10 @@ TEMP_PDF_FILE="$(basename ${input_file}).pdf"
388388

389389
LATEX_LOG="${build_dir}/latex.log"
390390

391-
# Get the time in Unix epoch milliseconds of the given line
392-
timestamp_of() {
393-
local LINE="$1"
394-
local TIMESTAMP=$(echo "${LINE}" | cut -d ' ' -f 1 | tr -d "[]")
395-
396-
397-
local SECONDS=$(echo "${TIMESTAMP}" | cut -d '.' -f 1)
398-
local MILLISECONDS=$(echo "${TIMESTAMP}" | cut -d '.' -f 2 | head -c 3)
399-
# MILLISECONDS might have some leading 0's. Trim them by converting it as a base-10 integer.
400-
echo $(( $SECONDS * 1000 + 10#$MILLISECONDS ))
401-
}
402-
403-
# Get the duration in human-readable time between two patterns in the logfile
404-
time_between() {
405-
local LOGFILE="$1"
406-
local FIRST_PATTERN="$2"
407-
local SECOND_PATTERN="$3"
408-
409-
local FIRST_LINE=$(grep "${FIRST_PATTERN}" "${LOGFILE}" | head -n 1)
410-
local SECOND_LINE=$(grep "${SECOND_PATTERN}" "${LOGFILE}" | head -n 1)
411-
412-
if [ -z "${FIRST_LINE}" -o -z "${SECOND_LINE}" ]; then
413-
echo "n/a"
414-
else
415-
local FIRST_TIME=$(timestamp_of "${FIRST_LINE}")
416-
local SECOND_TIME=$(timestamp_of "${SECOND_LINE}")
417-
418-
ELAPSED_MS=$(( ${SECOND_TIME} - ${FIRST_TIME} ))
419-
420-
ELAPSED_S=$(( $ELAPSED_MS / 1000 ))
421-
ELAPSED_MS=$(( $ELAPSED_MS % 1000 ))
422-
423-
ELAPSED_M=$(( $ELAPSED_S / 60 ))
424-
ELAPSED_S=$(( $ELAPSED_S % 60 ))
425-
426-
ELAPSED_MS="${ELAPSED_MS}ms"
427-
428-
if [ ${ELAPSED_M} -gt 0 ]; then
429-
ELAPSED_M="${ELAPSED_M}m "
430-
# Don't print the milliseconds if we got more than a minute.
431-
ELAPSED_MS=""
432-
else
433-
ELAPSED_M=""
434-
fi
435-
436-
if [ ${ELAPSED_S} -gt 0 ]; then
437-
ELAPSED_S="${ELAPSED_S}s "
438-
else
439-
ELAPSED_S=""
440-
fi
441-
442-
echo "${ELAPSED_M}${ELAPSED_S}${ELAPSED_MS}"
443-
fi
444-
}
445-
446391
analyze_latex_logs() {
447392
local LOGFILE=$1
448393

449-
local RUNCOUNT=$(grep "Run number " "${LOGFILE}" | tail -n 1 | cut -d ' ' -f 4)
394+
local RUNCOUNT=$(grep "Run number " "${LOGFILE}" | tail -n 1 | cut -d ' ' -f 3)
450395
local PASSES="passes"
451396
if [ "${RUNCOUNT}" -eq "1" ]; then
452397
PASSES="pass"
@@ -457,10 +402,7 @@ analyze_latex_logs() {
457402
local WARNINGS=$(sed -n "/Run number ${RUNCOUNT}/,$ p" "${LOGFILE}" | grep "LaTeX Warning: ")
458403
if [ ! -z "${WARNINGS}" ]; then
459404
echo "LaTeX warnings (may be ignorable - check the output!):"
460-
echo "${WARNINGS}" | while read LINE; do
461-
local CUT_LINE=$(echo "${LINE}" | cut -d ' ' -f2-)
462-
echo " ${CUT_LINE}"
463-
done
405+
echo "${WARNINGS}"
464406
fi
465407
}
466408

@@ -521,7 +463,7 @@ if [ -n "${pdf_output}" -o -n "${latex_output}" ]; then
521463
start=$(date +%s)
522464
# Run twice to populate aux, lof, lot, toc, then update the page numbers due
523465
# to the impact of populating the lof, lot, toc.
524-
latexmk "${TEMP_TEX_FILE}" -pdflatex=xelatex -pdf -diagnostics | ts '[%.s]' > "${LATEX_LOG}"
466+
latexmk "${TEMP_TEX_FILE}" -pdflatex=xelatex -pdf -diagnostics > "${LATEX_LOG}"
525467
if [ $? -ne 0 ]; then
526468
FAILED=true
527469
echo "PDF output failed"
@@ -538,7 +480,7 @@ if [ -n "${pdf_output}" -o -n "${latex_output}" ]; then
538480
fi
539481
echo "Elapsed time: $(($end-$start)) seconds"
540482
# Write any LaTeX errors to stderr.
541-
>&2 grep -A 5 "] ! " "${LATEX_LOG}"
483+
>&2 grep -A 5 "! " "${LATEX_LOG}"
542484
if [[ ! "${FAILED}" = "true" ]]; then
543485
mv "${TEMP_PDF_FILE}" "${pdf_output}"
544486
analyze_latex_logs "${LATEX_LOG}"

filter/tabularx.lua

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,33 @@ function GetCellCode(cell)
5151
return cell_code
5252
end
5353

54+
-- For === Special Header === rows in rowspans.
55+
function SpecialSeparatorRow(width, contents, i, plain)
56+
local code = ''
57+
local colspec = 'c'
58+
if not plain then
59+
code = code .. '\\hline'
60+
colspec = '|c|'
61+
end
62+
63+
local inner_contents = string.format('\\textbf{\\textit{\\footnotesize %s}}', contents)
64+
code = code .. string.format('\\multicolumn{%d}{%s}{\\cellcolor{table-section-background}\\textcolor{table-section-foreground}{%s}} \\\\*\n', width, colspec, inner_contents)
65+
66+
return code
67+
end
68+
5469
-- TODO: This code's a real spaghetti factory. Refactor it in the future.
5570
function TabularRow(height, colspecs, skips, rows_with_rowspans, row, i, plain, no_first_hline, header)
5671
local width = Length(colspecs)
72+
73+
-- Special case: this row's first cell spans the entire table and begins and ends with ===.
74+
if row.cells[1] and row.cells[1].col_span == width then
75+
local contents = pandoc.utils.stringify(row.cells[1].contents):match('===+ ?(.*) ===+')
76+
if contents then
77+
return SpecialSeparatorRow(width, contents, i, plain)
78+
end
79+
end
80+
5781
local n = 1
5882
-- Prepare a list of latex snippets to be concatenated together below.
5983
local row_code = {}

guide.tcg

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,60 @@ Table: Fruits (Grid) {#tbl:fruits-grid}
814814
| Banana | Yellow | No |
815815
+-------------+--------+----------------------------+
816816

817+
A grid table can be divided into sections using `===` in a full-span row,
818+
as in @tbl:some-command:
819+
820+
```md
821+
Table: Some Command {#tbl:some-command}
822+
823+
+-------------+--------+----------------------------+
824+
| Type | Name | Description |
825+
+=============+========+============================+
826+
| ================= Header ======================== |
827+
+-------------+--------+----------------------------+
828+
| UINT32 | Siz | The size of the following |
829+
| | | contents. |
830+
+-------------+--------+----------------------------+
831+
| ================ Contents ======================= |
832+
+-------------+--------+----------------------------+
833+
| BYTE\[Siz\] | Items | `Size` many items. |
834+
+-------------+--------+----------------------------+
835+
```
836+
837+
Table: Some Command {#tbl:some-command}
838+
839+
+-------------+--------+----------------------------+
840+
| Type | Name | Description |
841+
+=============+========+============================+
842+
| ================= Header ======================== |
843+
+-------------+--------+----------------------------+
844+
| UINT32 | Siz | The size of the following |
845+
| | | contents. |
846+
+-------------+--------+----------------------------+
847+
| ================ Contents ======================= |
848+
+-------------+--------+----------------------------+
849+
| BYTE\[Siz\] | Items | `Siz` many items. |
850+
+-------------+--------+----------------------------+
851+
852+
* The row must span the entire table
853+
* The row must begin and end with at least three equals signs
854+
* The row must be separated from its equals signs by spaces
855+
856+
Below is a table with full-span rows that do not use this feature:
857+
858+
+-------------+--------+----------------------------+
859+
| Type | Name | Description |
860+
+=============+========+============================+
861+
| Header |
862+
+-------------+--------+----------------------------+
863+
| UINT32 | Siz | The size of the following |
864+
| | | contents. |
865+
+-------------+--------+----------------------------+
866+
| Contents |
867+
+-------------+--------+----------------------------+
868+
| BYTE\[Siz\] | Items | `Siz` many items. |
869+
+-------------+--------+----------------------------+
870+
817871
### Styling Markdown Tables
818872

819873
#### Removing Lines

template/tcg.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@
271271
\definecolor{informative-header}{RGB}{75, 77, 78}
272272
\definecolor{informative-foreground}{RGB}{10, 10, 10}
273273

274+
\definecolor{table-section-background}{RGB}{224, 224, 224}
275+
\definecolor{table-section-foreground}{RGB}{75, 77, 78}
274276

275277
%
276278
% code block style

0 commit comments

Comments
 (0)