Skip to content

Commit 0445d10

Browse files
Yuki IzumiYuki Izumi
authored andcommitted
Table extension from c068469 reworked
Note this includes a hack to the core code to escape pipes in the 'commonmark' renderer. This is to fix test cases with the table extension; i.e. we treat pipes as special characters that need escaping. We use the cmark_mem of the parser in order to ensure we use the arena allocator when necessary. A very flexible table format is supported; see test/extensions.txt for examples. Leading and trailing pipes can be omitted, and alignment specifiers can be used in the separator between the header and body. Table bodies don't need to be a consistent width. Embedded HTML is OK. Note we reuse the inline parser from cmark to parse tables -- this is to ensure pipes e.g. in the middle of an inline code block don't prematurely terminate a table cell.
1 parent 3e3761a commit 0445d10

File tree

14 files changed

+1630
-14
lines changed

14 files changed

+1630
-14
lines changed

Makefile

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
SRCDIR=src
2+
EXTDIR=extensions
23
DATADIR=data
34
BUILDDIR?=build
45
GENERATOR?=Unix Makefiles
56
MINGW_BUILDDIR?=build-mingw
67
MINGW_INSTALLDIR?=windows
78
SPEC=test/spec.txt
9+
EXTENSIONS_SPEC=test/extensions.txt
810
SITE=_site
911
SPECVERSION=$(shell perl -ne 'print $$1 if /^version: *([0-9.]+)/' $(SPEC))
1012
FUZZCHARS?=2000000 # for fuzztest
@@ -80,7 +82,7 @@ afl:
8082
-o test/afl_results \
8183
-x test/fuzzing_dictionary \
8284
-t 100 \
83-
$(CMARK) $(CMARK_OPTS)
85+
$(CMARK) -e table $(CMARK_OPTS)
8486

8587
libFuzzer:
8688
@[ -n "$(LIB_FUZZER_PATH)" ] || { echo '$$LIB_FUZZER_PATH not set'; false; }
@@ -126,6 +128,19 @@ $(SRCDIR)/scanners.c: $(SRCDIR)/scanners.re
126128
--encoding-policy substitute -o $@ $<
127129
$(CLANG_FORMAT) $@
128130

131+
# We include scanners.c in the repository, so this shouldn't
132+
# normally need to be generated.
133+
$(EXTDIR)/ext_scanners.c: $(EXTDIR)/ext_scanners.re
134+
@case "$$(re2c -v)" in \
135+
*\ 0.13.*|*\ 0.14|*\ 0.14.1) \
136+
echo "re2c >= 0.14.2 is required"; \
137+
false; \
138+
;; \
139+
esac
140+
re2c --case-insensitive -b -i --no-generation-date -8 \
141+
--encoding-policy substitute -o $@ $<
142+
clang-format -style llvm -i $@
143+
129144
# We include entities.inc in the repository, so normally this
130145
# doesn't need to be regenerated:
131146
$(SRCDIR)/entities.inc: tools/make_entities_inc.py
@@ -138,14 +153,19 @@ update-spec:
138153
test: $(SPEC) cmake_build
139154
$(MAKE) -C $(BUILDDIR) test || (cat $(BUILDDIR)/Testing/Temporary/LastTest.log && exit 1)
140155

141-
$(ALLTESTS): $(SPEC)
142-
python3 test/spec_tests.py --spec $< --dump-tests | python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))' > $@
156+
$(ALLTESTS): $(SPEC) $(EXTENSIONS_SPEC)
157+
( \
158+
python3 test/spec_tests.py --spec $(SPEC) --dump-tests | \
159+
python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))'; \
160+
python3 test/spec_tests.py --spec $(EXTENSIONS_SPEC) --dump-tests | \
161+
python3 -c 'import json; import sys; tests = json.loads(sys.stdin.read()); print("\n".join([test["markdown"] for test in tests]))'; \
162+
) > $@
143163

144164
leakcheck: $(ALLTESTS)
145165
for format in html man xml latex commonmark; do \
146166
for opts in "" "--smart"; do \
147-
echo "cmark -t $$format $$opts" ; \
148-
valgrind -q --leak-check=full --dsymutil=yes --error-exitcode=1 $(PROG) -t $$format $$opts $(ALLTESTS) >/dev/null || exit 1;\
167+
echo "cmark -t $$format -e table $$opts" ; \
168+
valgrind -q --leak-check=full --dsymutil=yes --suppressions=suppressions --error-exitcode=1 $(PROG) -t $$format -e table $$opts $(ALLTESTS) >/dev/null || exit 1;\
149169
done; \
150170
done;
151171

extensions/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ cmake_minimum_required(VERSION 2.8)
22
set(STATICLIBRARY "libcmarkextensions_static")
33
set(LIBRARY_SOURCES
44
core-extensions.c
5+
table.c
6+
ext_scanners.c
7+
ext_scanners.re
8+
ext_scanners.h
59
)
610

711
include_directories(

extensions/core-extensions.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
#include "core-extensions.h"
2+
#include "table.h"
23

3-
int core_extensions_registration(cmark_plugin *plugin) { return 1; }
4+
int core_extensions_registration(cmark_plugin *plugin) {
5+
cmark_plugin_register_syntax_extension(plugin, create_table_extension());
6+
return 1;
7+
}

0 commit comments

Comments
 (0)