commonmarker 0.17.5 → 0.17.6
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of commonmarker might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/ext/commonmarker/cmark/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/README.md +3 -2
- data/ext/commonmarker/cmark/api_test/CMakeLists.txt +1 -1
- data/ext/commonmarker/cmark/api_test/main.c +91 -0
- data/ext/commonmarker/cmark/changelog.txt +24 -1
- data/ext/commonmarker/cmark/extensions/core-extensions.c +1 -0
- data/ext/commonmarker/cmark/extensions/core-extensions.h +1 -0
- data/ext/commonmarker/cmark/extensions/strikethrough.c +2 -1
- data/ext/commonmarker/cmark/extensions/table.c +1 -0
- data/ext/commonmarker/cmark/man/man3/cmark-gfm.3 +41 -1
- data/ext/commonmarker/cmark/src/CMakeLists.txt +12 -4
- data/ext/commonmarker/cmark/src/blocks.c +115 -3
- data/ext/commonmarker/cmark/src/buffer.h +0 -2
- data/ext/commonmarker/cmark/src/chunk.h +1 -1
- data/ext/commonmarker/cmark/src/cmark.c +2 -2
- data/ext/commonmarker/cmark/src/cmark.h +9 -0
- data/ext/commonmarker/cmark/src/cmark_extension_api.h +9 -7
- data/ext/commonmarker/cmark/src/commonmark.c +23 -0
- data/ext/commonmarker/cmark/src/footnotes.c +40 -0
- data/ext/commonmarker/cmark/src/footnotes.h +25 -0
- data/ext/commonmarker/cmark/src/html.c +56 -1
- data/ext/commonmarker/cmark/src/inlines.c +46 -25
- data/ext/commonmarker/cmark/src/inlines.h +2 -2
- data/ext/commonmarker/cmark/src/latex.c +5 -0
- data/ext/commonmarker/cmark/src/libcmark-gfm.pc.in +1 -1
- data/ext/commonmarker/cmark/src/main.c +3 -0
- data/ext/commonmarker/cmark/src/man.c +5 -0
- data/ext/commonmarker/cmark/src/map.c +122 -0
- data/ext/commonmarker/cmark/src/map.h +42 -0
- data/ext/commonmarker/cmark/src/node.c +5 -0
- data/ext/commonmarker/cmark/src/parser.h +1 -1
- data/ext/commonmarker/cmark/src/plaintext.c +1 -0
- data/ext/commonmarker/cmark/src/references.c +11 -125
- data/ext/commonmarker/cmark/src/references.h +5 -20
- data/ext/commonmarker/cmark/src/render.c +2 -1
- data/ext/commonmarker/cmark/src/render.h +3 -0
- data/ext/commonmarker/cmark/src/scanners.c +168 -32
- data/ext/commonmarker/cmark/src/scanners.h +2 -0
- data/ext/commonmarker/cmark/src/scanners.re +10 -0
- data/ext/commonmarker/cmark/src/syntax_extension.c +3 -2
- data/ext/commonmarker/cmark/src/syntax_extension.h +1 -0
- data/ext/commonmarker/cmark/test/CMakeLists.txt +7 -2
- data/ext/commonmarker/cmark/test/extensions.txt +59 -0
- data/ext/commonmarker/cmark/test/pathological_tests.py +21 -3
- data/ext/commonmarker/cmark/wrappers/wrapper.js +6 -0
- data/ext/commonmarker/commonmarker.c +14 -0
- data/lib/commonmarker/config.rb +1 -0
- data/lib/commonmarker/renderer/html_renderer.rb +41 -0
- data/lib/commonmarker/version.rb +1 -1
- data/test/test_footnotes.rb +25 -0
- metadata +9 -148
- data/ext/commonmarker/cmark/build/CMakeCache.txt +0 -481
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CMakeCCompiler.cmake +0 -68
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CMakeCXXCompiler.cmake +0 -70
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CMakeDetermineCompilerABI_C.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CMakeDetermineCompilerABI_CXX.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CMakeSystem.cmake +0 -15
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CompilerIdC/CMakeCCompilerId.c +0 -567
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CompilerIdC/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -539
- data/ext/commonmarker/cmark/build/CMakeFiles/3.8.2/CompilerIdCXX/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CMakeCCompiler.cmake +0 -71
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CMakeCXXCompiler.cmake +0 -73
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CMakeDetermineCompilerABI_C.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CMakeDetermineCompilerABI_CXX.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CMakeSystem.cmake +0 -15
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CompilerIdC/CMakeCCompilerId.c +0 -567
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CompilerIdC/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CompilerIdCXX/CMakeCXXCompilerId.cpp +0 -539
- data/ext/commonmarker/cmark/build/CMakeFiles/3.9.4/CompilerIdCXX/a.out +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeDirectoryInformation.cmake +0 -16
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeError.log +0 -14
- data/ext/commonmarker/cmark/build/CMakeFiles/CMakeOutput.log +0 -1169
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile.cmake +0 -155
- data/ext/commonmarker/cmark/build/CMakeFiles/Makefile2 +0 -391
- data/ext/commonmarker/cmark/build/CMakeFiles/TargetDirectories.txt +0 -48
- data/ext/commonmarker/cmark/build/CMakeFiles/cmake.check_cache +0 -1
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.bin +0 -0
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.c +0 -34
- data/ext/commonmarker/cmark/build/CMakeFiles/feature_tests.cxx +0 -405
- data/ext/commonmarker/cmark/build/CMakeFiles/progress.marks +0 -1
- data/ext/commonmarker/cmark/build/CTestTestfile.cmake +0 -11
- data/ext/commonmarker/cmark/build/Makefile +0 -280
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/CMakeDirectoryInformation.cmake +0 -16
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/DependInfo.cmake +0 -38
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/build.make +0 -169
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/cmake_clean.cmake +0 -12
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/depend.make +0 -2
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/flags.make +0 -17
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/link.txt +0 -1
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/api_test.dir/progress.make +0 -5
- data/ext/commonmarker/cmark/build/api_test/CMakeFiles/progress.marks +0 -1
- data/ext/commonmarker/cmark/build/api_test/Makefile +0 -302
- data/ext/commonmarker/cmark/build/api_test/cmake_install.cmake +0 -29
- data/ext/commonmarker/cmark/build/cmake_install.cmake +0 -49
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/CMakeDirectoryInformation.cmake +0 -16
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/Export/lib/cmake-gfmextensions/cmark-gfmextensions-release.cmake +0 -30
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/Export/lib/cmake-gfmextensions/cmark-gfmextensions.cmake +0 -108
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/DependInfo.cmake +0 -36
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/build.make +0 -253
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/cmake_clean.cmake +0 -16
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/depend.make +0 -2
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/flags.make +0 -10
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/link.txt +0 -1
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions.dir/progress.make +0 -8
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/C.includecache +0 -236
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/DependInfo.cmake +0 -29
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/autolink.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/build.make +0 -249
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/cmake_clean.cmake +0 -15
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/cmake_clean_target.cmake +0 -3
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/core-extensions.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/depend.internal +0 -102
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/depend.make +0 -102
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/ext_scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/flags.make +0 -10
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/link.txt +0 -2
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/progress.make +0 -8
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/strikethrough.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/table.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/libcmark-gfmextensions_static.dir/tagfilter.c.o +0 -0
- data/ext/commonmarker/cmark/build/extensions/CMakeFiles/progress.marks +0 -1
- data/ext/commonmarker/cmark/build/extensions/Makefile +0 -426
- data/ext/commonmarker/cmark/build/extensions/cmake_install.cmake +0 -84
- data/ext/commonmarker/cmark/build/extensions/cmarkextensions_export.h +0 -42
- data/ext/commonmarker/cmark/build/extensions/libcmark-gfmextensions.a +0 -0
- data/ext/commonmarker/cmark/build/man/CMakeFiles/CMakeDirectoryInformation.cmake +0 -16
- data/ext/commonmarker/cmark/build/man/CMakeFiles/progress.marks +0 -1
- data/ext/commonmarker/cmark/build/man/Makefile +0 -196
- data/ext/commonmarker/cmark/build/man/cmake_install.cmake +0 -37
- data/ext/commonmarker/cmark/build/src/CMakeFiles/CMakeDirectoryInformation.cmake +0 -16
- data/ext/commonmarker/cmark/build/src/CMakeFiles/Export/lib/cmake-gfm/cmark-gfm-release.cmake +0 -38
- data/ext/commonmarker/cmark/build/src/CMakeFiles/Export/lib/cmake-gfm/cmark-gfm.cmake +0 -95
- data/ext/commonmarker/cmark/build/src/CMakeFiles/Export/lib/cmake/cmark-release.cmake +0 -38
- data/ext/commonmarker/cmark/build/src/CMakeFiles/Export/lib/cmake/cmark.cmake +0 -95
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/DependInfo.cmake +0 -30
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/build.make +0 -115
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/cmake_clean.cmake +0 -10
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/depend.make +0 -2
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/flags.make +0 -10
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/link.txt +0 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/cmark-gfm.dir/progress.make +0 -3
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/DependInfo.cmake +0 -58
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/build.make +0 -765
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/cmake_clean.cmake +0 -35
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/depend.make +0 -2
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/flags.make +0 -10
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/link.txt +0 -1
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm.dir/progress.make +0 -27
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/C.includecache +0 -624
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/DependInfo.cmake +0 -52
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/arena.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/blocks.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/buffer.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/build.make +0 -762
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/cmake_clean.cmake +0 -34
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/cmake_clean_target.cmake +0 -3
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/cmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/cmark_ctype.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/commonmark.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/depend.internal +0 -310
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/depend.make +0 -310
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/flags.make +0 -10
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/houdini_href_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/houdini_html_e.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/houdini_html_u.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/html.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/inlines.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/iterator.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/latex.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/link.txt +0 -2
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/linked_list.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/man.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/node.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/plaintext.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/plugin.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/progress.make +0 -27
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/references.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/registry.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/render.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/scanners.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/syntax_extension.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/utf8.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/libcmark-gfm_static.dir/xml.c.o +0 -0
- data/ext/commonmarker/cmark/build/src/CMakeFiles/progress.marks +0 -1
- data/ext/commonmarker/cmark/build/src/Makefile +0 -1099
- data/ext/commonmarker/cmark/build/src/cmake_install.cmake +0 -97
- data/ext/commonmarker/cmark/build/src/cmark_export.h +0 -42
- data/ext/commonmarker/cmark/build/src/cmark_version.h +0 -8
- data/ext/commonmarker/cmark/build/src/config.h +0 -76
- data/ext/commonmarker/cmark/build/src/libcmark-gfm.a +0 -0
- data/ext/commonmarker/cmark/build/src/libcmark-gfm.pc +0 -10
- data/ext/commonmarker/cmark/build/testdir/CMakeFiles/CMakeDirectoryInformation.cmake +0 -16
- data/ext/commonmarker/cmark/build/testdir/CMakeFiles/progress.marks +0 -1
- data/ext/commonmarker/cmark/build/testdir/CTestTestfile.cmake +0 -17
- data/ext/commonmarker/cmark/build/testdir/Makefile +0 -196
- data/ext/commonmarker/cmark/build/testdir/cmake_install.cmake +0 -29
@@ -13,11 +13,11 @@ cmark_chunk cmark_clean_title(cmark_mem *mem, cmark_chunk *title);
|
|
13
13
|
CMARK_EXPORT
|
14
14
|
void cmark_parse_inlines(cmark_parser *parser,
|
15
15
|
cmark_node *parent,
|
16
|
-
|
16
|
+
cmark_map *refmap,
|
17
17
|
int options);
|
18
18
|
|
19
19
|
bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input,
|
20
|
-
|
20
|
+
cmark_map *refmap);
|
21
21
|
|
22
22
|
void cmark_inlines_add_special_character(unsigned char c, bool emphasis);
|
23
23
|
void cmark_inlines_remove_special_character(unsigned char c, bool emphasis);
|
@@ -41,6 +41,7 @@ void print_usage() {
|
|
41
41
|
printf(" --smart Use smart punctuation\n");
|
42
42
|
printf(" --validate-utf8 Replace UTF-8 invalid sequences with U+FFFD\n");
|
43
43
|
printf(" --github-pre-lang Use GitHub-style <pre lang> for code blocks\n");
|
44
|
+
printf(" --footnotes Parse footnotes\n");
|
44
45
|
printf(" --extension, -e EXTENSION_NAME Specify an extension name to use\n");
|
45
46
|
printf(" --list-extensions List available extensions and quit\n");
|
46
47
|
printf(" --help, -h Print usage information\n");
|
@@ -138,6 +139,8 @@ int main(int argc, char *argv[]) {
|
|
138
139
|
options |= CMARK_OPT_SMART;
|
139
140
|
} else if (strcmp(argv[i], "--github-pre-lang") == 0) {
|
140
141
|
options |= CMARK_OPT_GITHUB_PRE_LANG;
|
142
|
+
} else if (strcmp(argv[i], "--footnotes") == 0) {
|
143
|
+
options |= CMARK_OPT_FOOTNOTES;
|
141
144
|
} else if (strcmp(argv[i], "--safe") == 0) {
|
142
145
|
options |= CMARK_OPT_SAFE;
|
143
146
|
} else if (strcmp(argv[i], "--validate-utf8") == 0) {
|
@@ -0,0 +1,122 @@
|
|
1
|
+
#include "map.h"
|
2
|
+
#include "utf8.h"
|
3
|
+
#include "parser.h"
|
4
|
+
|
5
|
+
// normalize map label: collapse internal whitespace to single space,
|
6
|
+
// remove leading/trailing whitespace, case fold
|
7
|
+
// Return NULL if the label is actually empty (i.e. composed solely from
|
8
|
+
// whitespace)
|
9
|
+
unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref) {
|
10
|
+
cmark_strbuf normalized = CMARK_BUF_INIT(mem);
|
11
|
+
unsigned char *result;
|
12
|
+
|
13
|
+
if (ref == NULL)
|
14
|
+
return NULL;
|
15
|
+
|
16
|
+
if (ref->len == 0)
|
17
|
+
return NULL;
|
18
|
+
|
19
|
+
cmark_utf8proc_case_fold(&normalized, ref->data, ref->len);
|
20
|
+
cmark_strbuf_trim(&normalized);
|
21
|
+
cmark_strbuf_normalize_whitespace(&normalized);
|
22
|
+
|
23
|
+
result = cmark_strbuf_detach(&normalized);
|
24
|
+
assert(result);
|
25
|
+
|
26
|
+
if (result[0] == '\0') {
|
27
|
+
mem->free(result);
|
28
|
+
return NULL;
|
29
|
+
}
|
30
|
+
|
31
|
+
return result;
|
32
|
+
}
|
33
|
+
|
34
|
+
static int
|
35
|
+
labelcmp(const unsigned char *a, const unsigned char *b) {
|
36
|
+
return strcmp((const char *)a, (const char *)b);
|
37
|
+
}
|
38
|
+
|
39
|
+
static int
|
40
|
+
refcmp(const void *p1, const void *p2) {
|
41
|
+
cmark_map_entry *r1 = *(cmark_map_entry **)p1;
|
42
|
+
cmark_map_entry *r2 = *(cmark_map_entry **)p2;
|
43
|
+
int res = labelcmp(r1->label, r2->label);
|
44
|
+
return res ? res : ((int)r1->age - (int)r2->age);
|
45
|
+
}
|
46
|
+
|
47
|
+
static int
|
48
|
+
refsearch(const void *label, const void *p2) {
|
49
|
+
cmark_map_entry *ref = *(cmark_map_entry **)p2;
|
50
|
+
return labelcmp((const unsigned char *)label, ref->label);
|
51
|
+
}
|
52
|
+
|
53
|
+
static void sort_map(cmark_map *map) {
|
54
|
+
unsigned int i = 0, last = 0, size = map->size;
|
55
|
+
cmark_map_entry *r = map->refs, **sorted = NULL;
|
56
|
+
|
57
|
+
sorted = (cmark_map_entry **)map->mem->calloc(size, sizeof(cmark_map_entry *));
|
58
|
+
while (r) {
|
59
|
+
sorted[i++] = r;
|
60
|
+
r = r->next;
|
61
|
+
}
|
62
|
+
|
63
|
+
qsort(sorted, size, sizeof(cmark_map_entry *), refcmp);
|
64
|
+
|
65
|
+
for (i = 1; i < size; i++) {
|
66
|
+
if (labelcmp(sorted[i]->label, sorted[last]->label) != 0)
|
67
|
+
sorted[++last] = sorted[i];
|
68
|
+
}
|
69
|
+
|
70
|
+
map->sorted = sorted;
|
71
|
+
map->size = last + 1;
|
72
|
+
}
|
73
|
+
|
74
|
+
cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label) {
|
75
|
+
cmark_map_entry **ref = NULL;
|
76
|
+
unsigned char *norm;
|
77
|
+
|
78
|
+
if (label->len < 1 || label->len > MAX_LINK_LABEL_LENGTH)
|
79
|
+
return NULL;
|
80
|
+
|
81
|
+
if (map == NULL || !map->size)
|
82
|
+
return NULL;
|
83
|
+
|
84
|
+
norm = normalize_map_label(map->mem, label);
|
85
|
+
if (norm == NULL)
|
86
|
+
return NULL;
|
87
|
+
|
88
|
+
if (!map->sorted)
|
89
|
+
sort_map(map);
|
90
|
+
|
91
|
+
ref = (cmark_map_entry **)bsearch(norm, map->sorted, map->size, sizeof(cmark_map_entry *), refsearch);
|
92
|
+
map->mem->free(norm);
|
93
|
+
|
94
|
+
if (!ref)
|
95
|
+
return NULL;
|
96
|
+
|
97
|
+
return ref[0];
|
98
|
+
}
|
99
|
+
|
100
|
+
void cmark_map_free(cmark_map *map) {
|
101
|
+
cmark_map_entry *ref;
|
102
|
+
|
103
|
+
if (map == NULL)
|
104
|
+
return;
|
105
|
+
|
106
|
+
ref = map->refs;
|
107
|
+
while (ref) {
|
108
|
+
cmark_map_entry *next = ref->next;
|
109
|
+
map->free(map, ref);
|
110
|
+
ref = next;
|
111
|
+
}
|
112
|
+
|
113
|
+
map->mem->free(map->sorted);
|
114
|
+
map->mem->free(map);
|
115
|
+
}
|
116
|
+
|
117
|
+
cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free) {
|
118
|
+
cmark_map *map = (cmark_map *)mem->calloc(1, sizeof(cmark_map));
|
119
|
+
map->mem = mem;
|
120
|
+
map->free = free;
|
121
|
+
return map;
|
122
|
+
}
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#ifndef CMARK_MAP_H
|
2
|
+
#define CMARK_MAP_H
|
3
|
+
|
4
|
+
#include "memory.h"
|
5
|
+
#include "chunk.h"
|
6
|
+
|
7
|
+
#ifdef __cplusplus
|
8
|
+
extern "C" {
|
9
|
+
#endif
|
10
|
+
|
11
|
+
struct cmark_map_entry {
|
12
|
+
struct cmark_map_entry *next;
|
13
|
+
unsigned char *label;
|
14
|
+
unsigned int age;
|
15
|
+
};
|
16
|
+
|
17
|
+
typedef struct cmark_map_entry cmark_map_entry;
|
18
|
+
|
19
|
+
struct cmark_map;
|
20
|
+
|
21
|
+
typedef void (*cmark_map_free_f)(struct cmark_map *, cmark_map_entry *);
|
22
|
+
|
23
|
+
struct cmark_map {
|
24
|
+
cmark_mem *mem;
|
25
|
+
cmark_map_entry *refs;
|
26
|
+
cmark_map_entry **sorted;
|
27
|
+
unsigned int size;
|
28
|
+
cmark_map_free_f free;
|
29
|
+
};
|
30
|
+
|
31
|
+
typedef struct cmark_map cmark_map;
|
32
|
+
|
33
|
+
unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref);
|
34
|
+
cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free);
|
35
|
+
void cmark_map_free(cmark_map *map);
|
36
|
+
cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label);
|
37
|
+
|
38
|
+
#ifdef __cplusplus
|
39
|
+
}
|
40
|
+
#endif
|
41
|
+
|
42
|
+
#endif
|
@@ -21,6 +21,7 @@ bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type) {
|
|
21
21
|
switch (node->type) {
|
22
22
|
case CMARK_NODE_DOCUMENT:
|
23
23
|
case CMARK_NODE_BLOCK_QUOTE:
|
24
|
+
case CMARK_NODE_FOOTNOTE_DEFINITION:
|
24
25
|
case CMARK_NODE_ITEM:
|
25
26
|
return CMARK_NODE_TYPE_BLOCK_P(child_type) && child_type != CMARK_NODE_ITEM;
|
26
27
|
|
@@ -108,6 +109,8 @@ static void free_node_as(cmark_node *node) {
|
|
108
109
|
case CMARK_NODE_HTML_INLINE:
|
109
110
|
case CMARK_NODE_CODE:
|
110
111
|
case CMARK_NODE_HTML_BLOCK:
|
112
|
+
case CMARK_NODE_FOOTNOTE_REFERENCE:
|
113
|
+
case CMARK_NODE_FOOTNOTE_DEFINITION:
|
111
114
|
cmark_chunk_free(NODE_MEM(node), &node->as.literal);
|
112
115
|
break;
|
113
116
|
case CMARK_NODE_LINK:
|
@@ -319,6 +322,7 @@ const char *cmark_node_get_literal(cmark_node *node) {
|
|
319
322
|
case CMARK_NODE_TEXT:
|
320
323
|
case CMARK_NODE_HTML_INLINE:
|
321
324
|
case CMARK_NODE_CODE:
|
325
|
+
case CMARK_NODE_FOOTNOTE_REFERENCE:
|
322
326
|
return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.literal);
|
323
327
|
|
324
328
|
case CMARK_NODE_CODE_BLOCK:
|
@@ -341,6 +345,7 @@ int cmark_node_set_literal(cmark_node *node, const char *content) {
|
|
341
345
|
case CMARK_NODE_TEXT:
|
342
346
|
case CMARK_NODE_HTML_INLINE:
|
343
347
|
case CMARK_NODE_CODE:
|
348
|
+
case CMARK_NODE_FOOTNOTE_REFERENCE:
|
344
349
|
cmark_chunk_set_cstr(NODE_MEM(node), &node->as.literal, content);
|
345
350
|
return 1;
|
346
351
|
|
@@ -15,7 +15,7 @@ extern "C" {
|
|
15
15
|
struct cmark_parser {
|
16
16
|
struct cmark_mem *mem;
|
17
17
|
/* A hashtable of urls in the current document for cross-references */
|
18
|
-
struct
|
18
|
+
struct cmark_map *refmap;
|
19
19
|
/* The root node of the parser, always a CMARK_NODE_DOCUMENT */
|
20
20
|
struct cmark_node *root;
|
21
21
|
/* The last open block after a line is fully processed */
|
@@ -1,53 +1,24 @@
|
|
1
1
|
#include "cmark.h"
|
2
|
-
#include "utf8.h"
|
3
2
|
#include "parser.h"
|
4
3
|
#include "references.h"
|
5
4
|
#include "inlines.h"
|
6
5
|
#include "chunk.h"
|
7
6
|
|
8
|
-
static void reference_free(
|
7
|
+
static void reference_free(cmark_map *map, cmark_map_entry *_ref) {
|
8
|
+
cmark_reference *ref = (cmark_reference *)_ref;
|
9
9
|
cmark_mem *mem = map->mem;
|
10
10
|
if (ref != NULL) {
|
11
|
-
mem->free(ref->label);
|
11
|
+
mem->free(ref->entry.label);
|
12
12
|
cmark_chunk_free(mem, &ref->url);
|
13
13
|
cmark_chunk_free(mem, &ref->title);
|
14
14
|
mem->free(ref);
|
15
15
|
}
|
16
16
|
}
|
17
17
|
|
18
|
-
|
19
|
-
// remove leading/trailing whitespace, case fold
|
20
|
-
// Return NULL if the reference name is actually empty (i.e. composed
|
21
|
-
// solely from whitespace)
|
22
|
-
static unsigned char *normalize_reference(cmark_mem *mem, cmark_chunk *ref) {
|
23
|
-
cmark_strbuf normalized = CMARK_BUF_INIT(mem);
|
24
|
-
unsigned char *result;
|
25
|
-
|
26
|
-
if (ref == NULL)
|
27
|
-
return NULL;
|
28
|
-
|
29
|
-
if (ref->len == 0)
|
30
|
-
return NULL;
|
31
|
-
|
32
|
-
cmark_utf8proc_case_fold(&normalized, ref->data, ref->len);
|
33
|
-
cmark_strbuf_trim(&normalized);
|
34
|
-
cmark_strbuf_normalize_whitespace(&normalized);
|
35
|
-
|
36
|
-
result = cmark_strbuf_detach(&normalized);
|
37
|
-
assert(result);
|
38
|
-
|
39
|
-
if (result[0] == '\0') {
|
40
|
-
mem->free(result);
|
41
|
-
return NULL;
|
42
|
-
}
|
43
|
-
|
44
|
-
return result;
|
45
|
-
}
|
46
|
-
|
47
|
-
void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label,
|
18
|
+
void cmark_reference_create(cmark_map *map, cmark_chunk *label,
|
48
19
|
cmark_chunk *url, cmark_chunk *title) {
|
49
20
|
cmark_reference *ref;
|
50
|
-
unsigned char *reflabel =
|
21
|
+
unsigned char *reflabel = normalize_map_label(map->mem, label);
|
51
22
|
|
52
23
|
/* empty reference name, or composed from only whitespace */
|
53
24
|
if (reflabel == NULL)
|
@@ -56,101 +27,16 @@ void cmark_reference_create(cmark_reference_map *map, cmark_chunk *label,
|
|
56
27
|
assert(map->sorted == NULL);
|
57
28
|
|
58
29
|
ref = (cmark_reference *)map->mem->calloc(1, sizeof(*ref));
|
59
|
-
ref->label = reflabel;
|
30
|
+
ref->entry.label = reflabel;
|
60
31
|
ref->url = cmark_clean_url(map->mem, url);
|
61
32
|
ref->title = cmark_clean_title(map->mem, title);
|
62
|
-
ref->age = map->size;
|
63
|
-
ref->next = map->refs;
|
33
|
+
ref->entry.age = map->size;
|
34
|
+
ref->entry.next = map->refs;
|
64
35
|
|
65
|
-
map->refs = ref;
|
36
|
+
map->refs = (cmark_map_entry *)ref;
|
66
37
|
map->size++;
|
67
38
|
}
|
68
39
|
|
69
|
-
|
70
|
-
|
71
|
-
return strcmp((const char *)a, (const char *)b);
|
72
|
-
}
|
73
|
-
|
74
|
-
static int
|
75
|
-
refcmp(const void *p1, const void *p2) {
|
76
|
-
cmark_reference *r1 = *(cmark_reference **)p1;
|
77
|
-
cmark_reference *r2 = *(cmark_reference **)p2;
|
78
|
-
int res = labelcmp(r1->label, r2->label);
|
79
|
-
return res ? res : ((int)r1->age - (int)r2->age);
|
80
|
-
}
|
81
|
-
|
82
|
-
static int
|
83
|
-
refsearch(const void *label, const void *p2) {
|
84
|
-
cmark_reference *ref = *(cmark_reference **)p2;
|
85
|
-
return labelcmp((const unsigned char *)label, ref->label);
|
86
|
-
}
|
87
|
-
|
88
|
-
static void sort_references(cmark_reference_map *map) {
|
89
|
-
unsigned int i = 0, last = 0, size = map->size;
|
90
|
-
cmark_reference *r = map->refs, **sorted = NULL;
|
91
|
-
|
92
|
-
sorted = (cmark_reference **)map->mem->calloc(size, sizeof(cmark_reference *));
|
93
|
-
while (r) {
|
94
|
-
sorted[i++] = r;
|
95
|
-
r = r->next;
|
96
|
-
}
|
97
|
-
|
98
|
-
qsort(sorted, size, sizeof(cmark_reference *), refcmp);
|
99
|
-
|
100
|
-
for (i = 1; i < size; i++) {
|
101
|
-
if (labelcmp(sorted[i]->label, sorted[last]->label) != 0)
|
102
|
-
sorted[++last] = sorted[i];
|
103
|
-
}
|
104
|
-
|
105
|
-
map->sorted = sorted;
|
106
|
-
map->size = last + 1;
|
107
|
-
}
|
108
|
-
|
109
|
-
// Returns reference if refmap contains a reference with matching
|
110
|
-
// label, otherwise NULL.
|
111
|
-
cmark_reference *cmark_reference_lookup(cmark_reference_map *map,
|
112
|
-
cmark_chunk *label) {
|
113
|
-
cmark_reference **ref = NULL;
|
114
|
-
unsigned char *norm;
|
115
|
-
|
116
|
-
if (label->len < 1 || label->len > MAX_LINK_LABEL_LENGTH)
|
117
|
-
return NULL;
|
118
|
-
|
119
|
-
if (map == NULL || !map->size)
|
120
|
-
return NULL;
|
121
|
-
|
122
|
-
norm = normalize_reference(map->mem, label);
|
123
|
-
if (norm == NULL)
|
124
|
-
return NULL;
|
125
|
-
|
126
|
-
if (!map->sorted)
|
127
|
-
sort_references(map);
|
128
|
-
|
129
|
-
ref = (cmark_reference **)bsearch(norm, map->sorted, map->size, sizeof(cmark_reference *), refsearch);
|
130
|
-
map->mem->free(norm);
|
131
|
-
return ref ? ref[0] : NULL;
|
132
|
-
}
|
133
|
-
|
134
|
-
void cmark_reference_map_free(cmark_reference_map *map) {
|
135
|
-
cmark_reference *ref;
|
136
|
-
|
137
|
-
if (map == NULL)
|
138
|
-
return;
|
139
|
-
|
140
|
-
ref = map->refs;
|
141
|
-
while (ref) {
|
142
|
-
cmark_reference *next = ref->next;
|
143
|
-
reference_free(map, ref);
|
144
|
-
ref = next;
|
145
|
-
}
|
146
|
-
|
147
|
-
map->mem->free(map->sorted);
|
148
|
-
map->mem->free(map);
|
149
|
-
}
|
150
|
-
|
151
|
-
cmark_reference_map *cmark_reference_map_new(cmark_mem *mem) {
|
152
|
-
cmark_reference_map *map =
|
153
|
-
(cmark_reference_map *)mem->calloc(1, sizeof(cmark_reference_map));
|
154
|
-
map->mem = mem;
|
155
|
-
return map;
|
40
|
+
cmark_map *cmark_reference_map_new(cmark_mem *mem) {
|
41
|
+
return cmark_map_new(mem, reference_free);
|
156
42
|
}
|