aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFelix (xq) Queißner <git@mq32.de>2020-06-22 20:53:39 +0200
committerFelix (xq) Queißner <git@mq32.de>2020-06-22 20:53:39 +0200
commit8dbfb0890560fd1cd698d06fa05ac868c4db8576 (patch)
tree57d138d7e9967473b8ed52863dabeb739a34ac8e /lib
parent058aeef80e8a33d0e385f284b23eeb117f5ec547 (diff)
Removes 'cruft' from cmark. We only care for the source anyways.
Diffstat (limited to 'lib')
-rw-r--r--lib/cmark/CMakeLists.txt76
-rw-r--r--lib/cmark/FindAsan.cmake74
-rw-r--r--lib/cmark/api_test/CMakeLists.txt11
-rw-r--r--lib/cmark/api_test/cplusplus.cpp15
-rw-r--r--lib/cmark/api_test/cplusplus.h16
-rw-r--r--lib/cmark/api_test/harness.c83
-rw-r--r--lib/cmark/api_test/harness.h35
-rw-r--r--lib/cmark/api_test/main.c1076
-rw-r--r--lib/cmark/bench/samples/block-bq-flat.md16
-rw-r--r--lib/cmark/bench/samples/block-bq-nested.md13
-rw-r--r--lib/cmark/bench/samples/block-code.md11
-rw-r--r--lib/cmark/bench/samples/block-fences.md14
-rw-r--r--lib/cmark/bench/samples/block-heading.md9
-rw-r--r--lib/cmark/bench/samples/block-hr.md10
-rw-r--r--lib/cmark/bench/samples/block-html.md32
-rw-r--r--lib/cmark/bench/samples/block-lheading.md8
-rw-r--r--lib/cmark/bench/samples/block-list-flat.md67
-rw-r--r--lib/cmark/bench/samples/block-list-nested.md36
-rw-r--r--lib/cmark/bench/samples/block-ref-flat.md15
-rw-r--r--lib/cmark/bench/samples/block-ref-nested.md17
-rw-r--r--lib/cmark/bench/samples/inline-autolink.md14
-rw-r--r--lib/cmark/bench/samples/inline-backticks.md3
-rw-r--r--lib/cmark/bench/samples/inline-em-flat.md5
-rw-r--r--lib/cmark/bench/samples/inline-em-nested.md5
-rw-r--r--lib/cmark/bench/samples/inline-em-worst.md5
-rw-r--r--lib/cmark/bench/samples/inline-entity.md11
-rw-r--r--lib/cmark/bench/samples/inline-escape.md15
-rw-r--r--lib/cmark/bench/samples/inline-html.md44
-rw-r--r--lib/cmark/bench/samples/inline-links-flat.md23
-rw-r--r--lib/cmark/bench/samples/inline-links-nested.md13
-rw-r--r--lib/cmark/bench/samples/inline-newlines.md24
-rw-r--r--lib/cmark/bench/samples/lorem1.md13
-rw-r--r--lib/cmark/bench/samples/rawtabs.md18
-rw-r--r--lib/cmark/bench/statistics.py595
-rw-r--r--lib/cmark/bench/stats.py19
-rw-r--r--lib/cmark/benchmarks.md33
-rw-r--r--lib/cmark/man/CMakeLists.txt4
-rw-r--r--lib/cmark/man/make_man_page.py133
-rw-r--r--lib/cmark/man/man1/cmark.169
-rw-r--r--lib/cmark/man/man3/cmark.3849
-rw-r--r--lib/cmark/nmake.bat1
-rwxr-xr-xlib/cmark/test/CMakeLists.txt80
-rw-r--r--lib/cmark/test/afl_test_cases/test.md36
-rw-r--r--lib/cmark/test/cmark-fuzz.c33
-rw-r--r--lib/cmark/test/cmark.py62
-rw-r--r--lib/cmark/test/entity_tests.py67
-rw-r--r--lib/cmark/test/fuzzing_dictionary49
-rw-r--r--lib/cmark/test/normalize.py194
-rw-r--r--lib/cmark/test/pathological_tests.py169
-rw-r--r--lib/cmark/test/regression.txt164
-rw-r--r--lib/cmark/test/roundtrip_tests.py46
-rwxr-xr-xlib/cmark/test/run-cmark-fuzz4
-rw-r--r--lib/cmark/test/smart_punct.txt177
-rw-r--r--lib/cmark/test/spec.txt9720
-rwxr-xr-xlib/cmark/test/spec_tests.py142
-rw-r--r--lib/cmark/toolchain-mingw32.cmake17
-rw-r--r--lib/cmark/tools/appveyor-build.bat13
-rw-r--r--lib/cmark/tools/make_entities_inc.py32
-rwxr-xr-xlib/cmark/tools/mkcasefold.pl22
-rw-r--r--lib/cmark/tools/xml2md.xsl319
-rw-r--r--lib/cmark/why-cmark-and-not-x.md104
-rwxr-xr-xlib/cmark/wrappers/wrapper.py37
-rwxr-xr-xlib/cmark/wrappers/wrapper.rb15
-rw-r--r--lib/cmark/wrappers/wrapper.rkt208
64 files changed, 0 insertions, 15240 deletions
diff --git a/lib/cmark/CMakeLists.txt b/lib/cmark/CMakeLists.txt
deleted file mode 100644
index b3edd74..0000000
--- a/lib/cmark/CMakeLists.txt
+++ /dev/null
@@ -1,76 +0,0 @@
-cmake_minimum_required(VERSION 3.0)
-project(cmark VERSION 0.29.0)
-
-include("FindAsan.cmake")
-include(GNUInstallDirs)
-
-if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_BINARY_DIR}")
- message(FATAL_ERROR "Do not build in-source.\nPlease remove CMakeCache.txt and the CMakeFiles/ directory.\nThen: mkdir build ; cd build ; cmake .. ; make")
-endif()
-
-option(CMARK_TESTS "Build cmark tests and enable testing" ON)
-option(CMARK_STATIC "Build static libcmark library" ON)
-option(CMARK_SHARED "Build shared libcmark library" ON)
-option(CMARK_LIB_FUZZER "Build libFuzzer fuzzing harness" OFF)
-
-if(NOT MSVC)
- set(CMAKE_C_STANDARD 99)
- set(CMAKE_C_STANDARD_REQUIRED YES)
- set(CMAKE_C_EXTENSIONS NO)
-endif()
-
-set(CMAKE_INCLUDE_CURRENT_DIR ON)
-
-# The Linux modules distributed with CMake add "-rdynamic" to the build flags
-# which is incompatible with static linking under certain configurations.
-# Unsetting CMAKE_SHARED_LIBRARY_LINK_C_FLAGS ensures this does not happen.
-if(CMARK_STATIC AND "${CMAKE_SYSTEM_NAME}" STREQUAL "Linux")
- SET(CMAKE_SHARED_LIBRARY_LINK_C_FLAGS)
-endif()
-
-# Compiler flags
-if(MSVC)
- # Force to always compile with W4
- add_compile_options($<$<COMPILE_LANGUAGE:C>:/W4>)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:/wd4706>)
- # Compile as C++ under MSVC older than 12.0
- if(MSVC_VERSION LESS 1800)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:/TP>)
- endif()
- add_compile_options($<$<COMPILE_LANGUAGE:C>:/D_CRT_SECURE_NO_WARNINGS>)
-elseif(CMAKE_COMPILER_IS_GNUCC OR CMAKE_C_COMPILER_ID MATCHES Clang)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wall>)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:-Wextra>)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:-pedantic>)
-endif()
-
-# Check integrity of node structure when compiled as debug
-add_compile_options($<$<CONFIG:Debug>:-DCMARK_DEBUG_NODES>)
-
-add_compile_options($<$<AND:$<CONFIG:PROFILE>,$<COMPILE_LANGUAGE:C>>:-pg>)
-
-if(CMAKE_BUILD_TYPE STREQUAL Ubsan)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize=undefined>)
-endif()
-if(CMARK_LIB_FUZZER)
- add_compile_options($<$<COMPILE_LANGUAGE:C>:-fsanitize-coverage=trace-pc-guard>)
-endif()
-
-add_subdirectory(src)
-if(CMARK_TESTS AND (CMARK_SHARED OR CMARK_STATIC))
- add_subdirectory(api_test)
-endif()
-# TODO(compnerd) should this be enabled for MinGW, which sets CMAKE_SYSTEM_NAME
-# to Windows, but defines `MINGW`.
-if(NOT CMAKE_SYSTEM_NAME STREQUAL Windows)
- add_subdirectory(man)
-endif()
-if(CMARK_TESTS)
- enable_testing()
- add_subdirectory(test testdir)
-endif()
-
-if(NOT CMAKE_BUILD_TYPE)
- set(CMAKE_BUILD_TYPE "Release" CACHE STRING
- "Choose the type of build, options are: Debug Profile Release Asan Ubsan." FORCE)
-endif(NOT CMAKE_BUILD_TYPE)
diff --git a/lib/cmark/FindAsan.cmake b/lib/cmark/FindAsan.cmake
deleted file mode 100644
index 064b5b6..0000000
--- a/lib/cmark/FindAsan.cmake
+++ /dev/null
@@ -1,74 +0,0 @@
-#
-# The MIT License (MIT)
-#
-# Copyright (c) 2013 Matthew Arsenault
-#
-# Permission is hereby granted, free of charge, to any person obtaining a copy
-# of this software and associated documentation files (the "Software"), to deal
-# in the Software without restriction, including without limitation the rights
-# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-# copies of the Software, and to permit persons to whom the Software is
-# furnished to do so, subject to the following conditions:
-#
-# The above copyright notice and this permission notice shall be included in
-# all copies or substantial portions of the Software.
-#
-# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-# THE SOFTWARE.
-#
-# This module tests if address sanitizer is supported by the compiler,
-# and creates a ASan build type (i.e. set CMAKE_BUILD_TYPE=ASan to use
-# it). This sets the following variables:
-#
-# CMAKE_C_FLAGS_ASAN - Flags to use for C with asan
-# CMAKE_CXX_FLAGS_ASAN - Flags to use for C++ with asan
-# HAVE_ADDRESS_SANITIZER - True or false if the ASan build type is available
-
-include(CheckCCompilerFlag)
-
-# Set -Werror to catch "argument unused during compilation" warnings
-set(CMAKE_REQUIRED_FLAGS "-Werror -faddress-sanitizer") # Also needs to be a link flag for test to pass
-check_c_compiler_flag("-faddress-sanitizer" HAVE_FLAG_ADDRESS_SANITIZER)
-
-set(CMAKE_REQUIRED_FLAGS "-Werror -fsanitize=address") # Also needs to be a link flag for test to pass
-check_c_compiler_flag("-fsanitize=address" HAVE_FLAG_SANITIZE_ADDRESS)
-
-unset(CMAKE_REQUIRED_FLAGS)
-
-if(HAVE_FLAG_SANITIZE_ADDRESS)
- # Clang 3.2+ use this version
- set(ADDRESS_SANITIZER_FLAG "-fsanitize=address")
-elseif(HAVE_FLAG_ADDRESS_SANITIZER)
- # Older deprecated flag for ASan
- set(ADDRESS_SANITIZER_FLAG "-faddress-sanitizer")
-endif()
-
-if(NOT ADDRESS_SANITIZER_FLAG)
- return()
-else(NOT ADDRESS_SANITIZER_FLAG)
- set(HAVE_ADDRESS_SANITIZER FALSE)
-endif()
-
-set(HAVE_ADDRESS_SANITIZER TRUE)
-
-set(CMAKE_C_FLAGS_ASAN "-O1 -g ${ADDRESS_SANITIZER_FLAG} -fno-omit-frame-pointer -fno-optimize-sibling-calls"
- CACHE STRING "Flags used by the C compiler during ASan builds."
- FORCE)
-set(CMAKE_CXX_FLAGS_ASAN "-O1 -g ${ADDRESS_SANITIZER_FLAG} -fno-omit-frame-pointer -fno-optimize-sibling-calls"
- CACHE STRING "Flags used by the C++ compiler during ASan builds."
- FORCE)
-set(CMAKE_EXE_LINKER_FLAGS_ASAN "${ADDRESS_SANITIZER_FLAG}"
- CACHE STRING "Flags used for linking binaries during ASan builds."
- FORCE)
-set(CMAKE_SHARED_LINKER_FLAGS_ASAN "${ADDRESS_SANITIZER_FLAG}"
- CACHE STRING "Flags used by the shared libraries linker during ASan builds."
- FORCE)
-mark_as_advanced(CMAKE_C_FLAGS_ASAN
- CMAKE_CXX_FLAGS_ASAN
- CMAKE_EXE_LINKER_FLAGS_ASAN
- CMAKE_SHARED_LINKER_FLAGS_ASAN)
diff --git a/lib/cmark/api_test/CMakeLists.txt b/lib/cmark/api_test/CMakeLists.txt
deleted file mode 100644
index f868d01..0000000
--- a/lib/cmark/api_test/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-add_executable(api_test
- cplusplus.cpp
- harness.c
- harness.h
- main.c
-)
-if(CMARK_SHARED)
- target_link_libraries(api_test libcmark)
-else()
- target_link_libraries(api_test libcmark_static)
-endif()
diff --git a/lib/cmark/api_test/cplusplus.cpp b/lib/cmark/api_test/cplusplus.cpp
deleted file mode 100644
index 5e8f722..0000000
--- a/lib/cmark/api_test/cplusplus.cpp
+++ /dev/null
@@ -1,15 +0,0 @@
-#include <cstdlib>
-
-#include "cmark.h"
-#include "cplusplus.h"
-#include "harness.h"
-
-void
-test_cplusplus(test_batch_runner *runner)
-{
- static const char md[] = "paragraph\n";
- char *html = cmark_markdown_to_html(md, sizeof(md) - 1, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<p>paragraph</p>\n", "libcmark works with C++");
- free(html);
-}
-
diff --git a/lib/cmark/api_test/cplusplus.h b/lib/cmark/api_test/cplusplus.h
deleted file mode 100644
index 1f3dd15..0000000
--- a/lib/cmark/api_test/cplusplus.h
+++ /dev/null
@@ -1,16 +0,0 @@
-#ifndef CMARK_API_TEST_CPLUSPLUS_H
-#define CMARK_API_TEST_CPLUSPLUS_H
-
-#include "harness.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-void test_cplusplus(test_batch_runner *runner);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/lib/cmark/api_test/harness.c b/lib/cmark/api_test/harness.c
deleted file mode 100644
index f6fd0bc..0000000
--- a/lib/cmark/api_test/harness.c
+++ /dev/null
@@ -1,83 +0,0 @@
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "harness.h"
-
-test_batch_runner *test_batch_runner_new() {
- return (test_batch_runner *)calloc(1, sizeof(test_batch_runner));
-}
-
-static void test_result(test_batch_runner *runner, int cond, const char *msg,
- va_list ap) {
- ++runner->test_num;
-
- if (cond) {
- ++runner->num_passed;
- } else {
- fprintf(stderr, "FAILED test %d: ", runner->test_num);
- vfprintf(stderr, msg, ap);
- fprintf(stderr, "\n");
- ++runner->num_failed;
- }
-}
-
-void SKIP(test_batch_runner *runner, int num_tests) {
- runner->test_num += num_tests;
- runner->num_skipped += num_tests;
-}
-
-void OK(test_batch_runner *runner, int cond, const char *msg, ...) {
- va_list ap;
- va_start(ap, msg);
- test_result(runner, cond, msg, ap);
- va_end(ap);
-}
-
-void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg,
- ...) {
- int cond = got == expected;
-
- va_list ap;
- va_start(ap, msg);
- test_result(runner, cond, msg, ap);
- va_end(ap);
-
- if (!cond) {
- fprintf(stderr, " Got: %d\n", got);
- fprintf(stderr, " Expected: %d\n", expected);
- }
-}
-
-void STR_EQ(test_batch_runner *runner, const char *got, const char *expected,
- const char *msg, ...) {
- int cond = strcmp(got, expected) == 0;
-
- va_list ap;
- va_start(ap, msg);
- test_result(runner, cond, msg, ap);
- va_end(ap);
-
- if (!cond) {
- fprintf(stderr, " Got: \"%s\"\n", got);
- fprintf(stderr, " Expected: \"%s\"\n", expected);
- }
-}
-
-int test_ok(test_batch_runner *runner) { return runner->num_failed == 0; }
-
-void test_print_summary(test_batch_runner *runner) {
- int num_passed = runner->num_passed;
- int num_skipped = runner->num_skipped;
- int num_failed = runner->num_failed;
-
- fprintf(stderr, "%d tests passed, %d failed, %d skipped\n", num_passed,
- num_failed, num_skipped);
-
- if (test_ok(runner)) {
- fprintf(stderr, "PASS\n");
- } else {
- fprintf(stderr, "FAIL\n");
- }
-}
diff --git a/lib/cmark/api_test/harness.h b/lib/cmark/api_test/harness.h
deleted file mode 100644
index 53b9889..0000000
--- a/lib/cmark/api_test/harness.h
+++ /dev/null
@@ -1,35 +0,0 @@
-#ifndef CMARK_API_TEST_HARNESS_H
-#define CMARK_API_TEST_HARNESS_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-typedef struct {
- int test_num;
- int num_passed;
- int num_failed;
- int num_skipped;
-} test_batch_runner;
-
-test_batch_runner *test_batch_runner_new();
-
-void SKIP(test_batch_runner *runner, int num_tests);
-
-void OK(test_batch_runner *runner, int cond, const char *msg, ...);
-
-void INT_EQ(test_batch_runner *runner, int got, int expected, const char *msg,
- ...);
-
-void STR_EQ(test_batch_runner *runner, const char *got, const char *expected,
- const char *msg, ...);
-
-int test_ok(test_batch_runner *runner);
-
-void test_print_summary(test_batch_runner *runner);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/lib/cmark/api_test/main.c b/lib/cmark/api_test/main.c
deleted file mode 100644
index 29346b7..0000000
--- a/lib/cmark/api_test/main.c
+++ /dev/null
@@ -1,1076 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#define CMARK_NO_SHORT_NAMES
-#include "cmark.h"
-#include "node.h"
-
-#include "harness.h"
-#include "cplusplus.h"
-
-#define UTF8_REPL "\xEF\xBF\xBD"
-
-static const cmark_node_type node_types[] = {
- CMARK_NODE_DOCUMENT, CMARK_NODE_BLOCK_QUOTE, CMARK_NODE_LIST,
- CMARK_NODE_ITEM, CMARK_NODE_CODE_BLOCK, CMARK_NODE_HTML_BLOCK,
- CMARK_NODE_PARAGRAPH, CMARK_NODE_HEADING, CMARK_NODE_THEMATIC_BREAK,
- CMARK_NODE_TEXT, CMARK_NODE_SOFTBREAK, CMARK_NODE_LINEBREAK,
- CMARK_NODE_CODE, CMARK_NODE_HTML_INLINE, CMARK_NODE_EMPH,
- CMARK_NODE_STRONG, CMARK_NODE_LINK, CMARK_NODE_IMAGE};
-static const int num_node_types = sizeof(node_types) / sizeof(*node_types);
-
-static void test_md_to_html(test_batch_runner *runner, const char *markdown,
- const char *expected_html, const char *msg);
-
-static void test_content(test_batch_runner *runner, cmark_node_type type,
- int allowed_content);
-
-static void test_char(test_batch_runner *runner, int valid, const char *utf8,
- const char *msg);
-
-static void test_incomplete_char(test_batch_runner *runner, const char *utf8,
- const char *msg);
-
-static void test_continuation_byte(test_batch_runner *runner, const char *utf8);
-
-static void version(test_batch_runner *runner) {
- INT_EQ(runner, cmark_version(), CMARK_VERSION, "cmark_version");
- STR_EQ(runner, cmark_version_string(), CMARK_VERSION_STRING,
- "cmark_version_string");
-}
-
-static void constructor(test_batch_runner *runner) {
- for (int i = 0; i < num_node_types; ++i) {
- cmark_node_type type = node_types[i];
- cmark_node *node = cmark_node_new(type);
- OK(runner, node != NULL, "new type %d", type);
- INT_EQ(runner, cmark_node_get_type(node), type, "get_type %d", type);
-
- switch (node->type) {
- case CMARK_NODE_HEADING:
- INT_EQ(runner, cmark_node_get_heading_level(node), 1,
- "default heading level is 1");
- node->as.heading.level = 1;
- break;
-
- case CMARK_NODE_LIST:
- INT_EQ(runner, cmark_node_get_list_type(node), CMARK_BULLET_LIST,
- "default is list type is bullet");
- INT_EQ(runner, cmark_node_get_list_delim(node), CMARK_NO_DELIM,
- "default is list delim is NO_DELIM");
- INT_EQ(runner, cmark_node_get_list_start(node), 0,
- "default is list start is 0");
- INT_EQ(runner, cmark_node_get_list_tight(node), 0,
- "default is list is loose");
- break;
-
- default:
- break;
- }
-
- cmark_node_free(node);
- }
-}
-
-static void accessors(test_batch_runner *runner) {
- static const char markdown[] = "## Header\n"
- "\n"
- "* Item 1\n"
- "* Item 2\n"
- "\n"
- "2. Item 1\n"
- "\n"
- "3. Item 2\n"
- "\n"
- "``` lang\n"
- "fenced\n"
- "```\n"
- " code\n"
- "\n"
- "<div>html</div>\n"
- "\n"
- "[link](url 'title')\n";
-
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- // Getters
-
- cmark_node *heading = cmark_node_first_child(doc);
- INT_EQ(runner, cmark_node_get_heading_level(heading), 2, "get_heading_level");
-
- cmark_node *bullet_list = cmark_node_next(heading);
- INT_EQ(runner, cmark_node_get_list_type(bullet_list), CMARK_BULLET_LIST,
- "get_list_type bullet");
- INT_EQ(runner, cmark_node_get_list_tight(bullet_list), 1,
- "get_list_tight tight");
-
- cmark_node *ordered_list = cmark_node_next(bullet_list);
- INT_EQ(runner, cmark_node_get_list_type(ordered_list), CMARK_ORDERED_LIST,
- "get_list_type ordered");
- INT_EQ(runner, cmark_node_get_list_delim(ordered_list), CMARK_PERIOD_DELIM,
- "get_list_delim ordered");
- INT_EQ(runner, cmark_node_get_list_start(ordered_list), 2, "get_list_start");
- INT_EQ(runner, cmark_node_get_list_tight(ordered_list), 0,
- "get_list_tight loose");
-
- cmark_node *fenced = cmark_node_next(ordered_list);
- STR_EQ(runner, cmark_node_get_literal(fenced), "fenced\n",
- "get_literal fenced code");
- STR_EQ(runner, cmark_node_get_fence_info(fenced), "lang", "get_fence_info");
-
- cmark_node *code = cmark_node_next(fenced);
- STR_EQ(runner, cmark_node_get_literal(code), "code\n",
- "get_literal indented code");
-
- cmark_node *html = cmark_node_next(code);
- STR_EQ(runner, cmark_node_get_literal(html), "<div>html</div>\n",
- "get_literal html");
-
- cmark_node *paragraph = cmark_node_next(html);
- INT_EQ(runner, cmark_node_get_start_line(paragraph), 17, "get_start_line");
- INT_EQ(runner, cmark_node_get_start_column(paragraph), 1, "get_start_column");
- INT_EQ(runner, cmark_node_get_end_line(paragraph), 17, "get_end_line");
-
- cmark_node *link = cmark_node_first_child(paragraph);
- STR_EQ(runner, cmark_node_get_url(link), "url", "get_url");
- STR_EQ(runner, cmark_node_get_title(link), "title", "get_title");
-
- cmark_node *string = cmark_node_first_child(link);
- STR_EQ(runner, cmark_node_get_literal(string), "link", "get_literal string");
-
- // Setters
-
- OK(runner, cmark_node_set_heading_level(heading, 3), "set_heading_level");
-
- OK(runner, cmark_node_set_list_type(bullet_list, CMARK_ORDERED_LIST),
- "set_list_type ordered");
- OK(runner, cmark_node_set_list_delim(bullet_list, CMARK_PAREN_DELIM),
- "set_list_delim paren");
- OK(runner, cmark_node_set_list_start(bullet_list, 3), "set_list_start");
- OK(runner, cmark_node_set_list_tight(bullet_list, 0), "set_list_tight loose");
-
- OK(runner, cmark_node_set_list_type(ordered_list, CMARK_BULLET_LIST),
- "set_list_type bullet");
- OK(runner, cmark_node_set_list_tight(ordered_list, 1),
- "set_list_tight tight");
-
- OK(runner, cmark_node_set_literal(code, "CODE\n"),
- "set_literal indented code");
-
- OK(runner, cmark_node_set_literal(fenced, "FENCED\n"),
- "set_literal fenced code");
- OK(runner, cmark_node_set_fence_info(fenced, "LANG"), "set_fence_info");
-
- OK(runner, cmark_node_set_literal(html, "<div>HTML</div>\n"),
- "set_literal html");
-
- OK(runner, cmark_node_set_url(link, "URL"), "set_url");
- OK(runner, cmark_node_set_title(link, "TITLE"), "set_title");
-
- OK(runner, cmark_node_set_literal(string, "prefix-LINK"),
- "set_literal string");
-
- // Set literal to suffix of itself (issue #139).
- const char *literal = cmark_node_get_literal(string);
- OK(runner, cmark_node_set_literal(string, literal + sizeof("prefix")),
- "set_literal suffix");
-
- char *rendered_html = cmark_render_html(doc,
- CMARK_OPT_DEFAULT | CMARK_OPT_UNSAFE);
- static const char expected_html[] =
- "<h3>Header</h3>\n"
- "<ol start=\"3\">\n"
- "<li>\n"
- "<p>Item 1</p>\n"
- "</li>\n"
- "<li>\n"
- "<p>Item 2</p>\n"
- "</li>\n"
- "</ol>\n"
- "<ul>\n"
- "<li>Item 1</li>\n"
- "<li>Item 2</li>\n"
- "</ul>\n"
- "<pre><code class=\"language-LANG\">FENCED\n"
- "</code></pre>\n"
- "<pre><code>CODE\n"
- "</code></pre>\n"
- "<div>HTML</div>\n"
- "<p><a href=\"URL\" title=\"TITLE\">LINK</a></p>\n";
- STR_EQ(runner, rendered_html, expected_html, "setters work");
- free(rendered_html);
-
- // Getter errors
-
- INT_EQ(runner, cmark_node_get_heading_level(bullet_list), 0,
- "get_heading_level error");
- INT_EQ(runner, cmark_node_get_list_type(heading), CMARK_NO_LIST,
- "get_list_type error");
- INT_EQ(runner, cmark_node_get_list_start(code), 0, "get_list_start error");
- INT_EQ(runner, cmark_node_get_list_tight(fenced), 0, "get_list_tight error");
- OK(runner, cmark_node_get_literal(ordered_list) == NULL, "get_literal error");
- OK(runner, cmark_node_get_fence_info(paragraph) == NULL,
- "get_fence_info error");
- OK(runner, cmark_node_get_url(html) == NULL, "get_url error");
- OK(runner, cmark_node_get_title(heading) == NULL, "get_title error");
-
- // Setter errors
-
- OK(runner, !cmark_node_set_heading_level(bullet_list, 3),
- "set_heading_level error");
- OK(runner, !cmark_node_set_list_type(heading, CMARK_ORDERED_LIST),
- "set_list_type error");
- OK(runner, !cmark_node_set_list_start(code, 3), "set_list_start error");
- OK(runner, !cmark_node_set_list_tight(fenced, 0), "set_list_tight error");
- OK(runner, !cmark_node_set_literal(ordered_list, "content\n"),
- "set_literal error");
- OK(runner, !cmark_node_set_fence_info(paragraph, "lang"),
- "set_fence_info error");
- OK(runner, !cmark_node_set_url(html, "url"), "set_url error");
- OK(runner, !cmark_node_set_title(heading, "title"), "set_title error");
-
- OK(runner, !cmark_node_set_heading_level(heading, 0),
- "set_heading_level too small");
- OK(runner, !cmark_node_set_heading_level(heading, 7),
- "set_heading_level too large");
- OK(runner, !cmark_node_set_list_type(bullet_list, CMARK_NO_LIST),
- "set_list_type invalid");
- OK(runner, !cmark_node_set_list_start(bullet_list, -1),
- "set_list_start negative");
-
- cmark_node_free(doc);
-}
-
-static void free_parent(test_batch_runner *runner) {
- static const char markdown[] = "text\n";
-
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- cmark_node *para = cmark_node_first_child(doc);
- cmark_node *text = cmark_node_first_child(para);
- cmark_node_unlink(text);
- cmark_node_free(doc);
- STR_EQ(runner, cmark_node_get_literal(text), "text",
- "inline content after freeing parent block");
- cmark_node_free(text);
-}
-
-static void node_check(test_batch_runner *runner) {
- // Construct an incomplete tree.
- cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
- cmark_node *p1 = cmark_node_new(CMARK_NODE_PARAGRAPH);
- cmark_node *p2 = cmark_node_new(CMARK_NODE_PARAGRAPH);
- doc->first_child = p1;
- p1->next = p2;
-
- INT_EQ(runner, cmark_node_check(doc, NULL), 4, "node_check works");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "node_check fixes tree");
-
- cmark_node_free(doc);
-}
-
-static void iterator(test_batch_runner *runner) {
- cmark_node *doc = cmark_parse_document("> a *b*\n\nc", 10, CMARK_OPT_DEFAULT);
- int parnodes = 0;
- cmark_event_type ev_type;
- cmark_iter *iter = cmark_iter_new(doc);
- cmark_node *cur;
-
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
- cur = cmark_iter_get_node(iter);
- if (cur->type == CMARK_NODE_PARAGRAPH && ev_type == CMARK_EVENT_ENTER) {
- parnodes += 1;
- }
- }
- INT_EQ(runner, parnodes, 2, "iterate correctly counts paragraphs");
-
- cmark_iter_free(iter);
- cmark_node_free(doc);
-}
-
-static void iterator_delete(test_batch_runner *runner) {
- static const char md[] = "a *b* c\n"
- "\n"
- "* item1\n"
- "* item2\n"
- "\n"
- "a `b` c\n"
- "\n"
- "* item1\n"
- "* item2\n";
- cmark_node *doc = cmark_parse_document(md, sizeof(md) - 1, CMARK_OPT_DEFAULT);
- cmark_iter *iter = cmark_iter_new(doc);
- cmark_event_type ev_type;
-
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
- cmark_node *node = cmark_iter_get_node(iter);
- // Delete list, emph, and code nodes.
- if ((ev_type == CMARK_EVENT_EXIT && node->type == CMARK_NODE_LIST) ||
- (ev_type == CMARK_EVENT_EXIT && node->type == CMARK_NODE_EMPH) ||
- (ev_type == CMARK_EVENT_ENTER && node->type == CMARK_NODE_CODE)) {
- cmark_node_free(node);
- }
- }
-
- char *html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
- static const char expected[] = "<p>a c</p>\n"
- "<p>a c</p>\n";
- STR_EQ(runner, html, expected, "iterate and delete nodes");
-
- cmark_mem *allocator = cmark_get_default_mem_allocator();
-
- allocator->free(html);
- cmark_iter_free(iter);
- cmark_node_free(doc);
-}
-
-static void create_tree(test_batch_runner *runner) {
- char *html;
- cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
-
- cmark_node *p = cmark_node_new(CMARK_NODE_PARAGRAPH);
- OK(runner, !cmark_node_insert_before(doc, p), "insert before root fails");
- OK(runner, !cmark_node_insert_after(doc, p), "insert after root fails");
- OK(runner, cmark_node_append_child(doc, p), "append1");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append1 consistent");
- OK(runner, cmark_node_parent(p) == doc, "node_parent");
-
- cmark_node *emph = cmark_node_new(CMARK_NODE_EMPH);
- OK(runner, cmark_node_prepend_child(p, emph), "prepend1");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "prepend1 consistent");
-
- cmark_node *str1 = cmark_node_new(CMARK_NODE_TEXT);
- cmark_node_set_literal(str1, "Hello, ");
- OK(runner, cmark_node_prepend_child(p, str1), "prepend2");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "prepend2 consistent");
-
- cmark_node *str3 = cmark_node_new(CMARK_NODE_TEXT);
- cmark_node_set_literal(str3, "!");
- OK(runner, cmark_node_append_child(p, str3), "append2");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append2 consistent");
-
- cmark_node *str2 = cmark_node_new(CMARK_NODE_TEXT);
- cmark_node_set_literal(str2, "world");
- OK(runner, cmark_node_append_child(emph, str2), "append3");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "append3 consistent");
-
- html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<p>Hello, <em>world</em>!</p>\n", "render_html");
- free(html);
-
- OK(runner, cmark_node_insert_before(str1, str3), "ins before1");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins before1 consistent");
- // 31e
- OK(runner, cmark_node_first_child(p) == str3, "ins before1 works");
-
- OK(runner, cmark_node_insert_before(str1, emph), "ins before2");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins before2 consistent");
- // 3e1
- OK(runner, cmark_node_last_child(p) == str1, "ins before2 works");
-
- OK(runner, cmark_node_insert_after(str1, str3), "ins after1");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins after1 consistent");
- // e13
- OK(runner, cmark_node_next(str1) == str3, "ins after1 works");
-
- OK(runner, cmark_node_insert_after(str1, emph), "ins after2");
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "ins after2 consistent");
- // 1e3
- OK(runner, cmark_node_previous(emph) == str1, "ins after2 works");
-
- cmark_node *str4 = cmark_node_new(CMARK_NODE_TEXT);
- cmark_node_set_literal(str4, "brzz");
- OK(runner, cmark_node_replace(str1, str4), "replace");
- // The replaced node is not freed
- cmark_node_free(str1);
-
- INT_EQ(runner, cmark_node_check(doc, NULL), 0, "replace consistent");
- OK(runner, cmark_node_previous(emph) == str4, "replace works");
- INT_EQ(runner, cmark_node_replace(p, str4), 0, "replace str for p fails");
-
- cmark_node_unlink(emph);
-
- html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<p>brzz!</p>\n", "render_html after shuffling");
- free(html);
-
- cmark_node_free(doc);
- cmark_node_free(emph);
-}
-
-static void custom_nodes(test_batch_runner *runner) {
- char *html;
- char *man;
- cmark_node *doc = cmark_node_new(CMARK_NODE_DOCUMENT);
- cmark_node *p = cmark_node_new(CMARK_NODE_PARAGRAPH);
- cmark_node_append_child(doc, p);
- cmark_node *ci = cmark_node_new(CMARK_NODE_CUSTOM_INLINE);
- cmark_node *str1 = cmark_node_new(CMARK_NODE_TEXT);
- cmark_node_set_literal(str1, "Hello");
- OK(runner, cmark_node_append_child(ci, str1), "append1");
- OK(runner, cmark_node_set_on_enter(ci, "<ON ENTER|"), "set_on_enter");
- OK(runner, cmark_node_set_on_exit(ci, "|ON EXIT>"), "set_on_exit");
- STR_EQ(runner, cmark_node_get_on_enter(ci), "<ON ENTER|", "get_on_enter");
- STR_EQ(runner, cmark_node_get_on_exit(ci), "|ON EXIT>", "get_on_exit");
- cmark_node_append_child(p, ci);
- cmark_node *cb = cmark_node_new(CMARK_NODE_CUSTOM_BLOCK);
- cmark_node_set_on_enter(cb, "<on enter|");
- // leave on_exit unset
- STR_EQ(runner, cmark_node_get_on_exit(cb), "", "get_on_exit (empty)");
- cmark_node_append_child(doc, cb);
-
- html = cmark_render_html(doc, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<p><ON ENTER|Hello|ON EXIT></p>\n<on enter|\n",
- "render_html");
- free(html);
-
- man = cmark_render_man(doc, CMARK_OPT_DEFAULT, 0);
- STR_EQ(runner, man, ".PP\n<ON ENTER|Hello|ON EXIT>\n<on enter|\n",
- "render_man");
- free(man);
-
- cmark_node_free(doc);
-}
-
-void hierarchy(test_batch_runner *runner) {
- cmark_node *bquote1 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
- cmark_node *bquote2 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
- cmark_node *bquote3 = cmark_node_new(CMARK_NODE_BLOCK_QUOTE);
-
- OK(runner, cmark_node_append_child(bquote1, bquote2), "append bquote2");
- OK(runner, cmark_node_append_child(bquote2, bquote3), "append bquote3");
- OK(runner, !cmark_node_append_child(bquote3, bquote3),
- "adding a node as child of itself fails");
- OK(runner, !cmark_node_append_child(bquote3, bquote1),
- "adding a parent as child fails");
-
- cmark_node_free(bquote1);
-
- int max_node_type = CMARK_NODE_LAST_BLOCK > CMARK_NODE_LAST_INLINE
- ? CMARK_NODE_LAST_BLOCK
- : CMARK_NODE_LAST_INLINE;
- OK(runner, max_node_type < 32, "all node types < 32");
-
- int list_item_flag = 1 << CMARK_NODE_ITEM;
- int top_level_blocks =
- (1 << CMARK_NODE_BLOCK_QUOTE) | (1 << CMARK_NODE_LIST) |
- (1 << CMARK_NODE_CODE_BLOCK) | (1 << CMARK_NODE_HTML_BLOCK) |
- (1 << CMARK_NODE_PARAGRAPH) | (1 << CMARK_NODE_HEADING) |
- (1 << CMARK_NODE_THEMATIC_BREAK);
- int all_inlines = (1 << CMARK_NODE_TEXT) | (1 << CMARK_NODE_SOFTBREAK) |
- (1 << CMARK_NODE_LINEBREAK) | (1 << CMARK_NODE_CODE) |
- (1 << CMARK_NODE_HTML_INLINE) | (1 << CMARK_NODE_EMPH) |
- (1 << CMARK_NODE_STRONG) | (1 << CMARK_NODE_LINK) |
- (1 << CMARK_NODE_IMAGE);
-
- test_content(runner, CMARK_NODE_DOCUMENT, top_level_blocks);
- test_content(runner, CMARK_NODE_BLOCK_QUOTE, top_level_blocks);
- test_content(runner, CMARK_NODE_LIST, list_item_flag);
- test_content(runner, CMARK_NODE_ITEM, top_level_blocks);
- test_content(runner, CMARK_NODE_CODE_BLOCK, 0);
- test_content(runner, CMARK_NODE_HTML_BLOCK, 0);
- test_content(runner, CMARK_NODE_PARAGRAPH, all_inlines);
- test_content(runner, CMARK_NODE_HEADING, all_inlines);
- test_content(runner, CMARK_NODE_THEMATIC_BREAK, 0);
- test_content(runner, CMARK_NODE_TEXT, 0);
- test_content(runner, CMARK_NODE_SOFTBREAK, 0);
- test_content(runner, CMARK_NODE_LINEBREAK, 0);
- test_content(runner, CMARK_NODE_CODE, 0);
- test_content(runner, CMARK_NODE_HTML_INLINE, 0);
- test_content(runner, CMARK_NODE_EMPH, all_inlines);
- test_content(runner, CMARK_NODE_STRONG, all_inlines);
- test_content(runner, CMARK_NODE_LINK, all_inlines);
- test_content(runner, CMARK_NODE_IMAGE, all_inlines);
-}
-
-static void test_content(test_batch_runner *runner, cmark_node_type type,
- int allowed_content) {
- cmark_node *node = cmark_node_new(type);
-
- for (int i = 0; i < num_node_types; ++i) {
- cmark_node_type child_type = node_types[i];
- cmark_node *child = cmark_node_new(child_type);
-
- int got = cmark_node_append_child(node, child);
- int expected = (allowed_content >> child_type) & 1;
-
- INT_EQ(runner, got, expected, "add %d as child of %d", child_type, type);
-
- cmark_node_free(child);
- }
-
- cmark_node_free(node);
-}
-
-static void parser(test_batch_runner *runner) {
- test_md_to_html(runner, "No newline", "<p>No newline</p>\n",
- "document without trailing newline");
-}
-
-static void render_html(test_batch_runner *runner) {
- char *html;
-
- static const char markdown[] = "foo *bar*\n"
- "\n"
- "paragraph 2\n";
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- cmark_node *paragraph = cmark_node_first_child(doc);
- html = cmark_render_html(paragraph, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<p>foo <em>bar</em></p>\n", "render single paragraph");
- free(html);
-
- cmark_node *string = cmark_node_first_child(paragraph);
- html = cmark_render_html(string, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "foo ", "render single inline");
- free(html);
-
- cmark_node *emph = cmark_node_next(string);
- html = cmark_render_html(emph, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<em>bar</em>", "render inline with children");
- free(html);
-
- cmark_node_free(doc);
-}
-
-static void render_xml(test_batch_runner *runner) {
- char *xml;
-
- static const char markdown[] = "foo *bar*\n"
- "\n"
- "paragraph 2\n"
- "\n"
- "```\ncode\n```\n";
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT);
- STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
- "<document xmlns=\"http://commonmark.org/xml/1.0\">\n"
- " <paragraph>\n"
- " <text xml:space=\"preserve\">foo </text>\n"
- " <emph>\n"
- " <text xml:space=\"preserve\">bar</text>\n"
- " </emph>\n"
- " </paragraph>\n"
- " <paragraph>\n"
- " <text xml:space=\"preserve\">paragraph 2</text>\n"
- " </paragraph>\n"
- " <code_block xml:space=\"preserve\">code\n"
- "</code_block>\n"
- "</document>\n",
- "render document");
- free(xml);
- cmark_node *paragraph = cmark_node_first_child(doc);
- xml = cmark_render_xml(paragraph, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
- STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
- "<paragraph sourcepos=\"1:1-1:9\">\n"
- " <text sourcepos=\"1:1-1:4\" xml:space=\"preserve\">foo </text>\n"
- " <emph sourcepos=\"1:5-1:9\">\n"
- " <text sourcepos=\"1:6-1:8\" xml:space=\"preserve\">bar</text>\n"
- " </emph>\n"
- "</paragraph>\n",
- "render first paragraph with source pos");
- free(xml);
- cmark_node_free(doc);
-}
-
-static void render_man(test_batch_runner *runner) {
- char *man;
-
- static const char markdown[] = "foo *bar*\n"
- "\n"
- "- Lorem ipsum dolor sit amet,\n"
- " consectetur adipiscing elit,\n"
- "- sed do eiusmod tempor incididunt\n"
- " ut labore et dolore magna aliqua.\n";
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- man = cmark_render_man(doc, CMARK_OPT_DEFAULT, 20);
- STR_EQ(runner, man, ".PP\n"
- "foo \\f[I]bar\\f[]\n"
- ".IP \\[bu] 2\n"
- "Lorem ipsum dolor\n"
- "sit amet,\n"
- "consectetur\n"
- "adipiscing elit,\n"
- ".IP \\[bu] 2\n"
- "sed do eiusmod\n"
- "tempor incididunt ut\n"
- "labore et dolore\n"
- "magna aliqua.\n",
- "render document with wrapping");
- free(man);
- man = cmark_render_man(doc, CMARK_OPT_DEFAULT, 0);
- STR_EQ(runner, man, ".PP\n"
- "foo \\f[I]bar\\f[]\n"
- ".IP \\[bu] 2\n"
- "Lorem ipsum dolor sit amet,\n"
- "consectetur adipiscing elit,\n"
- ".IP \\[bu] 2\n"
- "sed do eiusmod tempor incididunt\n"
- "ut labore et dolore magna aliqua.\n",
- "render document without wrapping");
- free(man);
- cmark_node_free(doc);
-}
-
-static void render_latex(test_batch_runner *runner) {
- char *latex;
-
- static const char markdown[] = "foo *bar* $%\n"
- "\n"
- "- Lorem ipsum dolor sit amet,\n"
- " consectetur adipiscing elit,\n"
- "- sed do eiusmod tempor incididunt\n"
- " ut labore et dolore magna aliqua.\n";
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- latex = cmark_render_latex(doc, CMARK_OPT_DEFAULT, 20);
- STR_EQ(runner, latex, "foo \\emph{bar} \\$\\%\n"
- "\n"
- "\\begin{itemize}\n"
- "\\item Lorem ipsum\n"
- "dolor sit amet,\n"
- "consectetur\n"
- "adipiscing elit,\n"
- "\n"
- "\\item sed do eiusmod\n"
- "tempor incididunt ut\n"
- "labore et dolore\n"
- "magna aliqua.\n"
- "\n"
- "\\end{itemize}\n",
- "render document with wrapping");
- free(latex);
- latex = cmark_render_latex(doc, CMARK_OPT_DEFAULT, 0);
- STR_EQ(runner, latex, "foo \\emph{bar} \\$\\%\n"
- "\n"
- "\\begin{itemize}\n"
- "\\item Lorem ipsum dolor sit amet,\n"
- "consectetur adipiscing elit,\n"
- "\n"
- "\\item sed do eiusmod tempor incididunt\n"
- "ut labore et dolore magna aliqua.\n"
- "\n"
- "\\end{itemize}\n",
- "render document without wrapping");
- free(latex);
- cmark_node_free(doc);
-}
-
-static void render_commonmark(test_batch_runner *runner) {
- char *commonmark;
-
- static const char markdown[] = "> \\- foo *bar* \\*bar\\*\n"
- "\n"
- "- Lorem ipsum dolor sit amet,\n"
- " consectetur adipiscing elit,\n"
- "- sed do eiusmod tempor incididunt\n"
- " ut labore et dolore magna aliqua.\n";
- cmark_node *doc =
- cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
-
- commonmark = cmark_render_commonmark(doc, CMARK_OPT_DEFAULT, 26);
- STR_EQ(runner, commonmark, "> \\- foo *bar* \\*bar\\*\n"
- "\n"
- " - Lorem ipsum dolor sit\n"
- " amet, consectetur\n"
- " adipiscing elit,\n"
- " - sed do eiusmod tempor\n"
- " incididunt ut labore\n"
- " et dolore magna\n"
- " aliqua.\n",
- "render document with wrapping");
- free(commonmark);
- commonmark = cmark_render_commonmark(doc, CMARK_OPT_DEFAULT, 0);
- STR_EQ(runner, commonmark, "> \\- foo *bar* \\*bar\\*\n"
- "\n"
- " - Lorem ipsum dolor sit amet,\n"
- " consectetur adipiscing elit,\n"
- " - sed do eiusmod tempor incididunt\n"
- " ut labore et dolore magna aliqua.\n",
- "render document without wrapping");
- free(commonmark);
-
- cmark_node *text = cmark_node_new(CMARK_NODE_TEXT);
- cmark_node_set_literal(text, "Hi");
- commonmark = cmark_render_commonmark(text, CMARK_OPT_DEFAULT, 0);
- STR_EQ(runner, commonmark, "Hi\n", "render single inline node");
- free(commonmark);
-
- cmark_node_free(text);
- cmark_node_free(doc);
-}
-
-static void utf8(test_batch_runner *runner) {
- // Ranges
- test_char(runner, 1, "\x01", "valid utf8 01");
- test_char(runner, 1, "\x7F", "valid utf8 7F");
- test_char(runner, 0, "\x80", "invalid utf8 80");
- test_char(runner, 0, "\xBF", "invalid utf8 BF");
- test_char(runner, 0, "\xC0\x80", "invalid utf8 C080");
- test_char(runner, 0, "\xC1\xBF", "invalid utf8 C1BF");
- test_char(runner, 1, "\xC2\x80", "valid utf8 C280");
- test_char(runner, 1, "\xDF\xBF", "valid utf8 DFBF");
- test_char(runner, 0, "\xE0\x80\x80", "invalid utf8 E08080");
- test_char(runner, 0, "\xE0\x9F\xBF", "invalid utf8 E09FBF");
- test_char(runner, 1, "\xE0\xA0\x80", "valid utf8 E0A080");
- test_char(runner, 1, "\xED\x9F\xBF", "valid utf8 ED9FBF");
- test_char(runner, 0, "\xED\xA0\x80", "invalid utf8 EDA080");
- test_char(runner, 0, "\xED\xBF\xBF", "invalid utf8 EDBFBF");
- test_char(runner, 0, "\xF0\x80\x80\x80", "invalid utf8 F0808080");
- test_char(runner, 0, "\xF0\x8F\xBF\xBF", "invalid utf8 F08FBFBF");
- test_char(runner, 1, "\xF0\x90\x80\x80", "valid utf8 F0908080");
- test_char(runner, 1, "\xF4\x8F\xBF\xBF", "valid utf8 F48FBFBF");
- test_char(runner, 0, "\xF4\x90\x80\x80", "invalid utf8 F4908080");
- test_char(runner, 0, "\xF7\xBF\xBF\xBF", "invalid utf8 F7BFBFBF");
- test_char(runner, 0, "\xF8", "invalid utf8 F8");
- test_char(runner, 0, "\xFF", "invalid utf8 FF");
-
- // Incomplete byte sequences at end of input
- test_incomplete_char(runner, "\xE0\xA0", "invalid utf8 E0A0");
- test_incomplete_char(runner, "\xF0\x90\x80", "invalid utf8 F09080");
-
- // Invalid continuation bytes
- test_continuation_byte(runner, "\xC2\x80");
- test_continuation_byte(runner, "\xE0\xA0\x80");
- test_continuation_byte(runner, "\xF0\x90\x80\x80");
-
- // Test string containing null character
- static const char string_with_null[] = "((((\0))))";
- char *html = cmark_markdown_to_html(
- string_with_null, sizeof(string_with_null) - 1, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<p>((((" UTF8_REPL "))))</p>\n", "utf8 with U+0000");
- free(html);
-
- // Test NUL followed by newline
- static const char string_with_nul_lf[] = "```\n\0\n```\n";
- html = cmark_markdown_to_html(
- string_with_nul_lf, sizeof(string_with_nul_lf) - 1, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<pre><code>\xef\xbf\xbd\n</code></pre>\n",
- "utf8 with \\0\\n");
- free(html);
-}
-
-static void test_char(test_batch_runner *runner, int valid, const char *utf8,
- const char *msg) {
- char buf[20];
- sprintf(buf, "((((%s))))", utf8);
-
- if (valid) {
- char expected[30];
- sprintf(expected, "<p>((((%s))))</p>\n", utf8);
- test_md_to_html(runner, buf, expected, msg);
- } else {
- test_md_to_html(runner, buf, "<p>((((" UTF8_REPL "))))</p>\n", msg);
- }
-}
-
-static void test_incomplete_char(test_batch_runner *runner, const char *utf8,
- const char *msg) {
- char buf[20];
- sprintf(buf, "----%s", utf8);
- test_md_to_html(runner, buf, "<p>----" UTF8_REPL "</p>\n", msg);
-}
-
-static void test_continuation_byte(test_batch_runner *runner,
- const char *utf8) {
- size_t len = strlen(utf8);
-
- for (size_t pos = 1; pos < len; ++pos) {
- char buf[20];
- sprintf(buf, "((((%s))))", utf8);
- buf[4 + pos] = '\x20';
-
- char expected[50];
- strcpy(expected, "<p>((((" UTF8_REPL "\x20");
- for (size_t i = pos + 1; i < len; ++i) {
- strcat(expected, UTF8_REPL);
- }
- strcat(expected, "))))</p>\n");
-
- char *html =
- cmark_markdown_to_html(buf, strlen(buf), CMARK_OPT_VALIDATE_UTF8);
- STR_EQ(runner, html, expected, "invalid utf8 continuation byte %d/%d", pos,
- len);
- free(html);
- }
-}
-
-static void line_endings(test_batch_runner *runner) {
- // Test list with different line endings
- static const char list_with_endings[] = "- a\n- b\r\n- c\r- d";
- char *html = cmark_markdown_to_html(
- list_with_endings, sizeof(list_with_endings) - 1, CMARK_OPT_DEFAULT);
- STR_EQ(runner, html,
- "<ul>\n<li>a</li>\n<li>b</li>\n<li>c</li>\n<li>d</li>\n</ul>\n",
- "list with different line endings");
- free(html);
-
- static const char crlf_lines[] = "line\r\nline\r\n";
- html = cmark_markdown_to_html(crlf_lines, sizeof(crlf_lines) - 1,
- CMARK_OPT_DEFAULT | CMARK_OPT_HARDBREAKS);
- STR_EQ(runner, html, "<p>line<br />\nline</p>\n",
- "crlf endings with CMARK_OPT_HARDBREAKS");
- free(html);
- html = cmark_markdown_to_html(crlf_lines, sizeof(crlf_lines) - 1,
- CMARK_OPT_DEFAULT | CMARK_OPT_NOBREAKS);
- STR_EQ(runner, html, "<p>line line</p>\n",
- "crlf endings with CMARK_OPT_NOBREAKS");
- free(html);
-
- static const char no_line_ending[] = "```\nline\n```";
- html = cmark_markdown_to_html(no_line_ending, sizeof(no_line_ending) - 1,
- CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<pre><code>line\n</code></pre>\n",
- "fenced code block with no final newline");
- free(html);
-}
-
-static void numeric_entities(test_batch_runner *runner) {
- test_md_to_html(runner, "&#0;", "<p>" UTF8_REPL "</p>\n",
- "Invalid numeric entity 0");
- test_md_to_html(runner, "&#55295;", "<p>\xED\x9F\xBF</p>\n",
- "Valid numeric entity 0xD7FF");
- test_md_to_html(runner, "&#xD800;", "<p>" UTF8_REPL "</p>\n",
- "Invalid numeric entity 0xD800");
- test_md_to_html(runner, "&#xDFFF;", "<p>" UTF8_REPL "</p>\n",
- "Invalid numeric entity 0xDFFF");
- test_md_to_html(runner, "&#57344;", "<p>\xEE\x80\x80</p>\n",
- "Valid numeric entity 0xE000");
- test_md_to_html(runner, "&#x10FFFF;", "<p>\xF4\x8F\xBF\xBF</p>\n",
- "Valid numeric entity 0x10FFFF");
- test_md_to_html(runner, "&#x110000;", "<p>" UTF8_REPL "</p>\n",
- "Invalid numeric entity 0x110000");
- test_md_to_html(runner, "&#x80000000;", "<p>&amp;#x80000000;</p>\n",
- "Invalid numeric entity 0x80000000");
- test_md_to_html(runner, "&#xFFFFFFFF;", "<p>&amp;#xFFFFFFFF;</p>\n",
- "Invalid numeric entity 0xFFFFFFFF");
- test_md_to_html(runner, "&#99999999;", "<p>&amp;#99999999;</p>\n",
- "Invalid numeric entity 99999999");
-
- test_md_to_html(runner, "&#;", "<p>&amp;#;</p>\n",
- "Min decimal entity length");
- test_md_to_html(runner, "&#x;", "<p>&amp;#x;</p>\n",
- "Min hexadecimal entity length");
- test_md_to_html(runner, "&#999999999;", "<p>&amp;#999999999;</p>\n",
- "Max decimal entity length");
- test_md_to_html(runner, "&#x000000041;", "<p>&amp;#x000000041;</p>\n",
- "Max hexadecimal entity length");
-}
-
-static void test_safe(test_batch_runner *runner) {
- // Test safe mode
- static const char raw_html[] = "<div>\nhi\n</div>\n\n<a>hi</"
- "a>\n[link](JAVAscript:alert('hi'))\n![image]("
- "file:my.js)\n";
- char *html = cmark_markdown_to_html(raw_html, sizeof(raw_html) - 1,
- CMARK_OPT_DEFAULT);
- STR_EQ(runner, html, "<!-- raw HTML omitted -->\n<p><!-- raw HTML omitted "
- "-->hi<!-- raw HTML omitted -->\n<a "
- "href=\"\">link</a>\n<img src=\"\" alt=\"image\" "
- "/></p>\n",
- "input with raw HTML and dangerous links");
- free(html);
-}
-
-static void test_md_to_html(test_batch_runner *runner, const char *markdown,
- const char *expected_html, const char *msg) {
- char *html = cmark_markdown_to_html(markdown, strlen(markdown),
- CMARK_OPT_VALIDATE_UTF8);
- STR_EQ(runner, html, expected_html, msg);
- free(html);
-}
-
-static void test_feed_across_line_ending(test_batch_runner *runner) {
- // See #117
- cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
- cmark_parser_feed(parser, "line1\r", 6);
- cmark_parser_feed(parser, "\nline2\r\n", 8);
- cmark_node *document = cmark_parser_finish(parser);
- OK(runner, document->first_child->next == NULL, "document has one paragraph");
- cmark_parser_free(parser);
- cmark_node_free(document);
-}
-
-static void source_pos(test_batch_runner *runner) {
- static const char markdown[] =
- "# Hi *there*.\n"
- "\n"
- "Hello &ldquo; <http://www.google.com>\n"
- "there `hi` -- [okay](www.google.com (ok)).\n"
- "\n"
- "> 1. Okay.\n"
- "> Sure.\n"
- ">\n"
- "> 2. Yes, okay.\n"
- "> ![ok](hi \"yes\")\n";
-
- cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
- char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
- STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
- "<document sourcepos=\"1:1-10:20\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
- " <heading sourcepos=\"1:1-1:13\" level=\"1\">\n"
- " <text sourcepos=\"1:3-1:5\" xml:space=\"preserve\">Hi </text>\n"
- " <emph sourcepos=\"1:6-1:12\">\n"
- " <text sourcepos=\"1:7-1:11\" xml:space=\"preserve\">there</text>\n"
- " </emph>\n"
- " <text sourcepos=\"1:13-1:13\" xml:space=\"preserve\">.</text>\n"
- " </heading>\n"
- " <paragraph sourcepos=\"3:1-4:42\">\n"
- " <text sourcepos=\"3:1-3:14\" xml:space=\"preserve\">Hello “ </text>\n"
- " <link sourcepos=\"3:15-3:37\" destination=\"http://www.google.com\">\n"
- " <text sourcepos=\"3:16-3:36\" xml:space=\"preserve\">http://www.google.com</text>\n"
- " </link>\n"
- " <softbreak />\n"
- " <text sourcepos=\"4:1-4:6\" xml:space=\"preserve\">there </text>\n"
- " <code sourcepos=\"4:8-4:9\" xml:space=\"preserve\">hi</code>\n"
- " <text sourcepos=\"4:11-4:14\" xml:space=\"preserve\"> -- </text>\n"
- " <link sourcepos=\"4:15-4:41\" destination=\"www.google.com\" title=\"ok\">\n"
- " <text sourcepos=\"4:16-4:19\" xml:space=\"preserve\">okay</text>\n"
- " </link>\n"
- " <text sourcepos=\"4:42-4:42\" xml:space=\"preserve\">.</text>\n"
- " </paragraph>\n"
- " <block_quote sourcepos=\"6:1-10:20\">\n"
- " <list sourcepos=\"6:3-10:20\" type=\"ordered\" start=\"1\" delim=\"period\" tight=\"false\">\n"
- " <item sourcepos=\"6:3-8:1\">\n"
- " <paragraph sourcepos=\"6:6-7:10\">\n"
- " <text sourcepos=\"6:6-6:10\" xml:space=\"preserve\">Okay.</text>\n"
- " <softbreak />\n"
- " <text sourcepos=\"7:6-7:10\" xml:space=\"preserve\">Sure.</text>\n"
- " </paragraph>\n"
- " </item>\n"
- " <item sourcepos=\"9:3-10:20\">\n"
- " <paragraph sourcepos=\"9:6-10:20\">\n"
- " <text sourcepos=\"9:6-9:15\" xml:space=\"preserve\">Yes, okay.</text>\n"
- " <softbreak />\n"
- " <image sourcepos=\"10:6-10:20\" destination=\"hi\" title=\"yes\">\n"
- " <text sourcepos=\"10:8-10:9\" xml:space=\"preserve\">ok</text>\n"
- " </image>\n"
- " </paragraph>\n"
- " </item>\n"
- " </list>\n"
- " </block_quote>\n"
- "</document>\n",
- "sourcepos are as expected");
- free(xml);
- cmark_node_free(doc);
-}
-
-static void source_pos_inlines(test_batch_runner *runner) {
- {
- static const char markdown[] =
- "*first*\n"
- "second\n";
-
- cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
- char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
- STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
- "<document sourcepos=\"1:1-2:6\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
- " <paragraph sourcepos=\"1:1-2:6\">\n"
- " <emph sourcepos=\"1:1-1:7\">\n"
- " <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
- " </emph>\n"
- " <softbreak />\n"
- " <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
- " </paragraph>\n"
- "</document>\n",
- "sourcepos are as expected");
- free(xml);
- cmark_node_free(doc);
- }
- {
- static const char markdown[] =
- "*first\n"
- "second*\n";
-
- cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
- char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
- STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
- "<document sourcepos=\"1:1-2:7\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
- " <paragraph sourcepos=\"1:1-2:7\">\n"
- " <emph sourcepos=\"1:1-2:7\">\n"
- " <text sourcepos=\"1:2-1:6\" xml:space=\"preserve\">first</text>\n"
- " <softbreak />\n"
- " <text sourcepos=\"2:1-2:6\" xml:space=\"preserve\">second</text>\n"
- " </emph>\n"
- " </paragraph>\n"
- "</document>\n",
- "sourcepos are as expected");
- free(xml);
- cmark_node_free(doc);
- }
-}
-
-static void ref_source_pos(test_batch_runner *runner) {
- static const char markdown[] =
- "Let's try [reference] links.\n"
- "\n"
- "[reference]: https://github.com (GitHub)\n";
-
- cmark_node *doc = cmark_parse_document(markdown, sizeof(markdown) - 1, CMARK_OPT_DEFAULT);
- char *xml = cmark_render_xml(doc, CMARK_OPT_DEFAULT | CMARK_OPT_SOURCEPOS);
- STR_EQ(runner, xml, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
- "<!DOCTYPE document SYSTEM \"CommonMark.dtd\">\n"
- "<document sourcepos=\"1:1-3:40\" xmlns=\"http://commonmark.org/xml/1.0\">\n"
- " <paragraph sourcepos=\"1:1-1:28\">\n"
- " <text sourcepos=\"1:1-1:10\" xml:space=\"preserve\">Let's try </text>\n"
- " <link sourcepos=\"1:11-1:21\" destination=\"https://github.com\" title=\"GitHub\">\n"
- " <text sourcepos=\"1:12-1:20\" xml:space=\"preserve\">reference</text>\n"
- " </link>\n"
- " <text sourcepos=\"1:22-1:28\" xml:space=\"preserve\"> links.</text>\n"
- " </paragraph>\n"
- "</document>\n",
- "sourcepos are as expected");
- free(xml);
- cmark_node_free(doc);
-}
-
-int main() {
- int retval;
- test_batch_runner *runner = test_batch_runner_new();
-
- version(runner);
- constructor(runner);
- accessors(runner);
- free_parent(runner);
- node_check(runner);
- iterator(runner);
- iterator_delete(runner);
- create_tree(runner);
- custom_nodes(runner);
- hierarchy(runner);
- parser(runner);
- render_html(runner);
- render_xml(runner);
- render_man(runner);
- render_latex(runner);
- render_commonmark(runner);
- utf8(runner);
- line_endings(runner);
- numeric_entities(runner);
- test_cplusplus(runner);
- test_safe(runner);
- test_feed_across_line_ending(runner);
- source_pos(runner);
- source_pos_inlines(runner);
- ref_source_pos(runner);
-
- test_print_summary(runner);
- retval = test_ok(runner) ? 0 : 1;
- free(runner);
-
- return retval;
-}
diff --git a/lib/cmark/bench/samples/block-bq-flat.md b/lib/cmark/bench/samples/block-bq-flat.md
deleted file mode 100644
index 33e382a..0000000
--- a/lib/cmark/bench/samples/block-bq-flat.md
+++ /dev/null
@@ -1,16 +0,0 @@
-> the simple example of a blockquote
-> the simple example of a blockquote
-> the simple example of a blockquote
-> the simple example of a blockquote
-... continuation
-... continuation
-... continuation
-... continuation
-
-empty blockquote:
-
->
->
->
->
-
diff --git a/lib/cmark/bench/samples/block-bq-nested.md b/lib/cmark/bench/samples/block-bq-nested.md
deleted file mode 100644
index 7ddcffa..0000000
--- a/lib/cmark/bench/samples/block-bq-nested.md
+++ /dev/null
@@ -1,13 +0,0 @@
->>>>>> deeply nested blockquote
->>>>> deeply nested blockquote
->>>> deeply nested blockquote
->>> deeply nested blockquote
->> deeply nested blockquote
-> deeply nested blockquote
-
-> deeply nested blockquote
->> deeply nested blockquote
->>> deeply nested blockquote
->>>> deeply nested blockquote
->>>>> deeply nested blockquote
->>>>>> deeply nested blockquote
diff --git a/lib/cmark/bench/samples/block-code.md b/lib/cmark/bench/samples/block-code.md
deleted file mode 100644
index 2b1554f..0000000
--- a/lib/cmark/bench/samples/block-code.md
+++ /dev/null
@@ -1,11 +0,0 @@
-
- an
- example
-
- of
-
-
-
- a code
- block
-
diff --git a/lib/cmark/bench/samples/block-fences.md b/lib/cmark/bench/samples/block-fences.md
deleted file mode 100644
index 5fe8b3c..0000000
--- a/lib/cmark/bench/samples/block-fences.md
+++ /dev/null
@@ -1,14 +0,0 @@
-
-``````````text
-an
-example
-```
-of
-
-
-a fenced
-```
-code
-block
-``````````
-
diff --git a/lib/cmark/bench/samples/block-heading.md b/lib/cmark/bench/samples/block-heading.md
deleted file mode 100644
index fd98558..0000000
--- a/lib/cmark/bench/samples/block-heading.md
+++ /dev/null
@@ -1,9 +0,0 @@
-# heading
-### heading
-##### heading
-
-# heading #
-### heading ###
-##### heading \#\#\#\#\######
-
-############ not a heading
diff --git a/lib/cmark/bench/samples/block-hr.md b/lib/cmark/bench/samples/block-hr.md
deleted file mode 100644
index e1bad6f..0000000
--- a/lib/cmark/bench/samples/block-hr.md
+++ /dev/null
@@ -1,10 +0,0 @@
-
- * * * * *
-
- - - - - -
-
- ________
-
-
- ************************* text
-
diff --git a/lib/cmark/bench/samples/block-html.md b/lib/cmark/bench/samples/block-html.md
deleted file mode 100644
index ff7f8fa..0000000
--- a/lib/cmark/bench/samples/block-html.md
+++ /dev/null
@@ -1,32 +0,0 @@
-<div class="this is an html block">
-
-blah blah
-
-</div>
-
-<table>
- <tr>
- <td>
- **test**
- </td>
- </tr>
-</table>
-
-<table>
-
- <tr>
-
- <td>
-
- test
-
- </td>
-
- </tr>
-
-</table>
-
-<![CDATA[
- [[[[[[[[[[[... *cdata section - this should not be parsed* ...]]]]]]]]]]]
-]]>
-
diff --git a/lib/cmark/bench/samples/block-lheading.md b/lib/cmark/bench/samples/block-lheading.md
deleted file mode 100644
index e5c0d99..0000000
--- a/lib/cmark/bench/samples/block-lheading.md
+++ /dev/null
@@ -1,8 +0,0 @@
-heading
----
-
-heading
-===================================
-
-not a heading
------------------------------------ text
diff --git a/lib/cmark/bench/samples/block-list-flat.md b/lib/cmark/bench/samples/block-list-flat.md
deleted file mode 100644
index 14149db..0000000
--- a/lib/cmark/bench/samples/block-list-flat.md
+++ /dev/null
@@ -1,67 +0,0 @@
- - tidy
- - bullet
- - list
-
-
- - loose
-
- - bullet
-
- - list
-
-
- 0. ordered
- 1. list
- 2. example
-
-
- -
- -
- -
- -
-
-
- 1.
- 2.
- 3.
-
-
- - an example
-of a list item
- with a continuation
-
- this part is inside the list
-
- this part is just a paragraph
-
-
- 1. test
- - test
- 1. test
- - test
-
-
-111111111111111111111111111111111111111111. is this a valid bullet?
-
- - _________________________
-
- - this
- - is
-
- a
-
- long
- - loose
- - list
-
- - with
- - some
-
- tidy
-
- - list
- - items
- - in
-
- - between
- - _________________________
diff --git a/lib/cmark/bench/samples/block-list-nested.md b/lib/cmark/bench/samples/block-list-nested.md
deleted file mode 100644
index d30aed3..0000000
--- a/lib/cmark/bench/samples/block-list-nested.md
+++ /dev/null
@@ -1,36 +0,0 @@
-
- - this
- - is
- - a
- - deeply
- - nested
- - bullet
- - list
-
-
- 1. this
- 2. is
- 3. a
- 4. deeply
- 5. nested
- 6. unordered
- 7. list
-
-
- - 1
- - 2
- - 3
- - 4
- - 5
- - 6
- - 7
- - 6
- - 5
- - 4
- - 3
- - 2
- - 1
-
-
- - - - - - - - - - deeply-nested one-element item
-
diff --git a/lib/cmark/bench/samples/block-ref-flat.md b/lib/cmark/bench/samples/block-ref-flat.md
deleted file mode 100644
index c83dccb..0000000
--- a/lib/cmark/bench/samples/block-ref-flat.md
+++ /dev/null
@@ -1,15 +0,0 @@
-[1] [2] [3] [1] [2] [3]
-
-[looooooooooooooooooooooooooooooooooooooooooooooooooong label]
-
- [1]: <http://something.example.com/foo/bar>
- [2]: http://something.example.com/foo/bar 'test'
- [3]:
- http://foo/bar
- [ looooooooooooooooooooooooooooooooooooooooooooooooooong label ]:
- 111
- 'test'
- [[[[[[[[[[[[[[[[[[[[ this should not slow down anything ]]]]]]]]]]]]]]]]]]]]: q
- (as long as it is not referenced anywhere)
-
- [[[[[[[[[[[[[[[[[[[[]: this is not a valid reference
diff --git a/lib/cmark/bench/samples/block-ref-nested.md b/lib/cmark/bench/samples/block-ref-nested.md
deleted file mode 100644
index 1e10a8c..0000000
--- a/lib/cmark/bench/samples/block-ref-nested.md
+++ /dev/null
@@ -1,17 +0,0 @@
-[[[[[[[foo]]]]]]]
-
-[[[[[[[foo]]]]]]]: bar
-[[[[[[foo]]]]]]: bar
-[[[[[foo]]]]]: bar
-[[[[foo]]]]: bar
-[[[foo]]]: bar
-[[foo]]: bar
-[foo]: bar
-
-[*[*[*[*[foo]*]*]*]*]
-
-[*[*[*[*[foo]*]*]*]*]: bar
-[*[*[*[foo]*]*]*]: bar
-[*[*[foo]*]*]: bar
-[*[foo]*]: bar
-[foo]: bar
diff --git a/lib/cmark/bench/samples/inline-autolink.md b/lib/cmark/bench/samples/inline-autolink.md
deleted file mode 100644
index 0f71482..0000000
--- a/lib/cmark/bench/samples/inline-autolink.md
+++ /dev/null
@@ -1,14 +0,0 @@
-closed (valid) autolinks:
-
- <ftp://1.2.3.4:21/path/foo>
- <http://foo.bar.baz?q=hello&id=22&boolean>
- <http://veeeeeeeeeeeeeeeeeeery.loooooooooooooooooooooooooooooooong.autolink/>
- <teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest@gmail.com>
-
-these are not autolinks:
-
- <ftp://1.2.3.4:21/path/foo
- <http://foo.bar.baz?q=hello&id=22&boolean
- <http://veeeeeeeeeeeeeeeeeeery.loooooooooooooooooooooooooooooooong.autolink
- <teeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeest@gmail.com
- < http://foo.bar.baz?q=hello&id=22&boolean >
diff --git a/lib/cmark/bench/samples/inline-backticks.md b/lib/cmark/bench/samples/inline-backticks.md
deleted file mode 100644
index a6ec6e1..0000000
--- a/lib/cmark/bench/samples/inline-backticks.md
+++ /dev/null
@@ -1,3 +0,0 @@
-`lots`of`backticks`
-
-``i``wonder``how``this``will``be``parsed``
diff --git a/lib/cmark/bench/samples/inline-em-flat.md b/lib/cmark/bench/samples/inline-em-flat.md
deleted file mode 100644
index b7668a5..0000000
--- a/lib/cmark/bench/samples/inline-em-flat.md
+++ /dev/null
@@ -1,5 +0,0 @@
-*this* *is* *your* *basic* *boring* *emphasis*
-
-_this_ _is_ _your_ _basic_ _boring_ _emphasis_
-
-**this** **is** **your** **basic** **boring** **emphasis**
diff --git a/lib/cmark/bench/samples/inline-em-nested.md b/lib/cmark/bench/samples/inline-em-nested.md
deleted file mode 100644
index 6bb0a0d..0000000
--- a/lib/cmark/bench/samples/inline-em-nested.md
+++ /dev/null
@@ -1,5 +0,0 @@
-*this *is *a *bunch* of* nested* emphases*
-
-__this __is __a __bunch__ of__ nested__ emphases__
-
-***this ***is ***a ***bunch*** of*** nested*** emphases***
diff --git a/lib/cmark/bench/samples/inline-em-worst.md b/lib/cmark/bench/samples/inline-em-worst.md
deleted file mode 100644
index b6d21da..0000000
--- a/lib/cmark/bench/samples/inline-em-worst.md
+++ /dev/null
@@ -1,5 +0,0 @@
-*this *is *a *worst *case *for *em *backtracking
-
-__this __is __a __worst __case __for __em __backtracking
-
-***this ***is ***a ***worst ***case ***for ***em ***backtracking
diff --git a/lib/cmark/bench/samples/inline-entity.md b/lib/cmark/bench/samples/inline-entity.md
deleted file mode 100644
index da095ed..0000000
--- a/lib/cmark/bench/samples/inline-entity.md
+++ /dev/null
@@ -1,11 +0,0 @@
-entities:
-
-&nbsp; &amp; &copy; &AElig; &Dcaron; &frac34; &HilbertSpace; &DifferentialD; &ClockwiseContourIntegral;
-
-&#35; &#1234; &#992; &#98765432;
-
-non-entities:
-
-&18900987654321234567890; &1234567890098765432123456789009876543212345678987654;
-
-&qwertyuioppoiuytrewqwer; &oiuytrewqwertyuioiuytrewqwertyuioytrewqwertyuiiuytri;
diff --git a/lib/cmark/bench/samples/inline-escape.md b/lib/cmark/bench/samples/inline-escape.md
deleted file mode 100644
index 4e1bb39..0000000
--- a/lib/cmark/bench/samples/inline-escape.md
+++ /dev/null
@@ -1,15 +0,0 @@
-
-\t\e\s\t\i\n\g \e\s\c\a\p\e \s\e\q\u\e\n\c\e\s
-
-\!\\\"\#\$\%\&\'\(\)\*\+\,\.\/\:\;\<\=\>\?
-
-\@ \[ \] \^ \_ \` \{ \| \} \~ \- \'
-
-\
-\\
-\\\
-\\\\
-\\\\\
-
-\<this\> \<is\> \<not\> \<html\>
-
diff --git a/lib/cmark/bench/samples/inline-html.md b/lib/cmark/bench/samples/inline-html.md
deleted file mode 100644
index f6e6341..0000000
--- a/lib/cmark/bench/samples/inline-html.md
+++ /dev/null
@@ -1,44 +0,0 @@
-Taking commonmark tests from the spec for benchmarking here:
-
-<a><bab><c2c>
-
-<a/><b2/>
-
-<a /><b2
-data="foo" >
-
-<a foo="bar" bam = 'baz <em>"</em>'
-_boolean zoop:33=zoop:33 />
-
-<33> <__>
-
-<a h*#ref="hi">
-
-<a href="hi'> <a href=hi'>
-
-< a><
-foo><bar/ >
-
-<a href='bar'title=title>
-
-</a>
-</foo >
-
-</a href="foo">
-
-foo <!-- this is a
-comment - with hyphen -->
-
-foo <!-- not a comment -- two hyphens -->
-
-foo <?php echo $a; ?>
-
-foo <!ELEMENT br EMPTY>
-
-foo <![CDATA[>&<]]>
-
-<a href="&ouml;">
-
-<a href="\*">
-
-<a href="\"">
diff --git a/lib/cmark/bench/samples/inline-links-flat.md b/lib/cmark/bench/samples/inline-links-flat.md
deleted file mode 100644
index 5117db8..0000000
--- a/lib/cmark/bench/samples/inline-links-flat.md
+++ /dev/null
@@ -1,23 +0,0 @@
-Valid links:
-
- [this is a link]()
- [this is a link](<http://something.example.com/foo/bar>)
- [this is a link](http://something.example.com/foo/bar 'test')
- ![this is an image]()
- ![this is an image](<http://something.example.com/foo/bar>)
- ![this is an image](http://something.example.com/foo/bar 'test')
-
- [escape test](<\>\>\>\>\>\>\>\>\>\>\>\>\>\>> '\'\'\'\'\'\'\'\'\'\'\'\'\'\'')
- [escape test \]\]\]\]\]\]\]\]\]\]\]\]\]\]\]\]](\)\)\)\)\)\)\)\)\)\)\)\)\)\))
-
-Invalid links:
-
- [this is not a link
-
- [this is not a link](
-
- [this is not a link](http://something.example.com/foo/bar 'test'
-
- [this is not a link](((((((((((((((((((((((((((((((((((((((((((((((
-
- [this is not a link]((((((((((()))))))))) (((((((((()))))))))))
diff --git a/lib/cmark/bench/samples/inline-links-nested.md b/lib/cmark/bench/samples/inline-links-nested.md
deleted file mode 100644
index 4e7dc85..0000000
--- a/lib/cmark/bench/samples/inline-links-nested.md
+++ /dev/null
@@ -1,13 +0,0 @@
-Valid links:
-
-[[[[[[[[](test)](test)](test)](test)](test)](test)](test)]
-
-[ [[[[[[[[[[[[[[[[[[ [](test) ]]]]]]]]]]]]]]]]]] ](test)
-
-Invalid links:
-
-[[[[[[[[[
-
-[ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [ [
-
-![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![![
diff --git a/lib/cmark/bench/samples/inline-newlines.md b/lib/cmark/bench/samples/inline-newlines.md
deleted file mode 100644
index 068a807..0000000
--- a/lib/cmark/bench/samples/inline-newlines.md
+++ /dev/null
@@ -1,24 +0,0 @@
-
-this\
-should\
-be\
-separated\
-by\
-newlines
-
-this
-should
-be
-separated
-by
-newlines
-too
-
-this
-should
-not
-be
-separated
-by
-newlines
-
diff --git a/lib/cmark/bench/samples/lorem1.md b/lib/cmark/bench/samples/lorem1.md
deleted file mode 100644
index eccb898..0000000
--- a/lib/cmark/bench/samples/lorem1.md
+++ /dev/null
@@ -1,13 +0,0 @@
-Lorem ipsum dolor sit amet, __consectetur__ adipiscing elit. Cras imperdiet nec erat ac condimentum. Nulla vel rutrum ligula. Sed hendrerit interdum orci a posuere. Vivamus ut velit aliquet, mollis purus eget, iaculis nisl. Proin posuere malesuada ante. Proin auctor orci eros, ac molestie lorem dictum nec. Vestibulum sit amet erat est. Morbi luctus sed elit ac luctus. Proin blandit, enim vitae egestas posuere, neque elit ultricies dui, vel mattis nibh enim ac lorem. Maecenas molestie nisl sit amet velit dictum lobortis. Aliquam erat volutpat.
-
-Vivamus sagittis, diam in [vehicula](https://github.com/markdown-it/markdown-it) lobortis, sapien arcu mattis erat, vel aliquet sem urna et risus. Ut feugiat sapien vitae mi elementum laoreet. Suspendisse potenti. Aliquam erat nisl, aliquam pretium libero aliquet, sagittis eleifend nunc. In hac habitasse platea dictumst. Integer turpis augue, tincidunt dignissim mauris id, rhoncus dapibus purus. Maecenas et enim odio. Nullam massa metus, varius quis vehicula sed, pharetra mollis erat. In quis viverra velit. Vivamus placerat, est nec hendrerit varius, enim dui hendrerit magna, ut pulvinar nibh lorem vel lacus. Mauris a orci iaculis, hendrerit eros sed, gravida leo. In dictum mauris vel augue varius, ac ullamcorper nisl ornare. In eu posuere velit, ac fermentum arcu. Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam sed malesuada leo, at interdum elit.
-
-Nullam ut tincidunt nunc. [Pellentesque][1] metus lacus, commodo eget justo ut, rutrum varius nunc. Sed non rhoncus risus. Morbi sodales gravida pulvinar. Duis malesuada, odio volutpat elementum vulputate, massa magna scelerisque ante, et accumsan tellus nunc in sem. Donec mattis arcu et velit aliquet, non sagittis justo vestibulum. Suspendisse volutpat felis lectus, nec consequat ipsum mattis id. Donec dapibus vehicula facilisis. In tincidunt mi nisi, nec faucibus tortor euismod nec. Suspendisse ante ligula, aliquet vitae libero eu, vulputate dapibus libero. Sed bibendum, sapien at posuere interdum, libero est sollicitudin magna, ac gravida tellus purus eu ipsum. Proin ut quam arcu.
-
-Suspendisse potenti. Donec ante velit, ornare at augue quis, tristique laoreet sem. Etiam in ipsum elit. Nullam cursus dolor sit amet nulla feugiat tristique. Phasellus ac tellus tincidunt, imperdiet purus eget, ullamcorper ipsum. Cras eu tincidunt sem. Nullam sed dapibus magna. Lorem ipsum dolor sit amet, consectetur adipiscing elit. In id venenatis tortor. In consectetur sollicitudin pharetra. Etiam convallis nisi nunc, et aliquam turpis viverra sit amet. Maecenas faucibus sodales tortor. Suspendisse lobortis mi eu leo viverra volutpat. Pellentesque velit ante, vehicula sodales congue ut, elementum a urna. Cras tempor, ipsum eget luctus rhoncus, arcu ligula fermentum urna, vulputate pharetra enim enim non libero.
-
-Proin diam quam, elementum in eleifend id, elementum et metus. Cras in justo consequat justo semper ultrices. Sed dignissim lectus a ante mollis, nec vulputate ante molestie. Proin in porta nunc. Etiam pulvinar turpis sed velit porttitor, vel adipiscing velit fringilla. Cras ac tellus vitae purus pharetra tincidunt. Sed cursus aliquet aliquet. Cras eleifend commodo malesuada. In turpis turpis, ullamcorper ut tincidunt a, ullamcorper a nunc. Etiam luctus tellus ac dapibus gravida. Ut nec lacus laoreet neque ullamcorper volutpat.
-
-Nunc et leo erat. Aenean mattis ultrices lorem, eget adipiscing dolor ultricies eu. In hac habitasse platea dictumst. Vivamus cursus feugiat sapien quis aliquam. Mauris quam libero, porta vel volutpat ut, blandit a purus. Vivamus vestibulum dui vel tortor molestie, sit amet feugiat sem commodo. Nulla facilisi. Sed molestie arcu eget tellus vestibulum tristique.
-
-[1]: https://github.com/markdown-it
diff --git a/lib/cmark/bench/samples/rawtabs.md b/lib/cmark/bench/samples/rawtabs.md
deleted file mode 100644
index dc989ea..0000000
--- a/lib/cmark/bench/samples/rawtabs.md
+++ /dev/null
@@ -1,18 +0,0 @@
-
-this is a test for tab expansion, be careful not to replace them with spaces
-
-1 4444
-22 333
-333 22
-4444 1
-
-
- tab-indented line
- space-indented line
- tab-indented line
-
-
-a lot of spaces in between here
-
-a lot of tabs in between here
-
diff --git a/lib/cmark/bench/statistics.py b/lib/cmark/bench/statistics.py
deleted file mode 100644
index 25a26d4..0000000
--- a/lib/cmark/bench/statistics.py
+++ /dev/null
@@ -1,595 +0,0 @@
-## Module statistics.py
-##
-## Copyright (c) 2013 Steven D'Aprano <steve+python@pearwood.info>.
-##
-## Licensed under the Apache License, Version 2.0 (the "License");
-## you may not use this file except in compliance with the License.
-## You may obtain a copy of the License at
-##
-## http://www.apache.org/licenses/LICENSE-2.0
-##
-## Unless required by applicable law or agreed to in writing, software
-## distributed under the License is distributed on an "AS IS" BASIS,
-## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-## See the License for the specific language governing permissions and
-## limitations under the License.
-
-
-"""
-Basic statistics module.
-
-This module provides functions for calculating statistics of data, including
-averages, variance, and standard deviation.
-
-Calculating averages
---------------------
-
-================== =============================================
-Function Description
-================== =============================================
-mean Arithmetic mean (average) of data.
-median Median (middle value) of data.
-median_low Low median of data.
-median_high High median of data.
-median_grouped Median, or 50th percentile, of grouped data.
-mode Mode (most common value) of data.
-================== =============================================
-
-Calculate the arithmetic mean ("the average") of data:
-
->>> mean([-1.0, 2.5, 3.25, 5.75])
-2.625
-
-
-Calculate the standard median of discrete data:
-
->>> median([2, 3, 4, 5])
-3.5
-
-
-Calculate the median, or 50th percentile, of data grouped into class intervals
-centred on the data values provided. E.g. if your data points are rounded to
-the nearest whole number:
-
->>> median_grouped([2, 2, 3, 3, 3, 4]) #doctest: +ELLIPSIS
-2.8333333333...
-
-This should be interpreted in this way: you have two data points in the class
-interval 1.5-2.5, three data points in the class interval 2.5-3.5, and one in
-the class interval 3.5-4.5. The median of these data points is 2.8333...
-
-
-Calculating variability or spread
----------------------------------
-
-================== =============================================
-Function Description
-================== =============================================
-pvariance Population variance of data.
-variance Sample variance of data.
-pstdev Population standard deviation of data.
-stdev Sample standard deviation of data.
-================== =============================================
-
-Calculate the standard deviation of sample data:
-
->>> stdev([2.5, 3.25, 5.5, 11.25, 11.75]) #doctest: +ELLIPSIS
-4.38961843444...
-
-If you have previously calculated the mean, you can pass it as the optional
-second argument to the four "spread" functions to avoid recalculating it:
-
->>> data = [1, 2, 2, 4, 4, 4, 5, 6]
->>> mu = mean(data)
->>> pvariance(data, mu)
-2.5
-
-
-Exceptions
-----------
-
-A single exception is defined: StatisticsError is a subclass of ValueError.
-
-"""
-
-__all__ = [ 'StatisticsError',
- 'pstdev', 'pvariance', 'stdev', 'variance',
- 'median', 'median_low', 'median_high', 'median_grouped',
- 'mean', 'mode',
- ]
-
-
-import collections
-import math
-
-from fractions import Fraction
-from decimal import Decimal
-
-
-# === Exceptions ===
-
-class StatisticsError(ValueError):
- pass
-
-
-# === Private utilities ===
-
-def _sum(data, start=0):
- """_sum(data [, start]) -> value
-
- Return a high-precision sum of the given numeric data. If optional
- argument ``start`` is given, it is added to the total. If ``data`` is
- empty, ``start`` (defaulting to 0) is returned.
-
-
- Examples
- --------
-
- >>> _sum([3, 2.25, 4.5, -0.5, 1.0], 0.75)
- 11.0
-
- Some sources of round-off error will be avoided:
-
- >>> _sum([1e50, 1, -1e50] * 1000) # Built-in sum returns zero.
- 1000.0
-
- Fractions and Decimals are also supported:
-
- >>> from fractions import Fraction as F
- >>> _sum([F(2, 3), F(7, 5), F(1, 4), F(5, 6)])
- Fraction(63, 20)
-
- >>> from decimal import Decimal as D
- >>> data = [D("0.1375"), D("0.2108"), D("0.3061"), D("0.0419")]
- >>> _sum(data)
- Decimal('0.6963')
-
- Mixed types are currently treated as an error, except that int is
- allowed.
- """
- # We fail as soon as we reach a value that is not an int or the type of
- # the first value which is not an int. E.g. _sum([int, int, float, int])
- # is okay, but sum([int, int, float, Fraction]) is not.
- allowed_types = set([int, type(start)])
- n, d = _exact_ratio(start)
- partials = {d: n} # map {denominator: sum of numerators}
- # Micro-optimizations.
- exact_ratio = _exact_ratio
- partials_get = partials.get
- # Add numerators for each denominator.
- for x in data:
- _check_type(type(x), allowed_types)
- n, d = exact_ratio(x)
- partials[d] = partials_get(d, 0) + n
- # Find the expected result type. If allowed_types has only one item, it
- # will be int; if it has two, use the one which isn't int.
- assert len(allowed_types) in (1, 2)
- if len(allowed_types) == 1:
- assert allowed_types.pop() is int
- T = int
- else:
- T = (allowed_types - set([int])).pop()
- if None in partials:
- assert issubclass(T, (float, Decimal))
- assert not math.isfinite(partials[None])
- return T(partials[None])
- total = Fraction()
- for d, n in sorted(partials.items()):
- total += Fraction(n, d)
- if issubclass(T, int):
- assert total.denominator == 1
- return T(total.numerator)
- if issubclass(T, Decimal):
- return T(total.numerator)/total.denominator
- return T(total)
-
-
-def _check_type(T, allowed):
- if T not in allowed:
- if len(allowed) == 1:
- allowed.add(T)
- else:
- types = ', '.join([t.__name__ for t in allowed] + [T.__name__])
- raise TypeError("unsupported mixed types: %s" % types)
-
-
-def _exact_ratio(x):
- """Convert Real number x exactly to (numerator, denominator) pair.
-
- >>> _exact_ratio(0.25)
- (1, 4)
-
- x is expected to be an int, Fraction, Decimal or float.
- """
- try:
- try:
- # int, Fraction
- return (x.numerator, x.denominator)
- except AttributeError:
- # float
- try:
- return x.as_integer_ratio()
- except AttributeError:
- # Decimal
- try:
- return _decimal_to_ratio(x)
- except AttributeError:
- msg = "can't convert type '{}' to numerator/denominator"
- raise TypeError(msg.format(type(x).__name__)) from None
- except (OverflowError, ValueError):
- # INF or NAN
- if __debug__:
- # Decimal signalling NANs cannot be converted to float :-(
- if isinstance(x, Decimal):
- assert not x.is_finite()
- else:
- assert not math.isfinite(x)
- return (x, None)
-
-
-# FIXME This is faster than Fraction.from_decimal, but still too slow.
-def _decimal_to_ratio(d):
- """Convert Decimal d to exact integer ratio (numerator, denominator).
-
- >>> from decimal import Decimal
- >>> _decimal_to_ratio(Decimal("2.6"))
- (26, 10)
-
- """
- sign, digits, exp = d.as_tuple()
- if exp in ('F', 'n', 'N'): # INF, NAN, sNAN
- assert not d.is_finite()
- raise ValueError
- num = 0
- for digit in digits:
- num = num*10 + digit
- if exp < 0:
- den = 10**-exp
- else:
- num *= 10**exp
- den = 1
- if sign:
- num = -num
- return (num, den)
-
-
-def _counts(data):
- # Generate a table of sorted (value, frequency) pairs.
- table = collections.Counter(iter(data)).most_common()
- if not table:
- return table
- # Extract the values with the highest frequency.
- maxfreq = table[0][1]
- for i in range(1, len(table)):
- if table[i][1] != maxfreq:
- table = table[:i]
- break
- return table
-
-
-# === Measures of central tendency (averages) ===
-
-def mean(data):
- """Return the sample arithmetic mean of data.
-
- >>> mean([1, 2, 3, 4, 4])
- 2.8
-
- >>> from fractions import Fraction as F
- >>> mean([F(3, 7), F(1, 21), F(5, 3), F(1, 3)])
- Fraction(13, 21)
-
- >>> from decimal import Decimal as D
- >>> mean([D("0.5"), D("0.75"), D("0.625"), D("0.375")])
- Decimal('0.5625')
-
- If ``data`` is empty, StatisticsError will be raised.
- """
- if iter(data) is data:
- data = list(data)
- n = len(data)
- if n < 1:
- raise StatisticsError('mean requires at least one data point')
- return _sum(data)/n
-
-
-# FIXME: investigate ways to calculate medians without sorting? Quickselect?
-def median(data):
- """Return the median (middle value) of numeric data.
-
- When the number of data points is odd, return the middle data point.
- When the number of data points is even, the median is interpolated by
- taking the average of the two middle values:
-
- >>> median([1, 3, 5])
- 3
- >>> median([1, 3, 5, 7])
- 4.0
-
- """
- data = sorted(data)
- n = len(data)
- if n == 0:
- raise StatisticsError("no median for empty data")
- if n%2 == 1:
- return data[n//2]
- else:
- i = n//2
- return (data[i - 1] + data[i])/2
-
-
-def median_low(data):
- """Return the low median of numeric data.
-
- When the number of data points is odd, the middle value is returned.
- When it is even, the smaller of the two middle values is returned.
-
- >>> median_low([1, 3, 5])
- 3
- >>> median_low([1, 3, 5, 7])
- 3
-
- """
- data = sorted(data)
- n = len(data)
- if n == 0:
- raise StatisticsError("no median for empty data")
- if n%2 == 1:
- return data[n//2]
- else:
- return data[n//2 - 1]
-
-
-def median_high(data):
- """Return the high median of data.
-
- When the number of data points is odd, the middle value is returned.
- When it is even, the larger of the two middle values is returned.
-
- >>> median_high([1, 3, 5])
- 3
- >>> median_high([1, 3, 5, 7])
- 5
-
- """
- data = sorted(data)
- n = len(data)
- if n == 0:
- raise StatisticsError("no median for empty data")
- return data[n//2]
-
-
-def median_grouped(data, interval=1):
- """"Return the 50th percentile (median) of grouped continuous data.
-
- >>> median_grouped([1, 2, 2, 3, 4, 4, 4, 4, 4, 5])
- 3.7
- >>> median_grouped([52, 52, 53, 54])
- 52.5
-
- This calculates the median as the 50th percentile, and should be
- used when your data is continuous and grouped. In the above example,
- the values 1, 2, 3, etc. actually represent the midpoint of classes
- 0.5-1.5, 1.5-2.5, 2.5-3.5, etc. The middle value falls somewhere in
- class 3.5-4.5, and interpolation is used to estimate it.
-
- Optional argument ``interval`` represents the class interval, and
- defaults to 1. Changing the class interval naturally will change the
- interpolated 50th percentile value:
-
- >>> median_grouped([1, 3, 3, 5, 7], interval=1)
- 3.25
- >>> median_grouped([1, 3, 3, 5, 7], interval=2)
- 3.5
-
- This function does not check whether the data points are at least
- ``interval`` apart.
- """
- data = sorted(data)
- n = len(data)
- if n == 0:
- raise StatisticsError("no median for empty data")
- elif n == 1:
- return data[0]
- # Find the value at the midpoint. Remember this corresponds to the
- # centre of the class interval.
- x = data[n//2]
- for obj in (x, interval):
- if isinstance(obj, (str, bytes)):
- raise TypeError('expected number but got %r' % obj)
- try:
- L = x - interval/2 # The lower limit of the median interval.
- except TypeError:
- # Mixed type. For now we just coerce to float.
- L = float(x) - float(interval)/2
- cf = data.index(x) # Number of values below the median interval.
- # FIXME The following line could be more efficient for big lists.
- f = data.count(x) # Number of data points in the median interval.
- return L + interval*(n/2 - cf)/f
-
-
-def mode(data):
- """Return the most common data point from discrete or nominal data.
-
- ``mode`` assumes discrete data, and returns a single value. This is the
- standard treatment of the mode as commonly taught in schools:
-
- >>> mode([1, 1, 2, 3, 3, 3, 3, 4])
- 3
-
- This also works with nominal (non-numeric) data:
-
- >>> mode(["red", "blue", "blue", "red", "green", "red", "red"])
- 'red'
-
- If there is not exactly one most common value, ``mode`` will raise
- StatisticsError.
- """
- # Generate a table of sorted (value, frequency) pairs.
- table = _counts(data)
- if len(table) == 1:
- return table[0][0]
- elif table:
- raise StatisticsError(
- 'no unique mode; found %d equally common values' % len(table)
- )
- else:
- raise StatisticsError('no mode for empty data')
-
-
-# === Measures of spread ===
-
-# See http://mathworld.wolfram.com/Variance.html
-# http://mathworld.wolfram.com/SampleVariance.html
-# http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
-#
-# Under no circumstances use the so-called "computational formula for
-# variance", as that is only suitable for hand calculations with a small
-# amount of low-precision data. It has terrible numeric properties.
-#
-# See a comparison of three computational methods here:
-# http://www.johndcook.com/blog/2008/09/26/comparing-three-methods-of-computing-standard-deviation/
-
-def _ss(data, c=None):
- """Return sum of square deviations of sequence data.
-
- If ``c`` is None, the mean is calculated in one pass, and the deviations
- from the mean are calculated in a second pass. Otherwise, deviations are
- calculated from ``c`` as given. Use the second case with care, as it can
- lead to garbage results.
- """
- if c is None:
- c = mean(data)
- ss = _sum((x-c)**2 for x in data)
- # The following sum should mathematically equal zero, but due to rounding
- # error may not.
- ss -= _sum((x-c) for x in data)**2/len(data)
- assert not ss < 0, 'negative sum of square deviations: %f' % ss
- return ss
-
-
-def variance(data, xbar=None):
- """Return the sample variance of data.
-
- data should be an iterable of Real-valued numbers, with at least two
- values. The optional argument xbar, if given, should be the mean of
- the data. If it is missing or None, the mean is automatically calculated.
-
- Use this function when your data is a sample from a population. To
- calculate the variance from the entire population, see ``pvariance``.
-
- Examples:
-
- >>> data = [2.75, 1.75, 1.25, 0.25, 0.5, 1.25, 3.5]
- >>> variance(data)
- 1.3720238095238095
-
- If you have already calculated the mean of your data, you can pass it as
- the optional second argument ``xbar`` to avoid recalculating it:
-
- >>> m = mean(data)
- >>> variance(data, m)
- 1.3720238095238095
-
- This function does not check that ``xbar`` is actually the mean of
- ``data``. Giving arbitrary values for ``xbar`` may lead to invalid or
- impossible results.
-
- Decimals and Fractions are supported:
-
- >>> from decimal import Decimal as D
- >>> variance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])
- Decimal('31.01875')
-
- >>> from fractions import Fraction as F
- >>> variance([F(1, 6), F(1, 2), F(5, 3)])
- Fraction(67, 108)
-
- """
- if iter(data) is data:
- data = list(data)
- n = len(data)
- if n < 2:
- raise StatisticsError('variance requires at least two data points')
- ss = _ss(data, xbar)
- return ss/(n-1)
-
-
-def pvariance(data, mu=None):
- """Return the population variance of ``data``.
-
- data should be an iterable of Real-valued numbers, with at least one
- value. The optional argument mu, if given, should be the mean of
- the data. If it is missing or None, the mean is automatically calculated.
-
- Use this function to calculate the variance from the entire population.
- To estimate the variance from a sample, the ``variance`` function is
- usually a better choice.
-
- Examples:
-
- >>> data = [0.0, 0.25, 0.25, 1.25, 1.5, 1.75, 2.75, 3.25]
- >>> pvariance(data)
- 1.25
-
- If you have already calculated the mean of the data, you can pass it as
- the optional second argument to avoid recalculating it:
-
- >>> mu = mean(data)
- >>> pvariance(data, mu)
- 1.25
-
- This function does not check that ``mu`` is actually the mean of ``data``.
- Giving arbitrary values for ``mu`` may lead to invalid or impossible
- results.
-
- Decimals and Fractions are supported:
-
- >>> from decimal import Decimal as D
- >>> pvariance([D("27.5"), D("30.25"), D("30.25"), D("34.5"), D("41.75")])
- Decimal('24.815')
-
- >>> from fractions import Fraction as F
- >>> pvariance([F(1, 4), F(5, 4), F(1, 2)])
- Fraction(13, 72)
-
- """
- if iter(data) is data:
- data = list(data)
- n = len(data)
- if n < 1:
- raise StatisticsError('pvariance requires at least one data point')
- ss = _ss(data, mu)
- return ss/n
-
-
-def stdev(data, xbar=None):
- """Return the square root of the sample variance.
-
- See ``variance`` for arguments and other details.
-
- >>> stdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])
- 1.0810874155219827
-
- """
- var = variance(data, xbar)
- try:
- return var.sqrt()
- except AttributeError:
- return math.sqrt(var)
-
-
-def pstdev(data, mu=None):
- """Return the square root of the population variance.
-
- See ``pvariance`` for arguments and other details.
-
- >>> pstdev([1.5, 2.5, 2.5, 2.75, 3.25, 4.75])
- 0.986893273527251
-
- """
- var = pvariance(data, mu)
- try:
- return var.sqrt()
- except AttributeError:
- return math.sqrt(var)
diff --git a/lib/cmark/bench/stats.py b/lib/cmark/bench/stats.py
deleted file mode 100644
index c244b41..0000000
--- a/lib/cmark/bench/stats.py
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/env python3
-
-import sys
-import statistics
-
-def pairs(l, n):
- return zip(*[l[i::n] for i in range(n)])
-
-# data comes in pairs:
-# n - time for running the program with no input
-# m - time for running it with the benchmark input
-# we measure (m - n)
-
-values = [ float(y) - float(x) for (x,y) in pairs(sys.stdin.readlines(),2)]
-
-print("mean = %.4f, median = %.4f, stdev = %.4f" %
- (statistics.mean(values), statistics.median(values),
- statistics.stdev(values)))
-
diff --git a/lib/cmark/benchmarks.md b/lib/cmark/benchmarks.md
deleted file mode 100644
index ec96f6e..0000000
--- a/lib/cmark/benchmarks.md
+++ /dev/null
@@ -1,33 +0,0 @@
-# Benchmarks
-
-Here are some benchmarks, run on an ancient Thinkpad running Intel
-Core 2 Duo at 2GHz. The input text is a 11MB Markdown file built by
-concatenating the Markdown sources of all the localizations of the
-first edition of
-[*Pro Git*](https://github.com/progit/progit/tree/master/en) by Scott
-Chacon.
-
-|Implementation | Time (sec)|
-|-------------------|-----------:|
-| Markdown.pl | 2921.24 |
-| Python markdown | 291.25 |
-| PHP markdown | 20.82 |
-| kramdown | 17.32 |
-| cheapskate | 8.24 |
-| peg-markdown | 5.45 |
-| parsedown | 5.06 |
-| **commonmark.js** | 2.09 |
-| marked | 1.99 |
-| discount | 1.85 |
-| **cmark** | 0.29 |
-| hoedown | 0.21 |
-
-To run these benchmarks, use `make bench PROG=/path/to/program`.
-
-`time` is used to measure execution speed. The reported
-time is the *difference* between the time to run the program
-with the benchmark input and the time to run it with no input.
-(This procedure ensures that implementations in dynamic languages are
-not penalized by startup time.) A median of ten runs is taken. The
-process is reniced to a high priority so that the system doesn't
-interrupt runs.
diff --git a/lib/cmark/man/CMakeLists.txt b/lib/cmark/man/CMakeLists.txt
deleted file mode 100644
index 8ed5448..0000000
--- a/lib/cmark/man/CMakeLists.txt
+++ /dev/null
@@ -1,4 +0,0 @@
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man1/cmark.1
- DESTINATION ${CMAKE_INSTALL_MANDIR}/man1)
-install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/man3/cmark.3
- DESTINATION ${CMAKE_INSTALL_MANDIR}/man3)
diff --git a/lib/cmark/man/make_man_page.py b/lib/cmark/man/make_man_page.py
deleted file mode 100644
index 4b49dbd..0000000
--- a/lib/cmark/man/make_man_page.py
+++ /dev/null
@@ -1,133 +0,0 @@
-#!/usr/bin/env python
-
-# Creates a man page from a C file.
-
-# first argument if present is path to cmark dynamic library
-
-# Comments beginning with `/**` are treated as Groff man, except that
-# 'this' is converted to \fIthis\f[], and ''this'' to \fBthis\f[].
-
-# Non-blank lines immediately following a man page comment are treated
-# as function signatures or examples and parsed into .Ft, .Fo, .Fa, .Fc. The
-# immediately preceding man documentation chunk is printed after the example
-# as a comment on it.
-
-# That's about it!
-
-import sys, re, os, platform
-from datetime import date
-from ctypes import CDLL, c_char_p, c_long, c_void_p
-
-sysname = platform.system()
-
-if sysname == 'Darwin':
- cmark = CDLL("build/src/libcmark.dylib")
-else:
- cmark = CDLL("build/src/libcmark.so")
-
-parse_document = cmark.cmark_parse_document
-parse_document.restype = c_void_p
-parse_document.argtypes = [c_char_p, c_long]
-
-render_man = cmark.cmark_render_man
-render_man.restype = c_char_p
-render_man.argtypes = [c_void_p, c_long, c_long]
-
-def md2man(text):
- if sys.version_info >= (3,0):
- textbytes = text.encode('utf-8')
- textlen = len(textbytes)
- return render_man(parse_document(textbytes, textlen), 0, 65).decode('utf-8')
- else:
- textbytes = text
- textlen = len(text)
- return render_man(parse_document(textbytes, textlen), 0, 72)
-
-comment_start_re = re.compile('^\/\*\* ?')
-comment_delim_re = re.compile('^[/ ]\** ?')
-comment_end_re = re.compile('^ \**\/')
-function_re = re.compile('^ *(?:CMARK_EXPORT\s+)?(?P<type>(?:const\s+)?\w+(?:\s*[*])?)\s*(?P<name>\w+)\s*\((?P<args>[^)]*)\)')
-blank_re = re.compile('^\s*$')
-macro_re = re.compile('CMARK_EXPORT *')
-typedef_start_re = re.compile('typedef.*{$')
-typedef_end_re = re.compile('}')
-single_quote_re = re.compile("(?<!\w)'([^']+)'(?!\w)")
-double_quote_re = re.compile("(?<!\w)''([^']+)''(?!\w)")
-
-def handle_quotes(s):
- return re.sub(double_quote_re, '**\g<1>**', re.sub(single_quote_re, '*\g<1>*', s))
-
-typedef = False
-mdlines = []
-chunk = []
-sig = []
-
-if len(sys.argv) > 1:
- sourcefile = sys.argv[1]
-else:
- print("Usage: make_man_page.py sourcefile")
- exit(1)
-
-with open(sourcefile, 'r') as cmarkh:
- state = 'default'
- for line in cmarkh:
- # state transition
- oldstate = state
- if comment_start_re.match(line):
- state = 'man'
- elif comment_end_re.match(line) and state == 'man':
- continue
- elif comment_delim_re.match(line) and state == 'man':
- state = 'man'
- elif not typedef and blank_re.match(line):
- state = 'default'
- elif typedef and typedef_end_re.match(line):
- typedef = False
- elif typedef_start_re.match(line):
- typedef = True
- state = 'signature'
- elif state == 'man':
- state = 'signature'
-
- # handle line
- if state == 'man':
- chunk.append(handle_quotes(re.sub(comment_delim_re, '', line)))
- elif state == 'signature':
- ln = re.sub(macro_re, '', line)
- if typedef or not re.match(blank_re, ln):
- sig.append(ln)
- elif oldstate == 'signature' and state != 'signature':
- if len(mdlines) > 0 and mdlines[-1] != '\n':
- mdlines.append('\n')
- rawsig = ''.join(sig)
- m = function_re.match(rawsig)
- mdlines.append('.PP\n')
- if m:
- mdlines.append('\\fI' + m.group('type') + '\\f[]' + ' ')
- mdlines.append('\\fB' + m.group('name') + '\\f[]' + '(')
- first = True
- for argument in re.split(',', m.group('args')):
- if not first:
- mdlines.append(', ')
- first = False
- mdlines.append('\\fI' + argument.strip() + '\\f[]')
- mdlines.append(')\n')
- else:
- mdlines.append('.nf\n\\fC\n.RS 0n\n')
- mdlines += sig
- mdlines.append('.RE\n\\f[]\n.fi\n')
- if len(mdlines) > 0 and mdlines[-1] != '\n':
- mdlines.append('\n')
- mdlines += md2man(''.join(chunk))
- mdlines.append('\n')
- chunk = []
- sig = []
- elif oldstate == 'man' and state != 'signature':
- if len(mdlines) > 0 and mdlines[-1] != '\n':
- mdlines.append('\n')
- mdlines += md2man(''.join(chunk)) # add man chunk
- chunk = []
- mdlines.append('\n')
-
-sys.stdout.write('.TH ' + os.path.basename(sourcefile).replace('.h','') + ' 3 "' + date.today().strftime('%B %d, %Y') + '" "LOCAL" "Library Functions Manual"\n')
-sys.stdout.write(''.join(mdlines))
diff --git a/lib/cmark/man/man1/cmark.1 b/lib/cmark/man/man1/cmark.1
deleted file mode 100644
index 71db059..0000000
--- a/lib/cmark/man/man1/cmark.1
+++ /dev/null
@@ -1,69 +0,0 @@
-.TH "cmark" "1" "Feburary 11, 2020" "LOCAL" "General Commands Manual"
-.SH "NAME"
-\fBcmark\fR
-\- convert CommonMark formatted text to HTML
-.SH "SYNOPSIS"
-.HP 6n
-\fBcmark\fR
-[options]
-file*
-.SH "DESCRIPTION"
-\fBcmark\fR
-converts Markdown formatted plain text to either HTML, groff man,
-CommonMark XML, LaTeX, or CommonMark, using the conventions
-described in the CommonMark spec. It reads input from \fIstdin\fR
-or the specified files (concatenating their contents) and writes
-output to \fIstdout\fR.
-.SH "OPTIONS"
-.TP 12n
-.B \-\-to, \-t \f[I]FORMAT\f[]
-Specify output format (\f[C]html\f[], \f[C]man\f[], \f[C]xml\f[],
-\f[C]latex\f[], \f[C]commonmark\f[]).
-.TP 12n
-.B \-\-width \f[I]WIDTH\f[]
-Specify a column width to which to wrap the output. For no wrapping, use
-the value 0 (the default). This option currently only affects the
-commonmark, latex, and man renderers.
-.TP 12n
-.B \-\-hardbreaks
-Render soft breaks (newlines inside paragraphs in the CommonMark source)
-as hard line breaks in the target format. If this option is specified,
-hard wrapping is disabled for CommonMark output, regardless of the value
-given with \-\-width.
-.TP 12n
-.B \-\-nobreaks
-Render soft breaks as spaces. If this option is specified,
-hard wrapping is disabled for all output formats, regardless of the value
-given with \-\-width.
-.TP 12n
-.B \-\-sourcepos
-Include source position attribute.
-.TP 12n
-.B \-\-validate-utf8
-Validate UTF-8, replacing illegal sequences with U+FFFD.
-.TP 12n
-.B \-\-smart
-Use smart punctuation. Straight double and single quotes will
-be rendered as curly quotes, depending on their position.
-\f[C]\-\-\f[] will be rendered as an en-dash.
-\f[C]\-\-\-\f[] will be rendered as an em-dash.
-\f[C]...\f[] will be rendered as ellipses.
-.TP 12n
-.B \-\-unsafe
-Render raw HTML or potentially dangerous URLs.
-By default, raw HTML is replaced by a placeholder comment
-and potentially dangerous URLs are replaced by empty strings.
-Dangerous URLs are those that begin with `javascript:`,
-`vbscript:`, `file:`, or `data:` (except for `image/png`,
-`image/gif`, `image/jpeg`, or `image/webp` mime types).
-.TP 12n
-.B \-\-help
-Print usage information.
-.TP 12n
-.B \-\-version
-Print version.
-.SH "AUTHORS"
-John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
-.SH "SEE ALSO"
-.PP
-CommonMark spec: \f[C]https://spec.commonmark.org\f[].
diff --git a/lib/cmark/man/man3/cmark.3 b/lib/cmark/man/man3/cmark.3
deleted file mode 100644
index a4c68f6..0000000
--- a/lib/cmark/man/man3/cmark.3
+++ /dev/null
@@ -1,849 +0,0 @@
-.TH cmark 3 "June 22, 2020" "LOCAL" "Library Functions Manual"
-.SH
-NAME
-.PP
-\f[B]cmark\f[] \- CommonMark parsing, manipulating, and rendering
-
-.SH
-DESCRIPTION
-.SS
-Simple Interface
-
-.PP
-\fIchar *\f[] \fBcmark_markdown_to_html\f[](\fIconst char *text\f[], \fIsize_t len\f[], \fIint options\f[])
-
-.PP
-Convert \f[I]text\f[] (assumed to be a UTF\-8 encoded string with
-length \f[I]len\f[]) from CommonMark Markdown to HTML, returning
-a null\-terminated, UTF\-8\-encoded string. It is the caller's
-responsibility to free the returned buffer.
-
-.SS
-Node Structure
-
-.PP
-.nf
-\fC
-.RS 0n
-typedef enum {
- /* Error status */
- CMARK_NODE_NONE,
-
- /* Block */
- CMARK_NODE_DOCUMENT,
- CMARK_NODE_BLOCK_QUOTE,
- CMARK_NODE_LIST,
- CMARK_NODE_ITEM,
- CMARK_NODE_CODE_BLOCK,
- CMARK_NODE_HTML_BLOCK,
- CMARK_NODE_CUSTOM_BLOCK,
- CMARK_NODE_PARAGRAPH,
- CMARK_NODE_HEADING,
- CMARK_NODE_THEMATIC_BREAK,
-
- CMARK_NODE_FIRST_BLOCK = CMARK_NODE_DOCUMENT,
- CMARK_NODE_LAST_BLOCK = CMARK_NODE_THEMATIC_BREAK,
-
- /* Inline */
- CMARK_NODE_TEXT,
- CMARK_NODE_SOFTBREAK,
- CMARK_NODE_LINEBREAK,
- CMARK_NODE_CODE,
- CMARK_NODE_HTML_INLINE,
- CMARK_NODE_CUSTOM_INLINE,
- CMARK_NODE_EMPH,
- CMARK_NODE_STRONG,
- CMARK_NODE_LINK,
- CMARK_NODE_IMAGE,
-
- CMARK_NODE_FIRST_INLINE = CMARK_NODE_TEXT,
- CMARK_NODE_LAST_INLINE = CMARK_NODE_IMAGE,
-} cmark_node_type;
-.RE
-\f[]
-.fi
-
-
-
-.PP
-.nf
-\fC
-.RS 0n
-typedef enum {
- CMARK_NO_LIST,
- CMARK_BULLET_LIST,
- CMARK_ORDERED_LIST
-} cmark_list_type;
-.RE
-\f[]
-.fi
-
-
-
-.PP
-.nf
-\fC
-.RS 0n
-typedef enum {
- CMARK_NO_DELIM,
- CMARK_PERIOD_DELIM,
- CMARK_PAREN_DELIM
-} cmark_delim_type;
-.RE
-\f[]
-.fi
-
-
-
-.SS
-Custom memory allocator support
-
-.PP
-.nf
-\fC
-.RS 0n
-typedef struct cmark_mem {
- void *(*calloc)(size_t, size_t);
- void *(*realloc)(void *, size_t);
- void (*free)(void *);
-} cmark_mem;
-.RE
-\f[]
-.fi
-
-.PP
-Defines the memory allocation functions to be used by CMark when
-parsing and allocating a document tree
-
-.PP
-\fIcmark_mem *\f[] \fBcmark_get_default_mem_allocator\f[](\fI\f[])
-
-.PP
-Returns a pointer to the default memory allocator.
-
-.SS
-Creating and Destroying Nodes
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_new\f[](\fIcmark_node_type type\f[])
-
-.PP
-Creates a new node of type \f[I]type\f[]. Note that the node may
-have other required properties, which it is the caller's
-responsibility to assign.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_new_with_mem\f[](\fIcmark_node_type type\f[], \fIcmark_mem *mem\f[])
-
-.PP
-Same as \f[C]cmark_node_new\f[], but explicitly listing the
-memory allocator used to allocate the node. Note: be sure to use
-the same allocator for every node in a tree, or bad things can
-happen.
-
-.PP
-\fIvoid\f[] \fBcmark_node_free\f[](\fIcmark_node *node\f[])
-
-.PP
-Frees the memory allocated for a node and any children.
-
-.SS
-Tree Traversal
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_next\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the next node in the sequence after \f[I]node\f[], or
-NULL if there is none.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_previous\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the previous node in the sequence after \f[I]node\f[], or
-NULL if there is none.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_parent\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the parent of \f[I]node\f[], or NULL if there is none.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_first_child\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the first child of \f[I]node\f[], or NULL if
-\f[I]node\f[] has no children.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_node_last_child\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the last child of \f[I]node\f[], or NULL if \f[I]node\f[]
-has no children.
-
-.SS
-Iterator
-.PP
-An iterator will walk through a tree of nodes, starting from a
-root node, returning one node at a time, together with
-information about whether the node is being entered or exited.
-The iterator will first descend to a child node, if there is one.
-When there is no child, the iterator will go to the next sibling.
-When there is no next sibling, the iterator will return to the
-parent (but with a \f[I]cmark_event_type\f[] of
-\f[C]CMARK_EVENT_EXIT\f[]). The iterator will return
-\f[C]CMARK_EVENT_DONE\f[] when it reaches the root node again.
-One natural application is an HTML renderer, where an
-\f[C]ENTER\f[] event outputs an open tag and an \f[C]EXIT\f[]
-event outputs a close tag. An iterator might also be used to
-transform an AST in some systematic way, for example, turning all
-level\-3 headings into regular paragraphs.
-.IP
-.nf
-\f[C]
-void
-usage_example(cmark_node *root) {
- cmark_event_type ev_type;
- cmark_iter *iter = cmark_iter_new(root);
-
- while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) {
- cmark_node *cur = cmark_iter_get_node(iter);
- // Do something with `cur` and `ev_type`
- }
-
- cmark_iter_free(iter);
-}
-\f[]
-.fi
-.PP
-Iterators will never return \f[C]EXIT\f[] events for leaf nodes,
-which are nodes of type:
-.IP \[bu] 2
-CMARK_NODE_HTML_BLOCK
-.IP \[bu] 2
-CMARK_NODE_THEMATIC_BREAK
-.IP \[bu] 2
-CMARK_NODE_CODE_BLOCK
-.IP \[bu] 2
-CMARK_NODE_TEXT
-.IP \[bu] 2
-CMARK_NODE_SOFTBREAK
-.IP \[bu] 2
-CMARK_NODE_LINEBREAK
-.IP \[bu] 2
-CMARK_NODE_CODE
-.IP \[bu] 2
-CMARK_NODE_HTML_INLINE
-.PP
-Nodes must only be modified after an \f[C]EXIT\f[] event, or an
-\f[C]ENTER\f[] event for leaf nodes.
-
-.PP
-.nf
-\fC
-.RS 0n
-typedef enum {
- CMARK_EVENT_NONE,
- CMARK_EVENT_DONE,
- CMARK_EVENT_ENTER,
- CMARK_EVENT_EXIT
-} cmark_event_type;
-.RE
-\f[]
-.fi
-
-
-
-.PP
-\fIcmark_iter *\f[] \fBcmark_iter_new\f[](\fIcmark_node *root\f[])
-
-.PP
-Creates a new iterator starting at \f[I]root\f[]. The current
-node and event type are undefined until \f[I]cmark_iter_next\f[]
-is called for the first time. The memory allocated for the
-iterator should be released using \f[I]cmark_iter_free\f[] when
-it is no longer needed.
-
-.PP
-\fIvoid\f[] \fBcmark_iter_free\f[](\fIcmark_iter *iter\f[])
-
-.PP
-Frees the memory allocated for an iterator.
-
-.PP
-\fIcmark_event_type\f[] \fBcmark_iter_next\f[](\fIcmark_iter *iter\f[])
-
-.PP
-Advances to the next node and returns the event type
-(\f[C]CMARK_EVENT_ENTER\f[], \f[C]CMARK_EVENT_EXIT\f[] or
-\f[C]CMARK_EVENT_DONE\f[]).
-
-.PP
-\fIcmark_node *\f[] \fBcmark_iter_get_node\f[](\fIcmark_iter *iter\f[])
-
-.PP
-Returns the current node.
-
-.PP
-\fIcmark_event_type\f[] \fBcmark_iter_get_event_type\f[](\fIcmark_iter *iter\f[])
-
-.PP
-Returns the current event type.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_iter_get_root\f[](\fIcmark_iter *iter\f[])
-
-.PP
-Returns the root node.
-
-.PP
-\fIvoid\f[] \fBcmark_iter_reset\f[](\fIcmark_iter *iter\f[], \fIcmark_node *current\f[], \fIcmark_event_type event_type\f[])
-
-.PP
-Resets the iterator so that the current node is \f[I]current\f[]
-and the event type is \f[I]event_type\f[]. The new current node
-must be a descendant of the root node or the root node itself.
-
-.SS
-Accessors
-
-.PP
-\fIvoid *\f[] \fBcmark_node_get_user_data\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the user data of \f[I]node\f[].
-
-.PP
-\fIint\f[] \fBcmark_node_set_user_data\f[](\fIcmark_node *node\f[], \fIvoid *user_data\f[])
-
-.PP
-Sets arbitrary user data for \f[I]node\f[]. Returns 1 on success,
-0 on failure.
-
-.PP
-\fIcmark_node_type\f[] \fBcmark_node_get_type\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the type of \f[I]node\f[], or \f[C]CMARK_NODE_NONE\f[] on
-error.
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_type_string\f[](\fIcmark_node *node\f[])
-
-.PP
-Like \f[I]cmark_node_get_type\f[], but returns a string
-representation of the type, or \f[C]"<unknown>"\f[].
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_literal\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the string contents of \f[I]node\f[], or an empty string
-if none is set. Returns NULL if called on a node that does not
-have string content.
-
-.PP
-\fIint\f[] \fBcmark_node_set_literal\f[](\fIcmark_node *node\f[], \fIconst char *content\f[])
-
-.PP
-Sets the string contents of \f[I]node\f[]. Returns 1 on success,
-0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_get_heading_level\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the heading level of \f[I]node\f[], or 0 if \f[I]node\f[]
-is not a heading.
-
-.PP
-\fIint\f[] \fBcmark_node_set_heading_level\f[](\fIcmark_node *node\f[], \fIint level\f[])
-
-.PP
-Sets the heading level of \f[I]node\f[], returning 1 on success
-and 0 on error.
-
-.PP
-\fIcmark_list_type\f[] \fBcmark_node_get_list_type\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the list type of \f[I]node\f[], or \f[C]CMARK_NO_LIST\f[]
-if \f[I]node\f[] is not a list.
-
-.PP
-\fIint\f[] \fBcmark_node_set_list_type\f[](\fIcmark_node *node\f[], \fIcmark_list_type type\f[])
-
-.PP
-Sets the list type of \f[I]node\f[], returning 1 on success and 0
-on error.
-
-.PP
-\fIcmark_delim_type\f[] \fBcmark_node_get_list_delim\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the list delimiter type of \f[I]node\f[], or
-\f[C]CMARK_NO_DELIM\f[] if \f[I]node\f[] is not a list.
-
-.PP
-\fIint\f[] \fBcmark_node_set_list_delim\f[](\fIcmark_node *node\f[], \fIcmark_delim_type delim\f[])
-
-.PP
-Sets the list delimiter type of \f[I]node\f[], returning 1 on
-success and 0 on error.
-
-.PP
-\fIint\f[] \fBcmark_node_get_list_start\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns starting number of \f[I]node\f[], if it is an ordered
-list, otherwise 0.
-
-.PP
-\fIint\f[] \fBcmark_node_set_list_start\f[](\fIcmark_node *node\f[], \fIint start\f[])
-
-.PP
-Sets starting number of \f[I]node\f[], if it is an ordered list.
-Returns 1 on success, 0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_get_list_tight\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns 1 if \f[I]node\f[] is a tight list, 0 otherwise.
-
-.PP
-\fIint\f[] \fBcmark_node_set_list_tight\f[](\fIcmark_node *node\f[], \fIint tight\f[])
-
-.PP
-Sets the "tightness" of a list. Returns 1 on success, 0 on
-failure.
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_fence_info\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the info string from a fenced code block.
-
-.PP
-\fIint\f[] \fBcmark_node_set_fence_info\f[](\fIcmark_node *node\f[], \fIconst char *info\f[])
-
-.PP
-Sets the info string in a fenced code block, returning 1 on
-success and 0 on failure.
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_url\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the URL of a link or image \f[I]node\f[], or an empty
-string if no URL is set. Returns NULL if called on a node that is
-not a link or image.
-
-.PP
-\fIint\f[] \fBcmark_node_set_url\f[](\fIcmark_node *node\f[], \fIconst char *url\f[])
-
-.PP
-Sets the URL of a link or image \f[I]node\f[]. Returns 1 on
-success, 0 on failure.
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_title\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the title of a link or image \f[I]node\f[], or an empty
-string if no title is set. Returns NULL if called on a node that
-is not a link or image.
-
-.PP
-\fIint\f[] \fBcmark_node_set_title\f[](\fIcmark_node *node\f[], \fIconst char *title\f[])
-
-.PP
-Sets the title of a link or image \f[I]node\f[]. Returns 1 on
-success, 0 on failure.
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_on_enter\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the literal "on enter" text for a custom \f[I]node\f[],
-or an empty string if no on_enter is set. Returns NULL if called
-on a non\-custom node.
-
-.PP
-\fIint\f[] \fBcmark_node_set_on_enter\f[](\fIcmark_node *node\f[], \fIconst char *on_enter\f[])
-
-.PP
-Sets the literal text to render "on enter" for a custom
-\f[I]node\f[]. Any children of the node will be rendered after
-this text. Returns 1 on success 0 on failure.
-
-.PP
-\fIconst char *\f[] \fBcmark_node_get_on_exit\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the literal "on exit" text for a custom \f[I]node\f[], or
-an empty string if no on_exit is set. Returns NULL if called on a
-non\-custom node.
-
-.PP
-\fIint\f[] \fBcmark_node_set_on_exit\f[](\fIcmark_node *node\f[], \fIconst char *on_exit\f[])
-
-.PP
-Sets the literal text to render "on exit" for a custom
-\f[I]node\f[]. Any children of the node will be rendered before
-this text. Returns 1 on success 0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_get_start_line\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the line on which \f[I]node\f[] begins.
-
-.PP
-\fIint\f[] \fBcmark_node_get_start_column\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the column at which \f[I]node\f[] begins.
-
-.PP
-\fIint\f[] \fBcmark_node_get_end_line\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the line on which \f[I]node\f[] ends.
-
-.PP
-\fIint\f[] \fBcmark_node_get_end_column\f[](\fIcmark_node *node\f[])
-
-.PP
-Returns the column at which \f[I]node\f[] ends.
-
-.SS
-Tree Manipulation
-
-.PP
-\fIvoid\f[] \fBcmark_node_unlink\f[](\fIcmark_node *node\f[])
-
-.PP
-Unlinks a \f[I]node\f[], removing it from the tree, but not
-freeing its memory. (Use \f[I]cmark_node_free\f[] for that.)
-
-.PP
-\fIint\f[] \fBcmark_node_insert_before\f[](\fIcmark_node *node\f[], \fIcmark_node *sibling\f[])
-
-.PP
-Inserts \f[I]sibling\f[] before \f[I]node\f[]. Returns 1 on
-success, 0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_insert_after\f[](\fIcmark_node *node\f[], \fIcmark_node *sibling\f[])
-
-.PP
-Inserts \f[I]sibling\f[] after \f[I]node\f[]. Returns 1 on
-success, 0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_replace\f[](\fIcmark_node *oldnode\f[], \fIcmark_node *newnode\f[])
-
-.PP
-Replaces \f[I]oldnode\f[] with \f[I]newnode\f[] and unlinks
-\f[I]oldnode\f[] (but does not free its memory). Returns 1 on
-success, 0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_prepend_child\f[](\fIcmark_node *node\f[], \fIcmark_node *child\f[])
-
-.PP
-Adds \f[I]child\f[] to the beginning of the children of
-\f[I]node\f[]. Returns 1 on success, 0 on failure.
-
-.PP
-\fIint\f[] \fBcmark_node_append_child\f[](\fIcmark_node *node\f[], \fIcmark_node *child\f[])
-
-.PP
-Adds \f[I]child\f[] to the end of the children of \f[I]node\f[].
-Returns 1 on success, 0 on failure.
-
-.PP
-\fIvoid\f[] \fBcmark_consolidate_text_nodes\f[](\fIcmark_node *root\f[])
-
-.PP
-Consolidates adjacent text nodes.
-
-.SS
-Parsing
-.PP
-Simple interface:
-.IP
-.nf
-\f[C]
-cmark_node *document = cmark_parse_document("Hello *world*", 13,
- CMARK_OPT_DEFAULT);
-\f[]
-.fi
-.PP
-Streaming interface:
-.IP
-.nf
-\f[C]
-cmark_parser *parser = cmark_parser_new(CMARK_OPT_DEFAULT);
-FILE *fp = fopen("myfile.md", "rb");
-while ((bytes = fread(buffer, 1, sizeof(buffer), fp)) > 0) {
- cmark_parser_feed(parser, buffer, bytes);
- if (bytes < sizeof(buffer)) {
- break;
- }
-}
-document = cmark_parser_finish(parser);
-cmark_parser_free(parser);
-\f[]
-.fi
-
-.PP
-\fIcmark_parser *\f[] \fBcmark_parser_new\f[](\fIint options\f[])
-
-.PP
-Creates a new parser object.
-
-.PP
-\fIcmark_parser *\f[] \fBcmark_parser_new_with_mem\f[](\fIint options\f[], \fIcmark_mem *mem\f[])
-
-.PP
-Creates a new parser object with the given memory allocator
-
-.PP
-\fIvoid\f[] \fBcmark_parser_free\f[](\fIcmark_parser *parser\f[])
-
-.PP
-Frees memory allocated for a parser object.
-
-.PP
-\fIvoid\f[] \fBcmark_parser_feed\f[](\fIcmark_parser *parser\f[], \fIconst char *buffer\f[], \fIsize_t len\f[])
-
-.PP
-Feeds a string of length \f[I]len\f[] to \f[I]parser\f[].
-
-.PP
-\fIcmark_node *\f[] \fBcmark_parser_finish\f[](\fIcmark_parser *parser\f[])
-
-.PP
-Finish parsing and return a pointer to a tree of nodes.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_parse_document\f[](\fIconst char *buffer\f[], \fIsize_t len\f[], \fIint options\f[])
-
-.PP
-Parse a CommonMark document in \f[I]buffer\f[] of length
-\f[I]len\f[]. Returns a pointer to a tree of nodes. The memory
-allocated for the node tree should be released using
-\f[I]cmark_node_free\f[] when it is no longer needed.
-
-.PP
-\fIcmark_node *\f[] \fBcmark_parse_file\f[](\fIFILE *f\f[], \fIint options\f[])
-
-.PP
-Parse a CommonMark document in file \f[I]f\f[], returning a
-pointer to a tree of nodes. The memory allocated for the node
-tree should be released using \f[I]cmark_node_free\f[] when it is
-no longer needed.
-
-.SS
-Rendering
-
-.PP
-\fIchar *\f[] \fBcmark_render_xml\f[](\fIcmark_node *root\f[], \fIint options\f[])
-
-.PP
-Render a \f[I]node\f[] tree as XML. It is the caller's
-responsibility to free the returned buffer.
-
-.PP
-\fIchar *\f[] \fBcmark_render_html\f[](\fIcmark_node *root\f[], \fIint options\f[])
-
-.PP
-Render a \f[I]node\f[] tree as an HTML fragment. It is up to the
-user to add an appropriate header and footer. It is the caller's
-responsibility to free the returned buffer.
-
-.PP
-\fIchar *\f[] \fBcmark_render_man\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[])
-
-.PP
-Render a \f[I]node\f[] tree as a groff man page, without the
-header. It is the caller's responsibility to free the returned
-buffer.
-
-.PP
-\fIchar *\f[] \fBcmark_render_commonmark\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[])
-
-.PP
-Render a \f[I]node\f[] tree as a commonmark document. It is the
-caller's responsibility to free the returned buffer.
-
-.PP
-\fIchar *\f[] \fBcmark_render_latex\f[](\fIcmark_node *root\f[], \fIint options\f[], \fIint width\f[])
-
-.PP
-Render a \f[I]node\f[] tree as a LaTeX document. It is the
-caller's responsibility to free the returned buffer.
-
-.SS
-Options
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_DEFAULT 0
-.RE
-\f[]
-.fi
-
-.PP
-Default options.
-
-.SS
-Options affecting rendering
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_SOURCEPOS (1 << 1)
-.RE
-\f[]
-.fi
-
-.PP
-Include a \f[C]data\-sourcepos\f[] attribute on all block
-elements.
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_HARDBREAKS (1 << 2)
-.RE
-\f[]
-.fi
-
-.PP
-Render \f[C]softbreak\f[] elements as hard line breaks.
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_SAFE (1 << 3)
-.RE
-\f[]
-.fi
-
-.PP
-\f[C]CMARK_OPT_SAFE\f[] is defined here for API compatibility,
-but it no longer has any effect. "Safe" mode is now the default:
-set \f[C]CMARK_OPT_UNSAFE\f[] to disable it.
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_UNSAFE (1 << 17)
-.RE
-\f[]
-.fi
-
-.PP
-Render raw HTML and unsafe links (\f[C]javascript:\f[],
-\f[C]vbscript:\f[], \f[C]file:\f[], and \f[C]data:\f[], except
-for \f[C]image/png\f[], \f[C]image/gif\f[], \f[C]image/jpeg\f[],
-or \f[C]image/webp\f[] mime types). By default, raw HTML is
-replaced by a placeholder HTML comment. Unsafe links are replaced
-by empty strings.
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_NOBREAKS (1 << 4)
-.RE
-\f[]
-.fi
-
-.PP
-Render \f[C]softbreak\f[] elements as spaces.
-
-.SS
-Options affecting parsing
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_NORMALIZE (1 << 8)
-.RE
-\f[]
-.fi
-
-.PP
-Legacy option (no effect).
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_VALIDATE_UTF8 (1 << 9)
-.RE
-\f[]
-.fi
-
-.PP
-Validate UTF\-8 in the input before parsing, replacing illegal
-sequences with the replacement character U+FFFD.
-
-.PP
-.nf
-\fC
-.RS 0n
-#define CMARK_OPT_SMART (1 << 10)
-.RE
-\f[]
-.fi
-
-.PP
-Convert straight quotes to curly, \-\-\- to em dashes, \-\- to en
-dashes.
-
-.SS
-Version information
-
-.PP
-\fIint\f[] \fBcmark_version\f[](\fIvoid\f[])
-
-.PP
-The library version as integer for runtime checks. Also available
-as macro CMARK_VERSION for compile time checks.
-.IP \[bu] 2
-Bits 16\-23 contain the major version.
-.IP \[bu] 2
-Bits 8\-15 contain the minor version.
-.IP \[bu] 2
-Bits 0\-7 contain the patchlevel.
-.PP
-In hexadecimal format, the number 0x010203 represents
-version 1.2.3.
-
-.PP
-\fIconst char *\f[] \fBcmark_version_string\f[](\fIvoid\f[])
-
-.PP
-The library version string for runtime checks. Also available as
-macro CMARK_VERSION_STRING for compile time checks.
-
-.SH
-AUTHORS
-.PP
-John MacFarlane, Vicent Marti, Kārlis Gaņģis, Nick Wellnhofer.
-
diff --git a/lib/cmark/nmake.bat b/lib/cmark/nmake.bat
deleted file mode 100644
index 11d76c9..0000000
--- a/lib/cmark/nmake.bat
+++ /dev/null
@@ -1 +0,0 @@
-@nmake.exe /nologo /f Makefile.nmake %*
diff --git a/lib/cmark/test/CMakeLists.txt b/lib/cmark/test/CMakeLists.txt
deleted file mode 100755
index 5c07fb7..0000000
--- a/lib/cmark/test/CMakeLists.txt
+++ /dev/null
@@ -1,80 +0,0 @@
-# To get verbose output: cmake --build build --target "test" -- ARGS='-V'
-
-# By default, we run the spec tests only if python3 is available.
-# To require the spec tests, compile with -DSPEC_TESTS=1
-
-if (SPEC_TESTS)
- find_package(PythonInterp 3 REQUIRED)
-else(SPEC_TESTS)
- find_package(PythonInterp 3)
-endif(SPEC_TESTS)
-
-if (CMARK_SHARED OR CMARK_STATIC)
- add_test(NAME api_test COMMAND api_test)
-endif()
-
-if (WIN32)
- file(TO_NATIVE_PATH ${CMAKE_BINARY_DIR}/src WIN_DLL_DIR)
- set(NEWPATH "${WIN_DLL_DIR};$ENV{PATH}")
- string(REPLACE ";" "\\;" NEWPATH "${NEWPATH}")
- set_tests_properties(api_test PROPERTIES ENVIRONMENT "PATH=${NEWPATH}")
- set(ROUNDTRIP "${CMAKE_CURRENT_SOURCE_DIR}/roundtrip.bat")
-else(WIN32)
- set(ROUNDTRIP "${CMAKE_CURRENT_SOURCE_DIR}/roundtrip.sh")
-endif(WIN32)
-
-IF (PYTHONINTERP_FOUND)
-
- add_test(html_normalization
- ${PYTHON_EXECUTABLE} "-m" "doctest"
- "${CMAKE_CURRENT_SOURCE_DIR}/normalize.py"
- )
-
- if (CMARK_SHARED)
- add_test(spectest_library
- ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec"
- "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src"
- )
-
- add_test(pathological_tests_library
- ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/pathological_tests.py"
- "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src"
- )
-
- add_test(roundtriptest_library
- ${PYTHON_EXECUTABLE}
- "${CMAKE_CURRENT_SOURCE_DIR}/roundtrip_tests.py"
- "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt"
- "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src"
- )
-
- add_test(entity_library
- ${PYTHON_EXECUTABLE}
- "${CMAKE_CURRENT_SOURCE_DIR}/entity_tests.py"
- "--library-dir" "${CMAKE_CURRENT_BINARY_DIR}/../src"
- )
- endif()
-
- add_test(spectest_executable
- ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/spec.txt" "--program" "${CMAKE_CURRENT_BINARY_DIR}/../src/cmark"
- )
-
- add_test(smartpuncttest_executable
- ${PYTHON_EXECUTABLE} "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec" "${CMAKE_CURRENT_SOURCE_DIR}/smart_punct.txt" "--program" "${CMAKE_CURRENT_BINARY_DIR}/../src/cmark --smart"
- )
-
- add_test(regressiontest_executable
- ${PYTHON_EXECUTABLE}
- "${CMAKE_CURRENT_SOURCE_DIR}/spec_tests.py" "--no-normalize" "--spec"
- "${CMAKE_CURRENT_SOURCE_DIR}/regression.txt" "--program"
- "${CMAKE_CURRENT_BINARY_DIR}/../src/cmark"
- )
-
-ELSE(PYTHONINTERP_FOUND)
-
- message("\n*** A python 3 interpreter is required to run the spec tests.\n")
- add_test(skipping_spectests
- echo "Skipping spec tests, because no python 3 interpreter is available.")
-
-ENDIF(PYTHONINTERP_FOUND)
-
diff --git a/lib/cmark/test/afl_test_cases/test.md b/lib/cmark/test/afl_test_cases/test.md
deleted file mode 100644
index 27eee00..0000000
--- a/lib/cmark/test/afl_test_cases/test.md
+++ /dev/null
@@ -1,36 +0,0 @@
-# H1
-
-H2
---
-
-t ☺
-*b* **em** `c`
-&ge;\&\
-\_e\_
-
-4) I1
-
-5) I2
- > [l](/u "t")
- >
- > - [f]
- > - ![a](/u "t")
- >
- >> <ftp://hh>
- >> <u@hh>
-
-~~~ l☺
-cb
-~~~
-
- c1
- c2
-
-***
-
-<div>
-<b>x</b>
-</div>
-
-[f]: /u "t"
-
diff --git a/lib/cmark/test/cmark-fuzz.c b/lib/cmark/test/cmark-fuzz.c
deleted file mode 100644
index b078e3d..0000000
--- a/lib/cmark/test/cmark-fuzz.c
+++ /dev/null
@@ -1,33 +0,0 @@
-#include <stdint.h>
-#include <stdlib.h>
-#include <string.h>
-#include "cmark.h"
-
-int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
- struct __attribute__((packed)) {
- int options;
- int width;
- } fuzz_config;
-
- if (size >= sizeof(fuzz_config)) {
- /* The beginning of `data` is treated as fuzzer configuration */
- memcpy(&fuzz_config, data, sizeof(fuzz_config));
-
- /* Mask off valid option bits */
- fuzz_config.options &= (CMARK_OPT_SOURCEPOS | CMARK_OPT_HARDBREAKS | CMARK_OPT_UNSAFE | CMARK_OPT_NOBREAKS | CMARK_OPT_NORMALIZE | CMARK_OPT_VALIDATE_UTF8 | CMARK_OPT_SMART);
-
- /* Remainder of input is the markdown */
- const char *markdown = (const char *)(data + sizeof(fuzz_config));
- const size_t markdown_size = size - sizeof(fuzz_config);
- cmark_node *doc = cmark_parse_document(markdown, markdown_size, fuzz_config.options);
-
- free(cmark_render_commonmark(doc, fuzz_config.options, fuzz_config.width));
- free(cmark_render_html(doc, fuzz_config.options));
- free(cmark_render_latex(doc, fuzz_config.options, fuzz_config.width));
- free(cmark_render_man(doc, fuzz_config.options, fuzz_config.width));
- free(cmark_render_xml(doc, fuzz_config.options));
-
- cmark_node_free(doc);
- }
- return 0;
-}
diff --git a/lib/cmark/test/cmark.py b/lib/cmark/test/cmark.py
deleted file mode 100644
index 38d2f59..0000000
--- a/lib/cmark/test/cmark.py
+++ /dev/null
@@ -1,62 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-from ctypes import CDLL, c_char_p, c_size_t, c_int, c_void_p
-from subprocess import *
-import platform
-import os
-
-def pipe_through_prog(prog, text):
- p1 = Popen(prog.split(), stdout=PIPE, stdin=PIPE, stderr=PIPE)
- [result, err] = p1.communicate(input=text.encode('utf-8'))
- return [p1.returncode, result.decode('utf-8'), err]
-
-def to_html(lib, text):
- markdown = lib.cmark_markdown_to_html
- markdown.restype = c_char_p
- markdown.argtypes = [c_char_p, c_size_t, c_int]
- textbytes = text.encode('utf-8')
- textlen = len(textbytes)
- # 1 << 17 == CMARK_OPT_UNSAFE
- result = markdown(textbytes, textlen, 1 << 17).decode('utf-8')
- return [0, result, '']
-
-def to_commonmark(lib, text):
- textbytes = text.encode('utf-8')
- textlen = len(textbytes)
- parse_document = lib.cmark_parse_document
- parse_document.restype = c_void_p
- parse_document.argtypes = [c_char_p, c_size_t, c_int]
- render_commonmark = lib.cmark_render_commonmark
- render_commonmark.restype = c_char_p
- render_commonmark.argtypes = [c_void_p, c_int, c_int]
- node = parse_document(textbytes, textlen, 0)
- result = render_commonmark(node, 0, 0).decode('utf-8')
- return [0, result, '']
-
-class CMark:
- def __init__(self, prog=None, library_dir=None):
- self.prog = prog
- if prog:
- prog += ' --unsafe'
- self.to_html = lambda x: pipe_through_prog(prog, x)
- self.to_commonmark = lambda x: pipe_through_prog(prog + ' -t commonmark', x)
- else:
- sysname = platform.system()
- if sysname == 'Darwin':
- libnames = [ "libcmark.dylib" ]
- elif sysname == 'Windows':
- libnames = [ "cmark.dll", "libcmark.dll" ]
- else:
- libnames = [ "libcmark.so" ]
- if not library_dir:
- library_dir = os.path.join("build", "src")
- for libname in libnames:
- candidate = os.path.join(library_dir, libname)
- if os.path.isfile(candidate):
- libpath = candidate
- break
- cmark = CDLL(libpath)
- self.to_html = lambda x: to_html(cmark, x)
- self.to_commonmark = lambda x: to_commonmark(cmark, x)
-
diff --git a/lib/cmark/test/entity_tests.py b/lib/cmark/test/entity_tests.py
deleted file mode 100644
index 27b70e6..0000000
--- a/lib/cmark/test/entity_tests.py
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-import re
-import os
-import argparse
-import sys
-import platform
-import html
-from cmark import CMark
-
-def get_entities():
- regex = r'^{\(unsigned char\*\)"([^"]+)", \{([^}]+)\}'
- with open(os.path.join(os.path.dirname(__file__), '..', 'src', 'entities.inc')) as f:
- code = f.read()
- entities = []
- for entity, utf8 in re.findall(regex, code, re.MULTILINE):
- utf8 = bytes(map(int, utf8.split(", ")[:-1])).decode('utf-8')
- entities.append((entity, utf8))
- return entities
-
-parser = argparse.ArgumentParser(description='Run cmark tests.')
-parser.add_argument('--program', dest='program', nargs='?', default=None,
- help='program to test')
-parser.add_argument('--library-dir', dest='library_dir', nargs='?',
- default=None, help='directory containing dynamic library')
-args = parser.parse_args(sys.argv[1:])
-
-cmark = CMark(prog=args.program, library_dir=args.library_dir)
-
-entities = get_entities()
-
-passed = 0
-errored = 0
-failed = 0
-
-exceptions = {
- 'quot': '&quot;',
- 'QUOT': '&quot;',
-
- # These are broken, but I'm not too worried about them.
- 'nvlt': '&lt;⃒',
- 'nvgt': '&gt;⃒',
-}
-
-print("Testing entities:")
-for entity, utf8 in entities:
- [rc, actual, err] = cmark.to_html("&{};".format(entity))
- check = exceptions.get(entity, utf8)
-
- if rc != 0:
- errored += 1
- print(entity, '[ERRORED (return code {})]'.format(rc))
- print(err)
- elif check in actual:
- # print(entity, '[PASSED]') # omit noisy success output
- passed += 1
- else:
- print(entity, '[FAILED]')
- print(repr(actual))
- failed += 1
-
-print("{} passed, {} failed, {} errored".format(passed, failed, errored))
-if failed == 0 and errored == 0:
- exit(0)
-else:
- exit(1)
diff --git a/lib/cmark/test/fuzzing_dictionary b/lib/cmark/test/fuzzing_dictionary
deleted file mode 100644
index b06783c..0000000
--- a/lib/cmark/test/fuzzing_dictionary
+++ /dev/null
@@ -1,49 +0,0 @@
-asterisk="*"
-attr_generic=" a=\"1\""
-attr_href=" href=\"1\""
-attr_xml_lang=" xml:lang=\"1\""
-attr_xmlns=" xmlns=\"1\""
-backslash="\\"
-backtick="`"
-colon=":"
-dashes="---"
-double_quote="\""
-entity_builtin="&lt;"
-entity_decimal="&#1;"
-entity_external="&a;"
-entity_hex="&#x1;"
-equals="==="
-exclamation="!"
-greater_than=">"
-hash="#"
-hyphen="-"
-indent=" "
-left_bracket="["
-left_paren="("
-less_than="<"
-plus="+"
-right_bracket="]"
-right_paren=")"
-single_quote="'"
-string_any="ANY"
-string_brackets="[]"
-string_cdata="CDATA"
-string_dashes="--"
-string_empty_dblquotes="\"\""
-string_empty_quotes="''"
-string_idrefs="IDREFS"
-string_parentheses="()"
-string_pcdata="#PCDATA"
-tag_cdata="<![CDATA["
-tag_close="</a>"
-tag_doctype="<!DOCTYPE"
-tag_element="<!ELEMENT"
-tag_entity="<!ENTITY"
-tag_notation="<!NOTATION"
-tag_open="<a>"
-tag_open_close="<a />"
-tag_open_exclamation="<!"
-tag_open_q="<?"
-tag_sq2_close="]]>"
-tag_xml_q="<?xml?>"
-underscore="_"
diff --git a/lib/cmark/test/normalize.py b/lib/cmark/test/normalize.py
deleted file mode 100644
index f8ece18..0000000
--- a/lib/cmark/test/normalize.py
+++ /dev/null
@@ -1,194 +0,0 @@
-# -*- coding: utf-8 -*-
-from html.parser import HTMLParser
-import urllib
-
-try:
- from html.parser import HTMLParseError
-except ImportError:
- # HTMLParseError was removed in Python 3.5. It could never be
- # thrown, so we define a placeholder instead.
- class HTMLParseError(Exception):
- pass
-
-from html.entities import name2codepoint
-import sys
-import re
-import html
-
-# Normalization code, adapted from
-# https://github.com/karlcow/markdown-testsuite/
-significant_attrs = ["alt", "href", "src", "title"]
-whitespace_re = re.compile('\s+')
-class MyHTMLParser(HTMLParser):
- def __init__(self):
- HTMLParser.__init__(self)
- self.convert_charrefs = False
- self.last = "starttag"
- self.in_pre = False
- self.output = ""
- self.last_tag = ""
- def handle_data(self, data):
- after_tag = self.last == "endtag" or self.last == "starttag"
- after_block_tag = after_tag and self.is_block_tag(self.last_tag)
- if after_tag and self.last_tag == "br":
- data = data.lstrip('\n')
- if not self.in_pre:
- data = whitespace_re.sub(' ', data)
- if after_block_tag and not self.in_pre:
- if self.last == "starttag":
- data = data.lstrip()
- elif self.last == "endtag":
- data = data.strip()
- self.output += data
- self.last = "data"
- def handle_endtag(self, tag):
- if tag == "pre":
- self.in_pre = False
- elif self.is_block_tag(tag):
- self.output = self.output.rstrip()
- self.output += "</" + tag + ">"
- self.last_tag = tag
- self.last = "endtag"
- def handle_starttag(self, tag, attrs):
- if tag == "pre":
- self.in_pre = True
- if self.is_block_tag(tag):
- self.output = self.output.rstrip()
- self.output += "<" + tag
- # For now we don't strip out 'extra' attributes, because of
- # raw HTML test cases.
- # attrs = filter(lambda attr: attr[0] in significant_attrs, attrs)
- if attrs:
- attrs.sort()
- for (k,v) in attrs:
- self.output += " " + k
- if v in ['href','src']:
- self.output += ("=" + '"' +
- urllib.quote(urllib.unquote(v), safe='/') + '"')
- elif v != None:
- self.output += ("=" + '"' + html.escape(v,quote=True) + '"')
- self.output += ">"
- self.last_tag = tag
- self.last = "starttag"
- def handle_startendtag(self, tag, attrs):
- """Ignore closing tag for self-closing """
- self.handle_starttag(tag, attrs)
- self.last_tag = tag
- self.last = "endtag"
- def handle_comment(self, data):
- self.output += '<!--' + data + '-->'
- self.last = "comment"
- def handle_decl(self, data):
- self.output += '<!' + data + '>'
- self.last = "decl"
- def unknown_decl(self, data):
- self.output += '<!' + data + '>'
- self.last = "decl"
- def handle_pi(self,data):
- self.output += '<?' + data + '>'
- self.last = "pi"
- def handle_entityref(self, name):
- try:
- c = chr(name2codepoint[name])
- except KeyError:
- c = None
- self.output_char(c, '&' + name + ';')
- self.last = "ref"
- def handle_charref(self, name):
- try:
- if name.startswith("x"):
- c = chr(int(name[1:], 16))
- else:
- c = chr(int(name))
- except ValueError:
- c = None
- self.output_char(c, '&' + name + ';')
- self.last = "ref"
- # Helpers.
- def output_char(self, c, fallback):
- if c == '<':
- self.output += "&lt;"
- elif c == '>':
- self.output += "&gt;"
- elif c == '&':
- self.output += "&amp;"
- elif c == '"':
- self.output += "&quot;"
- elif c == None:
- self.output += fallback
- else:
- self.output += c
-
- def is_block_tag(self,tag):
- return (tag in ['article', 'header', 'aside', 'hgroup', 'blockquote',
- 'hr', 'iframe', 'body', 'li', 'map', 'button', 'object', 'canvas',
- 'ol', 'caption', 'output', 'col', 'p', 'colgroup', 'pre', 'dd',
- 'progress', 'div', 'section', 'dl', 'table', 'td', 'dt',
- 'tbody', 'embed', 'textarea', 'fieldset', 'tfoot', 'figcaption',
- 'th', 'figure', 'thead', 'footer', 'tr', 'form', 'ul',
- 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'video', 'script', 'style'])
-
-def normalize_html(html):
- r"""
- Return normalized form of HTML which ignores insignificant output
- differences:
-
- Multiple inner whitespaces are collapsed to a single space (except
- in pre tags):
-
- >>> normalize_html("<p>a \t b</p>")
- '<p>a b</p>'
-
- >>> normalize_html("<p>a \t\nb</p>")
- '<p>a b</p>'
-
- * Whitespace surrounding block-level tags is removed.
-
- >>> normalize_html("<p>a b</p>")
- '<p>a b</p>'
-
- >>> normalize_html(" <p>a b</p>")
- '<p>a b</p>'
-
- >>> normalize_html("<p>a b</p> ")
- '<p>a b</p>'
-
- >>> normalize_html("\n\t<p>\n\t\ta b\t\t</p>\n\t")
- '<p>a b</p>'
-
- >>> normalize_html("<i>a b</i> ")
- '<i>a b</i> '
-
- * Self-closing tags are converted to open tags.
-
- >>> normalize_html("<br />")
- '<br>'
-
- * Attributes are sorted and lowercased.
-
- >>> normalize_html('<a title="bar" HREF="foo">x</a>')
- '<a href="foo" title="bar">x</a>'
-
- * References are converted to unicode, except that '<', '>', '&', and
- '"' are rendered using entities.
-
- >>> normalize_html("&forall;&amp;&gt;&lt;&quot;")
- '\u2200&amp;&gt;&lt;&quot;'
-
- """
- html_chunk_re = re.compile("(\<!\[CDATA\[.*?\]\]\>|\<[^>]*\>|[^<]+)")
- try:
- parser = MyHTMLParser()
- # We work around HTMLParser's limitations parsing CDATA
- # by breaking the input into chunks and passing CDATA chunks
- # through verbatim.
- for chunk in re.finditer(html_chunk_re, html):
- if chunk.group(0)[:8] == "<![CDATA":
- parser.output += chunk.group(0)
- else:
- parser.feed(chunk.group(0))
- parser.close()
- return parser.output
- except HTMLParseError as e:
- sys.stderr.write("Normalization error: " + e.msg + "\n")
- return html # on error, return unnormalized HTML
diff --git a/lib/cmark/test/pathological_tests.py b/lib/cmark/test/pathological_tests.py
deleted file mode 100644
index 76cc913..0000000
--- a/lib/cmark/test/pathological_tests.py
+++ /dev/null
@@ -1,169 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-import re
-import argparse
-import sys
-import platform
-import itertools
-import multiprocessing
-import time
-from cmark import CMark
-
-TIMEOUT = 5
-
-parser = argparse.ArgumentParser(description='Run cmark tests.')
-parser.add_argument('--program', dest='program', nargs='?', default=None,
- help='program to test')
-parser.add_argument('--library-dir', dest='library_dir', nargs='?',
- default=None, help='directory containing dynamic library')
-args = parser.parse_args(sys.argv[1:])
-
-allowed_failures = {"many references": True}
-
-cmark = CMark(prog=args.program, library_dir=args.library_dir)
-
-def hash_collisions():
- REFMAP_SIZE = 16
- COUNT = 50000
-
- def badhash(ref):
- h = 0
- for c in ref:
- a = (h << 6) & 0xFFFFFFFF
- b = (h << 16) & 0xFFFFFFFF
- h = ord(c) + a + b - h
- h = h & 0xFFFFFFFF
-
- return (h % REFMAP_SIZE) == 0
-
- keys = ("x%d" % i for i in itertools.count())
- collisions = itertools.islice((k for k in keys if badhash(k)), COUNT)
- bad_key = next(collisions)
-
- document = ''.join("[%s]: /url\n\n[%s]\n\n" % (key, bad_key) for key in collisions)
-
- return document, re.compile("(<p>\[%s\]</p>\n){%d}" % (bad_key, COUNT-1))
-
-
-# list of pairs consisting of input and a regex that must match the output.
-pathological = {
- # note - some pythons have limit of 65535 for {num-matches} in re.
- "nested strong emph":
- (("*a **a " * 65000) + "b" + (" a** a*" * 65000),
- re.compile("(<em>a <strong>a ){65000}b( a</strong> a</em>){65000}")),
- "many emph closers with no openers":
- (("a_ " * 65000),
- re.compile("(a[_] ){64999}a_")),
- "many emph openers with no closers":
- (("_a " * 65000),
- re.compile("(_a ){64999}_a")),
- "many link closers with no openers":
- (("a]" * 65000),
- re.compile("(a\]){65000}")),
- "many link openers with no closers":
- (("[a" * 65000),
- re.compile("(\[a){65000}")),
- "mismatched openers and closers":
- (("*a_ " * 50000),
- re.compile("([*]a[_] ){49999}[*]a_")),
- "openers and closers multiple of 3":
- (("a**b" + ("c* " * 50000)),
- re.compile("a[*][*]b(c[*] ){49999}c[*]")),
- "link openers and emph closers":
- (("[ a_" * 50000),
- re.compile("(\[ a_){50000}")),
- "pattern [ (]( repeated":
- (("[ (](" * 80000),
- re.compile("(\[ \(\]\(){80000}")),
- "hard link/emph case":
- ("**x [a*b**c*](d)",
- re.compile("\\*\\*x <a href=\"d\">a<em>b\\*\\*c</em></a>")),
- "nested brackets":
- (("[" * 50000) + "a" + ("]" * 50000),
- re.compile("\[{50000}a\]{50000}")),
- "nested block quotes":
- ((("> " * 50000) + "a"),
- re.compile("(<blockquote>\n){50000}")),
- "deeply nested lists":
- ("".join(map(lambda x: (" " * x + "* a\n"), range(0,1000))),
- re.compile("<ul>\n(<li>a\n<ul>\n){999}<li>a</li>\n</ul>\n(</li>\n</ul>\n){999}")),
- "U+0000 in input":
- ("abc\u0000de\u0000",
- re.compile("abc\ufffd?de\ufffd?")),
- "backticks":
- ("".join(map(lambda x: ("e" + "`" * x), range(1,5000))),
- re.compile("^<p>[e`]*</p>\n$")),
- "unclosed links A":
- ("[a](<b" * 30000,
- re.compile("(\[a\]\(&lt;b){30000}")),
- "unclosed links B":
- ("[a](b" * 30000,
- re.compile("(\[a\]\(b){30000}")),
- "reference collisions": hash_collisions()
-# "many references":
-# ("".join(map(lambda x: ("[" + str(x) + "]: u\n"), range(1,5000 * 16))) + "[0] " * 5000,
-# re.compile("(\[0\] ){4999}"))
- }
-
-whitespace_re = re.compile('/s+/')
-
-results = {'passed': [], 'errored': [], 'failed': [], 'ignored': []}
-
-def run_pathological_test(description, results):
- (inp, regex) = pathological[description]
- [rc, actual, err] = cmark.to_html(inp)
- extra = ""
- if rc != 0:
- print(description, '[ERRORED (return code %d)]' %rc)
- print(err)
- if allowed_failures[description]:
- results['ignored'].append(description)
- else:
- results['errored'].append(description)
- elif regex.search(actual):
- print(description, '[PASSED]')
- results['passed'].append(description)
- else:
- print(description, '[FAILED]')
- print(repr(actual))
- if allowed_failures[description]:
- results['ignored'].append(description)
- else:
- results['failed'].append(description)
-
-def run_tests():
- print("Testing pathological cases:")
- for description in pathological:
- p = multiprocessing.Process(target=run_pathological_test,
- args=(description, results,))
- p.start()
- # wait TIMEOUT seconds or until it finishes
- p.join(TIMEOUT)
- # kill it if still active
- if p.is_alive():
- print(description, '[TIMEOUT]')
- if allowed_failures[description]:
- results['ignored'].append(description)
- else:
- results['errored'].append(description)
- p.terminate()
- p.join()
-
- passed = len(results['passed'])
- failed = len(results['failed'])
- errored = len(results['errored'])
- ignored = len(results['ignored'])
-
- print("%d passed, %d failed, %d errored" % (passed, failed, errored))
- if ignored > 0:
- print("Ignoring these allowed failures:")
- for x in results['ignored']:
- print(x)
- if failed == 0 and errored == 0:
- exit(0)
- else:
- exit(1)
-
-if __name__ == "__main__":
- run_tests()
diff --git a/lib/cmark/test/regression.txt b/lib/cmark/test/regression.txt
deleted file mode 100644
index d77c8f2..0000000
--- a/lib/cmark/test/regression.txt
+++ /dev/null
@@ -1,164 +0,0 @@
-### Regression tests
-
-Issue #113: EOL character weirdness on Windows
-(Important: first line ends with CR + CR + LF)
-
-```````````````````````````````` example
-line1
-line2
-.
-<p>line1</p>
-<p>line2</p>
-````````````````````````````````
-
-Issue #114: cmark skipping first character in line
-(Important: the blank lines around "Repeatedly" contain a tab.)
-
-```````````````````````````````` example
-By taking it apart
-
-- alternative solutions
-→
-Repeatedly solving
-→
-- how techniques
-.
-<p>By taking it apart</p>
-<ul>
-<li>alternative solutions</li>
-</ul>
-<p>Repeatedly solving</p>
-<ul>
-<li>how techniques</li>
-</ul>
-````````````````````````````````
-
-Issue jgm/CommonMark#430: h2..h6 not recognized as block tags.
-
-```````````````````````````````` example
-<h1>lorem</h1>
-
-<h2>lorem</h2>
-
-<h3>lorem</h3>
-
-<h4>lorem</h4>
-
-<h5>lorem</h5>
-
-<h6>lorem</h6>
-.
-<h1>lorem</h1>
-<h2>lorem</h2>
-<h3>lorem</h3>
-<h4>lorem</h4>
-<h5>lorem</h5>
-<h6>lorem</h6>
-````````````````````````````````
-
-Issue jgm/commonmark.js#109 - tabs after setext header line
-
-
-```````````````````````````````` example
-hi
---→
-.
-<h2>hi</h2>
-````````````````````````````````
-
-Issue #177 - incorrect emphasis parsing
-
-```````````````````````````````` example
-a***b* c*
-.
-<p>a*<em><em>b</em> c</em></p>
-````````````````````````````````
-
-Issue #193 - unescaped left angle brackets in link destination
-
-```````````````````````````````` example
-[a]
-
-[a]: <te<st>
-.
-<p>[a]</p>
-<p>[a]: &lt;te<st></p>
-````````````````````````````````
-
-Issue #192 - escaped spaces in link destination
-
-
-```````````````````````````````` example
-[a](te\ st)
-.
-<p>[a](te\ st)</p>
-````````````````````````````````
-
-Issue #527 - meta tags in inline contexts
-
-```````````````````````````````` example
-City:
-<span itemprop="contentLocation" itemscope itemtype="https://schema.org/City">
- <meta itemprop="name" content="Springfield">
-</span>
-.
-<p>City:
-<span itemprop="contentLocation" itemscope itemtype="https://schema.org/City">
-<meta itemprop="name" content="Springfield">
-</span></p>
-````````````````````````````````
-
-Issue #530 - link parsing corner cases
-
-```````````````````````````````` example
-[a](\ b)
-
-[a](<<b)
-
-[a](<b
-)
-.
-<p>[a](\ b)</p>
-<p>[a](&lt;&lt;b)</p>
-<p>[a](&lt;b
-)</p>
-````````````````````````````````
-
-Issue commonmark#526 - unescaped ( in link title
-
-```````````````````````````````` example
-[link](url ((title))
-.
-<p>[link](url ((title))</p>
-````````````````````````````````
-
-Issue commonamrk#517 - script, pre, style close tag without
-opener.
-
-```````````````````````````````` example
-</script>
-
-</pre>
-
-</style>
-.
-</script>
-</pre>
-</style>
-````````````````````````````````
-
-Issue #289.
-
-```````````````````````````````` example
-[a](<b) c>
-.
-<p>[a](&lt;b) c&gt;</p>
-````````````````````````````````
-
-Issue #334 - UTF-8 BOM
-
-```````````````````````````````` example
-# Hi
-.
-<h1>Hi</h1>
-````````````````````````````````
diff --git a/lib/cmark/test/roundtrip_tests.py b/lib/cmark/test/roundtrip_tests.py
deleted file mode 100644
index 13444b1..0000000
--- a/lib/cmark/test/roundtrip_tests.py
+++ /dev/null
@@ -1,46 +0,0 @@
-import re
-import sys
-from spec_tests import get_tests, do_test
-from cmark import CMark
-import argparse
-
-parser = argparse.ArgumentParser(description='Run cmark roundtrip tests.')
-parser.add_argument('-p', '--program', dest='program', nargs='?', default=None,
- help='program to test')
-parser.add_argument('-s', '--spec', dest='spec', nargs='?', default='spec.txt',
- help='path to spec')
-parser.add_argument('-P', '--pattern', dest='pattern', nargs='?',
- default=None, help='limit to sections matching regex pattern')
-parser.add_argument('--library-dir', dest='library_dir', nargs='?',
- default=None, help='directory containing dynamic library')
-parser.add_argument('--no-normalize', dest='normalize',
- action='store_const', const=False, default=True,
- help='do not normalize HTML')
-parser.add_argument('-n', '--number', type=int, default=None,
- help='only consider the test with the given number')
-args = parser.parse_args(sys.argv[1:])
-
-spec = sys.argv[1]
-
-def converter(md):
- cmark = CMark(prog=args.program, library_dir=args.library_dir)
- [ec, result, err] = cmark.to_commonmark(md)
- if ec == 0:
- [ec, html, err] = cmark.to_html(result)
- if ec == 0:
- # In the commonmark writer we insert dummy HTML
- # comments between lists, and between lists and code
- # blocks. Strip these out, since the spec uses
- # two blank lines instead:
- return [ec, re.sub('<!-- end list -->\n', '', html), '']
- else:
- return [ec, html, err]
- else:
- return [ec, result, err]
-
-tests = get_tests(args.spec)
-result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': 0}
-for test in tests:
- do_test(converter, test, args.normalize, result_counts)
-
-exit(result_counts['fail'] + result_counts['error'])
diff --git a/lib/cmark/test/run-cmark-fuzz b/lib/cmark/test/run-cmark-fuzz
deleted file mode 100755
index 75100b8..0000000
--- a/lib/cmark/test/run-cmark-fuzz
+++ /dev/null
@@ -1,4 +0,0 @@
-#!/bin/bash -eu
-CMARK_FUZZ="$1"
-shift
-ASAN_OPTIONS="quarantine_size_mb=10:detect_leaks=1" "${CMARK_FUZZ}" -max_len=256 -timeout=1 -dict=test/fuzzing_dictionary "$@"
diff --git a/lib/cmark/test/smart_punct.txt b/lib/cmark/test/smart_punct.txt
deleted file mode 100644
index fd55e62..0000000
--- a/lib/cmark/test/smart_punct.txt
+++ /dev/null
@@ -1,177 +0,0 @@
-## Smart punctuation
-
-Open quotes are matched with closed quotes.
-The same method is used for matching openers and closers
-as is used in emphasis parsing:
-
-```````````````````````````````` example
-"Hello," said the spider.
-"'Shelob' is my name."
-.
-<p>“Hello,” said the spider.
-“‘Shelob’ is my name.”</p>
-````````````````````````````````
-
-```````````````````````````````` example
-'A', 'B', and 'C' are letters.
-.
-<p>‘A’, ‘B’, and ‘C’ are letters.</p>
-````````````````````````````````
-
-```````````````````````````````` example
-'Oak,' 'elm,' and 'beech' are names of trees.
-So is 'pine.'
-.
-<p>‘Oak,’ ‘elm,’ and ‘beech’ are names of trees.
-So is ‘pine.’</p>
-````````````````````````````````
-
-```````````````````````````````` example
-'He said, "I want to go."'
-.
-<p>‘He said, “I want to go.”’</p>
-````````````````````````````````
-
-A single quote that isn't an open quote matched
-with a close quote will be treated as an
-apostrophe:
-
-```````````````````````````````` example
-Were you alive in the 70's?
-.
-<p>Were you alive in the 70’s?</p>
-````````````````````````````````
-
-```````````````````````````````` example
-Here is some quoted '`code`' and a "[quoted link](url)".
-.
-<p>Here is some quoted ‘<code>code</code>’ and a “<a href="url">quoted link</a>”.</p>
-````````````````````````````````
-
-Here the first `'` is treated as an apostrophe, not
-an open quote, because the final single quote is matched
-by the single quote before `jolly`:
-
-```````````````````````````````` example
-'tis the season to be 'jolly'
-.
-<p>’tis the season to be ‘jolly’</p>
-````````````````````````````````
-
-Multiple apostrophes should not be marked as open/closing quotes.
-
-```````````````````````````````` example
-'We'll use Jane's boat and John's truck,' Jenna said.
-.
-<p>‘We’ll use Jane’s boat and John’s truck,’ Jenna said.</p>
-````````````````````````````````
-
-An unmatched double quote will be interpreted as a
-left double quote, to facilitate this style:
-
-```````````````````````````````` example
-"A paragraph with no closing quote.
-
-"Second paragraph by same speaker, in fiction."
-.
-<p>“A paragraph with no closing quote.</p>
-<p>“Second paragraph by same speaker, in fiction.”</p>
-````````````````````````````````
-
-A quote following a `]` or `)` character cannot
-be an open quote:
-
-```````````````````````````````` example
-[a]'s b'
-.
-<p>[a]’s b’</p>
-````````````````````````````````
-
-Quotes that are escaped come out as literal straight
-quotes:
-
-```````````````````````````````` example
-\"This is not smart.\"
-This isn\'t either.
-5\'8\"
-.
-<p>&quot;This is not smart.&quot;
-This isn't either.
-5'8&quot;</p>
-````````````````````````````````
-
-Two hyphens form an en-dash, three an em-dash.
-
-```````````````````````````````` example
-Some dashes: em---em
-en--en
-em --- em
-en -- en
-2--3
-.
-<p>Some dashes: em—em
-en–en
-em — em
-en – en
-2–3</p>
-````````````````````````````````
-
-A sequence of more than three hyphens is
-parsed as a sequence of em and/or en dashes,
-with no hyphens. If possible, a homogeneous
-sequence of dashes is used (so, 10 hyphens
-= 5 en dashes, and 9 hyphens = 3 em dashes).
-When a heterogeneous sequence must be used,
-the em dashes come first, followed by the en
-dashes, and as few en dashes as possible are
-used (so, 7 hyphens = 2 em dashes an 1 en
-dash).
-
-```````````````````````````````` example
-one-
-two--
-three---
-four----
-five-----
-six------
-seven-------
-eight--------
-nine---------
-thirteen-------------.
-.
-<p>one-
-two–
-three—
-four––
-five—–
-six——
-seven—––
-eight––––
-nine———
-thirteen———––.</p>
-````````````````````````````````
-
-Hyphens can be escaped:
-
-```````````````````````````````` example
-Escaped hyphens: \-- \-\-\-.
-.
-<p>Escaped hyphens: -- ---.</p>
-````````````````````````````````
-
-Three periods form an ellipsis:
-
-```````````````````````````````` example
-Ellipses...and...and....
-.
-<p>Ellipses…and…and….</p>
-````````````````````````````````
-
-Periods can be escaped if ellipsis-formation
-is not wanted:
-
-```````````````````````````````` example
-No ellipses\.\.\.
-.
-<p>No ellipses...</p>
-````````````````````````````````
diff --git a/lib/cmark/test/spec.txt b/lib/cmark/test/spec.txt
deleted file mode 100644
index 1197d1b..0000000
--- a/lib/cmark/test/spec.txt
+++ /dev/null
@@ -1,9720 +0,0 @@
----
-title: CommonMark Spec
-author: John MacFarlane
-version: 0.29
-date: '2019-04-06'
-license: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)'
-...
-
-# Introduction
-
-## What is Markdown?
-
-Markdown is a plain text format for writing structured documents,
-based on conventions for indicating formatting in email
-and usenet posts. It was developed by John Gruber (with
-help from Aaron Swartz) and released in 2004 in the form of a
-[syntax description](http://daringfireball.net/projects/markdown/syntax)
-and a Perl script (`Markdown.pl`) for converting Markdown to
-HTML. In the next decade, dozens of implementations were
-developed in many languages. Some extended the original
-Markdown syntax with conventions for footnotes, tables, and
-other document elements. Some allowed Markdown documents to be
-rendered in formats other than HTML. Websites like Reddit,
-StackOverflow, and GitHub had millions of people using Markdown.
-And Markdown started to be used beyond the web, to author books,
-articles, slide shows, letters, and lecture notes.
-
-What distinguishes Markdown from many other lightweight markup
-syntaxes, which are often easier to write, is its readability.
-As Gruber writes:
-
-> The overriding design goal for Markdown's formatting syntax is
-> to make it as readable as possible. The idea is that a
-> Markdown-formatted document should be publishable as-is, as
-> plain text, without looking like it's been marked up with tags
-> or formatting instructions.
-> (<http://daringfireball.net/projects/markdown/>)
-
-The point can be illustrated by comparing a sample of
-[AsciiDoc](http://www.methods.co.nz/asciidoc/) with
-an equivalent sample of Markdown. Here is a sample of
-AsciiDoc from the AsciiDoc manual:
-
-```
-1. List item one.
-+
-List item one continued with a second paragraph followed by an
-Indented block.
-+
-.................
-$ ls *.sh
-$ mv *.sh ~/tmp
-.................
-+
-List item continued with a third paragraph.
-
-2. List item two continued with an open block.
-+
---
-This paragraph is part of the preceding list item.
-
-a. This list is nested and does not require explicit item
-continuation.
-+
-This paragraph is part of the preceding list item.
-
-b. List item b.
-
-This paragraph belongs to item two of the outer list.
---
-```
-
-And here is the equivalent in Markdown:
-```
-1. List item one.
-
- List item one continued with a second paragraph followed by an
- Indented block.
-
- $ ls *.sh
- $ mv *.sh ~/tmp
-
- List item continued with a third paragraph.
-
-2. List item two continued with an open block.
-
- This paragraph is part of the preceding list item.
-
- 1. This list is nested and does not require explicit item continuation.
-
- This paragraph is part of the preceding list item.
-
- 2. List item b.
-
- This paragraph belongs to item two of the outer list.
-```
-
-The AsciiDoc version is, arguably, easier to write. You don't need
-to worry about indentation. But the Markdown version is much easier
-to read. The nesting of list items is apparent to the eye in the
-source, not just in the processed document.
-
-## Why is a spec needed?
-
-John Gruber's [canonical description of Markdown's
-syntax](http://daringfireball.net/projects/markdown/syntax)
-does not specify the syntax unambiguously. Here are some examples of
-questions it does not answer:
-
-1. How much indentation is needed for a sublist? The spec says that
- continuation paragraphs need to be indented four spaces, but is
- not fully explicit about sublists. It is natural to think that
- they, too, must be indented four spaces, but `Markdown.pl` does
- not require that. This is hardly a "corner case," and divergences
- between implementations on this issue often lead to surprises for
- users in real documents. (See [this comment by John
- Gruber](http://article.gmane.org/gmane.text.markdown.general/1997).)
-
-2. Is a blank line needed before a block quote or heading?
- Most implementations do not require the blank line. However,
- this can lead to unexpected results in hard-wrapped text, and
- also to ambiguities in parsing (note that some implementations
- put the heading inside the blockquote, while others do not).
- (John Gruber has also spoken [in favor of requiring the blank
- lines](http://article.gmane.org/gmane.text.markdown.general/2146).)
-
-3. Is a blank line needed before an indented code block?
- (`Markdown.pl` requires it, but this is not mentioned in the
- documentation, and some implementations do not require it.)
-
- ``` markdown
- paragraph
- code?
- ```
-
-4. What is the exact rule for determining when list items get
- wrapped in `<p>` tags? Can a list be partially "loose" and partially
- "tight"? What should we do with a list like this?
-
- ``` markdown
- 1. one
-
- 2. two
- 3. three
- ```
-
- Or this?
-
- ``` markdown
- 1. one
- - a
-
- - b
- 2. two
- ```
-
- (There are some relevant comments by John Gruber
- [here](http://article.gmane.org/gmane.text.markdown.general/2554).)
-
-5. Can list markers be indented? Can ordered list markers be right-aligned?
-
- ``` markdown
- 8. item 1
- 9. item 2
- 10. item 2a
- ```
-
-6. Is this one list with a thematic break in its second item,
- or two lists separated by a thematic break?
-
- ``` markdown
- * a
- * * * * *
- * b
- ```
-
-7. When list markers change from numbers to bullets, do we have
- two lists or one? (The Markdown syntax description suggests two,
- but the perl scripts and many other implementations produce one.)
-
- ``` markdown
- 1. fee
- 2. fie
- - foe
- - fum
- ```
-
-8. What are the precedence rules for the markers of inline structure?
- For example, is the following a valid link, or does the code span
- take precedence ?
-
- ``` markdown
- [a backtick (`)](/url) and [another backtick (`)](/url).
- ```
-
-9. What are the precedence rules for markers of emphasis and strong
- emphasis? For example, how should the following be parsed?
-
- ``` markdown
- *foo *bar* baz*
- ```
-
-10. What are the precedence rules between block-level and inline-level
- structure? For example, how should the following be parsed?
-
- ``` markdown
- - `a long code span can contain a hyphen like this
- - and it can screw things up`
- ```
-
-11. Can list items include section headings? (`Markdown.pl` does not
- allow this, but does allow blockquotes to include headings.)
-
- ``` markdown
- - # Heading
- ```
-
-12. Can list items be empty?
-
- ``` markdown
- * a
- *
- * b
- ```
-
-13. Can link references be defined inside block quotes or list items?
-
- ``` markdown
- > Blockquote [foo].
- >
- > [foo]: /url
- ```
-
-14. If there are multiple definitions for the same reference, which takes
- precedence?
-
- ``` markdown
- [foo]: /url1
- [foo]: /url2
-
- [foo][]
- ```
-
-In the absence of a spec, early implementers consulted `Markdown.pl`
-to resolve these ambiguities. But `Markdown.pl` was quite buggy, and
-gave manifestly bad results in many cases, so it was not a
-satisfactory replacement for a spec.
-
-Because there is no unambiguous spec, implementations have diverged
-considerably. As a result, users are often surprised to find that
-a document that renders one way on one system (say, a GitHub wiki)
-renders differently on another (say, converting to docbook using
-pandoc). To make matters worse, because nothing in Markdown counts
-as a "syntax error," the divergence often isn't discovered right away.
-
-## About this document
-
-This document attempts to specify Markdown syntax unambiguously.
-It contains many examples with side-by-side Markdown and
-HTML. These are intended to double as conformance tests. An
-accompanying script `spec_tests.py` can be used to run the tests
-against any Markdown program:
-
- python test/spec_tests.py --spec spec.txt --program PROGRAM
-
-Since this document describes how Markdown is to be parsed into
-an abstract syntax tree, it would have made sense to use an abstract
-representation of the syntax tree instead of HTML. But HTML is capable
-of representing the structural distinctions we need to make, and the
-choice of HTML for the tests makes it possible to run the tests against
-an implementation without writing an abstract syntax tree renderer.
-
-This document is generated from a text file, `spec.txt`, written
-in Markdown with a small extension for the side-by-side tests.
-The script `tools/makespec.py` can be used to convert `spec.txt` into
-HTML or CommonMark (which can then be converted into other formats).
-
-In the examples, the `→` character is used to represent tabs.
-
-# Preliminaries
-
-## Characters and lines
-
-Any sequence of [characters] is a valid CommonMark
-document.
-
-A [character](@) is a Unicode code point. Although some
-code points (for example, combining accents) do not correspond to
-characters in an intuitive sense, all code points count as characters
-for purposes of this spec.
-
-This spec does not specify an encoding; it thinks of lines as composed
-of [characters] rather than bytes. A conforming parser may be limited
-to a certain encoding.
-
-A [line](@) is a sequence of zero or more [characters]
-other than newline (`U+000A`) or carriage return (`U+000D`),
-followed by a [line ending] or by the end of file.
-
-A [line ending](@) is a newline (`U+000A`), a carriage return
-(`U+000D`) not followed by a newline, or a carriage return and a
-following newline.
-
-A line containing no characters, or a line containing only spaces
-(`U+0020`) or tabs (`U+0009`), is called a [blank line](@).
-
-The following definitions of character classes will be used in this spec:
-
-A [whitespace character](@) is a space
-(`U+0020`), tab (`U+0009`), newline (`U+000A`), line tabulation (`U+000B`),
-form feed (`U+000C`), or carriage return (`U+000D`).
-
-[Whitespace](@) is a sequence of one or more [whitespace
-characters].
-
-A [Unicode whitespace character](@) is
-any code point in the Unicode `Zs` general category, or a tab (`U+0009`),
-carriage return (`U+000D`), newline (`U+000A`), or form feed
-(`U+000C`).
-
-[Unicode whitespace](@) is a sequence of one
-or more [Unicode whitespace characters].
-
-A [space](@) is `U+0020`.
-
-A [non-whitespace character](@) is any character
-that is not a [whitespace character].
-
-An [ASCII control character](@) is a character between `U+0000–1F` (both
-including) or `U+007F`.
-
-An [ASCII punctuation character](@)
-is `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`,
-`*`, `+`, `,`, `-`, `.`, `/` (U+0021–2F),
-`:`, `;`, `<`, `=`, `>`, `?`, `@` (U+003A–0040),
-`[`, `\`, `]`, `^`, `_`, `` ` `` (U+005B–0060),
-`{`, `|`, `}`, or `~` (U+007B–007E).
-
-A [punctuation character](@) is an [ASCII
-punctuation character] or anything in
-the general Unicode categories `Pc`, `Pd`, `Pe`, `Pf`, `Pi`, `Po`, or `Ps`.
-
-## Tabs
-
-Tabs in lines are not expanded to [spaces]. However,
-in contexts where whitespace helps to define block structure,
-tabs behave as if they were replaced by spaces with a tab stop
-of 4 characters.
-
-Thus, for example, a tab can be used instead of four spaces
-in an indented code block. (Note, however, that internal
-tabs are passed through as literal tabs, not expanded to
-spaces.)
-
-```````````````````````````````` example
-→foo→baz→→bim
-.
-<pre><code>foo→baz→→bim
-</code></pre>
-````````````````````````````````
-
-```````````````````````````````` example
- →foo→baz→→bim
-.
-<pre><code>foo→baz→→bim
-</code></pre>
-````````````````````````````````
-
-```````````````````````````````` example
- a→a
- ὐ→a
-.
-<pre><code>a→a
-ὐ→a
-</code></pre>
-````````````````````````````````
-
-In the following example, a continuation paragraph of a list
-item is indented with a tab; this has exactly the same effect
-as indentation with four spaces would:
-
-```````````````````````````````` example
- - foo
-
-→bar
-.
-<ul>
-<li>
-<p>foo</p>
-<p>bar</p>
-</li>
-</ul>
-````````````````````````````````
-
-```````````````````````````````` example
-- foo
-
-→→bar
-.
-<ul>
-<li>
-<p>foo</p>
-<pre><code> bar
-</code></pre>
-</li>
-</ul>
-````````````````````````````````
-
-Normally the `>` that begins a block quote may be followed
-optionally by a space, which is not considered part of the
-content. In the following case `>` is followed by a tab,
-which is treated as if it were expanded into three spaces.
-Since one of these spaces is considered part of the
-delimiter, `foo` is considered to be indented six spaces
-inside the block quote context, so we get an indented
-code block starting with two spaces.
-
-```````````````````````````````` example
->→→foo
-.
-<blockquote>
-<pre><code> foo
-</code></pre>
-</blockquote>
-````````````````````````````````
-
-```````````````````````````````` example
--→→foo
-.
-<ul>
-<li>
-<pre><code> foo
-</code></pre>
-</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
- foo
-→bar
-.
-<pre><code>foo
-bar
-</code></pre>
-````````````````````````````````
-
-```````````````````````````````` example
- - foo
- - bar
-→ - baz
-.
-<ul>
-<li>foo
-<ul>
-<li>bar
-<ul>
-<li>baz</li>
-</ul>
-</li>
-</ul>
-</li>
-</ul>
-````````````````````````````````
-
-```````````````````````````````` example
-#→Foo
-.
-<h1>Foo</h1>
-````````````````````````````````
-
-```````````````````````````````` example
-*→*→*→
-.
-<hr />
-````````````````````````````````
-
-
-## Insecure characters
-
-For security reasons, the Unicode character `U+0000` must be replaced
-with the REPLACEMENT CHARACTER (`U+FFFD`).
-
-
-## Backslash escapes
-
-Any ASCII punctuation character may be backslash-escaped:
-
-```````````````````````````````` example
-\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~
-.
-<p>!&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~</p>
-````````````````````````````````
-
-
-Backslashes before other characters are treated as literal
-backslashes:
-
-```````````````````````````````` example
-\→\A\a\ \3\φ\«
-.
-<p>\→\A\a\ \3\φ\«</p>
-````````````````````````````````
-
-
-Escaped characters are treated as regular characters and do
-not have their usual Markdown meanings:
-
-```````````````````````````````` example
-\*not emphasized*
-\<br/> not a tag
-\[not a link](/foo)
-\`not code`
-1\. not a list
-\* not a list
-\# not a heading
-\[foo]: /url "not a reference"
-\&ouml; not a character entity
-.
-<p>*not emphasized*
-&lt;br/&gt; not a tag
-[not a link](/foo)
-`not code`
-1. not a list
-* not a list
-# not a heading
-[foo]: /url &quot;not a reference&quot;
-&amp;ouml; not a character entity</p>
-````````````````````````````````
-
-
-If a backslash is itself escaped, the following character is not:
-
-```````````````````````````````` example
-\\*emphasis*
-.
-<p>\<em>emphasis</em></p>
-````````````````````````````````
-
-
-A backslash at the end of the line is a [hard line break]:
-
-```````````````````````````````` example
-foo\
-bar
-.
-<p>foo<br />
-bar</p>
-````````````````````````````````
-
-
-Backslash escapes do not work in code blocks, code spans, autolinks, or
-raw HTML:
-
-```````````````````````````````` example
-`` \[\` ``
-.
-<p><code>\[\`</code></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
- \[\]
-.
-<pre><code>\[\]
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-~~~
-\[\]
-~~~
-.
-<pre><code>\[\]
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<http://example.com?find=\*>
-.
-<p><a href="http://example.com?find=%5C*">http://example.com?find=\*</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<a href="/bar\/)">
-.
-<a href="/bar\/)">
-````````````````````````````````
-
-
-But they work in all other contexts, including URLs and link titles,
-link references, and [info strings] in [fenced code blocks]:
-
-```````````````````````````````` example
-[foo](/bar\* "ti\*tle")
-.
-<p><a href="/bar*" title="ti*tle">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo]
-
-[foo]: /bar\* "ti\*tle"
-.
-<p><a href="/bar*" title="ti*tle">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-``` foo\+bar
-foo
-```
-.
-<pre><code class="language-foo+bar">foo
-</code></pre>
-````````````````````````````````
-
-
-## Entity and numeric character references
-
-Valid HTML entity references and numeric character references
-can be used in place of the corresponding Unicode character,
-with the following exceptions:
-
-- Entity and character references are not recognized in code
- blocks and code spans.
-
-- Entity and character references cannot stand in place of
- special characters that define structural elements in
- CommonMark. For example, although `&#42;` can be used
- in place of a literal `*` character, `&#42;` cannot replace
- `*` in emphasis delimiters, bullet list markers, or thematic
- breaks.
-
-Conforming CommonMark parsers need not store information about
-whether a particular character was represented in the source
-using a Unicode character or an entity reference.
-
-[Entity references](@) consist of `&` + any of the valid
-HTML5 entity names + `;`. The
-document <https://html.spec.whatwg.org/entities.json>
-is used as an authoritative source for the valid entity
-references and their corresponding code points.
-
-```````````````````````````````` example
-&nbsp; &amp; &copy; &AElig; &Dcaron;
-&frac34; &HilbertSpace; &DifferentialD;
-&ClockwiseContourIntegral; &ngE;
-.
-<p>  &amp; © Æ Ď
-¾ ℋ ⅆ
-∲ ≧̸</p>
-````````````````````````````````
-
-
-[Decimal numeric character
-references](@)
-consist of `&#` + a string of 1--7 arabic digits + `;`. A
-numeric character reference is parsed as the corresponding
-Unicode character. Invalid Unicode code points will be replaced by
-the REPLACEMENT CHARACTER (`U+FFFD`). For security reasons,
-the code point `U+0000` will also be replaced by `U+FFFD`.
-
-```````````````````````````````` example
-&#35; &#1234; &#992; &#0;
-.
-<p># Ӓ Ϡ �</p>
-````````````````````````````````
-
-
-[Hexadecimal numeric character
-references](@) consist of `&#` +
-either `X` or `x` + a string of 1-6 hexadecimal digits + `;`.
-They too are parsed as the corresponding Unicode character (this
-time specified with a hexadecimal numeral instead of decimal).
-
-```````````````````````````````` example
-&#X22; &#XD06; &#xcab;
-.
-<p>&quot; ആ ಫ</p>
-````````````````````````````````
-
-
-Here are some nonentities:
-
-```````````````````````````````` example
-&nbsp &x; &#; &#x;
-&#87654321;
-&#abcdef0;
-&ThisIsNotDefined; &hi?;
-.
-<p>&amp;nbsp &amp;x; &amp;#; &amp;#x;
-&amp;#87654321;
-&amp;#abcdef0;
-&amp;ThisIsNotDefined; &amp;hi?;</p>
-````````````````````````````````
-
-
-Although HTML5 does accept some entity references
-without a trailing semicolon (such as `&copy`), these are not
-recognized here, because it makes the grammar too ambiguous:
-
-```````````````````````````````` example
-&copy
-.
-<p>&amp;copy</p>
-````````````````````````````````
-
-
-Strings that are not on the list of HTML5 named entities are not
-recognized as entity references either:
-
-```````````````````````````````` example
-&MadeUpEntity;
-.
-<p>&amp;MadeUpEntity;</p>
-````````````````````````````````
-
-
-Entity and numeric character references are recognized in any
-context besides code spans or code blocks, including
-URLs, [link titles], and [fenced code block][] [info strings]:
-
-```````````````````````````````` example
-<a href="&ouml;&ouml;.html">
-.
-<a href="&ouml;&ouml;.html">
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo](/f&ouml;&ouml; "f&ouml;&ouml;")
-.
-<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo]
-
-[foo]: /f&ouml;&ouml; "f&ouml;&ouml;"
-.
-<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-``` f&ouml;&ouml;
-foo
-```
-.
-<pre><code class="language-föö">foo
-</code></pre>
-````````````````````````````````
-
-
-Entity and numeric character references are treated as literal
-text in code spans and code blocks:
-
-```````````````````````````````` example
-`f&ouml;&ouml;`
-.
-<p><code>f&amp;ouml;&amp;ouml;</code></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
- f&ouml;f&ouml;
-.
-<pre><code>f&amp;ouml;f&amp;ouml;
-</code></pre>
-````````````````````````````````
-
-
-Entity and numeric character references cannot be used
-in place of symbols indicating structure in CommonMark
-documents.
-
-```````````````````````````````` example
-&#42;foo&#42;
-*foo*
-.
-<p>*foo*
-<em>foo</em></p>
-````````````````````````````````
-
-```````````````````````````````` example
-&#42; foo
-
-* foo
-.
-<p>* foo</p>
-<ul>
-<li>foo</li>
-</ul>
-````````````````````````````````
-
-```````````````````````````````` example
-foo&#10;&#10;bar
-.
-<p>foo
-
-bar</p>
-````````````````````````````````
-
-```````````````````````````````` example
-&#9;foo
-.
-<p>→foo</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[a](url &quot;tit&quot;)
-.
-<p>[a](url &quot;tit&quot;)</p>
-````````````````````````````````
-
-
-
-# Blocks and inlines
-
-We can think of a document as a sequence of
-[blocks](@)---structural elements like paragraphs, block
-quotations, lists, headings, rules, and code blocks. Some blocks (like
-block quotes and list items) contain other blocks; others (like
-headings and paragraphs) contain [inline](@) content---text,
-links, emphasized text, images, code spans, and so on.
-
-## Precedence
-
-Indicators of block structure always take precedence over indicators
-of inline structure. So, for example, the following is a list with
-two items, not a list with one item containing a code span:
-
-```````````````````````````````` example
-- `one
-- two`
-.
-<ul>
-<li>`one</li>
-<li>two`</li>
-</ul>
-````````````````````````````````
-
-
-This means that parsing can proceed in two steps: first, the block
-structure of the document can be discerned; second, text lines inside
-paragraphs, headings, and other block constructs can be parsed for inline
-structure. The second step requires information about link reference
-definitions that will be available only at the end of the first
-step. Note that the first step requires processing lines in sequence,
-but the second can be parallelized, since the inline parsing of
-one block element does not affect the inline parsing of any other.
-
-## Container blocks and leaf blocks
-
-We can divide blocks into two types:
-[container blocks](@),
-which can contain other blocks, and [leaf blocks](@),
-which cannot.
-
-# Leaf blocks
-
-This section describes the different kinds of leaf block that make up a
-Markdown document.
-
-## Thematic breaks
-
-A line consisting of 0-3 spaces of indentation, followed by a sequence
-of three or more matching `-`, `_`, or `*` characters, each followed
-optionally by any number of spaces or tabs, forms a
-[thematic break](@).
-
-```````````````````````````````` example
-***
----
-___
-.
-<hr />
-<hr />
-<hr />
-````````````````````````````````
-
-
-Wrong characters:
-
-```````````````````````````````` example
-+++
-.
-<p>+++</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-===
-.
-<p>===</p>
-````````````````````````````````
-
-
-Not enough characters:
-
-```````````````````````````````` example
---
-**
-__
-.
-<p>--
-**
-__</p>
-````````````````````````````````
-
-
-One to three spaces indent are allowed:
-
-```````````````````````````````` example
- ***
- ***
- ***
-.
-<hr />
-<hr />
-<hr />
-````````````````````````````````
-
-
-Four spaces is too many:
-
-```````````````````````````````` example
- ***
-.
-<pre><code>***
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-Foo
- ***
-.
-<p>Foo
-***</p>
-````````````````````````````````
-
-
-More than three characters may be used:
-
-```````````````````````````````` example
-_____________________________________
-.
-<hr />
-````````````````````````````````
-
-
-Spaces are allowed between the characters:
-
-```````````````````````````````` example
- - - -
-.
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
- ** * ** * ** * **
-.
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
-- - - -
-.
-<hr />
-````````````````````````````````
-
-
-Spaces are allowed at the end:
-
-```````````````````````````````` example
-- - - -
-.
-<hr />
-````````````````````````````````
-
-
-However, no other characters may occur in the line:
-
-```````````````````````````````` example
-_ _ _ _ a
-
-a------
-
----a---
-.
-<p>_ _ _ _ a</p>
-<p>a------</p>
-<p>---a---</p>
-````````````````````````````````
-
-
-It is required that all of the [non-whitespace characters] be the same.
-So, this is not a thematic break:
-
-```````````````````````````````` example
- *-*
-.
-<p><em>-</em></p>
-````````````````````````````````
-
-
-Thematic breaks do not need blank lines before or after:
-
-```````````````````````````````` example
-- foo
-***
-- bar
-.
-<ul>
-<li>foo</li>
-</ul>
-<hr />
-<ul>
-<li>bar</li>
-</ul>
-````````````````````````````````
-
-
-Thematic breaks can interrupt a paragraph:
-
-```````````````````````````````` example
-Foo
-***
-bar
-.
-<p>Foo</p>
-<hr />
-<p>bar</p>
-````````````````````````````````
-
-
-If a line of dashes that meets the above conditions for being a
-thematic break could also be interpreted as the underline of a [setext
-heading], the interpretation as a
-[setext heading] takes precedence. Thus, for example,
-this is a setext heading, not a paragraph followed by a thematic break:
-
-```````````````````````````````` example
-Foo
----
-bar
-.
-<h2>Foo</h2>
-<p>bar</p>
-````````````````````````````````
-
-
-When both a thematic break and a list item are possible
-interpretations of a line, the thematic break takes precedence:
-
-```````````````````````````````` example
-* Foo
-* * *
-* Bar
-.
-<ul>
-<li>Foo</li>
-</ul>
-<hr />
-<ul>
-<li>Bar</li>
-</ul>
-````````````````````````````````
-
-
-If you want a thematic break in a list item, use a different bullet:
-
-```````````````````````````````` example
-- Foo
-- * * *
-.
-<ul>
-<li>Foo</li>
-<li>
-<hr />
-</li>
-</ul>
-````````````````````````````````
-
-
-## ATX headings
-
-An [ATX heading](@)
-consists of a string of characters, parsed as inline content, between an
-opening sequence of 1--6 unescaped `#` characters and an optional
-closing sequence of any number of unescaped `#` characters.
-The opening sequence of `#` characters must be followed by a
-[space] or by the end of line. The optional closing sequence of `#`s must be
-preceded by a [space] and may be followed by spaces only. The opening
-`#` character may be indented 0-3 spaces. The raw contents of the
-heading are stripped of leading and trailing spaces before being parsed
-as inline content. The heading level is equal to the number of `#`
-characters in the opening sequence.
-
-Simple headings:
-
-```````````````````````````````` example
-# foo
-## foo
-### foo
-#### foo
-##### foo
-###### foo
-.
-<h1>foo</h1>
-<h2>foo</h2>
-<h3>foo</h3>
-<h4>foo</h4>
-<h5>foo</h5>
-<h6>foo</h6>
-````````````````````````````````
-
-
-More than six `#` characters is not a heading:
-
-```````````````````````````````` example
-####### foo
-.
-<p>####### foo</p>
-````````````````````````````````
-
-
-At least one space is required between the `#` characters and the
-heading's contents, unless the heading is empty. Note that many
-implementations currently do not require the space. However, the
-space was required by the
-[original ATX implementation](http://www.aaronsw.com/2002/atx/atx.py),
-and it helps prevent things like the following from being parsed as
-headings:
-
-```````````````````````````````` example
-#5 bolt
-
-#hashtag
-.
-<p>#5 bolt</p>
-<p>#hashtag</p>
-````````````````````````````````
-
-
-This is not a heading, because the first `#` is escaped:
-
-```````````````````````````````` example
-\## foo
-.
-<p>## foo</p>
-````````````````````````````````
-
-
-Contents are parsed as inlines:
-
-```````````````````````````````` example
-# foo *bar* \*baz\*
-.
-<h1>foo <em>bar</em> *baz*</h1>
-````````````````````````````````
-
-
-Leading and trailing [whitespace] is ignored in parsing inline content:
-
-```````````````````````````````` example
-# foo
-.
-<h1>foo</h1>
-````````````````````````````````
-
-
-One to three spaces indentation are allowed:
-
-```````````````````````````````` example
- ### foo
- ## foo
- # foo
-.
-<h3>foo</h3>
-<h2>foo</h2>
-<h1>foo</h1>
-````````````````````````````````
-
-
-Four spaces are too much:
-
-```````````````````````````````` example
- # foo
-.
-<pre><code># foo
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo
- # bar
-.
-<p>foo
-# bar</p>
-````````````````````````````````
-
-
-A closing sequence of `#` characters is optional:
-
-```````````````````````````````` example
-## foo ##
- ### bar ###
-.
-<h2>foo</h2>
-<h3>bar</h3>
-````````````````````````````````
-
-
-It need not be the same length as the opening sequence:
-
-```````````````````````````````` example
-# foo ##################################
-##### foo ##
-.
-<h1>foo</h1>
-<h5>foo</h5>
-````````````````````````````````
-
-
-Spaces are allowed after the closing sequence:
-
-```````````````````````````````` example
-### foo ###
-.
-<h3>foo</h3>
-````````````````````````````````
-
-
-A sequence of `#` characters with anything but [spaces] following it
-is not a closing sequence, but counts as part of the contents of the
-heading:
-
-```````````````````````````````` example
-### foo ### b
-.
-<h3>foo ### b</h3>
-````````````````````````````````
-
-
-The closing sequence must be preceded by a space:
-
-```````````````````````````````` example
-# foo#
-.
-<h1>foo#</h1>
-````````````````````````````````
-
-
-Backslash-escaped `#` characters do not count as part
-of the closing sequence:
-
-```````````````````````````````` example
-### foo \###
-## foo #\##
-# foo \#
-.
-<h3>foo ###</h3>
-<h2>foo ###</h2>
-<h1>foo #</h1>
-````````````````````````````````
-
-
-ATX headings need not be separated from surrounding content by blank
-lines, and they can interrupt paragraphs:
-
-```````````````````````````````` example
-****
-## foo
-****
-.
-<hr />
-<h2>foo</h2>
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
-Foo bar
-# baz
-Bar foo
-.
-<p>Foo bar</p>
-<h1>baz</h1>
-<p>Bar foo</p>
-````````````````````````````````
-
-
-ATX headings can be empty:
-
-```````````````````````````````` example
-##
-#
-### ###
-.
-<h2></h2>
-<h1></h1>
-<h3></h3>
-````````````````````````````````
-
-
-## Setext headings
-
-A [setext heading](@) consists of one or more
-lines of text, each containing at least one [non-whitespace
-character], with no more than 3 spaces indentation, followed by
-a [setext heading underline]. The lines of text must be such
-that, were they not followed by the setext heading underline,
-they would be interpreted as a paragraph: they cannot be
-interpretable as a [code fence], [ATX heading][ATX headings],
-[block quote][block quotes], [thematic break][thematic breaks],
-[list item][list items], or [HTML block][HTML blocks].
-
-A [setext heading underline](@) is a sequence of
-`=` characters or a sequence of `-` characters, with no more than 3
-spaces indentation and any number of trailing spaces. If a line
-containing a single `-` can be interpreted as an
-empty [list items], it should be interpreted this way
-and not as a [setext heading underline].
-
-The heading is a level 1 heading if `=` characters are used in
-the [setext heading underline], and a level 2 heading if `-`
-characters are used. The contents of the heading are the result
-of parsing the preceding lines of text as CommonMark inline
-content.
-
-In general, a setext heading need not be preceded or followed by a
-blank line. However, it cannot interrupt a paragraph, so when a
-setext heading comes after a paragraph, a blank line is needed between
-them.
-
-Simple examples:
-
-```````````````````````````````` example
-Foo *bar*
-=========
-
-Foo *bar*
----------
-.
-<h1>Foo <em>bar</em></h1>
-<h2>Foo <em>bar</em></h2>
-````````````````````````````````
-
-
-The content of the header may span more than one line:
-
-```````````````````````````````` example
-Foo *bar
-baz*
-====
-.
-<h1>Foo <em>bar
-baz</em></h1>
-````````````````````````````````
-
-The contents are the result of parsing the headings's raw
-content as inlines. The heading's raw content is formed by
-concatenating the lines and removing initial and final
-[whitespace].
-
-```````````````````````````````` example
- Foo *bar
-baz*→
-====
-.
-<h1>Foo <em>bar
-baz</em></h1>
-````````````````````````````````
-
-
-The underlining can be any length:
-
-```````````````````````````````` example
-Foo
--------------------------
-
-Foo
-=
-.
-<h2>Foo</h2>
-<h1>Foo</h1>
-````````````````````````````````
-
-
-The heading content can be indented up to three spaces, and need
-not line up with the underlining:
-
-```````````````````````````````` example
- Foo
----
-
- Foo
------
-
- Foo
- ===
-.
-<h2>Foo</h2>
-<h2>Foo</h2>
-<h1>Foo</h1>
-````````````````````````````````
-
-
-Four spaces indent is too much:
-
-```````````````````````````````` example
- Foo
- ---
-
- Foo
----
-.
-<pre><code>Foo
----
-
-Foo
-</code></pre>
-<hr />
-````````````````````````````````
-
-
-The setext heading underline can be indented up to three spaces, and
-may have trailing spaces:
-
-```````````````````````````````` example
-Foo
- ----
-.
-<h2>Foo</h2>
-````````````````````````````````
-
-
-Four spaces is too much:
-
-```````````````````````````````` example
-Foo
- ---
-.
-<p>Foo
----</p>
-````````````````````````````````
-
-
-The setext heading underline cannot contain internal spaces:
-
-```````````````````````````````` example
-Foo
-= =
-
-Foo
---- -
-.
-<p>Foo
-= =</p>
-<p>Foo</p>
-<hr />
-````````````````````````````````
-
-
-Trailing spaces in the content line do not cause a line break:
-
-```````````````````````````````` example
-Foo
------
-.
-<h2>Foo</h2>
-````````````````````````````````
-
-
-Nor does a backslash at the end:
-
-```````````````````````````````` example
-Foo\
-----
-.
-<h2>Foo\</h2>
-````````````````````````````````
-
-
-Since indicators of block structure take precedence over
-indicators of inline structure, the following are setext headings:
-
-```````````````````````````````` example
-`Foo
-----
-`
-
-<a title="a lot
----
-of dashes"/>
-.
-<h2>`Foo</h2>
-<p>`</p>
-<h2>&lt;a title=&quot;a lot</h2>
-<p>of dashes&quot;/&gt;</p>
-````````````````````````````````
-
-
-The setext heading underline cannot be a [lazy continuation
-line] in a list item or block quote:
-
-```````````````````````````````` example
-> Foo
----
-.
-<blockquote>
-<p>Foo</p>
-</blockquote>
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
-> foo
-bar
-===
-.
-<blockquote>
-<p>foo
-bar
-===</p>
-</blockquote>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- Foo
----
-.
-<ul>
-<li>Foo</li>
-</ul>
-<hr />
-````````````````````````````````
-
-
-A blank line is needed between a paragraph and a following
-setext heading, since otherwise the paragraph becomes part
-of the heading's content:
-
-```````````````````````````````` example
-Foo
-Bar
----
-.
-<h2>Foo
-Bar</h2>
-````````````````````````````````
-
-
-But in general a blank line is not required before or after
-setext headings:
-
-```````````````````````````````` example
----
-Foo
----
-Bar
----
-Baz
-.
-<hr />
-<h2>Foo</h2>
-<h2>Bar</h2>
-<p>Baz</p>
-````````````````````````````````
-
-
-Setext headings cannot be empty:
-
-```````````````````````````````` example
-
-====
-.
-<p>====</p>
-````````````````````````````````
-
-
-Setext heading text lines must not be interpretable as block
-constructs other than paragraphs. So, the line of dashes
-in these examples gets interpreted as a thematic break:
-
-```````````````````````````````` example
----
----
-.
-<hr />
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
-- foo
------
-.
-<ul>
-<li>foo</li>
-</ul>
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
- foo
----
-.
-<pre><code>foo
-</code></pre>
-<hr />
-````````````````````````````````
-
-
-```````````````````````````````` example
-> foo
------
-.
-<blockquote>
-<p>foo</p>
-</blockquote>
-<hr />
-````````````````````````````````
-
-
-If you want a heading with `> foo` as its literal text, you can
-use backslash escapes:
-
-```````````````````````````````` example
-\> foo
-------
-.
-<h2>&gt; foo</h2>
-````````````````````````````````
-
-
-**Compatibility note:** Most existing Markdown implementations
-do not allow the text of setext headings to span multiple lines.
-But there is no consensus about how to interpret
-
-``` markdown
-Foo
-bar
----
-baz
-```
-
-One can find four different interpretations:
-
-1. paragraph "Foo", heading "bar", paragraph "baz"
-2. paragraph "Foo bar", thematic break, paragraph "baz"
-3. paragraph "Foo bar --- baz"
-4. heading "Foo bar", paragraph "baz"
-
-We find interpretation 4 most natural, and interpretation 4
-increases the expressive power of CommonMark, by allowing
-multiline headings. Authors who want interpretation 1 can
-put a blank line after the first paragraph:
-
-```````````````````````````````` example
-Foo
-
-bar
----
-baz
-.
-<p>Foo</p>
-<h2>bar</h2>
-<p>baz</p>
-````````````````````````````````
-
-
-Authors who want interpretation 2 can put blank lines around
-the thematic break,
-
-```````````````````````````````` example
-Foo
-bar
-
----
-
-baz
-.
-<p>Foo
-bar</p>
-<hr />
-<p>baz</p>
-````````````````````````````````
-
-
-or use a thematic break that cannot count as a [setext heading
-underline], such as
-
-```````````````````````````````` example
-Foo
-bar
-* * *
-baz
-.
-<p>Foo
-bar</p>
-<hr />
-<p>baz</p>
-````````````````````````````````
-
-
-Authors who want interpretation 3 can use backslash escapes:
-
-```````````````````````````````` example
-Foo
-bar
-\---
-baz
-.
-<p>Foo
-bar
----
-baz</p>
-````````````````````````````````
-
-
-## Indented code blocks
-
-An [indented code block](@) is composed of one or more
-[indented chunks] separated by blank lines.
-An [indented chunk](@) is a sequence of non-blank lines,
-each indented four or more spaces. The contents of the code block are
-the literal contents of the lines, including trailing
-[line endings], minus four spaces of indentation.
-An indented code block has no [info string].
-
-An indented code block cannot interrupt a paragraph, so there must be
-a blank line between a paragraph and a following indented code block.
-(A blank line is not needed, however, between a code block and a following
-paragraph.)
-
-```````````````````````````````` example
- a simple
- indented code block
-.
-<pre><code>a simple
- indented code block
-</code></pre>
-````````````````````````````````
-
-
-If there is any ambiguity between an interpretation of indentation
-as a code block and as indicating that material belongs to a [list
-item][list items], the list item interpretation takes precedence:
-
-```````````````````````````````` example
- - foo
-
- bar
-.
-<ul>
-<li>
-<p>foo</p>
-<p>bar</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-1. foo
-
- - bar
-.
-<ol>
-<li>
-<p>foo</p>
-<ul>
-<li>bar</li>
-</ul>
-</li>
-</ol>
-````````````````````````````````
-
-
-
-The contents of a code block are literal text, and do not get parsed
-as Markdown:
-
-```````````````````````````````` example
- <a/>
- *hi*
-
- - one
-.
-<pre><code>&lt;a/&gt;
-*hi*
-
-- one
-</code></pre>
-````````````````````````````````
-
-
-Here we have three chunks separated by blank lines:
-
-```````````````````````````````` example
- chunk1
-
- chunk2
-
-
-
- chunk3
-.
-<pre><code>chunk1
-
-chunk2
-
-
-
-chunk3
-</code></pre>
-````````````````````````````````
-
-
-Any initial spaces beyond four will be included in the content, even
-in interior blank lines:
-
-```````````````````````````````` example
- chunk1
-
- chunk2
-.
-<pre><code>chunk1
-
- chunk2
-</code></pre>
-````````````````````````````````
-
-
-An indented code block cannot interrupt a paragraph. (This
-allows hanging indents and the like.)
-
-```````````````````````````````` example
-Foo
- bar
-
-.
-<p>Foo
-bar</p>
-````````````````````````````````
-
-
-However, any non-blank line with fewer than four leading spaces ends
-the code block immediately. So a paragraph may occur immediately
-after indented code:
-
-```````````````````````````````` example
- foo
-bar
-.
-<pre><code>foo
-</code></pre>
-<p>bar</p>
-````````````````````````````````
-
-
-And indented code can occur immediately before and after other kinds of
-blocks:
-
-```````````````````````````````` example
-# Heading
- foo
-Heading
-------
- foo
-----
-.
-<h1>Heading</h1>
-<pre><code>foo
-</code></pre>
-<h2>Heading</h2>
-<pre><code>foo
-</code></pre>
-<hr />
-````````````````````````````````
-
-
-The first line can be indented more than four spaces:
-
-```````````````````````````````` example
- foo
- bar
-.
-<pre><code> foo
-bar
-</code></pre>
-````````````````````````````````
-
-
-Blank lines preceding or following an indented code block
-are not included in it:
-
-```````````````````````````````` example
-
-
- foo
-
-
-.
-<pre><code>foo
-</code></pre>
-````````````````````````````````
-
-
-Trailing spaces are included in the code block's content:
-
-```````````````````````````````` example
- foo
-.
-<pre><code>foo
-</code></pre>
-````````````````````````````````
-
-
-
-## Fenced code blocks
-
-A [code fence](@) is a sequence
-of at least three consecutive backtick characters (`` ` ``) or
-tildes (`~`). (Tildes and backticks cannot be mixed.)
-A [fenced code block](@)
-begins with a code fence, indented no more than three spaces.
-
-The line with the opening code fence may optionally contain some text
-following the code fence; this is trimmed of leading and trailing
-whitespace and called the [info string](@). If the [info string] comes
-after a backtick fence, it may not contain any backtick
-characters. (The reason for this restriction is that otherwise
-some inline code would be incorrectly interpreted as the
-beginning of a fenced code block.)
-
-The content of the code block consists of all subsequent lines, until
-a closing [code fence] of the same type as the code block
-began with (backticks or tildes), and with at least as many backticks
-or tildes as the opening code fence. If the leading code fence is
-indented N spaces, then up to N spaces of indentation are removed from
-each line of the content (if present). (If a content line is not
-indented, it is preserved unchanged. If it is indented less than N
-spaces, all of the indentation is removed.)
-
-The closing code fence may be indented up to three spaces, and may be
-followed only by spaces, which are ignored. If the end of the
-containing block (or document) is reached and no closing code fence
-has been found, the code block contains all of the lines after the
-opening code fence until the end of the containing block (or
-document). (An alternative spec would require backtracking in the
-event that a closing code fence is not found. But this makes parsing
-much less efficient, and there seems to be no real down side to the
-behavior described here.)
-
-A fenced code block may interrupt a paragraph, and does not require
-a blank line either before or after.
-
-The content of a code fence is treated as literal text, not parsed
-as inlines. The first word of the [info string] is typically used to
-specify the language of the code sample, and rendered in the `class`
-attribute of the `code` tag. However, this spec does not mandate any
-particular treatment of the [info string].
-
-Here is a simple example with backticks:
-
-```````````````````````````````` example
-```
-<
- >
-```
-.
-<pre><code>&lt;
- &gt;
-</code></pre>
-````````````````````````````````
-
-
-With tildes:
-
-```````````````````````````````` example
-~~~
-<
- >
-~~~
-.
-<pre><code>&lt;
- &gt;
-</code></pre>
-````````````````````````````````
-
-Fewer than three backticks is not enough:
-
-```````````````````````````````` example
-``
-foo
-``
-.
-<p><code>foo</code></p>
-````````````````````````````````
-
-The closing code fence must use the same character as the opening
-fence:
-
-```````````````````````````````` example
-```
-aaa
-~~~
-```
-.
-<pre><code>aaa
-~~~
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-~~~
-aaa
-```
-~~~
-.
-<pre><code>aaa
-```
-</code></pre>
-````````````````````````````````
-
-
-The closing code fence must be at least as long as the opening fence:
-
-```````````````````````````````` example
-````
-aaa
-```
-``````
-.
-<pre><code>aaa
-```
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-~~~~
-aaa
-~~~
-~~~~
-.
-<pre><code>aaa
-~~~
-</code></pre>
-````````````````````````````````
-
-
-Unclosed code blocks are closed by the end of the document
-(or the enclosing [block quote][block quotes] or [list item][list items]):
-
-```````````````````````````````` example
-```
-.
-<pre><code></code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-`````
-
-```
-aaa
-.
-<pre><code>
-```
-aaa
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-> ```
-> aaa
-
-bbb
-.
-<blockquote>
-<pre><code>aaa
-</code></pre>
-</blockquote>
-<p>bbb</p>
-````````````````````````````````
-
-
-A code block can have all empty lines as its content:
-
-```````````````````````````````` example
-```
-
-
-```
-.
-<pre><code>
-
-</code></pre>
-````````````````````````````````
-
-
-A code block can be empty:
-
-```````````````````````````````` example
-```
-```
-.
-<pre><code></code></pre>
-````````````````````````````````
-
-
-Fences can be indented. If the opening fence is indented,
-content lines will have equivalent opening indentation removed,
-if present:
-
-```````````````````````````````` example
- ```
- aaa
-aaa
-```
-.
-<pre><code>aaa
-aaa
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
- ```
-aaa
- aaa
-aaa
- ```
-.
-<pre><code>aaa
-aaa
-aaa
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
- ```
- aaa
- aaa
- aaa
- ```
-.
-<pre><code>aaa
- aaa
-aaa
-</code></pre>
-````````````````````````````````
-
-
-Four spaces indentation produces an indented code block:
-
-```````````````````````````````` example
- ```
- aaa
- ```
-.
-<pre><code>```
-aaa
-```
-</code></pre>
-````````````````````````````````
-
-
-Closing fences may be indented by 0-3 spaces, and their indentation
-need not match that of the opening fence:
-
-```````````````````````````````` example
-```
-aaa
- ```
-.
-<pre><code>aaa
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
- ```
-aaa
- ```
-.
-<pre><code>aaa
-</code></pre>
-````````````````````````````````
-
-
-This is not a closing fence, because it is indented 4 spaces:
-
-```````````````````````````````` example
-```
-aaa
- ```
-.
-<pre><code>aaa
- ```
-</code></pre>
-````````````````````````````````
-
-
-
-Code fences (opening and closing) cannot contain internal spaces:
-
-```````````````````````````````` example
-``` ```
-aaa
-.
-<p><code> </code>
-aaa</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-~~~~~~
-aaa
-~~~ ~~
-.
-<pre><code>aaa
-~~~ ~~
-</code></pre>
-````````````````````````````````
-
-
-Fenced code blocks can interrupt paragraphs, and can be followed
-directly by paragraphs, without a blank line between:
-
-```````````````````````````````` example
-foo
-```
-bar
-```
-baz
-.
-<p>foo</p>
-<pre><code>bar
-</code></pre>
-<p>baz</p>
-````````````````````````````````
-
-
-Other blocks can also occur before and after fenced code blocks
-without an intervening blank line:
-
-```````````````````````````````` example
-foo
----
-~~~
-bar
-~~~
-# baz
-.
-<h2>foo</h2>
-<pre><code>bar
-</code></pre>
-<h1>baz</h1>
-````````````````````````````````
-
-
-An [info string] can be provided after the opening code fence.
-Although this spec doesn't mandate any particular treatment of
-the info string, the first word is typically used to specify
-the language of the code block. In HTML output, the language is
-normally indicated by adding a class to the `code` element consisting
-of `language-` followed by the language name.
-
-```````````````````````````````` example
-```ruby
-def foo(x)
- return 3
-end
-```
-.
-<pre><code class="language-ruby">def foo(x)
- return 3
-end
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-~~~~ ruby startline=3 $%@#$
-def foo(x)
- return 3
-end
-~~~~~~~
-.
-<pre><code class="language-ruby">def foo(x)
- return 3
-end
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-````;
-````
-.
-<pre><code class="language-;"></code></pre>
-````````````````````````````````
-
-
-[Info strings] for backtick code blocks cannot contain backticks:
-
-```````````````````````````````` example
-``` aa ```
-foo
-.
-<p><code>aa</code>
-foo</p>
-````````````````````````````````
-
-
-[Info strings] for tilde code blocks can contain backticks and tildes:
-
-```````````````````````````````` example
-~~~ aa ``` ~~~
-foo
-~~~
-.
-<pre><code class="language-aa">foo
-</code></pre>
-````````````````````````````````
-
-
-Closing code fences cannot have [info strings]:
-
-```````````````````````````````` example
-```
-``` aaa
-```
-.
-<pre><code>``` aaa
-</code></pre>
-````````````````````````````````
-
-
-
-## HTML blocks
-
-An [HTML block](@) is a group of lines that is treated
-as raw HTML (and will not be escaped in HTML output).
-
-There are seven kinds of [HTML block], which can be defined by their
-start and end conditions. The block begins with a line that meets a
-[start condition](@) (after up to three spaces optional indentation).
-It ends with the first subsequent line that meets a matching [end
-condition](@), or the last line of the document, or the last line of
-the [container block](#container-blocks) containing the current HTML
-block, if no line is encountered that meets the [end condition]. If
-the first line meets both the [start condition] and the [end
-condition], the block will contain just that line.
-
-1. **Start condition:** line begins with the string `<script`,
-`<pre`, or `<style` (case-insensitive), followed by whitespace,
-the string `>`, or the end of the line.\
-**End condition:** line contains an end tag
-`</script>`, `</pre>`, or `</style>` (case-insensitive; it
-need not match the start tag).
-
-2. **Start condition:** line begins with the string `<!--`.\
-**End condition:** line contains the string `-->`.
-
-3. **Start condition:** line begins with the string `<?`.\
-**End condition:** line contains the string `?>`.
-
-4. **Start condition:** line begins with the string `<!`
-followed by an ASCII letter.\
-**End condition:** line contains the character `>`.
-
-5. **Start condition:** line begins with the string
-`<![CDATA[`.\
-**End condition:** line contains the string `]]>`.
-
-6. **Start condition:** line begins the string `<` or `</`
-followed by one of the strings (case-insensitive) `address`,
-`article`, `aside`, `base`, `basefont`, `blockquote`, `body`,
-`caption`, `center`, `col`, `colgroup`, `dd`, `details`, `dialog`,
-`dir`, `div`, `dl`, `dt`, `fieldset`, `figcaption`, `figure`,
-`footer`, `form`, `frame`, `frameset`,
-`h1`, `h2`, `h3`, `h4`, `h5`, `h6`, `head`, `header`, `hr`,
-`html`, `iframe`, `legend`, `li`, `link`, `main`, `menu`, `menuitem`,
-`nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`,
-`section`, `source`, `summary`, `table`, `tbody`, `td`,
-`tfoot`, `th`, `thead`, `title`, `tr`, `track`, `ul`, followed
-by [whitespace], the end of the line, the string `>`, or
-the string `/>`.\
-**End condition:** line is followed by a [blank line].
-
-7. **Start condition:** line begins with a complete [open tag]
-(with any [tag name] other than `script`,
-`style`, or `pre`) or a complete [closing tag],
-followed only by [whitespace] or the end of the line.\
-**End condition:** line is followed by a [blank line].
-
-HTML blocks continue until they are closed by their appropriate
-[end condition], or the last line of the document or other [container
-block](#container-blocks). This means any HTML **within an HTML
-block** that might otherwise be recognised as a start condition will
-be ignored by the parser and passed through as-is, without changing
-the parser's state.
-
-For instance, `<pre>` within a HTML block started by `<table>` will not affect
-the parser state; as the HTML block was started in by start condition 6, it
-will end at any blank line. This can be surprising:
-
-```````````````````````````````` example
-<table><tr><td>
-<pre>
-**Hello**,
-
-_world_.
-</pre>
-</td></tr></table>
-.
-<table><tr><td>
-<pre>
-**Hello**,
-<p><em>world</em>.
-</pre></p>
-</td></tr></table>
-````````````````````````````````
-
-In this case, the HTML block is terminated by the newline — the `**Hello**`
-text remains verbatim — and regular parsing resumes, with a paragraph,
-emphasised `world` and inline and block HTML following.
-
-All types of [HTML blocks] except type 7 may interrupt
-a paragraph. Blocks of type 7 may not interrupt a paragraph.
-(This restriction is intended to prevent unwanted interpretation
-of long tags inside a wrapped paragraph as starting HTML blocks.)
-
-Some simple examples follow. Here are some basic HTML blocks
-of type 6:
-
-```````````````````````````````` example
-<table>
- <tr>
- <td>
- hi
- </td>
- </tr>
-</table>
-
-okay.
-.
-<table>
- <tr>
- <td>
- hi
- </td>
- </tr>
-</table>
-<p>okay.</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
- <div>
- *hello*
- <foo><a>
-.
- <div>
- *hello*
- <foo><a>
-````````````````````````````````
-
-
-A block can also start with a closing tag:
-
-```````````````````````````````` example
-</div>
-*foo*
-.
-</div>
-*foo*
-````````````````````````````````
-
-
-Here we have two HTML blocks with a Markdown paragraph between them:
-
-```````````````````````````````` example
-<DIV CLASS="foo">
-
-*Markdown*
-
-</DIV>
-.
-<DIV CLASS="foo">
-<p><em>Markdown</em></p>
-</DIV>
-````````````````````````````````
-
-
-The tag on the first line can be partial, as long
-as it is split where there would be whitespace:
-
-```````````````````````````````` example
-<div id="foo"
- class="bar">
-</div>
-.
-<div id="foo"
- class="bar">
-</div>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<div id="foo" class="bar
- baz">
-</div>
-.
-<div id="foo" class="bar
- baz">
-</div>
-````````````````````````````````
-
-
-An open tag need not be closed:
-```````````````````````````````` example
-<div>
-*foo*
-
-*bar*
-.
-<div>
-*foo*
-<p><em>bar</em></p>
-````````````````````````````````
-
-
-
-A partial tag need not even be completed (garbage
-in, garbage out):
-
-```````````````````````````````` example
-<div id="foo"
-*hi*
-.
-<div id="foo"
-*hi*
-````````````````````````````````
-
-
-```````````````````````````````` example
-<div class
-foo
-.
-<div class
-foo
-````````````````````````````````
-
-
-The initial tag doesn't even need to be a valid
-tag, as long as it starts like one:
-
-```````````````````````````````` example
-<div *???-&&&-<---
-*foo*
-.
-<div *???-&&&-<---
-*foo*
-````````````````````````````````
-
-
-In type 6 blocks, the initial tag need not be on a line by
-itself:
-
-```````````````````````````````` example
-<div><a href="bar">*foo*</a></div>
-.
-<div><a href="bar">*foo*</a></div>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<table><tr><td>
-foo
-</td></tr></table>
-.
-<table><tr><td>
-foo
-</td></tr></table>
-````````````````````````````````
-
-
-Everything until the next blank line or end of document
-gets included in the HTML block. So, in the following
-example, what looks like a Markdown code block
-is actually part of the HTML block, which continues until a blank
-line or the end of the document is reached:
-
-```````````````````````````````` example
-<div></div>
-``` c
-int x = 33;
-```
-.
-<div></div>
-``` c
-int x = 33;
-```
-````````````````````````````````
-
-
-To start an [HTML block] with a tag that is *not* in the
-list of block-level tags in (6), you must put the tag by
-itself on the first line (and it must be complete):
-
-```````````````````````````````` example
-<a href="foo">
-*bar*
-</a>
-.
-<a href="foo">
-*bar*
-</a>
-````````````````````````````````
-
-
-In type 7 blocks, the [tag name] can be anything:
-
-```````````````````````````````` example
-<Warning>
-*bar*
-</Warning>
-.
-<Warning>
-*bar*
-</Warning>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<i class="foo">
-*bar*
-</i>
-.
-<i class="foo">
-*bar*
-</i>
-````````````````````````````````
-
-
-```````````````````````````````` example
-</ins>
-*bar*
-.
-</ins>
-*bar*
-````````````````````````````````
-
-
-These rules are designed to allow us to work with tags that
-can function as either block-level or inline-level tags.
-The `<del>` tag is a nice example. We can surround content with
-`<del>` tags in three different ways. In this case, we get a raw
-HTML block, because the `<del>` tag is on a line by itself:
-
-```````````````````````````````` example
-<del>
-*foo*
-</del>
-.
-<del>
-*foo*
-</del>
-````````````````````````````````
-
-
-In this case, we get a raw HTML block that just includes
-the `<del>` tag (because it ends with the following blank
-line). So the contents get interpreted as CommonMark:
-
-```````````````````````````````` example
-<del>
-
-*foo*
-
-</del>
-.
-<del>
-<p><em>foo</em></p>
-</del>
-````````````````````````````````
-
-
-Finally, in this case, the `<del>` tags are interpreted
-as [raw HTML] *inside* the CommonMark paragraph. (Because
-the tag is not on a line by itself, we get inline HTML
-rather than an [HTML block].)
-
-```````````````````````````````` example
-<del>*foo*</del>
-.
-<p><del><em>foo</em></del></p>
-````````````````````````````````
-
-
-HTML tags designed to contain literal content
-(`script`, `style`, `pre`), comments, processing instructions,
-and declarations are treated somewhat differently.
-Instead of ending at the first blank line, these blocks
-end at the first line containing a corresponding end tag.
-As a result, these blocks can contain blank lines:
-
-A pre tag (type 1):
-
-```````````````````````````````` example
-<pre language="haskell"><code>
-import Text.HTML.TagSoup
-
-main :: IO ()
-main = print $ parseTags tags
-</code></pre>
-okay
-.
-<pre language="haskell"><code>
-import Text.HTML.TagSoup
-
-main :: IO ()
-main = print $ parseTags tags
-</code></pre>
-<p>okay</p>
-````````````````````````````````
-
-
-A script tag (type 1):
-
-```````````````````````````````` example
-<script type="text/javascript">
-// JavaScript example
-
-document.getElementById("demo").innerHTML = "Hello JavaScript!";
-</script>
-okay
-.
-<script type="text/javascript">
-// JavaScript example
-
-document.getElementById("demo").innerHTML = "Hello JavaScript!";
-</script>
-<p>okay</p>
-````````````````````````````````
-
-
-A style tag (type 1):
-
-```````````````````````````````` example
-<style
- type="text/css">
-h1 {color:red;}
-
-p {color:blue;}
-</style>
-okay
-.
-<style
- type="text/css">
-h1 {color:red;}
-
-p {color:blue;}
-</style>
-<p>okay</p>
-````````````````````````````````
-
-
-If there is no matching end tag, the block will end at the
-end of the document (or the enclosing [block quote][block quotes]
-or [list item][list items]):
-
-```````````````````````````````` example
-<style
- type="text/css">
-
-foo
-.
-<style
- type="text/css">
-
-foo
-````````````````````````````````
-
-
-```````````````````````````````` example
-> <div>
-> foo
-
-bar
-.
-<blockquote>
-<div>
-foo
-</blockquote>
-<p>bar</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- <div>
-- foo
-.
-<ul>
-<li>
-<div>
-</li>
-<li>foo</li>
-</ul>
-````````````````````````````````
-
-
-The end tag can occur on the same line as the start tag:
-
-```````````````````````````````` example
-<style>p{color:red;}</style>
-*foo*
-.
-<style>p{color:red;}</style>
-<p><em>foo</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<!-- foo -->*bar*
-*baz*
-.
-<!-- foo -->*bar*
-<p><em>baz</em></p>
-````````````````````````````````
-
-
-Note that anything on the last line after the
-end tag will be included in the [HTML block]:
-
-```````````````````````````````` example
-<script>
-foo
-</script>1. *bar*
-.
-<script>
-foo
-</script>1. *bar*
-````````````````````````````````
-
-
-A comment (type 2):
-
-```````````````````````````````` example
-<!-- Foo
-
-bar
- baz -->
-okay
-.
-<!-- Foo
-
-bar
- baz -->
-<p>okay</p>
-````````````````````````````````
-
-
-
-A processing instruction (type 3):
-
-```````````````````````````````` example
-<?php
-
- echo '>';
-
-?>
-okay
-.
-<?php
-
- echo '>';
-
-?>
-<p>okay</p>
-````````````````````````````````
-
-
-A declaration (type 4):
-
-```````````````````````````````` example
-<!DOCTYPE html>
-.
-<!DOCTYPE html>
-````````````````````````````````
-
-
-CDATA (type 5):
-
-```````````````````````````````` example
-<![CDATA[
-function matchwo(a,b)
-{
- if (a < b && a < 0) then {
- return 1;
-
- } else {
-
- return 0;
- }
-}
-]]>
-okay
-.
-<![CDATA[
-function matchwo(a,b)
-{
- if (a < b && a < 0) then {
- return 1;
-
- } else {
-
- return 0;
- }
-}
-]]>
-<p>okay</p>
-````````````````````````````````
-
-
-The opening tag can be indented 1-3 spaces, but not 4:
-
-```````````````````````````````` example
- <!-- foo -->
-
- <!-- foo -->
-.
- <!-- foo -->
-<pre><code>&lt;!-- foo --&gt;
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
- <div>
-
- <div>
-.
- <div>
-<pre><code>&lt;div&gt;
-</code></pre>
-````````````````````````````````
-
-
-An HTML block of types 1--6 can interrupt a paragraph, and need not be
-preceded by a blank line.
-
-```````````````````````````````` example
-Foo
-<div>
-bar
-</div>
-.
-<p>Foo</p>
-<div>
-bar
-</div>
-````````````````````````````````
-
-
-However, a following blank line is needed, except at the end of
-a document, and except for blocks of types 1--5, [above][HTML
-block]:
-
-```````````````````````````````` example
-<div>
-bar
-</div>
-*foo*
-.
-<div>
-bar
-</div>
-*foo*
-````````````````````````````````
-
-
-HTML blocks of type 7 cannot interrupt a paragraph:
-
-```````````````````````````````` example
-Foo
-<a href="bar">
-baz
-.
-<p>Foo
-<a href="bar">
-baz</p>
-````````````````````````````````
-
-
-This rule differs from John Gruber's original Markdown syntax
-specification, which says:
-
-> The only restrictions are that block-level HTML elements —
-> e.g. `<div>`, `<table>`, `<pre>`, `<p>`, etc. — must be separated from
-> surrounding content by blank lines, and the start and end tags of the
-> block should not be indented with tabs or spaces.
-
-In some ways Gruber's rule is more restrictive than the one given
-here:
-
-- It requires that an HTML block be preceded by a blank line.
-- It does not allow the start tag to be indented.
-- It requires a matching end tag, which it also does not allow to
- be indented.
-
-Most Markdown implementations (including some of Gruber's own) do not
-respect all of these restrictions.
-
-There is one respect, however, in which Gruber's rule is more liberal
-than the one given here, since it allows blank lines to occur inside
-an HTML block. There are two reasons for disallowing them here.
-First, it removes the need to parse balanced tags, which is
-expensive and can require backtracking from the end of the document
-if no matching end tag is found. Second, it provides a very simple
-and flexible way of including Markdown content inside HTML tags:
-simply separate the Markdown from the HTML using blank lines:
-
-Compare:
-
-```````````````````````````````` example
-<div>
-
-*Emphasized* text.
-
-</div>
-.
-<div>
-<p><em>Emphasized</em> text.</p>
-</div>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<div>
-*Emphasized* text.
-</div>
-.
-<div>
-*Emphasized* text.
-</div>
-````````````````````````````````
-
-
-Some Markdown implementations have adopted a convention of
-interpreting content inside tags as text if the open tag has
-the attribute `markdown=1`. The rule given above seems a simpler and
-more elegant way of achieving the same expressive power, which is also
-much simpler to parse.
-
-The main potential drawback is that one can no longer paste HTML
-blocks into Markdown documents with 100% reliability. However,
-*in most cases* this will work fine, because the blank lines in
-HTML are usually followed by HTML block tags. For example:
-
-```````````````````````````````` example
-<table>
-
-<tr>
-
-<td>
-Hi
-</td>
-
-</tr>
-
-</table>
-.
-<table>
-<tr>
-<td>
-Hi
-</td>
-</tr>
-</table>
-````````````````````````````````
-
-
-There are problems, however, if the inner tags are indented
-*and* separated by spaces, as then they will be interpreted as
-an indented code block:
-
-```````````````````````````````` example
-<table>
-
- <tr>
-
- <td>
- Hi
- </td>
-
- </tr>
-
-</table>
-.
-<table>
- <tr>
-<pre><code>&lt;td&gt;
- Hi
-&lt;/td&gt;
-</code></pre>
- </tr>
-</table>
-````````````````````````````````
-
-
-Fortunately, blank lines are usually not necessary and can be
-deleted. The exception is inside `<pre>` tags, but as described
-[above][HTML blocks], raw HTML blocks starting with `<pre>`
-*can* contain blank lines.
-
-## Link reference definitions
-
-A [link reference definition](@)
-consists of a [link label], indented up to three spaces, followed
-by a colon (`:`), optional [whitespace] (including up to one
-[line ending]), a [link destination],
-optional [whitespace] (including up to one
-[line ending]), and an optional [link
-title], which if it is present must be separated
-from the [link destination] by [whitespace].
-No further [non-whitespace characters] may occur on the line.
-
-A [link reference definition]
-does not correspond to a structural element of a document. Instead, it
-defines a label which can be used in [reference links]
-and reference-style [images] elsewhere in the document. [Link
-reference definitions] can come either before or after the links that use
-them.
-
-```````````````````````````````` example
-[foo]: /url "title"
-
-[foo]
-.
-<p><a href="/url" title="title">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
- [foo]:
- /url
- 'the title'
-
-[foo]
-.
-<p><a href="/url" title="the title">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[Foo*bar\]]:my_(url) 'title (with parens)'
-
-[Foo*bar\]]
-.
-<p><a href="my_(url)" title="title (with parens)">Foo*bar]</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[Foo bar]:
-<my url>
-'title'
-
-[Foo bar]
-.
-<p><a href="my%20url" title="title">Foo bar</a></p>
-````````````````````````````````
-
-
-The title may extend over multiple lines:
-
-```````````````````````````````` example
-[foo]: /url '
-title
-line1
-line2
-'
-
-[foo]
-.
-<p><a href="/url" title="
-title
-line1
-line2
-">foo</a></p>
-````````````````````````````````
-
-
-However, it may not contain a [blank line]:
-
-```````````````````````````````` example
-[foo]: /url 'title
-
-with blank line'
-
-[foo]
-.
-<p>[foo]: /url 'title</p>
-<p>with blank line'</p>
-<p>[foo]</p>
-````````````````````````````````
-
-
-The title may be omitted:
-
-```````````````````````````````` example
-[foo]:
-/url
-
-[foo]
-.
-<p><a href="/url">foo</a></p>
-````````````````````````````````
-
-
-The link destination may not be omitted:
-
-```````````````````````````````` example
-[foo]:
-
-[foo]
-.
-<p>[foo]:</p>
-<p>[foo]</p>
-````````````````````````````````
-
- However, an empty link destination may be specified using
- angle brackets:
-
-```````````````````````````````` example
-[foo]: <>
-
-[foo]
-.
-<p><a href="">foo</a></p>
-````````````````````````````````
-
-The title must be separated from the link destination by
-whitespace:
-
-```````````````````````````````` example
-[foo]: <bar>(baz)
-
-[foo]
-.
-<p>[foo]: <bar>(baz)</p>
-<p>[foo]</p>
-````````````````````````````````
-
-
-Both title and destination can contain backslash escapes
-and literal backslashes:
-
-```````````````````````````````` example
-[foo]: /url\bar\*baz "foo\"bar\baz"
-
-[foo]
-.
-<p><a href="/url%5Cbar*baz" title="foo&quot;bar\baz">foo</a></p>
-````````````````````````````````
-
-
-A link can come before its corresponding definition:
-
-```````````````````````````````` example
-[foo]
-
-[foo]: url
-.
-<p><a href="url">foo</a></p>
-````````````````````````````````
-
-
-If there are several matching definitions, the first one takes
-precedence:
-
-```````````````````````````````` example
-[foo]
-
-[foo]: first
-[foo]: second
-.
-<p><a href="first">foo</a></p>
-````````````````````````````````
-
-
-As noted in the section on [Links], matching of labels is
-case-insensitive (see [matches]).
-
-```````````````````````````````` example
-[FOO]: /url
-
-[Foo]
-.
-<p><a href="/url">Foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[ΑΓΩ]: /φου
-
-[αγω]
-.
-<p><a href="/%CF%86%CE%BF%CF%85">αγω</a></p>
-````````````````````````````````
-
-
-Here is a link reference definition with no corresponding link.
-It contributes nothing to the document.
-
-```````````````````````````````` example
-[foo]: /url
-.
-````````````````````````````````
-
-
-Here is another one:
-
-```````````````````````````````` example
-[
-foo
-]: /url
-bar
-.
-<p>bar</p>
-````````````````````````````````
-
-
-This is not a link reference definition, because there are
-[non-whitespace characters] after the title:
-
-```````````````````````````````` example
-[foo]: /url "title" ok
-.
-<p>[foo]: /url &quot;title&quot; ok</p>
-````````````````````````````````
-
-
-This is a link reference definition, but it has no title:
-
-```````````````````````````````` example
-[foo]: /url
-"title" ok
-.
-<p>&quot;title&quot; ok</p>
-````````````````````````````````
-
-
-This is not a link reference definition, because it is indented
-four spaces:
-
-```````````````````````````````` example
- [foo]: /url "title"
-
-[foo]
-.
-<pre><code>[foo]: /url &quot;title&quot;
-</code></pre>
-<p>[foo]</p>
-````````````````````````````````
-
-
-This is not a link reference definition, because it occurs inside
-a code block:
-
-```````````````````````````````` example
-```
-[foo]: /url
-```
-
-[foo]
-.
-<pre><code>[foo]: /url
-</code></pre>
-<p>[foo]</p>
-````````````````````````````````
-
-
-A [link reference definition] cannot interrupt a paragraph.
-
-```````````````````````````````` example
-Foo
-[bar]: /baz
-
-[bar]
-.
-<p>Foo
-[bar]: /baz</p>
-<p>[bar]</p>
-````````````````````````````````
-
-
-However, it can directly follow other block elements, such as headings
-and thematic breaks, and it need not be followed by a blank line.
-
-```````````````````````````````` example
-# [Foo]
-[foo]: /url
-> bar
-.
-<h1><a href="/url">Foo</a></h1>
-<blockquote>
-<p>bar</p>
-</blockquote>
-````````````````````````````````
-
-```````````````````````````````` example
-[foo]: /url
-bar
-===
-[foo]
-.
-<h1>bar</h1>
-<p><a href="/url">foo</a></p>
-````````````````````````````````
-
-```````````````````````````````` example
-[foo]: /url
-===
-[foo]
-.
-<p>===
-<a href="/url">foo</a></p>
-````````````````````````````````
-
-
-Several [link reference definitions]
-can occur one after another, without intervening blank lines.
-
-```````````````````````````````` example
-[foo]: /foo-url "foo"
-[bar]: /bar-url
- "bar"
-[baz]: /baz-url
-
-[foo],
-[bar],
-[baz]
-.
-<p><a href="/foo-url" title="foo">foo</a>,
-<a href="/bar-url" title="bar">bar</a>,
-<a href="/baz-url">baz</a></p>
-````````````````````````````````
-
-
-[Link reference definitions] can occur
-inside block containers, like lists and block quotations. They
-affect the entire document, not just the container in which they
-are defined:
-
-```````````````````````````````` example
-[foo]
-
-> [foo]: /url
-.
-<p><a href="/url">foo</a></p>
-<blockquote>
-</blockquote>
-````````````````````````````````
-
-
-Whether something is a [link reference definition] is
-independent of whether the link reference it defines is
-used in the document. Thus, for example, the following
-document contains just a link reference definition, and
-no visible content:
-
-```````````````````````````````` example
-[foo]: /url
-.
-````````````````````````````````
-
-
-## Paragraphs
-
-A sequence of non-blank lines that cannot be interpreted as other
-kinds of blocks forms a [paragraph](@).
-The contents of the paragraph are the result of parsing the
-paragraph's raw content as inlines. The paragraph's raw content
-is formed by concatenating the lines and removing initial and final
-[whitespace].
-
-A simple example with two paragraphs:
-
-```````````````````````````````` example
-aaa
-
-bbb
-.
-<p>aaa</p>
-<p>bbb</p>
-````````````````````````````````
-
-
-Paragraphs can contain multiple lines, but no blank lines:
-
-```````````````````````````````` example
-aaa
-bbb
-
-ccc
-ddd
-.
-<p>aaa
-bbb</p>
-<p>ccc
-ddd</p>
-````````````````````````````````
-
-
-Multiple blank lines between paragraph have no effect:
-
-```````````````````````````````` example
-aaa
-
-
-bbb
-.
-<p>aaa</p>
-<p>bbb</p>
-````````````````````````````````
-
-
-Leading spaces are skipped:
-
-```````````````````````````````` example
- aaa
- bbb
-.
-<p>aaa
-bbb</p>
-````````````````````````````````
-
-
-Lines after the first may be indented any amount, since indented
-code blocks cannot interrupt paragraphs.
-
-```````````````````````````````` example
-aaa
- bbb
- ccc
-.
-<p>aaa
-bbb
-ccc</p>
-````````````````````````````````
-
-
-However, the first line may be indented at most three spaces,
-or an indented code block will be triggered:
-
-```````````````````````````````` example
- aaa
-bbb
-.
-<p>aaa
-bbb</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
- aaa
-bbb
-.
-<pre><code>aaa
-</code></pre>
-<p>bbb</p>
-````````````````````````````````
-
-
-Final spaces are stripped before inline parsing, so a paragraph
-that ends with two or more spaces will not end with a [hard line
-break]:
-
-```````````````````````````````` example
-aaa
-bbb
-.
-<p>aaa<br />
-bbb</p>
-````````````````````````````````
-
-
-## Blank lines
-
-[Blank lines] between block-level elements are ignored,
-except for the role they play in determining whether a [list]
-is [tight] or [loose].
-
-Blank lines at the beginning and end of the document are also ignored.
-
-```````````````````````````````` example
-
-
-aaa
-
-
-# aaa
-
-
-.
-<p>aaa</p>
-<h1>aaa</h1>
-````````````````````````````````
-
-
-
-# Container blocks
-
-A [container block](#container-blocks) is a block that has other
-blocks as its contents. There are two basic kinds of container blocks:
-[block quotes] and [list items].
-[Lists] are meta-containers for [list items].
-
-We define the syntax for container blocks recursively. The general
-form of the definition is:
-
-> If X is a sequence of blocks, then the result of
-> transforming X in such-and-such a way is a container of type Y
-> with these blocks as its content.
-
-So, we explain what counts as a block quote or list item by explaining
-how these can be *generated* from their contents. This should suffice
-to define the syntax, although it does not give a recipe for *parsing*
-these constructions. (A recipe is provided below in the section entitled
-[A parsing strategy](#appendix-a-parsing-strategy).)
-
-## Block quotes
-
-A [block quote marker](@)
-consists of 0-3 spaces of initial indent, plus (a) the character `>` together
-with a following space, or (b) a single character `>` not followed by a space.
-
-The following rules define [block quotes]:
-
-1. **Basic case.** If a string of lines *Ls* constitute a sequence
- of blocks *Bs*, then the result of prepending a [block quote
- marker] to the beginning of each line in *Ls*
- is a [block quote](#block-quotes) containing *Bs*.
-
-2. **Laziness.** If a string of lines *Ls* constitute a [block
- quote](#block-quotes) with contents *Bs*, then the result of deleting
- the initial [block quote marker] from one or
- more lines in which the next [non-whitespace character] after the [block
- quote marker] is [paragraph continuation
- text] is a block quote with *Bs* as its content.
- [Paragraph continuation text](@) is text
- that will be parsed as part of the content of a paragraph, but does
- not occur at the beginning of the paragraph.
-
-3. **Consecutiveness.** A document cannot contain two [block
- quotes] in a row unless there is a [blank line] between them.
-
-Nothing else counts as a [block quote](#block-quotes).
-
-Here is a simple example:
-
-```````````````````````````````` example
-> # Foo
-> bar
-> baz
-.
-<blockquote>
-<h1>Foo</h1>
-<p>bar
-baz</p>
-</blockquote>
-````````````````````````````````
-
-
-The spaces after the `>` characters can be omitted:
-
-```````````````````````````````` example
-># Foo
->bar
-> baz
-.
-<blockquote>
-<h1>Foo</h1>
-<p>bar
-baz</p>
-</blockquote>
-````````````````````````````````
-
-
-The `>` characters can be indented 1-3 spaces:
-
-```````````````````````````````` example
- > # Foo
- > bar
- > baz
-.
-<blockquote>
-<h1>Foo</h1>
-<p>bar
-baz</p>
-</blockquote>
-````````````````````````````````
-
-
-Four spaces gives us a code block:
-
-```````````````````````````````` example
- > # Foo
- > bar
- > baz
-.
-<pre><code>&gt; # Foo
-&gt; bar
-&gt; baz
-</code></pre>
-````````````````````````````````
-
-
-The Laziness clause allows us to omit the `>` before
-[paragraph continuation text]:
-
-```````````````````````````````` example
-> # Foo
-> bar
-baz
-.
-<blockquote>
-<h1>Foo</h1>
-<p>bar
-baz</p>
-</blockquote>
-````````````````````````````````
-
-
-A block quote can contain some lazy and some non-lazy
-continuation lines:
-
-```````````````````````````````` example
-> bar
-baz
-> foo
-.
-<blockquote>
-<p>bar
-baz
-foo</p>
-</blockquote>
-````````````````````````````````
-
-
-Laziness only applies to lines that would have been continuations of
-paragraphs had they been prepended with [block quote markers].
-For example, the `> ` cannot be omitted in the second line of
-
-``` markdown
-> foo
-> ---
-```
-
-without changing the meaning:
-
-```````````````````````````````` example
-> foo
----
-.
-<blockquote>
-<p>foo</p>
-</blockquote>
-<hr />
-````````````````````````````````
-
-
-Similarly, if we omit the `> ` in the second line of
-
-``` markdown
-> - foo
-> - bar
-```
-
-then the block quote ends after the first line:
-
-```````````````````````````````` example
-> - foo
-- bar
-.
-<blockquote>
-<ul>
-<li>foo</li>
-</ul>
-</blockquote>
-<ul>
-<li>bar</li>
-</ul>
-````````````````````````````````
-
-
-For the same reason, we can't omit the `> ` in front of
-subsequent lines of an indented or fenced code block:
-
-```````````````````````````````` example
-> foo
- bar
-.
-<blockquote>
-<pre><code>foo
-</code></pre>
-</blockquote>
-<pre><code>bar
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-> ```
-foo
-```
-.
-<blockquote>
-<pre><code></code></pre>
-</blockquote>
-<p>foo</p>
-<pre><code></code></pre>
-````````````````````````````````
-
-
-Note that in the following case, we have a [lazy
-continuation line]:
-
-```````````````````````````````` example
-> foo
- - bar
-.
-<blockquote>
-<p>foo
-- bar</p>
-</blockquote>
-````````````````````````````````
-
-
-To see why, note that in
-
-```markdown
-> foo
-> - bar
-```
-
-the `- bar` is indented too far to start a list, and can't
-be an indented code block because indented code blocks cannot
-interrupt paragraphs, so it is [paragraph continuation text].
-
-A block quote can be empty:
-
-```````````````````````````````` example
->
-.
-<blockquote>
-</blockquote>
-````````````````````````````````
-
-
-```````````````````````````````` example
->
->
->
-.
-<blockquote>
-</blockquote>
-````````````````````````````````
-
-
-A block quote can have initial or final blank lines:
-
-```````````````````````````````` example
->
-> foo
->
-.
-<blockquote>
-<p>foo</p>
-</blockquote>
-````````````````````````````````
-
-
-A blank line always separates block quotes:
-
-```````````````````````````````` example
-> foo
-
-> bar
-.
-<blockquote>
-<p>foo</p>
-</blockquote>
-<blockquote>
-<p>bar</p>
-</blockquote>
-````````````````````````````````
-
-
-(Most current Markdown implementations, including John Gruber's
-original `Markdown.pl`, will parse this example as a single block quote
-with two paragraphs. But it seems better to allow the author to decide
-whether two block quotes or one are wanted.)
-
-Consecutiveness means that if we put these block quotes together,
-we get a single block quote:
-
-```````````````````````````````` example
-> foo
-> bar
-.
-<blockquote>
-<p>foo
-bar</p>
-</blockquote>
-````````````````````````````````
-
-
-To get a block quote with two paragraphs, use:
-
-```````````````````````````````` example
-> foo
->
-> bar
-.
-<blockquote>
-<p>foo</p>
-<p>bar</p>
-</blockquote>
-````````````````````````````````
-
-
-Block quotes can interrupt paragraphs:
-
-```````````````````````````````` example
-foo
-> bar
-.
-<p>foo</p>
-<blockquote>
-<p>bar</p>
-</blockquote>
-````````````````````````````````
-
-
-In general, blank lines are not needed before or after block
-quotes:
-
-```````````````````````````````` example
-> aaa
-***
-> bbb
-.
-<blockquote>
-<p>aaa</p>
-</blockquote>
-<hr />
-<blockquote>
-<p>bbb</p>
-</blockquote>
-````````````````````````````````
-
-
-However, because of laziness, a blank line is needed between
-a block quote and a following paragraph:
-
-```````````````````````````````` example
-> bar
-baz
-.
-<blockquote>
-<p>bar
-baz</p>
-</blockquote>
-````````````````````````````````
-
-
-```````````````````````````````` example
-> bar
-
-baz
-.
-<blockquote>
-<p>bar</p>
-</blockquote>
-<p>baz</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-> bar
->
-baz
-.
-<blockquote>
-<p>bar</p>
-</blockquote>
-<p>baz</p>
-````````````````````````````````
-
-
-It is a consequence of the Laziness rule that any number
-of initial `>`s may be omitted on a continuation line of a
-nested block quote:
-
-```````````````````````````````` example
-> > > foo
-bar
-.
-<blockquote>
-<blockquote>
-<blockquote>
-<p>foo
-bar</p>
-</blockquote>
-</blockquote>
-</blockquote>
-````````````````````````````````
-
-
-```````````````````````````````` example
->>> foo
-> bar
->>baz
-.
-<blockquote>
-<blockquote>
-<blockquote>
-<p>foo
-bar
-baz</p>
-</blockquote>
-</blockquote>
-</blockquote>
-````````````````````````````````
-
-
-When including an indented code block in a block quote,
-remember that the [block quote marker] includes
-both the `>` and a following space. So *five spaces* are needed after
-the `>`:
-
-```````````````````````````````` example
-> code
-
-> not code
-.
-<blockquote>
-<pre><code>code
-</code></pre>
-</blockquote>
-<blockquote>
-<p>not code</p>
-</blockquote>
-````````````````````````````````
-
-
-
-## List items
-
-A [list marker](@) is a
-[bullet list marker] or an [ordered list marker].
-
-A [bullet list marker](@)
-is a `-`, `+`, or `*` character.
-
-An [ordered list marker](@)
-is a sequence of 1--9 arabic digits (`0-9`), followed by either a
-`.` character or a `)` character. (The reason for the length
-limit is that with 10 digits we start seeing integer overflows
-in some browsers.)
-
-The following rules define [list items]:
-
-1. **Basic case.** If a sequence of lines *Ls* constitute a sequence of
- blocks *Bs* starting with a [non-whitespace character], and *M* is a
- list marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces, then the result
- of prepending *M* and the following spaces to the first line of
- *Ls*, and indenting subsequent lines of *Ls* by *W + N* spaces, is a
- list item with *Bs* as its contents. The type of the list item
- (bullet or ordered) is determined by the type of its list marker.
- If the list item is ordered, then it is also assigned a start
- number, based on the ordered list marker.
-
- Exceptions:
-
- 1. When the first list item in a [list] interrupts
- a paragraph---that is, when it starts on a line that would
- otherwise count as [paragraph continuation text]---then (a)
- the lines *Ls* must not begin with a blank line, and (b) if
- the list item is ordered, the start number must be 1.
- 2. If any line is a [thematic break][thematic breaks] then
- that line is not a list item.
-
-For example, let *Ls* be the lines
-
-```````````````````````````````` example
-A paragraph
-with two lines.
-
- indented code
-
-> A block quote.
-.
-<p>A paragraph
-with two lines.</p>
-<pre><code>indented code
-</code></pre>
-<blockquote>
-<p>A block quote.</p>
-</blockquote>
-````````````````````````````````
-
-
-And let *M* be the marker `1.`, and *N* = 2. Then rule #1 says
-that the following is an ordered list item with start number 1,
-and the same contents as *Ls*:
-
-```````````````````````````````` example
-1. A paragraph
- with two lines.
-
- indented code
-
- > A block quote.
-.
-<ol>
-<li>
-<p>A paragraph
-with two lines.</p>
-<pre><code>indented code
-</code></pre>
-<blockquote>
-<p>A block quote.</p>
-</blockquote>
-</li>
-</ol>
-````````````````````````````````
-
-
-The most important thing to notice is that the position of
-the text after the list marker determines how much indentation
-is needed in subsequent blocks in the list item. If the list
-marker takes up two spaces, and there are three spaces between
-the list marker and the next [non-whitespace character], then blocks
-must be indented five spaces in order to fall under the list
-item.
-
-Here are some examples showing how far content must be indented to be
-put under the list item:
-
-```````````````````````````````` example
-- one
-
- two
-.
-<ul>
-<li>one</li>
-</ul>
-<p>two</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- one
-
- two
-.
-<ul>
-<li>
-<p>one</p>
-<p>two</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
- - one
-
- two
-.
-<ul>
-<li>one</li>
-</ul>
-<pre><code> two
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
- - one
-
- two
-.
-<ul>
-<li>
-<p>one</p>
-<p>two</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-It is tempting to think of this in terms of columns: the continuation
-blocks must be indented at least to the column of the first
-[non-whitespace character] after the list marker. However, that is not quite right.
-The spaces after the list marker determine how much relative indentation
-is needed. Which column this indentation reaches will depend on
-how the list item is embedded in other constructions, as shown by
-this example:
-
-```````````````````````````````` example
- > > 1. one
->>
->> two
-.
-<blockquote>
-<blockquote>
-<ol>
-<li>
-<p>one</p>
-<p>two</p>
-</li>
-</ol>
-</blockquote>
-</blockquote>
-````````````````````````````````
-
-
-Here `two` occurs in the same column as the list marker `1.`,
-but is actually contained in the list item, because there is
-sufficient indentation after the last containing blockquote marker.
-
-The converse is also possible. In the following example, the word `two`
-occurs far to the right of the initial text of the list item, `one`, but
-it is not considered part of the list item, because it is not indented
-far enough past the blockquote marker:
-
-```````````````````````````````` example
->>- one
->>
- > > two
-.
-<blockquote>
-<blockquote>
-<ul>
-<li>one</li>
-</ul>
-<p>two</p>
-</blockquote>
-</blockquote>
-````````````````````````````````
-
-
-Note that at least one space is needed between the list marker and
-any following content, so these are not list items:
-
-```````````````````````````````` example
--one
-
-2.two
-.
-<p>-one</p>
-<p>2.two</p>
-````````````````````````````````
-
-
-A list item may contain blocks that are separated by more than
-one blank line.
-
-```````````````````````````````` example
-- foo
-
-
- bar
-.
-<ul>
-<li>
-<p>foo</p>
-<p>bar</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-A list item may contain any kind of block:
-
-```````````````````````````````` example
-1. foo
-
- ```
- bar
- ```
-
- baz
-
- > bam
-.
-<ol>
-<li>
-<p>foo</p>
-<pre><code>bar
-</code></pre>
-<p>baz</p>
-<blockquote>
-<p>bam</p>
-</blockquote>
-</li>
-</ol>
-````````````````````````````````
-
-
-A list item that contains an indented code block will preserve
-empty lines within the code block verbatim.
-
-```````````````````````````````` example
-- Foo
-
- bar
-
-
- baz
-.
-<ul>
-<li>
-<p>Foo</p>
-<pre><code>bar
-
-
-baz
-</code></pre>
-</li>
-</ul>
-````````````````````````````````
-
-Note that ordered list start numbers must be nine digits or less:
-
-```````````````````````````````` example
-123456789. ok
-.
-<ol start="123456789">
-<li>ok</li>
-</ol>
-````````````````````````````````
-
-
-```````````````````````````````` example
-1234567890. not ok
-.
-<p>1234567890. not ok</p>
-````````````````````````````````
-
-
-A start number may begin with 0s:
-
-```````````````````````````````` example
-0. ok
-.
-<ol start="0">
-<li>ok</li>
-</ol>
-````````````````````````````````
-
-
-```````````````````````````````` example
-003. ok
-.
-<ol start="3">
-<li>ok</li>
-</ol>
-````````````````````````````````
-
-
-A start number may not be negative:
-
-```````````````````````````````` example
--1. not ok
-.
-<p>-1. not ok</p>
-````````````````````````````````
-
-
-
-2. **Item starting with indented code.** If a sequence of lines *Ls*
- constitute a sequence of blocks *Bs* starting with an indented code
- block, and *M* is a list marker of width *W* followed by
- one space, then the result of prepending *M* and the following
- space to the first line of *Ls*, and indenting subsequent lines of
- *Ls* by *W + 1* spaces, is a list item with *Bs* as its contents.
- If a line is empty, then it need not be indented. The type of the
- list item (bullet or ordered) is determined by the type of its list
- marker. If the list item is ordered, then it is also assigned a
- start number, based on the ordered list marker.
-
-An indented code block will have to be indented four spaces beyond
-the edge of the region where text will be included in the list item.
-In the following case that is 6 spaces:
-
-```````````````````````````````` example
-- foo
-
- bar
-.
-<ul>
-<li>
-<p>foo</p>
-<pre><code>bar
-</code></pre>
-</li>
-</ul>
-````````````````````````````````
-
-
-And in this case it is 11 spaces:
-
-```````````````````````````````` example
- 10. foo
-
- bar
-.
-<ol start="10">
-<li>
-<p>foo</p>
-<pre><code>bar
-</code></pre>
-</li>
-</ol>
-````````````````````````````````
-
-
-If the *first* block in the list item is an indented code block,
-then by rule #2, the contents must be indented *one* space after the
-list marker:
-
-```````````````````````````````` example
- indented code
-
-paragraph
-
- more code
-.
-<pre><code>indented code
-</code></pre>
-<p>paragraph</p>
-<pre><code>more code
-</code></pre>
-````````````````````````````````
-
-
-```````````````````````````````` example
-1. indented code
-
- paragraph
-
- more code
-.
-<ol>
-<li>
-<pre><code>indented code
-</code></pre>
-<p>paragraph</p>
-<pre><code>more code
-</code></pre>
-</li>
-</ol>
-````````````````````````````````
-
-
-Note that an additional space indent is interpreted as space
-inside the code block:
-
-```````````````````````````````` example
-1. indented code
-
- paragraph
-
- more code
-.
-<ol>
-<li>
-<pre><code> indented code
-</code></pre>
-<p>paragraph</p>
-<pre><code>more code
-</code></pre>
-</li>
-</ol>
-````````````````````````````````
-
-
-Note that rules #1 and #2 only apply to two cases: (a) cases
-in which the lines to be included in a list item begin with a
-[non-whitespace character], and (b) cases in which
-they begin with an indented code
-block. In a case like the following, where the first block begins with
-a three-space indent, the rules do not allow us to form a list item by
-indenting the whole thing and prepending a list marker:
-
-```````````````````````````````` example
- foo
-
-bar
-.
-<p>foo</p>
-<p>bar</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- foo
-
- bar
-.
-<ul>
-<li>foo</li>
-</ul>
-<p>bar</p>
-````````````````````````````````
-
-
-This is not a significant restriction, because when a block begins
-with 1-3 spaces indent, the indentation can always be removed without
-a change in interpretation, allowing rule #1 to be applied. So, in
-the above case:
-
-```````````````````````````````` example
-- foo
-
- bar
-.
-<ul>
-<li>
-<p>foo</p>
-<p>bar</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-3. **Item starting with a blank line.** If a sequence of lines *Ls*
- starting with a single [blank line] constitute a (possibly empty)
- sequence of blocks *Bs*, not separated from each other by more than
- one blank line, and *M* is a list marker of width *W*,
- then the result of prepending *M* to the first line of *Ls*, and
- indenting subsequent lines of *Ls* by *W + 1* spaces, is a list
- item with *Bs* as its contents.
- If a line is empty, then it need not be indented. The type of the
- list item (bullet or ordered) is determined by the type of its list
- marker. If the list item is ordered, then it is also assigned a
- start number, based on the ordered list marker.
-
-Here are some list items that start with a blank line but are not empty:
-
-```````````````````````````````` example
--
- foo
--
- ```
- bar
- ```
--
- baz
-.
-<ul>
-<li>foo</li>
-<li>
-<pre><code>bar
-</code></pre>
-</li>
-<li>
-<pre><code>baz
-</code></pre>
-</li>
-</ul>
-````````````````````````````````
-
-When the list item starts with a blank line, the number of spaces
-following the list marker doesn't change the required indentation:
-
-```````````````````````````````` example
--
- foo
-.
-<ul>
-<li>foo</li>
-</ul>
-````````````````````````````````
-
-
-A list item can begin with at most one blank line.
-In the following example, `foo` is not part of the list
-item:
-
-```````````````````````````````` example
--
-
- foo
-.
-<ul>
-<li></li>
-</ul>
-<p>foo</p>
-````````````````````````````````
-
-
-Here is an empty bullet list item:
-
-```````````````````````````````` example
-- foo
--
-- bar
-.
-<ul>
-<li>foo</li>
-<li></li>
-<li>bar</li>
-</ul>
-````````````````````````````````
-
-
-It does not matter whether there are spaces following the [list marker]:
-
-```````````````````````````````` example
-- foo
--
-- bar
-.
-<ul>
-<li>foo</li>
-<li></li>
-<li>bar</li>
-</ul>
-````````````````````````````````
-
-
-Here is an empty ordered list item:
-
-```````````````````````````````` example
-1. foo
-2.
-3. bar
-.
-<ol>
-<li>foo</li>
-<li></li>
-<li>bar</li>
-</ol>
-````````````````````````````````
-
-
-A list may start or end with an empty list item:
-
-```````````````````````````````` example
-*
-.
-<ul>
-<li></li>
-</ul>
-````````````````````````````````
-
-However, an empty list item cannot interrupt a paragraph:
-
-```````````````````````````````` example
-foo
-*
-
-foo
-1.
-.
-<p>foo
-*</p>
-<p>foo
-1.</p>
-````````````````````````````````
-
-
-4. **Indentation.** If a sequence of lines *Ls* constitutes a list item
- according to rule #1, #2, or #3, then the result of indenting each line
- of *Ls* by 1-3 spaces (the same for each line) also constitutes a
- list item with the same contents and attributes. If a line is
- empty, then it need not be indented.
-
-Indented one space:
-
-```````````````````````````````` example
- 1. A paragraph
- with two lines.
-
- indented code
-
- > A block quote.
-.
-<ol>
-<li>
-<p>A paragraph
-with two lines.</p>
-<pre><code>indented code
-</code></pre>
-<blockquote>
-<p>A block quote.</p>
-</blockquote>
-</li>
-</ol>
-````````````````````````````````
-
-
-Indented two spaces:
-
-```````````````````````````````` example
- 1. A paragraph
- with two lines.
-
- indented code
-
- > A block quote.
-.
-<ol>
-<li>
-<p>A paragraph
-with two lines.</p>
-<pre><code>indented code
-</code></pre>
-<blockquote>
-<p>A block quote.</p>
-</blockquote>
-</li>
-</ol>
-````````````````````````````````
-
-
-Indented three spaces:
-
-```````````````````````````````` example
- 1. A paragraph
- with two lines.
-
- indented code
-
- > A block quote.
-.
-<ol>
-<li>
-<p>A paragraph
-with two lines.</p>
-<pre><code>indented code
-</code></pre>
-<blockquote>
-<p>A block quote.</p>
-</blockquote>
-</li>
-</ol>
-````````````````````````````````
-
-
-Four spaces indent gives a code block:
-
-```````````````````````````````` example
- 1. A paragraph
- with two lines.
-
- indented code
-
- > A block quote.
-.
-<pre><code>1. A paragraph
- with two lines.
-
- indented code
-
- &gt; A block quote.
-</code></pre>
-````````````````````````````````
-
-
-
-5. **Laziness.** If a string of lines *Ls* constitute a [list
- item](#list-items) with contents *Bs*, then the result of deleting
- some or all of the indentation from one or more lines in which the
- next [non-whitespace character] after the indentation is
- [paragraph continuation text] is a
- list item with the same contents and attributes. The unindented
- lines are called
- [lazy continuation line](@)s.
-
-Here is an example with [lazy continuation lines]:
-
-```````````````````````````````` example
- 1. A paragraph
-with two lines.
-
- indented code
-
- > A block quote.
-.
-<ol>
-<li>
-<p>A paragraph
-with two lines.</p>
-<pre><code>indented code
-</code></pre>
-<blockquote>
-<p>A block quote.</p>
-</blockquote>
-</li>
-</ol>
-````````````````````````````````
-
-
-Indentation can be partially deleted:
-
-```````````````````````````````` example
- 1. A paragraph
- with two lines.
-.
-<ol>
-<li>A paragraph
-with two lines.</li>
-</ol>
-````````````````````````````````
-
-
-These examples show how laziness can work in nested structures:
-
-```````````````````````````````` example
-> 1. > Blockquote
-continued here.
-.
-<blockquote>
-<ol>
-<li>
-<blockquote>
-<p>Blockquote
-continued here.</p>
-</blockquote>
-</li>
-</ol>
-</blockquote>
-````````````````````````````````
-
-
-```````````````````````````````` example
-> 1. > Blockquote
-> continued here.
-.
-<blockquote>
-<ol>
-<li>
-<blockquote>
-<p>Blockquote
-continued here.</p>
-</blockquote>
-</li>
-</ol>
-</blockquote>
-````````````````````````````````
-
-
-
-6. **That's all.** Nothing that is not counted as a list item by rules
- #1--5 counts as a [list item](#list-items).
-
-The rules for sublists follow from the general rules
-[above][List items]. A sublist must be indented the same number
-of spaces a paragraph would need to be in order to be included
-in the list item.
-
-So, in this case we need two spaces indent:
-
-```````````````````````````````` example
-- foo
- - bar
- - baz
- - boo
-.
-<ul>
-<li>foo
-<ul>
-<li>bar
-<ul>
-<li>baz
-<ul>
-<li>boo</li>
-</ul>
-</li>
-</ul>
-</li>
-</ul>
-</li>
-</ul>
-````````````````````````````````
-
-
-One is not enough:
-
-```````````````````````````````` example
-- foo
- - bar
- - baz
- - boo
-.
-<ul>
-<li>foo</li>
-<li>bar</li>
-<li>baz</li>
-<li>boo</li>
-</ul>
-````````````````````````````````
-
-
-Here we need four, because the list marker is wider:
-
-```````````````````````````````` example
-10) foo
- - bar
-.
-<ol start="10">
-<li>foo
-<ul>
-<li>bar</li>
-</ul>
-</li>
-</ol>
-````````````````````````````````
-
-
-Three is not enough:
-
-```````````````````````````````` example
-10) foo
- - bar
-.
-<ol start="10">
-<li>foo</li>
-</ol>
-<ul>
-<li>bar</li>
-</ul>
-````````````````````````````````
-
-
-A list may be the first block in a list item:
-
-```````````````````````````````` example
-- - foo
-.
-<ul>
-<li>
-<ul>
-<li>foo</li>
-</ul>
-</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-1. - 2. foo
-.
-<ol>
-<li>
-<ul>
-<li>
-<ol start="2">
-<li>foo</li>
-</ol>
-</li>
-</ul>
-</li>
-</ol>
-````````````````````````````````
-
-
-A list item can contain a heading:
-
-```````````````````````````````` example
-- # Foo
-- Bar
- ---
- baz
-.
-<ul>
-<li>
-<h1>Foo</h1>
-</li>
-<li>
-<h2>Bar</h2>
-baz</li>
-</ul>
-````````````````````````````````
-
-
-### Motivation
-
-John Gruber's Markdown spec says the following about list items:
-
-1. "List markers typically start at the left margin, but may be indented
- by up to three spaces. List markers must be followed by one or more
- spaces or a tab."
-
-2. "To make lists look nice, you can wrap items with hanging indents....
- But if you don't want to, you don't have to."
-
-3. "List items may consist of multiple paragraphs. Each subsequent
- paragraph in a list item must be indented by either 4 spaces or one
- tab."
-
-4. "It looks nice if you indent every line of the subsequent paragraphs,
- but here again, Markdown will allow you to be lazy."
-
-5. "To put a blockquote within a list item, the blockquote's `>`
- delimiters need to be indented."
-
-6. "To put a code block within a list item, the code block needs to be
- indented twice — 8 spaces or two tabs."
-
-These rules specify that a paragraph under a list item must be indented
-four spaces (presumably, from the left margin, rather than the start of
-the list marker, but this is not said), and that code under a list item
-must be indented eight spaces instead of the usual four. They also say
-that a block quote must be indented, but not by how much; however, the
-example given has four spaces indentation. Although nothing is said
-about other kinds of block-level content, it is certainly reasonable to
-infer that *all* block elements under a list item, including other
-lists, must be indented four spaces. This principle has been called the
-*four-space rule*.
-
-The four-space rule is clear and principled, and if the reference
-implementation `Markdown.pl` had followed it, it probably would have
-become the standard. However, `Markdown.pl` allowed paragraphs and
-sublists to start with only two spaces indentation, at least on the
-outer level. Worse, its behavior was inconsistent: a sublist of an
-outer-level list needed two spaces indentation, but a sublist of this
-sublist needed three spaces. It is not surprising, then, that different
-implementations of Markdown have developed very different rules for
-determining what comes under a list item. (Pandoc and python-Markdown,
-for example, stuck with Gruber's syntax description and the four-space
-rule, while discount, redcarpet, marked, PHP Markdown, and others
-followed `Markdown.pl`'s behavior more closely.)
-
-Unfortunately, given the divergences between implementations, there
-is no way to give a spec for list items that will be guaranteed not
-to break any existing documents. However, the spec given here should
-correctly handle lists formatted with either the four-space rule or
-the more forgiving `Markdown.pl` behavior, provided they are laid out
-in a way that is natural for a human to read.
-
-The strategy here is to let the width and indentation of the list marker
-determine the indentation necessary for blocks to fall under the list
-item, rather than having a fixed and arbitrary number. The writer can
-think of the body of the list item as a unit which gets indented to the
-right enough to fit the list marker (and any indentation on the list
-marker). (The laziness rule, #5, then allows continuation lines to be
-unindented if needed.)
-
-This rule is superior, we claim, to any rule requiring a fixed level of
-indentation from the margin. The four-space rule is clear but
-unnatural. It is quite unintuitive that
-
-``` markdown
-- foo
-
- bar
-
- - baz
-```
-
-should be parsed as two lists with an intervening paragraph,
-
-``` html
-<ul>
-<li>foo</li>
-</ul>
-<p>bar</p>
-<ul>
-<li>baz</li>
-</ul>
-```
-
-as the four-space rule demands, rather than a single list,
-
-``` html
-<ul>
-<li>
-<p>foo</p>
-<p>bar</p>
-<ul>
-<li>baz</li>
-</ul>
-</li>
-</ul>
-```
-
-The choice of four spaces is arbitrary. It can be learned, but it is
-not likely to be guessed, and it trips up beginners regularly.
-
-Would it help to adopt a two-space rule? The problem is that such
-a rule, together with the rule allowing 1--3 spaces indentation of the
-initial list marker, allows text that is indented *less than* the
-original list marker to be included in the list item. For example,
-`Markdown.pl` parses
-
-``` markdown
- - one
-
- two
-```
-
-as a single list item, with `two` a continuation paragraph:
-
-``` html
-<ul>
-<li>
-<p>one</p>
-<p>two</p>
-</li>
-</ul>
-```
-
-and similarly
-
-``` markdown
-> - one
->
-> two
-```
-
-as
-
-``` html
-<blockquote>
-<ul>
-<li>
-<p>one</p>
-<p>two</p>
-</li>
-</ul>
-</blockquote>
-```
-
-This is extremely unintuitive.
-
-Rather than requiring a fixed indent from the margin, we could require
-a fixed indent (say, two spaces, or even one space) from the list marker (which
-may itself be indented). This proposal would remove the last anomaly
-discussed. Unlike the spec presented above, it would count the following
-as a list item with a subparagraph, even though the paragraph `bar`
-is not indented as far as the first paragraph `foo`:
-
-``` markdown
- 10. foo
-
- bar
-```
-
-Arguably this text does read like a list item with `bar` as a subparagraph,
-which may count in favor of the proposal. However, on this proposal indented
-code would have to be indented six spaces after the list marker. And this
-would break a lot of existing Markdown, which has the pattern:
-
-``` markdown
-1. foo
-
- indented code
-```
-
-where the code is indented eight spaces. The spec above, by contrast, will
-parse this text as expected, since the code block's indentation is measured
-from the beginning of `foo`.
-
-The one case that needs special treatment is a list item that *starts*
-with indented code. How much indentation is required in that case, since
-we don't have a "first paragraph" to measure from? Rule #2 simply stipulates
-that in such cases, we require one space indentation from the list marker
-(and then the normal four spaces for the indented code). This will match the
-four-space rule in cases where the list marker plus its initial indentation
-takes four spaces (a common case), but diverge in other cases.
-
-## Lists
-
-A [list](@) is a sequence of one or more
-list items [of the same type]. The list items
-may be separated by any number of blank lines.
-
-Two list items are [of the same type](@)
-if they begin with a [list marker] of the same type.
-Two list markers are of the
-same type if (a) they are bullet list markers using the same character
-(`-`, `+`, or `*`) or (b) they are ordered list numbers with the same
-delimiter (either `.` or `)`).
-
-A list is an [ordered list](@)
-if its constituent list items begin with
-[ordered list markers], and a
-[bullet list](@) if its constituent list
-items begin with [bullet list markers].
-
-The [start number](@)
-of an [ordered list] is determined by the list number of
-its initial list item. The numbers of subsequent list items are
-disregarded.
-
-A list is [loose](@) if any of its constituent
-list items are separated by blank lines, or if any of its constituent
-list items directly contain two block-level elements with a blank line
-between them. Otherwise a list is [tight](@).
-(The difference in HTML output is that paragraphs in a loose list are
-wrapped in `<p>` tags, while paragraphs in a tight list are not.)
-
-Changing the bullet or ordered list delimiter starts a new list:
-
-```````````````````````````````` example
-- foo
-- bar
-+ baz
-.
-<ul>
-<li>foo</li>
-<li>bar</li>
-</ul>
-<ul>
-<li>baz</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-1. foo
-2. bar
-3) baz
-.
-<ol>
-<li>foo</li>
-<li>bar</li>
-</ol>
-<ol start="3">
-<li>baz</li>
-</ol>
-````````````````````````````````
-
-
-In CommonMark, a list can interrupt a paragraph. That is,
-no blank line is needed to separate a paragraph from a following
-list:
-
-```````````````````````````````` example
-Foo
-- bar
-- baz
-.
-<p>Foo</p>
-<ul>
-<li>bar</li>
-<li>baz</li>
-</ul>
-````````````````````````````````
-
-`Markdown.pl` does not allow this, through fear of triggering a list
-via a numeral in a hard-wrapped line:
-
-``` markdown
-The number of windows in my house is
-14. The number of doors is 6.
-```
-
-Oddly, though, `Markdown.pl` *does* allow a blockquote to
-interrupt a paragraph, even though the same considerations might
-apply.
-
-In CommonMark, we do allow lists to interrupt paragraphs, for
-two reasons. First, it is natural and not uncommon for people
-to start lists without blank lines:
-
-``` markdown
-I need to buy
-- new shoes
-- a coat
-- a plane ticket
-```
-
-Second, we are attracted to a
-
-> [principle of uniformity](@):
-> if a chunk of text has a certain
-> meaning, it will continue to have the same meaning when put into a
-> container block (such as a list item or blockquote).
-
-(Indeed, the spec for [list items] and [block quotes] presupposes
-this principle.) This principle implies that if
-
-``` markdown
- * I need to buy
- - new shoes
- - a coat
- - a plane ticket
-```
-
-is a list item containing a paragraph followed by a nested sublist,
-as all Markdown implementations agree it is (though the paragraph
-may be rendered without `<p>` tags, since the list is "tight"),
-then
-
-``` markdown
-I need to buy
-- new shoes
-- a coat
-- a plane ticket
-```
-
-by itself should be a paragraph followed by a nested sublist.
-
-Since it is well established Markdown practice to allow lists to
-interrupt paragraphs inside list items, the [principle of
-uniformity] requires us to allow this outside list items as
-well. ([reStructuredText](http://docutils.sourceforge.net/rst.html)
-takes a different approach, requiring blank lines before lists
-even inside other list items.)
-
-In order to solve of unwanted lists in paragraphs with
-hard-wrapped numerals, we allow only lists starting with `1` to
-interrupt paragraphs. Thus,
-
-```````````````````````````````` example
-The number of windows in my house is
-14. The number of doors is 6.
-.
-<p>The number of windows in my house is
-14. The number of doors is 6.</p>
-````````````````````````````````
-
-We may still get an unintended result in cases like
-
-```````````````````````````````` example
-The number of windows in my house is
-1. The number of doors is 6.
-.
-<p>The number of windows in my house is</p>
-<ol>
-<li>The number of doors is 6.</li>
-</ol>
-````````````````````````````````
-
-but this rule should prevent most spurious list captures.
-
-There can be any number of blank lines between items:
-
-```````````````````````````````` example
-- foo
-
-- bar
-
-
-- baz
-.
-<ul>
-<li>
-<p>foo</p>
-</li>
-<li>
-<p>bar</p>
-</li>
-<li>
-<p>baz</p>
-</li>
-</ul>
-````````````````````````````````
-
-```````````````````````````````` example
-- foo
- - bar
- - baz
-
-
- bim
-.
-<ul>
-<li>foo
-<ul>
-<li>bar
-<ul>
-<li>
-<p>baz</p>
-<p>bim</p>
-</li>
-</ul>
-</li>
-</ul>
-</li>
-</ul>
-````````````````````````````````
-
-
-To separate consecutive lists of the same type, or to separate a
-list from an indented code block that would otherwise be parsed
-as a subparagraph of the final list item, you can insert a blank HTML
-comment:
-
-```````````````````````````````` example
-- foo
-- bar
-
-<!-- -->
-
-- baz
-- bim
-.
-<ul>
-<li>foo</li>
-<li>bar</li>
-</ul>
-<!-- -->
-<ul>
-<li>baz</li>
-<li>bim</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- foo
-
- notcode
-
-- foo
-
-<!-- -->
-
- code
-.
-<ul>
-<li>
-<p>foo</p>
-<p>notcode</p>
-</li>
-<li>
-<p>foo</p>
-</li>
-</ul>
-<!-- -->
-<pre><code>code
-</code></pre>
-````````````````````````````````
-
-
-List items need not be indented to the same level. The following
-list items will be treated as items at the same list level,
-since none is indented enough to belong to the previous list
-item:
-
-```````````````````````````````` example
-- a
- - b
- - c
- - d
- - e
- - f
-- g
-.
-<ul>
-<li>a</li>
-<li>b</li>
-<li>c</li>
-<li>d</li>
-<li>e</li>
-<li>f</li>
-<li>g</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-1. a
-
- 2. b
-
- 3. c
-.
-<ol>
-<li>
-<p>a</p>
-</li>
-<li>
-<p>b</p>
-</li>
-<li>
-<p>c</p>
-</li>
-</ol>
-````````````````````````````````
-
-Note, however, that list items may not be indented more than
-three spaces. Here `- e` is treated as a paragraph continuation
-line, because it is indented more than three spaces:
-
-```````````````````````````````` example
-- a
- - b
- - c
- - d
- - e
-.
-<ul>
-<li>a</li>
-<li>b</li>
-<li>c</li>
-<li>d
-- e</li>
-</ul>
-````````````````````````````````
-
-And here, `3. c` is treated as in indented code block,
-because it is indented four spaces and preceded by a
-blank line.
-
-```````````````````````````````` example
-1. a
-
- 2. b
-
- 3. c
-.
-<ol>
-<li>
-<p>a</p>
-</li>
-<li>
-<p>b</p>
-</li>
-</ol>
-<pre><code>3. c
-</code></pre>
-````````````````````````````````
-
-
-This is a loose list, because there is a blank line between
-two of the list items:
-
-```````````````````````````````` example
-- a
-- b
-
-- c
-.
-<ul>
-<li>
-<p>a</p>
-</li>
-<li>
-<p>b</p>
-</li>
-<li>
-<p>c</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-So is this, with a empty second item:
-
-```````````````````````````````` example
-* a
-*
-
-* c
-.
-<ul>
-<li>
-<p>a</p>
-</li>
-<li></li>
-<li>
-<p>c</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-These are loose lists, even though there is no space between the items,
-because one of the items directly contains two block-level elements
-with a blank line between them:
-
-```````````````````````````````` example
-- a
-- b
-
- c
-- d
-.
-<ul>
-<li>
-<p>a</p>
-</li>
-<li>
-<p>b</p>
-<p>c</p>
-</li>
-<li>
-<p>d</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- a
-- b
-
- [ref]: /url
-- d
-.
-<ul>
-<li>
-<p>a</p>
-</li>
-<li>
-<p>b</p>
-</li>
-<li>
-<p>d</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-This is a tight list, because the blank lines are in a code block:
-
-```````````````````````````````` example
-- a
-- ```
- b
-
-
- ```
-- c
-.
-<ul>
-<li>a</li>
-<li>
-<pre><code>b
-
-
-</code></pre>
-</li>
-<li>c</li>
-</ul>
-````````````````````````````````
-
-
-This is a tight list, because the blank line is between two
-paragraphs of a sublist. So the sublist is loose while
-the outer list is tight:
-
-```````````````````````````````` example
-- a
- - b
-
- c
-- d
-.
-<ul>
-<li>a
-<ul>
-<li>
-<p>b</p>
-<p>c</p>
-</li>
-</ul>
-</li>
-<li>d</li>
-</ul>
-````````````````````````````````
-
-
-This is a tight list, because the blank line is inside the
-block quote:
-
-```````````````````````````````` example
-* a
- > b
- >
-* c
-.
-<ul>
-<li>a
-<blockquote>
-<p>b</p>
-</blockquote>
-</li>
-<li>c</li>
-</ul>
-````````````````````````````````
-
-
-This list is tight, because the consecutive block elements
-are not separated by blank lines:
-
-```````````````````````````````` example
-- a
- > b
- ```
- c
- ```
-- d
-.
-<ul>
-<li>a
-<blockquote>
-<p>b</p>
-</blockquote>
-<pre><code>c
-</code></pre>
-</li>
-<li>d</li>
-</ul>
-````````````````````````````````
-
-
-A single-paragraph list is tight:
-
-```````````````````````````````` example
-- a
-.
-<ul>
-<li>a</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- a
- - b
-.
-<ul>
-<li>a
-<ul>
-<li>b</li>
-</ul>
-</li>
-</ul>
-````````````````````````````````
-
-
-This list is loose, because of the blank line between the
-two block elements in the list item:
-
-```````````````````````````````` example
-1. ```
- foo
- ```
-
- bar
-.
-<ol>
-<li>
-<pre><code>foo
-</code></pre>
-<p>bar</p>
-</li>
-</ol>
-````````````````````````````````
-
-
-Here the outer list is loose, the inner list tight:
-
-```````````````````````````````` example
-* foo
- * bar
-
- baz
-.
-<ul>
-<li>
-<p>foo</p>
-<ul>
-<li>bar</li>
-</ul>
-<p>baz</p>
-</li>
-</ul>
-````````````````````````````````
-
-
-```````````````````````````````` example
-- a
- - b
- - c
-
-- d
- - e
- - f
-.
-<ul>
-<li>
-<p>a</p>
-<ul>
-<li>b</li>
-<li>c</li>
-</ul>
-</li>
-<li>
-<p>d</p>
-<ul>
-<li>e</li>
-<li>f</li>
-</ul>
-</li>
-</ul>
-````````````````````````````````
-
-
-# Inlines
-
-Inlines are parsed sequentially from the beginning of the character
-stream to the end (left to right, in left-to-right languages).
-Thus, for example, in
-
-```````````````````````````````` example
-`hi`lo`
-.
-<p><code>hi</code>lo`</p>
-````````````````````````````````
-
-`hi` is parsed as code, leaving the backtick at the end as a literal
-backtick.
-
-
-
-## Code spans
-
-A [backtick string](@)
-is a string of one or more backtick characters (`` ` ``) that is neither
-preceded nor followed by a backtick.
-
-A [code span](@) begins with a backtick string and ends with
-a backtick string of equal length. The contents of the code span are
-the characters between these two backtick strings, normalized in the
-following ways:
-
-- First, [line endings] are converted to [spaces].
-- If the resulting string both begins *and* ends with a [space]
- character, but does not consist entirely of [space]
- characters, a single [space] character is removed from the
- front and back. This allows you to include code that begins
- or ends with backtick characters, which must be separated by
- whitespace from the opening or closing backtick strings.
-
-This is a simple code span:
-
-```````````````````````````````` example
-`foo`
-.
-<p><code>foo</code></p>
-````````````````````````````````
-
-
-Here two backticks are used, because the code contains a backtick.
-This example also illustrates stripping of a single leading and
-trailing space:
-
-```````````````````````````````` example
-`` foo ` bar ``
-.
-<p><code>foo ` bar</code></p>
-````````````````````````````````
-
-
-This example shows the motivation for stripping leading and trailing
-spaces:
-
-```````````````````````````````` example
-` `` `
-.
-<p><code>``</code></p>
-````````````````````````````````
-
-Note that only *one* space is stripped:
-
-```````````````````````````````` example
-` `` `
-.
-<p><code> `` </code></p>
-````````````````````````````````
-
-The stripping only happens if the space is on both
-sides of the string:
-
-```````````````````````````````` example
-` a`
-.
-<p><code> a</code></p>
-````````````````````````````````
-
-Only [spaces], and not [unicode whitespace] in general, are
-stripped in this way:
-
-```````````````````````````````` example
-` b `
-.
-<p><code> b </code></p>
-````````````````````````````````
-
-No stripping occurs if the code span contains only spaces:
-
-```````````````````````````````` example
-` `
-` `
-.
-<p><code> </code>
-<code> </code></p>
-````````````````````````````````
-
-
-[Line endings] are treated like spaces:
-
-```````````````````````````````` example
-``
-foo
-bar
-baz
-``
-.
-<p><code>foo bar baz</code></p>
-````````````````````````````````
-
-```````````````````````````````` example
-``
-foo
-``
-.
-<p><code>foo </code></p>
-````````````````````````````````
-
-
-Interior spaces are not collapsed:
-
-```````````````````````````````` example
-`foo bar
-baz`
-.
-<p><code>foo bar baz</code></p>
-````````````````````````````````
-
-Note that browsers will typically collapse consecutive spaces
-when rendering `<code>` elements, so it is recommended that
-the following CSS be used:
-
- code{white-space: pre-wrap;}
-
-
-Note that backslash escapes do not work in code spans. All backslashes
-are treated literally:
-
-```````````````````````````````` example
-`foo\`bar`
-.
-<p><code>foo\</code>bar`</p>
-````````````````````````````````
-
-
-Backslash escapes are never needed, because one can always choose a
-string of *n* backtick characters as delimiters, where the code does
-not contain any strings of exactly *n* backtick characters.
-
-```````````````````````````````` example
-``foo`bar``
-.
-<p><code>foo`bar</code></p>
-````````````````````````````````
-
-```````````````````````````````` example
-` foo `` bar `
-.
-<p><code>foo `` bar</code></p>
-````````````````````````````````
-
-
-Code span backticks have higher precedence than any other inline
-constructs except HTML tags and autolinks. Thus, for example, this is
-not parsed as emphasized text, since the second `*` is part of a code
-span:
-
-```````````````````````````````` example
-*foo`*`
-.
-<p>*foo<code>*</code></p>
-````````````````````````````````
-
-
-And this is not parsed as a link:
-
-```````````````````````````````` example
-[not a `link](/foo`)
-.
-<p>[not a <code>link](/foo</code>)</p>
-````````````````````````````````
-
-
-Code spans, HTML tags, and autolinks have the same precedence.
-Thus, this is code:
-
-```````````````````````````````` example
-`<a href="`">`
-.
-<p><code>&lt;a href=&quot;</code>&quot;&gt;`</p>
-````````````````````````````````
-
-
-But this is an HTML tag:
-
-```````````````````````````````` example
-<a href="`">`
-.
-<p><a href="`">`</p>
-````````````````````````````````
-
-
-And this is code:
-
-```````````````````````````````` example
-`<http://foo.bar.`baz>`
-.
-<p><code>&lt;http://foo.bar.</code>baz&gt;`</p>
-````````````````````````````````
-
-
-But this is an autolink:
-
-```````````````````````````````` example
-<http://foo.bar.`baz>`
-.
-<p><a href="http://foo.bar.%60baz">http://foo.bar.`baz</a>`</p>
-````````````````````````````````
-
-
-When a backtick string is not closed by a matching backtick string,
-we just have literal backticks:
-
-```````````````````````````````` example
-```foo``
-.
-<p>```foo``</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-`foo
-.
-<p>`foo</p>
-````````````````````````````````
-
-The following case also illustrates the need for opening and
-closing backtick strings to be equal in length:
-
-```````````````````````````````` example
-`foo``bar``
-.
-<p>`foo<code>bar</code></p>
-````````````````````````````````
-
-
-## Emphasis and strong emphasis
-
-John Gruber's original [Markdown syntax
-description](http://daringfireball.net/projects/markdown/syntax#em) says:
-
-> Markdown treats asterisks (`*`) and underscores (`_`) as indicators of
-> emphasis. Text wrapped with one `*` or `_` will be wrapped with an HTML
-> `<em>` tag; double `*`'s or `_`'s will be wrapped with an HTML `<strong>`
-> tag.
-
-This is enough for most users, but these rules leave much undecided,
-especially when it comes to nested emphasis. The original
-`Markdown.pl` test suite makes it clear that triple `***` and
-`___` delimiters can be used for strong emphasis, and most
-implementations have also allowed the following patterns:
-
-``` markdown
-***strong emph***
-***strong** in emph*
-***emph* in strong**
-**in strong *emph***
-*in emph **strong***
-```
-
-The following patterns are less widely supported, but the intent
-is clear and they are useful (especially in contexts like bibliography
-entries):
-
-``` markdown
-*emph *with emph* in it*
-**strong **with strong** in it**
-```
-
-Many implementations have also restricted intraword emphasis to
-the `*` forms, to avoid unwanted emphasis in words containing
-internal underscores. (It is best practice to put these in code
-spans, but users often do not.)
-
-``` markdown
-internal emphasis: foo*bar*baz
-no emphasis: foo_bar_baz
-```
-
-The rules given below capture all of these patterns, while allowing
-for efficient parsing strategies that do not backtrack.
-
-First, some definitions. A [delimiter run](@) is either
-a sequence of one or more `*` characters that is not preceded or
-followed by a non-backslash-escaped `*` character, or a sequence
-of one or more `_` characters that is not preceded or followed by
-a non-backslash-escaped `_` character.
-
-A [left-flanking delimiter run](@) is
-a [delimiter run] that is (1) not followed by [Unicode whitespace],
-and either (2a) not followed by a [punctuation character], or
-(2b) followed by a [punctuation character] and
-preceded by [Unicode whitespace] or a [punctuation character].
-For purposes of this definition, the beginning and the end of
-the line count as Unicode whitespace.
-
-A [right-flanking delimiter run](@) is
-a [delimiter run] that is (1) not preceded by [Unicode whitespace],
-and either (2a) not preceded by a [punctuation character], or
-(2b) preceded by a [punctuation character] and
-followed by [Unicode whitespace] or a [punctuation character].
-For purposes of this definition, the beginning and the end of
-the line count as Unicode whitespace.
-
-Here are some examples of delimiter runs.
-
- - left-flanking but not right-flanking:
-
- ```
- ***abc
- _abc
- **"abc"
- _"abc"
- ```
-
- - right-flanking but not left-flanking:
-
- ```
- abc***
- abc_
- "abc"**
- "abc"_
- ```
-
- - Both left and right-flanking:
-
- ```
- abc***def
- "abc"_"def"
- ```
-
- - Neither left nor right-flanking:
-
- ```
- abc *** def
- a _ b
- ```
-
-(The idea of distinguishing left-flanking and right-flanking
-delimiter runs based on the character before and the character
-after comes from Roopesh Chander's
-[vfmd](http://www.vfmd.org/vfmd-spec/specification/#procedure-for-identifying-emphasis-tags).
-vfmd uses the terminology "emphasis indicator string" instead of "delimiter
-run," and its rules for distinguishing left- and right-flanking runs
-are a bit more complex than the ones given here.)
-
-The following rules define emphasis and strong emphasis:
-
-1. A single `*` character [can open emphasis](@)
- iff (if and only if) it is part of a [left-flanking delimiter run].
-
-2. A single `_` character [can open emphasis] iff
- it is part of a [left-flanking delimiter run]
- and either (a) not part of a [right-flanking delimiter run]
- or (b) part of a [right-flanking delimiter run]
- preceded by punctuation.
-
-3. A single `*` character [can close emphasis](@)
- iff it is part of a [right-flanking delimiter run].
-
-4. A single `_` character [can close emphasis] iff
- it is part of a [right-flanking delimiter run]
- and either (a) not part of a [left-flanking delimiter run]
- or (b) part of a [left-flanking delimiter run]
- followed by punctuation.
-
-5. A double `**` [can open strong emphasis](@)
- iff it is part of a [left-flanking delimiter run].
-
-6. A double `__` [can open strong emphasis] iff
- it is part of a [left-flanking delimiter run]
- and either (a) not part of a [right-flanking delimiter run]
- or (b) part of a [right-flanking delimiter run]
- preceded by punctuation.
-
-7. A double `**` [can close strong emphasis](@)
- iff it is part of a [right-flanking delimiter run].
-
-8. A double `__` [can close strong emphasis] iff
- it is part of a [right-flanking delimiter run]
- and either (a) not part of a [left-flanking delimiter run]
- or (b) part of a [left-flanking delimiter run]
- followed by punctuation.
-
-9. Emphasis begins with a delimiter that [can open emphasis] and ends
- with a delimiter that [can close emphasis], and that uses the same
- character (`_` or `*`) as the opening delimiter. The
- opening and closing delimiters must belong to separate
- [delimiter runs]. If one of the delimiters can both
- open and close emphasis, then the sum of the lengths of the
- delimiter runs containing the opening and closing delimiters
- must not be a multiple of 3 unless both lengths are
- multiples of 3.
-
-10. Strong emphasis begins with a delimiter that
- [can open strong emphasis] and ends with a delimiter that
- [can close strong emphasis], and that uses the same character
- (`_` or `*`) as the opening delimiter. The
- opening and closing delimiters must belong to separate
- [delimiter runs]. If one of the delimiters can both open
- and close strong emphasis, then the sum of the lengths of
- the delimiter runs containing the opening and closing
- delimiters must not be a multiple of 3 unless both lengths
- are multiples of 3.
-
-11. A literal `*` character cannot occur at the beginning or end of
- `*`-delimited emphasis or `**`-delimited strong emphasis, unless it
- is backslash-escaped.
-
-12. A literal `_` character cannot occur at the beginning or end of
- `_`-delimited emphasis or `__`-delimited strong emphasis, unless it
- is backslash-escaped.
-
-Where rules 1--12 above are compatible with multiple parsings,
-the following principles resolve ambiguity:
-
-13. The number of nestings should be minimized. Thus, for example,
- an interpretation `<strong>...</strong>` is always preferred to
- `<em><em>...</em></em>`.
-
-14. An interpretation `<em><strong>...</strong></em>` is always
- preferred to `<strong><em>...</em></strong>`.
-
-15. When two potential emphasis or strong emphasis spans overlap,
- so that the second begins before the first ends and ends after
- the first ends, the first takes precedence. Thus, for example,
- `*foo _bar* baz_` is parsed as `<em>foo _bar</em> baz_` rather
- than `*foo <em>bar* baz</em>`.
-
-16. When there are two potential emphasis or strong emphasis spans
- with the same closing delimiter, the shorter one (the one that
- opens later) takes precedence. Thus, for example,
- `**foo **bar baz**` is parsed as `**foo <strong>bar baz</strong>`
- rather than `<strong>foo **bar baz</strong>`.
-
-17. Inline code spans, links, images, and HTML tags group more tightly
- than emphasis. So, when there is a choice between an interpretation
- that contains one of these elements and one that does not, the
- former always wins. Thus, for example, `*[foo*](bar)` is
- parsed as `*<a href="bar">foo*</a>` rather than as
- `<em>[foo</em>](bar)`.
-
-These rules can be illustrated through a series of examples.
-
-Rule 1:
-
-```````````````````````````````` example
-*foo bar*
-.
-<p><em>foo bar</em></p>
-````````````````````````````````
-
-
-This is not emphasis, because the opening `*` is followed by
-whitespace, and hence not part of a [left-flanking delimiter run]:
-
-```````````````````````````````` example
-a * foo bar*
-.
-<p>a * foo bar*</p>
-````````````````````````````````
-
-
-This is not emphasis, because the opening `*` is preceded
-by an alphanumeric and followed by punctuation, and hence
-not part of a [left-flanking delimiter run]:
-
-```````````````````````````````` example
-a*"foo"*
-.
-<p>a*&quot;foo&quot;*</p>
-````````````````````````````````
-
-
-Unicode nonbreaking spaces count as whitespace, too:
-
-```````````````````````````````` example
-* a *
-.
-<p>* a *</p>
-````````````````````````````````
-
-
-Intraword emphasis with `*` is permitted:
-
-```````````````````````````````` example
-foo*bar*
-.
-<p>foo<em>bar</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-5*6*78
-.
-<p>5<em>6</em>78</p>
-````````````````````````````````
-
-
-Rule 2:
-
-```````````````````````````````` example
-_foo bar_
-.
-<p><em>foo bar</em></p>
-````````````````````````````````
-
-
-This is not emphasis, because the opening `_` is followed by
-whitespace:
-
-```````````````````````````````` example
-_ foo bar_
-.
-<p>_ foo bar_</p>
-````````````````````````````````
-
-
-This is not emphasis, because the opening `_` is preceded
-by an alphanumeric and followed by punctuation:
-
-```````````````````````````````` example
-a_"foo"_
-.
-<p>a_&quot;foo&quot;_</p>
-````````````````````````````````
-
-
-Emphasis with `_` is not allowed inside words:
-
-```````````````````````````````` example
-foo_bar_
-.
-<p>foo_bar_</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-5_6_78
-.
-<p>5_6_78</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-пристаням_стремятся_
-.
-<p>пристаням_стремятся_</p>
-````````````````````````````````
-
-
-Here `_` does not generate emphasis, because the first delimiter run
-is right-flanking and the second left-flanking:
-
-```````````````````````````````` example
-aa_"bb"_cc
-.
-<p>aa_&quot;bb&quot;_cc</p>
-````````````````````````````````
-
-
-This is emphasis, even though the opening delimiter is
-both left- and right-flanking, because it is preceded by
-punctuation:
-
-```````````````````````````````` example
-foo-_(bar)_
-.
-<p>foo-<em>(bar)</em></p>
-````````````````````````````````
-
-
-Rule 3:
-
-This is not emphasis, because the closing delimiter does
-not match the opening delimiter:
-
-```````````````````````````````` example
-_foo*
-.
-<p>_foo*</p>
-````````````````````````````````
-
-
-This is not emphasis, because the closing `*` is preceded by
-whitespace:
-
-```````````````````````````````` example
-*foo bar *
-.
-<p>*foo bar *</p>
-````````````````````````````````
-
-
-A newline also counts as whitespace:
-
-```````````````````````````````` example
-*foo bar
-*
-.
-<p>*foo bar
-*</p>
-````````````````````````````````
-
-
-This is not emphasis, because the second `*` is
-preceded by punctuation and followed by an alphanumeric
-(hence it is not part of a [right-flanking delimiter run]:
-
-```````````````````````````````` example
-*(*foo)
-.
-<p>*(*foo)</p>
-````````````````````````````````
-
-
-The point of this restriction is more easily appreciated
-with this example:
-
-```````````````````````````````` example
-*(*foo*)*
-.
-<p><em>(<em>foo</em>)</em></p>
-````````````````````````````````
-
-
-Intraword emphasis with `*` is allowed:
-
-```````````````````````````````` example
-*foo*bar
-.
-<p><em>foo</em>bar</p>
-````````````````````````````````
-
-
-
-Rule 4:
-
-This is not emphasis, because the closing `_` is preceded by
-whitespace:
-
-```````````````````````````````` example
-_foo bar _
-.
-<p>_foo bar _</p>
-````````````````````````````````
-
-
-This is not emphasis, because the second `_` is
-preceded by punctuation and followed by an alphanumeric:
-
-```````````````````````````````` example
-_(_foo)
-.
-<p>_(_foo)</p>
-````````````````````````````````
-
-
-This is emphasis within emphasis:
-
-```````````````````````````````` example
-_(_foo_)_
-.
-<p><em>(<em>foo</em>)</em></p>
-````````````````````````````````
-
-
-Intraword emphasis is disallowed for `_`:
-
-```````````````````````````````` example
-_foo_bar
-.
-<p>_foo_bar</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_пристаням_стремятся
-.
-<p>_пристаням_стремятся</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_foo_bar_baz_
-.
-<p><em>foo_bar_baz</em></p>
-````````````````````````````````
-
-
-This is emphasis, even though the closing delimiter is
-both left- and right-flanking, because it is followed by
-punctuation:
-
-```````````````````````````````` example
-_(bar)_.
-.
-<p><em>(bar)</em>.</p>
-````````````````````````````````
-
-
-Rule 5:
-
-```````````````````````````````` example
-**foo bar**
-.
-<p><strong>foo bar</strong></p>
-````````````````````````````````
-
-
-This is not strong emphasis, because the opening delimiter is
-followed by whitespace:
-
-```````````````````````````````` example
-** foo bar**
-.
-<p>** foo bar**</p>
-````````````````````````````````
-
-
-This is not strong emphasis, because the opening `**` is preceded
-by an alphanumeric and followed by punctuation, and hence
-not part of a [left-flanking delimiter run]:
-
-```````````````````````````````` example
-a**"foo"**
-.
-<p>a**&quot;foo&quot;**</p>
-````````````````````````````````
-
-
-Intraword strong emphasis with `**` is permitted:
-
-```````````````````````````````` example
-foo**bar**
-.
-<p>foo<strong>bar</strong></p>
-````````````````````````````````
-
-
-Rule 6:
-
-```````````````````````````````` example
-__foo bar__
-.
-<p><strong>foo bar</strong></p>
-````````````````````````````````
-
-
-This is not strong emphasis, because the opening delimiter is
-followed by whitespace:
-
-```````````````````````````````` example
-__ foo bar__
-.
-<p>__ foo bar__</p>
-````````````````````````````````
-
-
-A newline counts as whitespace:
-```````````````````````````````` example
-__
-foo bar__
-.
-<p>__
-foo bar__</p>
-````````````````````````````````
-
-
-This is not strong emphasis, because the opening `__` is preceded
-by an alphanumeric and followed by punctuation:
-
-```````````````````````````````` example
-a__"foo"__
-.
-<p>a__&quot;foo&quot;__</p>
-````````````````````````````````
-
-
-Intraword strong emphasis is forbidden with `__`:
-
-```````````````````````````````` example
-foo__bar__
-.
-<p>foo__bar__</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-5__6__78
-.
-<p>5__6__78</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-пристаням__стремятся__
-.
-<p>пристаням__стремятся__</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo, __bar__, baz__
-.
-<p><strong>foo, <strong>bar</strong>, baz</strong></p>
-````````````````````````````````
-
-
-This is strong emphasis, even though the opening delimiter is
-both left- and right-flanking, because it is preceded by
-punctuation:
-
-```````````````````````````````` example
-foo-__(bar)__
-.
-<p>foo-<strong>(bar)</strong></p>
-````````````````````````````````
-
-
-
-Rule 7:
-
-This is not strong emphasis, because the closing delimiter is preceded
-by whitespace:
-
-```````````````````````````````` example
-**foo bar **
-.
-<p>**foo bar **</p>
-````````````````````````````````
-
-
-(Nor can it be interpreted as an emphasized `*foo bar *`, because of
-Rule 11.)
-
-This is not strong emphasis, because the second `**` is
-preceded by punctuation and followed by an alphanumeric:
-
-```````````````````````````````` example
-**(**foo)
-.
-<p>**(**foo)</p>
-````````````````````````````````
-
-
-The point of this restriction is more easily appreciated
-with these examples:
-
-```````````````````````````````` example
-*(**foo**)*
-.
-<p><em>(<strong>foo</strong>)</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**Gomphocarpus (*Gomphocarpus physocarpus*, syn.
-*Asclepias physocarpa*)**
-.
-<p><strong>Gomphocarpus (<em>Gomphocarpus physocarpus</em>, syn.
-<em>Asclepias physocarpa</em>)</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo "*bar*" foo**
-.
-<p><strong>foo &quot;<em>bar</em>&quot; foo</strong></p>
-````````````````````````````````
-
-
-Intraword emphasis:
-
-```````````````````````````````` example
-**foo**bar
-.
-<p><strong>foo</strong>bar</p>
-````````````````````````````````
-
-
-Rule 8:
-
-This is not strong emphasis, because the closing delimiter is
-preceded by whitespace:
-
-```````````````````````````````` example
-__foo bar __
-.
-<p>__foo bar __</p>
-````````````````````````````````
-
-
-This is not strong emphasis, because the second `__` is
-preceded by punctuation and followed by an alphanumeric:
-
-```````````````````````````````` example
-__(__foo)
-.
-<p>__(__foo)</p>
-````````````````````````````````
-
-
-The point of this restriction is more easily appreciated
-with this example:
-
-```````````````````````````````` example
-_(__foo__)_
-.
-<p><em>(<strong>foo</strong>)</em></p>
-````````````````````````````````
-
-
-Intraword strong emphasis is forbidden with `__`:
-
-```````````````````````````````` example
-__foo__bar
-.
-<p>__foo__bar</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__пристаням__стремятся
-.
-<p>__пристаням__стремятся</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo__bar__baz__
-.
-<p><strong>foo__bar__baz</strong></p>
-````````````````````````````````
-
-
-This is strong emphasis, even though the closing delimiter is
-both left- and right-flanking, because it is followed by
-punctuation:
-
-```````````````````````````````` example
-__(bar)__.
-.
-<p><strong>(bar)</strong>.</p>
-````````````````````````````````
-
-
-Rule 9:
-
-Any nonempty sequence of inline elements can be the contents of an
-emphasized span.
-
-```````````````````````````````` example
-*foo [bar](/url)*
-.
-<p><em>foo <a href="/url">bar</a></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo
-bar*
-.
-<p><em>foo
-bar</em></p>
-````````````````````````````````
-
-
-In particular, emphasis and strong emphasis can be nested
-inside emphasis:
-
-```````````````````````````````` example
-_foo __bar__ baz_
-.
-<p><em>foo <strong>bar</strong> baz</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_foo _bar_ baz_
-.
-<p><em>foo <em>bar</em> baz</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo_ bar_
-.
-<p><em><em>foo</em> bar</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo *bar**
-.
-<p><em>foo <em>bar</em></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo **bar** baz*
-.
-<p><em>foo <strong>bar</strong> baz</em></p>
-````````````````````````````````
-
-```````````````````````````````` example
-*foo**bar**baz*
-.
-<p><em>foo<strong>bar</strong>baz</em></p>
-````````````````````````````````
-
-Note that in the preceding case, the interpretation
-
-``` markdown
-<p><em>foo</em><em>bar<em></em>baz</em></p>
-```
-
-
-is precluded by the condition that a delimiter that
-can both open and close (like the `*` after `foo`)
-cannot form emphasis if the sum of the lengths of
-the delimiter runs containing the opening and
-closing delimiters is a multiple of 3 unless
-both lengths are multiples of 3.
-
-
-For the same reason, we don't get two consecutive
-emphasis sections in this example:
-
-```````````````````````````````` example
-*foo**bar*
-.
-<p><em>foo**bar</em></p>
-````````````````````````````````
-
-
-The same condition ensures that the following
-cases are all strong emphasis nested inside
-emphasis, even when the interior spaces are
-omitted:
-
-
-```````````````````````````````` example
-***foo** bar*
-.
-<p><em><strong>foo</strong> bar</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo **bar***
-.
-<p><em>foo <strong>bar</strong></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo**bar***
-.
-<p><em>foo<strong>bar</strong></em></p>
-````````````````````````````````
-
-
-When the lengths of the interior closing and opening
-delimiter runs are *both* multiples of 3, though,
-they can match to create emphasis:
-
-```````````````````````````````` example
-foo***bar***baz
-.
-<p>foo<em><strong>bar</strong></em>baz</p>
-````````````````````````````````
-
-```````````````````````````````` example
-foo******bar*********baz
-.
-<p>foo<strong><strong><strong>bar</strong></strong></strong>***baz</p>
-````````````````````````````````
-
-
-Indefinite levels of nesting are possible:
-
-```````````````````````````````` example
-*foo **bar *baz* bim** bop*
-.
-<p><em>foo <strong>bar <em>baz</em> bim</strong> bop</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo [*bar*](/url)*
-.
-<p><em>foo <a href="/url"><em>bar</em></a></em></p>
-````````````````````````````````
-
-
-There can be no empty emphasis or strong emphasis:
-
-```````````````````````````````` example
-** is not an empty emphasis
-.
-<p>** is not an empty emphasis</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**** is not an empty strong emphasis
-.
-<p>**** is not an empty strong emphasis</p>
-````````````````````````````````
-
-
-
-Rule 10:
-
-Any nonempty sequence of inline elements can be the contents of an
-strongly emphasized span.
-
-```````````````````````````````` example
-**foo [bar](/url)**
-.
-<p><strong>foo <a href="/url">bar</a></strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo
-bar**
-.
-<p><strong>foo
-bar</strong></p>
-````````````````````````````````
-
-
-In particular, emphasis and strong emphasis can be nested
-inside strong emphasis:
-
-```````````````````````````````` example
-__foo _bar_ baz__
-.
-<p><strong>foo <em>bar</em> baz</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo __bar__ baz__
-.
-<p><strong>foo <strong>bar</strong> baz</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-____foo__ bar__
-.
-<p><strong><strong>foo</strong> bar</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo **bar****
-.
-<p><strong>foo <strong>bar</strong></strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo *bar* baz**
-.
-<p><strong>foo <em>bar</em> baz</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo*bar*baz**
-.
-<p><strong>foo<em>bar</em>baz</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-***foo* bar**
-.
-<p><strong><em>foo</em> bar</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo *bar***
-.
-<p><strong>foo <em>bar</em></strong></p>
-````````````````````````````````
-
-
-Indefinite levels of nesting are possible:
-
-```````````````````````````````` example
-**foo *bar **baz**
-bim* bop**
-.
-<p><strong>foo <em>bar <strong>baz</strong>
-bim</em> bop</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo [*bar*](/url)**
-.
-<p><strong>foo <a href="/url"><em>bar</em></a></strong></p>
-````````````````````````````````
-
-
-There can be no empty emphasis or strong emphasis:
-
-```````````````````````````````` example
-__ is not an empty emphasis
-.
-<p>__ is not an empty emphasis</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-____ is not an empty strong emphasis
-.
-<p>____ is not an empty strong emphasis</p>
-````````````````````````````````
-
-
-
-Rule 11:
-
-```````````````````````````````` example
-foo ***
-.
-<p>foo ***</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo *\**
-.
-<p>foo <em>*</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo *_*
-.
-<p>foo <em>_</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo *****
-.
-<p>foo *****</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo **\***
-.
-<p>foo <strong>*</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo **_**
-.
-<p>foo <strong>_</strong></p>
-````````````````````````````````
-
-
-Note that when delimiters do not match evenly, Rule 11 determines
-that the excess literal `*` characters will appear outside of the
-emphasis, rather than inside it:
-
-```````````````````````````````` example
-**foo*
-.
-<p>*<em>foo</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo**
-.
-<p><em>foo</em>*</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-***foo**
-.
-<p>*<strong>foo</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-****foo*
-.
-<p>***<em>foo</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**foo***
-.
-<p><strong>foo</strong>*</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo****
-.
-<p><em>foo</em>***</p>
-````````````````````````````````
-
-
-
-Rule 12:
-
-```````````````````````````````` example
-foo ___
-.
-<p>foo ___</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo _\__
-.
-<p>foo <em>_</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo _*_
-.
-<p>foo <em>*</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo _____
-.
-<p>foo _____</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo __\___
-.
-<p>foo <strong>_</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo __*__
-.
-<p>foo <strong>*</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo_
-.
-<p>_<em>foo</em></p>
-````````````````````````````````
-
-
-Note that when delimiters do not match evenly, Rule 12 determines
-that the excess literal `_` characters will appear outside of the
-emphasis, rather than inside it:
-
-```````````````````````````````` example
-_foo__
-.
-<p><em>foo</em>_</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-___foo__
-.
-<p>_<strong>foo</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-____foo_
-.
-<p>___<em>foo</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo___
-.
-<p><strong>foo</strong>_</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_foo____
-.
-<p><em>foo</em>___</p>
-````````````````````````````````
-
-
-Rule 13 implies that if you want emphasis nested directly inside
-emphasis, you must use different delimiters:
-
-```````````````````````````````` example
-**foo**
-.
-<p><strong>foo</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*_foo_*
-.
-<p><em><em>foo</em></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__foo__
-.
-<p><strong>foo</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_*foo*_
-.
-<p><em><em>foo</em></em></p>
-````````````````````````````````
-
-
-However, strong emphasis within strong emphasis is possible without
-switching delimiters:
-
-```````````````````````````````` example
-****foo****
-.
-<p><strong><strong>foo</strong></strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-____foo____
-.
-<p><strong><strong>foo</strong></strong></p>
-````````````````````````````````
-
-
-
-Rule 13 can be applied to arbitrarily long sequences of
-delimiters:
-
-```````````````````````````````` example
-******foo******
-.
-<p><strong><strong><strong>foo</strong></strong></strong></p>
-````````````````````````````````
-
-
-Rule 14:
-
-```````````````````````````````` example
-***foo***
-.
-<p><em><strong>foo</strong></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_____foo_____
-.
-<p><em><strong><strong>foo</strong></strong></em></p>
-````````````````````````````````
-
-
-Rule 15:
-
-```````````````````````````````` example
-*foo _bar* baz_
-.
-<p><em>foo _bar</em> baz_</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo __bar *baz bim__ bam*
-.
-<p><em>foo <strong>bar *baz bim</strong> bam</em></p>
-````````````````````````````````
-
-
-Rule 16:
-
-```````````````````````````````` example
-**foo **bar baz**
-.
-<p>**foo <strong>bar baz</strong></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo *bar baz*
-.
-<p>*foo <em>bar baz</em></p>
-````````````````````````````````
-
-
-Rule 17:
-
-```````````````````````````````` example
-*[bar*](/url)
-.
-<p>*<a href="/url">bar*</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_foo [bar_](/url)
-.
-<p>_foo <a href="/url">bar_</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*<img src="foo" title="*"/>
-.
-<p>*<img src="foo" title="*"/></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**<a href="**">
-.
-<p>**<a href="**"></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__<a href="__">
-.
-<p>__<a href="__"></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*a `*`*
-.
-<p><em>a <code>*</code></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-_a `_`_
-.
-<p><em>a <code>_</code></em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-**a<http://foo.bar/?q=**>
-.
-<p>**a<a href="http://foo.bar/?q=**">http://foo.bar/?q=**</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-__a<http://foo.bar/?q=__>
-.
-<p>__a<a href="http://foo.bar/?q=__">http://foo.bar/?q=__</a></p>
-````````````````````````````````
-
-
-
-## Links
-
-A link contains [link text] (the visible text), a [link destination]
-(the URI that is the link destination), and optionally a [link title].
-There are two basic kinds of links in Markdown. In [inline links] the
-destination and title are given immediately after the link text. In
-[reference links] the destination and title are defined elsewhere in
-the document.
-
-A [link text](@) consists of a sequence of zero or more
-inline elements enclosed by square brackets (`[` and `]`). The
-following rules apply:
-
-- Links may not contain other links, at any level of nesting. If
- multiple otherwise valid link definitions appear nested inside each
- other, the inner-most definition is used.
-
-- Brackets are allowed in the [link text] only if (a) they
- are backslash-escaped or (b) they appear as a matched pair of brackets,
- with an open bracket `[`, a sequence of zero or more inlines, and
- a close bracket `]`.
-
-- Backtick [code spans], [autolinks], and raw [HTML tags] bind more tightly
- than the brackets in link text. Thus, for example,
- `` [foo`]` `` could not be a link text, since the second `]`
- is part of a code span.
-
-- The brackets in link text bind more tightly than markers for
- [emphasis and strong emphasis]. Thus, for example, `*[foo*](url)` is a link.
-
-A [link destination](@) consists of either
-
-- a sequence of zero or more characters between an opening `<` and a
- closing `>` that contains no line breaks or unescaped
- `<` or `>` characters, or
-
-- a nonempty sequence of characters that does not start with `<`,
- does not include [ASCII control characters][ASCII control character]
- or [whitespace][], and includes parentheses only if (a) they are
- backslash-escaped or (b) they are part of a balanced pair of
- unescaped parentheses.
- (Implementations may impose limits on parentheses nesting to
- avoid performance issues, but at least three levels of nesting
- should be supported.)
-
-A [link title](@) consists of either
-
-- a sequence of zero or more characters between straight double-quote
- characters (`"`), including a `"` character only if it is
- backslash-escaped, or
-
-- a sequence of zero or more characters between straight single-quote
- characters (`'`), including a `'` character only if it is
- backslash-escaped, or
-
-- a sequence of zero or more characters between matching parentheses
- (`(...)`), including a `(` or `)` character only if it is
- backslash-escaped.
-
-Although [link titles] may span multiple lines, they may not contain
-a [blank line].
-
-An [inline link](@) consists of a [link text] followed immediately
-by a left parenthesis `(`, optional [whitespace], an optional
-[link destination], an optional [link title] separated from the link
-destination by [whitespace], optional [whitespace], and a right
-parenthesis `)`. The link's text consists of the inlines contained
-in the [link text] (excluding the enclosing square brackets).
-The link's URI consists of the link destination, excluding enclosing
-`<...>` if present, with backslash-escapes in effect as described
-above. The link's title consists of the link title, excluding its
-enclosing delimiters, with backslash-escapes in effect as described
-above.
-
-Here is a simple inline link:
-
-```````````````````````````````` example
-[link](/uri "title")
-.
-<p><a href="/uri" title="title">link</a></p>
-````````````````````````````````
-
-
-The title may be omitted:
-
-```````````````````````````````` example
-[link](/uri)
-.
-<p><a href="/uri">link</a></p>
-````````````````````````````````
-
-
-Both the title and the destination may be omitted:
-
-```````````````````````````````` example
-[link]()
-.
-<p><a href="">link</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link](<>)
-.
-<p><a href="">link</a></p>
-````````````````````````````````
-
-The destination can only contain spaces if it is
-enclosed in pointy brackets:
-
-```````````````````````````````` example
-[link](/my uri)
-.
-<p>[link](/my uri)</p>
-````````````````````````````````
-
-```````````````````````````````` example
-[link](</my uri>)
-.
-<p><a href="/my%20uri">link</a></p>
-````````````````````````````````
-
-The destination cannot contain line breaks,
-even if enclosed in pointy brackets:
-
-```````````````````````````````` example
-[link](foo
-bar)
-.
-<p>[link](foo
-bar)</p>
-````````````````````````````````
-
-```````````````````````````````` example
-[link](<foo
-bar>)
-.
-<p>[link](<foo
-bar>)</p>
-````````````````````````````````
-
-The destination can contain `)` if it is enclosed
-in pointy brackets:
-
-```````````````````````````````` example
-[a](<b)c>)
-.
-<p><a href="b)c">a</a></p>
-````````````````````````````````
-
-Pointy brackets that enclose links must be unescaped:
-
-```````````````````````````````` example
-[link](<foo\>)
-.
-<p>[link](&lt;foo&gt;)</p>
-````````````````````````````````
-
-These are not links, because the opening pointy bracket
-is not matched properly:
-
-```````````````````````````````` example
-[a](<b)c
-[a](<b)c>
-[a](<b>c)
-.
-<p>[a](&lt;b)c
-[a](&lt;b)c&gt;
-[a](<b>c)</p>
-````````````````````````````````
-
-Parentheses inside the link destination may be escaped:
-
-```````````````````````````````` example
-[link](\(foo\))
-.
-<p><a href="(foo)">link</a></p>
-````````````````````````````````
-
-Any number of parentheses are allowed without escaping, as long as they are
-balanced:
-
-```````````````````````````````` example
-[link](foo(and(bar)))
-.
-<p><a href="foo(and(bar))">link</a></p>
-````````````````````````````````
-
-However, if you have unbalanced parentheses, you need to escape or use the
-`<...>` form:
-
-```````````````````````````````` example
-[link](foo(and(bar))
-.
-<p>[link](foo(and(bar))</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link](foo\(and\(bar\))
-.
-<p><a href="foo(and(bar)">link</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link](<foo(and(bar)>)
-.
-<p><a href="foo(and(bar)">link</a></p>
-````````````````````````````````
-
-
-Parentheses and other symbols can also be escaped, as usual
-in Markdown:
-
-```````````````````````````````` example
-[link](foo\)\:)
-.
-<p><a href="foo):">link</a></p>
-````````````````````````````````
-
-
-A link can contain fragment identifiers and queries:
-
-```````````````````````````````` example
-[link](#fragment)
-
-[link](http://example.com#fragment)
-
-[link](http://example.com?foo=3#frag)
-.
-<p><a href="#fragment">link</a></p>
-<p><a href="http://example.com#fragment">link</a></p>
-<p><a href="http://example.com?foo=3#frag">link</a></p>
-````````````````````````````````
-
-
-Note that a backslash before a non-escapable character is
-just a backslash:
-
-```````````````````````````````` example
-[link](foo\bar)
-.
-<p><a href="foo%5Cbar">link</a></p>
-````````````````````````````````
-
-
-URL-escaping should be left alone inside the destination, as all
-URL-escaped characters are also valid URL characters. Entity and
-numerical character references in the destination will be parsed
-into the corresponding Unicode code points, as usual. These may
-be optionally URL-escaped when written as HTML, but this spec
-does not enforce any particular policy for rendering URLs in
-HTML or other formats. Renderers may make different decisions
-about how to escape or normalize URLs in the output.
-
-```````````````````````````````` example
-[link](foo%20b&auml;)
-.
-<p><a href="foo%20b%C3%A4">link</a></p>
-````````````````````````````````
-
-
-Note that, because titles can often be parsed as destinations,
-if you try to omit the destination and keep the title, you'll
-get unexpected results:
-
-```````````````````````````````` example
-[link]("title")
-.
-<p><a href="%22title%22">link</a></p>
-````````````````````````````````
-
-
-Titles may be in single quotes, double quotes, or parentheses:
-
-```````````````````````````````` example
-[link](/url "title")
-[link](/url 'title')
-[link](/url (title))
-.
-<p><a href="/url" title="title">link</a>
-<a href="/url" title="title">link</a>
-<a href="/url" title="title">link</a></p>
-````````````````````````````````
-
-
-Backslash escapes and entity and numeric character references
-may be used in titles:
-
-```````````````````````````````` example
-[link](/url "title \"&quot;")
-.
-<p><a href="/url" title="title &quot;&quot;">link</a></p>
-````````````````````````````````
-
-
-Titles must be separated from the link using a [whitespace].
-Other [Unicode whitespace] like non-breaking space doesn't work.
-
-```````````````````````````````` example
-[link](/url "title")
-.
-<p><a href="/url%C2%A0%22title%22">link</a></p>
-````````````````````````````````
-
-
-Nested balanced quotes are not allowed without escaping:
-
-```````````````````````````````` example
-[link](/url "title "and" title")
-.
-<p>[link](/url &quot;title &quot;and&quot; title&quot;)</p>
-````````````````````````````````
-
-
-But it is easy to work around this by using a different quote type:
-
-```````````````````````````````` example
-[link](/url 'title "and" title')
-.
-<p><a href="/url" title="title &quot;and&quot; title">link</a></p>
-````````````````````````````````
-
-
-(Note: `Markdown.pl` did allow double quotes inside a double-quoted
-title, and its test suite included a test demonstrating this.
-But it is hard to see a good rationale for the extra complexity this
-brings, since there are already many ways---backslash escaping,
-entity and numeric character references, or using a different
-quote type for the enclosing title---to write titles containing
-double quotes. `Markdown.pl`'s handling of titles has a number
-of other strange features. For example, it allows single-quoted
-titles in inline links, but not reference links. And, in
-reference links but not inline links, it allows a title to begin
-with `"` and end with `)`. `Markdown.pl` 1.0.1 even allows
-titles with no closing quotation mark, though 1.0.2b8 does not.
-It seems preferable to adopt a simple, rational rule that works
-the same way in inline links and link reference definitions.)
-
-[Whitespace] is allowed around the destination and title:
-
-```````````````````````````````` example
-[link]( /uri
- "title" )
-.
-<p><a href="/uri" title="title">link</a></p>
-````````````````````````````````
-
-
-But it is not allowed between the link text and the
-following parenthesis:
-
-```````````````````````````````` example
-[link] (/uri)
-.
-<p>[link] (/uri)</p>
-````````````````````````````````
-
-
-The link text may contain balanced brackets, but not unbalanced ones,
-unless they are escaped:
-
-```````````````````````````````` example
-[link [foo [bar]]](/uri)
-.
-<p><a href="/uri">link [foo [bar]]</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link] bar](/uri)
-.
-<p>[link] bar](/uri)</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link [bar](/uri)
-.
-<p>[link <a href="/uri">bar</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link \[bar](/uri)
-.
-<p><a href="/uri">link [bar</a></p>
-````````````````````````````````
-
-
-The link text may contain inline content:
-
-```````````````````````````````` example
-[link *foo **bar** `#`*](/uri)
-.
-<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[![moon](moon.jpg)](/uri)
-.
-<p><a href="/uri"><img src="moon.jpg" alt="moon" /></a></p>
-````````````````````````````````
-
-
-However, links may not contain other links, at any level of nesting.
-
-```````````````````````````````` example
-[foo [bar](/uri)](/uri)
-.
-<p>[foo <a href="/uri">bar</a>](/uri)</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo *[bar [baz](/uri)](/uri)*](/uri)
-.
-<p>[foo <em>[bar <a href="/uri">baz</a>](/uri)</em>](/uri)</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![[[foo](uri1)](uri2)](uri3)
-.
-<p><img src="uri3" alt="[foo](uri2)" /></p>
-````````````````````````````````
-
-
-These cases illustrate the precedence of link text grouping over
-emphasis grouping:
-
-```````````````````````````````` example
-*[foo*](/uri)
-.
-<p>*<a href="/uri">foo*</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo *bar](baz*)
-.
-<p><a href="baz*">foo *bar</a></p>
-````````````````````````````````
-
-
-Note that brackets that *aren't* part of links do not take
-precedence:
-
-```````````````````````````````` example
-*foo [bar* baz]
-.
-<p><em>foo [bar</em> baz]</p>
-````````````````````````````````
-
-
-These cases illustrate the precedence of HTML tags, code spans,
-and autolinks over link grouping:
-
-```````````````````````````````` example
-[foo <bar attr="](baz)">
-.
-<p>[foo <bar attr="](baz)"></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo`](/uri)`
-.
-<p>[foo<code>](/uri)</code></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo<http://example.com/?search=](uri)>
-.
-<p>[foo<a href="http://example.com/?search=%5D(uri)">http://example.com/?search=](uri)</a></p>
-````````````````````````````````
-
-
-There are three kinds of [reference link](@)s:
-[full](#full-reference-link), [collapsed](#collapsed-reference-link),
-and [shortcut](#shortcut-reference-link).
-
-A [full reference link](@)
-consists of a [link text] immediately followed by a [link label]
-that [matches] a [link reference definition] elsewhere in the document.
-
-A [link label](@) begins with a left bracket (`[`) and ends
-with the first right bracket (`]`) that is not backslash-escaped.
-Between these brackets there must be at least one [non-whitespace character].
-Unescaped square bracket characters are not allowed inside the
-opening and closing square brackets of [link labels]. A link
-label can have at most 999 characters inside the square
-brackets.
-
-One label [matches](@)
-another just in case their normalized forms are equal. To normalize a
-label, strip off the opening and closing brackets,
-perform the *Unicode case fold*, strip leading and trailing
-[whitespace] and collapse consecutive internal
-[whitespace] to a single space. If there are multiple
-matching reference link definitions, the one that comes first in the
-document is used. (It is desirable in such cases to emit a warning.)
-
-The link's URI and title are provided by the matching [link
-reference definition].
-
-Here is a simple example:
-
-```````````````````````````````` example
-[foo][bar]
-
-[bar]: /url "title"
-.
-<p><a href="/url" title="title">foo</a></p>
-````````````````````````````````
-
-
-The rules for the [link text] are the same as with
-[inline links]. Thus:
-
-The link text may contain balanced brackets, but not unbalanced ones,
-unless they are escaped:
-
-```````````````````````````````` example
-[link [foo [bar]]][ref]
-
-[ref]: /uri
-.
-<p><a href="/uri">link [foo [bar]]</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[link \[bar][ref]
-
-[ref]: /uri
-.
-<p><a href="/uri">link [bar</a></p>
-````````````````````````````````
-
-
-The link text may contain inline content:
-
-```````````````````````````````` example
-[link *foo **bar** `#`*][ref]
-
-[ref]: /uri
-.
-<p><a href="/uri">link <em>foo <strong>bar</strong> <code>#</code></em></a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[![moon](moon.jpg)][ref]
-
-[ref]: /uri
-.
-<p><a href="/uri"><img src="moon.jpg" alt="moon" /></a></p>
-````````````````````````````````
-
-
-However, links may not contain other links, at any level of nesting.
-
-```````````````````````````````` example
-[foo [bar](/uri)][ref]
-
-[ref]: /uri
-.
-<p>[foo <a href="/uri">bar</a>]<a href="/uri">ref</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo *bar [baz][ref]*][ref]
-
-[ref]: /uri
-.
-<p>[foo <em>bar <a href="/uri">baz</a></em>]<a href="/uri">ref</a></p>
-````````````````````````````````
-
-
-(In the examples above, we have two [shortcut reference links]
-instead of one [full reference link].)
-
-The following cases illustrate the precedence of link text grouping over
-emphasis grouping:
-
-```````````````````````````````` example
-*[foo*][ref]
-
-[ref]: /uri
-.
-<p>*<a href="/uri">foo*</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo *bar][ref]*
-
-[ref]: /uri
-.
-<p><a href="/uri">foo *bar</a>*</p>
-````````````````````````````````
-
-
-These cases illustrate the precedence of HTML tags, code spans,
-and autolinks over link grouping:
-
-```````````````````````````````` example
-[foo <bar attr="][ref]">
-
-[ref]: /uri
-.
-<p>[foo <bar attr="][ref]"></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo`][ref]`
-
-[ref]: /uri
-.
-<p>[foo<code>][ref]</code></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo<http://example.com/?search=][ref]>
-
-[ref]: /uri
-.
-<p>[foo<a href="http://example.com/?search=%5D%5Bref%5D">http://example.com/?search=][ref]</a></p>
-````````````````````````````````
-
-
-Matching is case-insensitive:
-
-```````````````````````````````` example
-[foo][BaR]
-
-[bar]: /url "title"
-.
-<p><a href="/url" title="title">foo</a></p>
-````````````````````````````````
-
-
-Unicode case fold is used:
-
-```````````````````````````````` example
-[ẞ]
-
-[SS]: /url
-.
-<p><a href="/url">ẞ</a></p>
-````````````````````````````````
-
-
-Consecutive internal [whitespace] is treated as one space for
-purposes of determining matching:
-
-```````````````````````````````` example
-[Foo
- bar]: /url
-
-[Baz][Foo bar]
-.
-<p><a href="/url">Baz</a></p>
-````````````````````````````````
-
-
-No [whitespace] is allowed between the [link text] and the
-[link label]:
-
-```````````````````````````````` example
-[foo] [bar]
-
-[bar]: /url "title"
-.
-<p>[foo] <a href="/url" title="title">bar</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo]
-[bar]
-
-[bar]: /url "title"
-.
-<p>[foo]
-<a href="/url" title="title">bar</a></p>
-````````````````````````````````
-
-
-This is a departure from John Gruber's original Markdown syntax
-description, which explicitly allows whitespace between the link
-text and the link label. It brings reference links in line with
-[inline links], which (according to both original Markdown and
-this spec) cannot have whitespace after the link text. More
-importantly, it prevents inadvertent capture of consecutive
-[shortcut reference links]. If whitespace is allowed between the
-link text and the link label, then in the following we will have
-a single reference link, not two shortcut reference links, as
-intended:
-
-``` markdown
-[foo]
-[bar]
-
-[foo]: /url1
-[bar]: /url2
-```
-
-(Note that [shortcut reference links] were introduced by Gruber
-himself in a beta version of `Markdown.pl`, but never included
-in the official syntax description. Without shortcut reference
-links, it is harmless to allow space between the link text and
-link label; but once shortcut references are introduced, it is
-too dangerous to allow this, as it frequently leads to
-unintended results.)
-
-When there are multiple matching [link reference definitions],
-the first is used:
-
-```````````````````````````````` example
-[foo]: /url1
-
-[foo]: /url2
-
-[bar][foo]
-.
-<p><a href="/url1">bar</a></p>
-````````````````````````````````
-
-
-Note that matching is performed on normalized strings, not parsed
-inline content. So the following does not match, even though the
-labels define equivalent inline content:
-
-```````````````````````````````` example
-[bar][foo\!]
-
-[foo!]: /url
-.
-<p>[bar][foo!]</p>
-````````````````````````````````
-
-
-[Link labels] cannot contain brackets, unless they are
-backslash-escaped:
-
-```````````````````````````````` example
-[foo][ref[]
-
-[ref[]: /uri
-.
-<p>[foo][ref[]</p>
-<p>[ref[]: /uri</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo][ref[bar]]
-
-[ref[bar]]: /uri
-.
-<p>[foo][ref[bar]]</p>
-<p>[ref[bar]]: /uri</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[[[foo]]]
-
-[[[foo]]]: /url
-.
-<p>[[[foo]]]</p>
-<p>[[[foo]]]: /url</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[foo][ref\[]
-
-[ref\[]: /uri
-.
-<p><a href="/uri">foo</a></p>
-````````````````````````````````
-
-
-Note that in this example `]` is not backslash-escaped:
-
-```````````````````````````````` example
-[bar\\]: /uri
-
-[bar\\]
-.
-<p><a href="/uri">bar\</a></p>
-````````````````````````````````
-
-
-A [link label] must contain at least one [non-whitespace character]:
-
-```````````````````````````````` example
-[]
-
-[]: /uri
-.
-<p>[]</p>
-<p>[]: /uri</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[
- ]
-
-[
- ]: /uri
-.
-<p>[
-]</p>
-<p>[
-]: /uri</p>
-````````````````````````````````
-
-
-A [collapsed reference link](@)
-consists of a [link label] that [matches] a
-[link reference definition] elsewhere in the
-document, followed by the string `[]`.
-The contents of the first link label are parsed as inlines,
-which are used as the link's text. The link's URI and title are
-provided by the matching reference link definition. Thus,
-`[foo][]` is equivalent to `[foo][foo]`.
-
-```````````````````````````````` example
-[foo][]
-
-[foo]: /url "title"
-.
-<p><a href="/url" title="title">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[*foo* bar][]
-
-[*foo* bar]: /url "title"
-.
-<p><a href="/url" title="title"><em>foo</em> bar</a></p>
-````````````````````````````````
-
-
-The link labels are case-insensitive:
-
-```````````````````````````````` example
-[Foo][]
-
-[foo]: /url "title"
-.
-<p><a href="/url" title="title">Foo</a></p>
-````````````````````````````````
-
-
-
-As with full reference links, [whitespace] is not
-allowed between the two sets of brackets:
-
-```````````````````````````````` example
-[foo]
-[]
-
-[foo]: /url "title"
-.
-<p><a href="/url" title="title">foo</a>
-[]</p>
-````````````````````````````````
-
-
-A [shortcut reference link](@)
-consists of a [link label] that [matches] a
-[link reference definition] elsewhere in the
-document and is not followed by `[]` or a link label.
-The contents of the first link label are parsed as inlines,
-which are used as the link's text. The link's URI and title
-are provided by the matching link reference definition.
-Thus, `[foo]` is equivalent to `[foo][]`.
-
-```````````````````````````````` example
-[foo]
-
-[foo]: /url "title"
-.
-<p><a href="/url" title="title">foo</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[*foo* bar]
-
-[*foo* bar]: /url "title"
-.
-<p><a href="/url" title="title"><em>foo</em> bar</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[[*foo* bar]]
-
-[*foo* bar]: /url "title"
-.
-<p>[<a href="/url" title="title"><em>foo</em> bar</a>]</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-[[bar [foo]
-
-[foo]: /url
-.
-<p>[[bar <a href="/url">foo</a></p>
-````````````````````````````````
-
-
-The link labels are case-insensitive:
-
-```````````````````````````````` example
-[Foo]
-
-[foo]: /url "title"
-.
-<p><a href="/url" title="title">Foo</a></p>
-````````````````````````````````
-
-
-A space after the link text should be preserved:
-
-```````````````````````````````` example
-[foo] bar
-
-[foo]: /url
-.
-<p><a href="/url">foo</a> bar</p>
-````````````````````````````````
-
-
-If you just want bracketed text, you can backslash-escape the
-opening bracket to avoid links:
-
-```````````````````````````````` example
-\[foo]
-
-[foo]: /url "title"
-.
-<p>[foo]</p>
-````````````````````````````````
-
-
-Note that this is a link, because a link label ends with the first
-following closing bracket:
-
-```````````````````````````````` example
-[foo*]: /url
-
-*[foo*]
-.
-<p>*<a href="/url">foo*</a></p>
-````````````````````````````````
-
-
-Full and compact references take precedence over shortcut
-references:
-
-```````````````````````````````` example
-[foo][bar]
-
-[foo]: /url1
-[bar]: /url2
-.
-<p><a href="/url2">foo</a></p>
-````````````````````````````````
-
-```````````````````````````````` example
-[foo][]
-
-[foo]: /url1
-.
-<p><a href="/url1">foo</a></p>
-````````````````````````````````
-
-Inline links also take precedence:
-
-```````````````````````````````` example
-[foo]()
-
-[foo]: /url1
-.
-<p><a href="">foo</a></p>
-````````````````````````````````
-
-```````````````````````````````` example
-[foo](not a link)
-
-[foo]: /url1
-.
-<p><a href="/url1">foo</a>(not a link)</p>
-````````````````````````````````
-
-In the following case `[bar][baz]` is parsed as a reference,
-`[foo]` as normal text:
-
-```````````````````````````````` example
-[foo][bar][baz]
-
-[baz]: /url
-.
-<p>[foo]<a href="/url">bar</a></p>
-````````````````````````````````
-
-
-Here, though, `[foo][bar]` is parsed as a reference, since
-`[bar]` is defined:
-
-```````````````````````````````` example
-[foo][bar][baz]
-
-[baz]: /url1
-[bar]: /url2
-.
-<p><a href="/url2">foo</a><a href="/url1">baz</a></p>
-````````````````````````````````
-
-
-Here `[foo]` is not parsed as a shortcut reference, because it
-is followed by a link label (even though `[bar]` is not defined):
-
-```````````````````````````````` example
-[foo][bar][baz]
-
-[baz]: /url1
-[foo]: /url2
-.
-<p>[foo]<a href="/url1">bar</a></p>
-````````````````````````````````
-
-
-
-## Images
-
-Syntax for images is like the syntax for links, with one
-difference. Instead of [link text], we have an
-[image description](@). The rules for this are the
-same as for [link text], except that (a) an
-image description starts with `![` rather than `[`, and
-(b) an image description may contain links.
-An image description has inline elements
-as its contents. When an image is rendered to HTML,
-this is standardly used as the image's `alt` attribute.
-
-```````````````````````````````` example
-![foo](/url "title")
-.
-<p><img src="/url" alt="foo" title="title" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo *bar*]
-
-[foo *bar*]: train.jpg "train & tracks"
-.
-<p><img src="train.jpg" alt="foo bar" title="train &amp; tracks" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo ![bar](/url)](/url2)
-.
-<p><img src="/url2" alt="foo bar" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo [bar](/url)](/url2)
-.
-<p><img src="/url2" alt="foo bar" /></p>
-````````````````````````````````
-
-
-Though this spec is concerned with parsing, not rendering, it is
-recommended that in rendering to HTML, only the plain string content
-of the [image description] be used. Note that in
-the above example, the alt attribute's value is `foo bar`, not `foo
-[bar](/url)` or `foo <a href="/url">bar</a>`. Only the plain string
-content is rendered, without formatting.
-
-```````````````````````````````` example
-![foo *bar*][]
-
-[foo *bar*]: train.jpg "train & tracks"
-.
-<p><img src="train.jpg" alt="foo bar" title="train &amp; tracks" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo *bar*][foobar]
-
-[FOOBAR]: train.jpg "train & tracks"
-.
-<p><img src="train.jpg" alt="foo bar" title="train &amp; tracks" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo](train.jpg)
-.
-<p><img src="train.jpg" alt="foo" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-My ![foo bar](/path/to/train.jpg "title" )
-.
-<p>My <img src="/path/to/train.jpg" alt="foo bar" title="title" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo](<url>)
-.
-<p><img src="url" alt="foo" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![](/url)
-.
-<p><img src="/url" alt="" /></p>
-````````````````````````````````
-
-
-Reference-style:
-
-```````````````````````````````` example
-![foo][bar]
-
-[bar]: /url
-.
-<p><img src="/url" alt="foo" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![foo][bar]
-
-[BAR]: /url
-.
-<p><img src="/url" alt="foo" /></p>
-````````````````````````````````
-
-
-Collapsed:
-
-```````````````````````````````` example
-![foo][]
-
-[foo]: /url "title"
-.
-<p><img src="/url" alt="foo" title="title" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![*foo* bar][]
-
-[*foo* bar]: /url "title"
-.
-<p><img src="/url" alt="foo bar" title="title" /></p>
-````````````````````````````````
-
-
-The labels are case-insensitive:
-
-```````````````````````````````` example
-![Foo][]
-
-[foo]: /url "title"
-.
-<p><img src="/url" alt="Foo" title="title" /></p>
-````````````````````````````````
-
-
-As with reference links, [whitespace] is not allowed
-between the two sets of brackets:
-
-```````````````````````````````` example
-![foo]
-[]
-
-[foo]: /url "title"
-.
-<p><img src="/url" alt="foo" title="title" />
-[]</p>
-````````````````````````````````
-
-
-Shortcut:
-
-```````````````````````````````` example
-![foo]
-
-[foo]: /url "title"
-.
-<p><img src="/url" alt="foo" title="title" /></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-![*foo* bar]
-
-[*foo* bar]: /url "title"
-.
-<p><img src="/url" alt="foo bar" title="title" /></p>
-````````````````````````````````
-
-
-Note that link labels cannot contain unescaped brackets:
-
-```````````````````````````````` example
-![[foo]]
-
-[[foo]]: /url "title"
-.
-<p>![[foo]]</p>
-<p>[[foo]]: /url &quot;title&quot;</p>
-````````````````````````````````
-
-
-The link labels are case-insensitive:
-
-```````````````````````````````` example
-![Foo]
-
-[foo]: /url "title"
-.
-<p><img src="/url" alt="Foo" title="title" /></p>
-````````````````````````````````
-
-
-If you just want a literal `!` followed by bracketed text, you can
-backslash-escape the opening `[`:
-
-```````````````````````````````` example
-!\[foo]
-
-[foo]: /url "title"
-.
-<p>![foo]</p>
-````````````````````````````````
-
-
-If you want a link after a literal `!`, backslash-escape the
-`!`:
-
-```````````````````````````````` example
-\![foo]
-
-[foo]: /url "title"
-.
-<p>!<a href="/url" title="title">foo</a></p>
-````````````````````````````````
-
-
-## Autolinks
-
-[Autolink](@)s are absolute URIs and email addresses inside
-`<` and `>`. They are parsed as links, with the URL or email address
-as the link label.
-
-A [URI autolink](@) consists of `<`, followed by an
-[absolute URI] followed by `>`. It is parsed as
-a link to the URI, with the URI as the link's label.
-
-An [absolute URI](@),
-for these purposes, consists of a [scheme] followed by a colon (`:`)
-followed by zero or more characters other [ASCII control
-characters][ASCII control character] or [whitespace][] , `<`, and `>`.
-If the URI includes these characters, they must be percent-encoded
-(e.g. `%20` for a space).
-
-For purposes of this spec, a [scheme](@) is any sequence
-of 2--32 characters beginning with an ASCII letter and followed
-by any combination of ASCII letters, digits, or the symbols plus
-("+"), period ("."), or hyphen ("-").
-
-Here are some valid autolinks:
-
-```````````````````````````````` example
-<http://foo.bar.baz>
-.
-<p><a href="http://foo.bar.baz">http://foo.bar.baz</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<http://foo.bar.baz/test?q=hello&id=22&boolean>
-.
-<p><a href="http://foo.bar.baz/test?q=hello&amp;id=22&amp;boolean">http://foo.bar.baz/test?q=hello&amp;id=22&amp;boolean</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<irc://foo.bar:2233/baz>
-.
-<p><a href="irc://foo.bar:2233/baz">irc://foo.bar:2233/baz</a></p>
-````````````````````````````````
-
-
-Uppercase is also fine:
-
-```````````````````````````````` example
-<MAILTO:FOO@BAR.BAZ>
-.
-<p><a href="MAILTO:FOO@BAR.BAZ">MAILTO:FOO@BAR.BAZ</a></p>
-````````````````````````````````
-
-
-Note that many strings that count as [absolute URIs] for
-purposes of this spec are not valid URIs, because their
-schemes are not registered or because of other problems
-with their syntax:
-
-```````````````````````````````` example
-<a+b+c:d>
-.
-<p><a href="a+b+c:d">a+b+c:d</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<made-up-scheme://foo,bar>
-.
-<p><a href="made-up-scheme://foo,bar">made-up-scheme://foo,bar</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<http://../>
-.
-<p><a href="http://../">http://../</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<localhost:5001/foo>
-.
-<p><a href="localhost:5001/foo">localhost:5001/foo</a></p>
-````````````````````````````````
-
-
-Spaces are not allowed in autolinks:
-
-```````````````````````````````` example
-<http://foo.bar/baz bim>
-.
-<p>&lt;http://foo.bar/baz bim&gt;</p>
-````````````````````````````````
-
-
-Backslash-escapes do not work inside autolinks:
-
-```````````````````````````````` example
-<http://example.com/\[\>
-.
-<p><a href="http://example.com/%5C%5B%5C">http://example.com/\[\</a></p>
-````````````````````````````````
-
-
-An [email autolink](@)
-consists of `<`, followed by an [email address],
-followed by `>`. The link's label is the email address,
-and the URL is `mailto:` followed by the email address.
-
-An [email address](@),
-for these purposes, is anything that matches
-the [non-normative regex from the HTML5
-spec](https://html.spec.whatwg.org/multipage/forms.html#e-mail-state-(type=email)):
-
- /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?
- (?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
-
-Examples of email autolinks:
-
-```````````````````````````````` example
-<foo@bar.example.com>
-.
-<p><a href="mailto:foo@bar.example.com">foo@bar.example.com</a></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<foo+special@Bar.baz-bar0.com>
-.
-<p><a href="mailto:foo+special@Bar.baz-bar0.com">foo+special@Bar.baz-bar0.com</a></p>
-````````````````````````````````
-
-
-Backslash-escapes do not work inside email autolinks:
-
-```````````````````````````````` example
-<foo\+@bar.example.com>
-.
-<p>&lt;foo+@bar.example.com&gt;</p>
-````````````````````````````````
-
-
-These are not autolinks:
-
-```````````````````````````````` example
-<>
-.
-<p>&lt;&gt;</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-< http://foo.bar >
-.
-<p>&lt; http://foo.bar &gt;</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<m:abc>
-.
-<p>&lt;m:abc&gt;</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<foo.bar.baz>
-.
-<p>&lt;foo.bar.baz&gt;</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-http://example.com
-.
-<p>http://example.com</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo@bar.example.com
-.
-<p>foo@bar.example.com</p>
-````````````````````````````````
-
-
-## Raw HTML
-
-Text between `<` and `>` that looks like an HTML tag is parsed as a
-raw HTML tag and will be rendered in HTML without escaping.
-Tag and attribute names are not limited to current HTML tags,
-so custom tags (and even, say, DocBook tags) may be used.
-
-Here is the grammar for tags:
-
-A [tag name](@) consists of an ASCII letter
-followed by zero or more ASCII letters, digits, or
-hyphens (`-`).
-
-An [attribute](@) consists of [whitespace],
-an [attribute name], and an optional
-[attribute value specification].
-
-An [attribute name](@)
-consists of an ASCII letter, `_`, or `:`, followed by zero or more ASCII
-letters, digits, `_`, `.`, `:`, or `-`. (Note: This is the XML
-specification restricted to ASCII. HTML5 is laxer.)
-
-An [attribute value specification](@)
-consists of optional [whitespace],
-a `=` character, optional [whitespace], and an [attribute
-value].
-
-An [attribute value](@)
-consists of an [unquoted attribute value],
-a [single-quoted attribute value], or a [double-quoted attribute value].
-
-An [unquoted attribute value](@)
-is a nonempty string of characters not
-including [whitespace], `"`, `'`, `=`, `<`, `>`, or `` ` ``.
-
-A [single-quoted attribute value](@)
-consists of `'`, zero or more
-characters not including `'`, and a final `'`.
-
-A [double-quoted attribute value](@)
-consists of `"`, zero or more
-characters not including `"`, and a final `"`.
-
-An [open tag](@) consists of a `<` character, a [tag name],
-zero or more [attributes], optional [whitespace], an optional `/`
-character, and a `>` character.
-
-A [closing tag](@) consists of the string `</`, a
-[tag name], optional [whitespace], and the character `>`.
-
-An [HTML comment](@) consists of `<!--` + *text* + `-->`,
-where *text* does not start with `>` or `->`, does not end with `-`,
-and does not contain `--`. (See the
-[HTML5 spec](http://www.w3.org/TR/html5/syntax.html#comments).)
-
-A [processing instruction](@)
-consists of the string `<?`, a string
-of characters not including the string `?>`, and the string
-`?>`.
-
-A [declaration](@) consists of the string `<!`, an ASCII letter, zero or more
-characters not including the character `>`, and the character `>`.
-
-A [CDATA section](@) consists of
-the string `<![CDATA[`, a string of characters not including the string
-`]]>`, and the string `]]>`.
-
-An [HTML tag](@) consists of an [open tag], a [closing tag],
-an [HTML comment], a [processing instruction], a [declaration],
-or a [CDATA section].
-
-Here are some simple open tags:
-
-```````````````````````````````` example
-<a><bab><c2c>
-.
-<p><a><bab><c2c></p>
-````````````````````````````````
-
-
-Empty elements:
-
-```````````````````````````````` example
-<a/><b2/>
-.
-<p><a/><b2/></p>
-````````````````````````````````
-
-
-[Whitespace] is allowed:
-
-```````````````````````````````` example
-<a /><b2
-data="foo" >
-.
-<p><a /><b2
-data="foo" ></p>
-````````````````````````````````
-
-
-With attributes:
-
-```````````````````````````````` example
-<a foo="bar" bam = 'baz <em>"</em>'
-_boolean zoop:33=zoop:33 />
-.
-<p><a foo="bar" bam = 'baz <em>"</em>'
-_boolean zoop:33=zoop:33 /></p>
-````````````````````````````````
-
-
-Custom tag names can be used:
-
-```````````````````````````````` example
-Foo <responsive-image src="foo.jpg" />
-.
-<p>Foo <responsive-image src="foo.jpg" /></p>
-````````````````````````````````
-
-
-Illegal tag names, not parsed as HTML:
-
-```````````````````````````````` example
-<33> <__>
-.
-<p>&lt;33&gt; &lt;__&gt;</p>
-````````````````````````````````
-
-
-Illegal attribute names:
-
-```````````````````````````````` example
-<a h*#ref="hi">
-.
-<p>&lt;a h*#ref=&quot;hi&quot;&gt;</p>
-````````````````````````````````
-
-
-Illegal attribute values:
-
-```````````````````````````````` example
-<a href="hi'> <a href=hi'>
-.
-<p>&lt;a href=&quot;hi'&gt; &lt;a href=hi'&gt;</p>
-````````````````````````````````
-
-
-Illegal [whitespace]:
-
-```````````````````````````````` example
-< a><
-foo><bar/ >
-<foo bar=baz
-bim!bop />
-.
-<p>&lt; a&gt;&lt;
-foo&gt;&lt;bar/ &gt;
-&lt;foo bar=baz
-bim!bop /&gt;</p>
-````````````````````````````````
-
-
-Missing [whitespace]:
-
-```````````````````````````````` example
-<a href='bar'title=title>
-.
-<p>&lt;a href='bar'title=title&gt;</p>
-````````````````````````````````
-
-
-Closing tags:
-
-```````````````````````````````` example
-</a></foo >
-.
-<p></a></foo ></p>
-````````````````````````````````
-
-
-Illegal attributes in closing tag:
-
-```````````````````````````````` example
-</a href="foo">
-.
-<p>&lt;/a href=&quot;foo&quot;&gt;</p>
-````````````````````````````````
-
-
-Comments:
-
-```````````````````````````````` example
-foo <!-- this is a
-comment - with hyphen -->
-.
-<p>foo <!-- this is a
-comment - with hyphen --></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo <!-- not a comment -- two hyphens -->
-.
-<p>foo &lt;!-- not a comment -- two hyphens --&gt;</p>
-````````````````````````````````
-
-
-Not comments:
-
-```````````````````````````````` example
-foo <!--> foo -->
-
-foo <!-- foo--->
-.
-<p>foo &lt;!--&gt; foo --&gt;</p>
-<p>foo &lt;!-- foo---&gt;</p>
-````````````````````````````````
-
-
-Processing instructions:
-
-```````````````````````````````` example
-foo <?php echo $a; ?>
-.
-<p>foo <?php echo $a; ?></p>
-````````````````````````````````
-
-
-Declarations:
-
-```````````````````````````````` example
-foo <!ELEMENT br EMPTY>
-.
-<p>foo <!ELEMENT br EMPTY></p>
-````````````````````````````````
-
-
-CDATA sections:
-
-```````````````````````````````` example
-foo <![CDATA[>&<]]>
-.
-<p>foo <![CDATA[>&<]]></p>
-````````````````````````````````
-
-
-Entity and numeric character references are preserved in HTML
-attributes:
-
-```````````````````````````````` example
-foo <a href="&ouml;">
-.
-<p>foo <a href="&ouml;"></p>
-````````````````````````````````
-
-
-Backslash escapes do not work in HTML attributes:
-
-```````````````````````````````` example
-foo <a href="\*">
-.
-<p>foo <a href="\*"></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<a href="\"">
-.
-<p>&lt;a href=&quot;&quot;&quot;&gt;</p>
-````````````````````````````````
-
-
-## Hard line breaks
-
-A line break (not in a code span or HTML tag) that is preceded
-by two or more spaces and does not occur at the end of a block
-is parsed as a [hard line break](@) (rendered
-in HTML as a `<br />` tag):
-
-```````````````````````````````` example
-foo
-baz
-.
-<p>foo<br />
-baz</p>
-````````````````````````````````
-
-
-For a more visible alternative, a backslash before the
-[line ending] may be used instead of two spaces:
-
-```````````````````````````````` example
-foo\
-baz
-.
-<p>foo<br />
-baz</p>
-````````````````````````````````
-
-
-More than two spaces can be used:
-
-```````````````````````````````` example
-foo
-baz
-.
-<p>foo<br />
-baz</p>
-````````````````````````````````
-
-
-Leading spaces at the beginning of the next line are ignored:
-
-```````````````````````````````` example
-foo
- bar
-.
-<p>foo<br />
-bar</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo\
- bar
-.
-<p>foo<br />
-bar</p>
-````````````````````````````````
-
-
-Line breaks can occur inside emphasis, links, and other constructs
-that allow inline content:
-
-```````````````````````````````` example
-*foo
-bar*
-.
-<p><em>foo<br />
-bar</em></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-*foo\
-bar*
-.
-<p><em>foo<br />
-bar</em></p>
-````````````````````````````````
-
-
-Line breaks do not occur inside code spans
-
-```````````````````````````````` example
-`code
-span`
-.
-<p><code>code span</code></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-`code\
-span`
-.
-<p><code>code\ span</code></p>
-````````````````````````````````
-
-
-or HTML tags:
-
-```````````````````````````````` example
-<a href="foo
-bar">
-.
-<p><a href="foo
-bar"></p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-<a href="foo\
-bar">
-.
-<p><a href="foo\
-bar"></p>
-````````````````````````````````
-
-
-Hard line breaks are for separating inline content within a block.
-Neither syntax for hard line breaks works at the end of a paragraph or
-other block element:
-
-```````````````````````````````` example
-foo\
-.
-<p>foo\</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-foo
-.
-<p>foo</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-### foo\
-.
-<h3>foo\</h3>
-````````````````````````````````
-
-
-```````````````````````````````` example
-### foo
-.
-<h3>foo</h3>
-````````````````````````````````
-
-
-## Soft line breaks
-
-A regular line break (not in a code span or HTML tag) that is not
-preceded by two or more spaces or a backslash is parsed as a
-[softbreak](@). (A softbreak may be rendered in HTML either as a
-[line ending] or as a space. The result will be the same in
-browsers. In the examples here, a [line ending] will be used.)
-
-```````````````````````````````` example
-foo
-baz
-.
-<p>foo
-baz</p>
-````````````````````````````````
-
-
-Spaces at the end of the line and beginning of the next line are
-removed:
-
-```````````````````````````````` example
-foo
- baz
-.
-<p>foo
-baz</p>
-````````````````````````````````
-
-
-A conforming parser may render a soft line break in HTML either as a
-line break or as a space.
-
-A renderer may also provide an option to render soft line breaks
-as hard line breaks.
-
-## Textual content
-
-Any characters not given an interpretation by the above rules will
-be parsed as plain textual content.
-
-```````````````````````````````` example
-hello $.;'there
-.
-<p>hello $.;'there</p>
-````````````````````````````````
-
-
-```````````````````````````````` example
-Foo χρῆν
-.
-<p>Foo χρῆν</p>
-````````````````````````````````
-
-
-Internal spaces are preserved verbatim:
-
-```````````````````````````````` example
-Multiple spaces
-.
-<p>Multiple spaces</p>
-````````````````````````````````
-
-
-<!-- END TESTS -->
-
-# Appendix: A parsing strategy
-
-In this appendix we describe some features of the parsing strategy
-used in the CommonMark reference implementations.
-
-## Overview
-
-Parsing has two phases:
-
-1. In the first phase, lines of input are consumed and the block
-structure of the document---its division into paragraphs, block quotes,
-list items, and so on---is constructed. Text is assigned to these
-blocks but not parsed. Link reference definitions are parsed and a
-map of links is constructed.
-
-2. In the second phase, the raw text contents of paragraphs and headings
-are parsed into sequences of Markdown inline elements (strings,
-code spans, links, emphasis, and so on), using the map of link
-references constructed in phase 1.
-
-At each point in processing, the document is represented as a tree of
-**blocks**. The root of the tree is a `document` block. The `document`
-may have any number of other blocks as **children**. These children
-may, in turn, have other blocks as children. The last child of a block
-is normally considered **open**, meaning that subsequent lines of input
-can alter its contents. (Blocks that are not open are **closed**.)
-Here, for example, is a possible document tree, with the open blocks
-marked by arrows:
-
-``` tree
--> document
- -> block_quote
- paragraph
- "Lorem ipsum dolor\nsit amet."
- -> list (type=bullet tight=true bullet_char=-)
- list_item
- paragraph
- "Qui *quodsi iracundia*"
- -> list_item
- -> paragraph
- "aliquando id"
-```
-
-## Phase 1: block structure
-
-Each line that is processed has an effect on this tree. The line is
-analyzed and, depending on its contents, the document may be altered
-in one or more of the following ways:
-
-1. One or more open blocks may be closed.
-2. One or more new blocks may be created as children of the
- last open block.
-3. Text may be added to the last (deepest) open block remaining
- on the tree.
-
-Once a line has been incorporated into the tree in this way,
-it can be discarded, so input can be read in a stream.
-
-For each line, we follow this procedure:
-
-1. First we iterate through the open blocks, starting with the
-root document, and descending through last children down to the last
-open block. Each block imposes a condition that the line must satisfy
-if the block is to remain open. For example, a block quote requires a
-`>` character. A paragraph requires a non-blank line.
-In this phase we may match all or just some of the open
-blocks. But we cannot close unmatched blocks yet, because we may have a
-[lazy continuation line].
-
-2. Next, after consuming the continuation markers for existing
-blocks, we look for new block starts (e.g. `>` for a block quote).
-If we encounter a new block start, we close any blocks unmatched
-in step 1 before creating the new block as a child of the last
-matched container block.
-
-3. Finally, we look at the remainder of the line (after block
-markers like `>`, list markers, and indentation have been consumed).
-This is text that can be incorporated into the last open
-block (a paragraph, code block, heading, or raw HTML).
-
-Setext headings are formed when we see a line of a paragraph
-that is a [setext heading underline].
-
-Reference link definitions are detected when a paragraph is closed;
-the accumulated text lines are parsed to see if they begin with
-one or more reference link definitions. Any remainder becomes a
-normal paragraph.
-
-We can see how this works by considering how the tree above is
-generated by four lines of Markdown:
-
-``` markdown
-> Lorem ipsum dolor
-sit amet.
-> - Qui *quodsi iracundia*
-> - aliquando id
-```
-
-At the outset, our document model is just
-
-``` tree
--> document
-```
-
-The first line of our text,
-
-``` markdown
-> Lorem ipsum dolor
-```
-
-causes a `block_quote` block to be created as a child of our
-open `document` block, and a `paragraph` block as a child of
-the `block_quote`. Then the text is added to the last open
-block, the `paragraph`:
-
-``` tree
--> document
- -> block_quote
- -> paragraph
- "Lorem ipsum dolor"
-```
-
-The next line,
-
-``` markdown
-sit amet.
-```
-
-is a "lazy continuation" of the open `paragraph`, so it gets added
-to the paragraph's text:
-
-``` tree
--> document
- -> block_quote
- -> paragraph
- "Lorem ipsum dolor\nsit amet."
-```
-
-The third line,
-
-``` markdown
-> - Qui *quodsi iracundia*
-```
-
-causes the `paragraph` block to be closed, and a new `list` block
-opened as a child of the `block_quote`. A `list_item` is also
-added as a child of the `list`, and a `paragraph` as a child of
-the `list_item`. The text is then added to the new `paragraph`:
-
-``` tree
--> document
- -> block_quote
- paragraph
- "Lorem ipsum dolor\nsit amet."
- -> list (type=bullet tight=true bullet_char=-)
- -> list_item
- -> paragraph
- "Qui *quodsi iracundia*"
-```
-
-The fourth line,
-
-``` markdown
-> - aliquando id
-```
-
-causes the `list_item` (and its child the `paragraph`) to be closed,
-and a new `list_item` opened up as child of the `list`. A `paragraph`
-is added as a child of the new `list_item`, to contain the text.
-We thus obtain the final tree:
-
-``` tree
--> document
- -> block_quote
- paragraph
- "Lorem ipsum dolor\nsit amet."
- -> list (type=bullet tight=true bullet_char=-)
- list_item
- paragraph
- "Qui *quodsi iracundia*"
- -> list_item
- -> paragraph
- "aliquando id"
-```
-
-## Phase 2: inline structure
-
-Once all of the input has been parsed, all open blocks are closed.
-
-We then "walk the tree," visiting every node, and parse raw
-string contents of paragraphs and headings as inlines. At this
-point we have seen all the link reference definitions, so we can
-resolve reference links as we go.
-
-``` tree
-document
- block_quote
- paragraph
- str "Lorem ipsum dolor"
- softbreak
- str "sit amet."
- list (type=bullet tight=true bullet_char=-)
- list_item
- paragraph
- str "Qui "
- emph
- str "quodsi iracundia"
- list_item
- paragraph
- str "aliquando id"
-```
-
-Notice how the [line ending] in the first paragraph has
-been parsed as a `softbreak`, and the asterisks in the first list item
-have become an `emph`.
-
-### An algorithm for parsing nested emphasis and links
-
-By far the trickiest part of inline parsing is handling emphasis,
-strong emphasis, links, and images. This is done using the following
-algorithm.
-
-When we're parsing inlines and we hit either
-
-- a run of `*` or `_` characters, or
-- a `[` or `![`
-
-we insert a text node with these symbols as its literal content, and we
-add a pointer to this text node to the [delimiter stack](@).
-
-The [delimiter stack] is a doubly linked list. Each
-element contains a pointer to a text node, plus information about
-
-- the type of delimiter (`[`, `![`, `*`, `_`)
-- the number of delimiters,
-- whether the delimiter is "active" (all are active to start), and
-- whether the delimiter is a potential opener, a potential closer,
- or both (which depends on what sort of characters precede
- and follow the delimiters).
-
-When we hit a `]` character, we call the *look for link or image*
-procedure (see below).
-
-When we hit the end of the input, we call the *process emphasis*
-procedure (see below), with `stack_bottom` = NULL.
-
-#### *look for link or image*
-
-Starting at the top of the delimiter stack, we look backwards
-through the stack for an opening `[` or `![` delimiter.
-
-- If we don't find one, we return a literal text node `]`.
-
-- If we do find one, but it's not *active*, we remove the inactive
- delimiter from the stack, and return a literal text node `]`.
-
-- If we find one and it's active, then we parse ahead to see if
- we have an inline link/image, reference link/image, compact reference
- link/image, or shortcut reference link/image.
-
- + If we don't, then we remove the opening delimiter from the
- delimiter stack and return a literal text node `]`.
-
- + If we do, then
-
- * We return a link or image node whose children are the inlines
- after the text node pointed to by the opening delimiter.
-
- * We run *process emphasis* on these inlines, with the `[` opener
- as `stack_bottom`.
-
- * We remove the opening delimiter.
-
- * If we have a link (and not an image), we also set all
- `[` delimiters before the opening delimiter to *inactive*. (This
- will prevent us from getting links within links.)
-
-#### *process emphasis*
-
-Parameter `stack_bottom` sets a lower bound to how far we
-descend in the [delimiter stack]. If it is NULL, we can
-go all the way to the bottom. Otherwise, we stop before
-visiting `stack_bottom`.
-
-Let `current_position` point to the element on the [delimiter stack]
-just above `stack_bottom` (or the first element if `stack_bottom`
-is NULL).
-
-We keep track of the `openers_bottom` for each delimiter
-type (`*`, `_`) and each length of the closing delimiter run
-(modulo 3). Initialize this to `stack_bottom`.
-
-Then we repeat the following until we run out of potential
-closers:
-
-- Move `current_position` forward in the delimiter stack (if needed)
- until we find the first potential closer with delimiter `*` or `_`.
- (This will be the potential closer closest
- to the beginning of the input -- the first one in parse order.)
-
-- Now, look back in the stack (staying above `stack_bottom` and
- the `openers_bottom` for this delimiter type) for the
- first matching potential opener ("matching" means same delimiter).
-
-- If one is found:
-
- + Figure out whether we have emphasis or strong emphasis:
- if both closer and opener spans have length >= 2, we have
- strong, otherwise regular.
-
- + Insert an emph or strong emph node accordingly, after
- the text node corresponding to the opener.
-
- + Remove any delimiters between the opener and closer from
- the delimiter stack.
-
- + Remove 1 (for regular emph) or 2 (for strong emph) delimiters
- from the opening and closing text nodes. If they become empty
- as a result, remove them and remove the corresponding element
- of the delimiter stack. If the closing node is removed, reset
- `current_position` to the next element in the stack.
-
-- If none is found:
-
- + Set `openers_bottom` to the element before `current_position`.
- (We know that there are no openers for this kind of closer up to and
- including this point, so this puts a lower bound on future searches.)
-
- + If the closer at `current_position` is not a potential opener,
- remove it from the delimiter stack (since we know it can't
- be a closer either).
-
- + Advance `current_position` to the next element in the stack.
-
-After we're done, we remove all delimiters above `stack_bottom` from the
-delimiter stack.
-
diff --git a/lib/cmark/test/spec_tests.py b/lib/cmark/test/spec_tests.py
deleted file mode 100755
index 1b00c90..0000000
--- a/lib/cmark/test/spec_tests.py
+++ /dev/null
@@ -1,142 +0,0 @@
-#!/usr/bin/env python3
-# -*- coding: utf-8 -*-
-
-import sys
-from difflib import unified_diff
-import argparse
-import re
-import json
-from cmark import CMark
-from normalize import normalize_html
-
-parser = argparse.ArgumentParser(description='Run cmark tests.')
-parser.add_argument('-p', '--program', dest='program', nargs='?', default=None,
- help='program to test')
-parser.add_argument('-s', '--spec', dest='spec', nargs='?', default='spec.txt',
- help='path to spec')
-parser.add_argument('-P', '--pattern', dest='pattern', nargs='?',
- default=None, help='limit to sections matching regex pattern')
-parser.add_argument('--library-dir', dest='library_dir', nargs='?',
- default=None, help='directory containing dynamic library')
-parser.add_argument('--no-normalize', dest='normalize',
- action='store_const', const=False, default=True,
- help='do not normalize HTML')
-parser.add_argument('-d', '--dump-tests', dest='dump_tests',
- action='store_const', const=True, default=False,
- help='dump tests in JSON format')
-parser.add_argument('--debug-normalization', dest='debug_normalization',
- action='store_const', const=True,
- default=False, help='filter stdin through normalizer for testing')
-parser.add_argument('-n', '--number', type=int, default=None,
- help='only consider the test with the given number')
-args = parser.parse_args(sys.argv[1:])
-
-def out(str):
- sys.stdout.buffer.write(str.encode('utf-8'))
-
-def print_test_header(headertext, example_number, start_line, end_line):
- out("Example %d (lines %d-%d) %s\n" % (example_number,start_line,end_line,headertext))
-
-def do_test(converter, test, normalize, result_counts):
- [retcode, actual_html, err] = converter(test['markdown'])
- if retcode == 0:
- expected_html = test['html']
- unicode_error = None
- if normalize:
- try:
- passed = normalize_html(actual_html) == normalize_html(expected_html)
- except UnicodeDecodeError as e:
- unicode_error = e
- passed = False
- else:
- passed = actual_html == expected_html
- if passed:
- result_counts['pass'] += 1
- else:
- print_test_header(test['section'], test['example'], test['start_line'], test['end_line'])
- out(test['markdown'] + '\n')
- if unicode_error:
- out("Unicode error: " + str(unicode_error) + '\n')
- out("Expected: " + repr(expected_html) + '\n')
- out("Got: " + repr(actual_html) + '\n')
- else:
- expected_html_lines = expected_html.splitlines(True)
- actual_html_lines = actual_html.splitlines(True)
- for diffline in unified_diff(expected_html_lines, actual_html_lines,
- "expected HTML", "actual HTML"):
- out(diffline)
- out('\n')
- result_counts['fail'] += 1
- else:
- print_test_header(test['section'], test['example'], test['start_line'], test['end_line'])
- out("program returned error code %d\n" % retcode)
- sys.stdout.buffer.write(err)
- result_counts['error'] += 1
-
-def get_tests(specfile):
- line_number = 0
- start_line = 0
- end_line = 0
- example_number = 0
- markdown_lines = []
- html_lines = []
- state = 0 # 0 regular text, 1 markdown example, 2 html output
- headertext = ''
- tests = []
-
- header_re = re.compile('#+ ')
-
- with open(specfile, 'r', encoding='utf-8', newline='\n') as specf:
- for line in specf:
- line_number = line_number + 1
- l = line.strip()
- if l == "`" * 32 + " example":
- state = 1
- elif l == "`" * 32:
- state = 0
- example_number = example_number + 1
- end_line = line_number
- tests.append({
- "markdown":''.join(markdown_lines).replace('→',"\t"),
- "html":''.join(html_lines).replace('→',"\t"),
- "example": example_number,
- "start_line": start_line,
- "end_line": end_line,
- "section": headertext})
- start_line = 0
- markdown_lines = []
- html_lines = []
- elif l == ".":
- state = 2
- elif state == 1:
- if start_line == 0:
- start_line = line_number - 1
- markdown_lines.append(line)
- elif state == 2:
- html_lines.append(line)
- elif state == 0 and re.match(header_re, line):
- headertext = header_re.sub('', line).strip()
- return tests
-
-if __name__ == "__main__":
- if args.debug_normalization:
- out(normalize_html(sys.stdin.read()))
- exit(0)
-
- all_tests = get_tests(args.spec)
- if args.pattern:
- pattern_re = re.compile(args.pattern, re.IGNORECASE)
- else:
- pattern_re = re.compile('.')
- tests = [ test for test in all_tests if re.search(pattern_re, test['section']) and (not args.number or test['example'] == args.number) ]
- if args.dump_tests:
- out(json.dumps(tests, ensure_ascii=False, indent=2))
- exit(0)
- else:
- skipped = len(all_tests) - len(tests)
- converter = CMark(prog=args.program, library_dir=args.library_dir).to_html
- result_counts = {'pass': 0, 'fail': 0, 'error': 0, 'skip': skipped}
- for test in tests:
- do_test(converter, test, args.normalize, result_counts)
- out("{pass} passed, {fail} failed, {error} errored, {skip} skipped\n".format(**result_counts))
- exit(result_counts['fail'] + result_counts['error'])
diff --git a/lib/cmark/toolchain-mingw32.cmake b/lib/cmark/toolchain-mingw32.cmake
deleted file mode 100644
index 61c62a8..0000000
--- a/lib/cmark/toolchain-mingw32.cmake
+++ /dev/null
@@ -1,17 +0,0 @@
-# the name of the target operating system
-SET(CMAKE_SYSTEM_NAME Windows)
-
-# which compilers to use for C and C++
-SET(CMAKE_C_COMPILER i586-mingw32msvc-gcc)
-SET(CMAKE_CXX_COMPILER i586-mingw32msvc-g++)
-SET(CMAKE_RC_COMPILER i586-mingw32msvc-windres)
-
-# here is the target environment located
-SET(CMAKE_FIND_ROOT_PATH /usr/i586-mingw32msvc "${CMAKE_SOURCE_DIR}/windows")
-
-# adjust the default behaviour of the FIND_XXX() commands:
-# search headers and libraries in the target environment, search
-# programs in the host environment
-set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
-set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
-set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
diff --git a/lib/cmark/tools/appveyor-build.bat b/lib/cmark/tools/appveyor-build.bat
deleted file mode 100644
index 73d555b..0000000
--- a/lib/cmark/tools/appveyor-build.bat
+++ /dev/null
@@ -1,13 +0,0 @@
-@echo off
-
-if "%MSVC_VERSION%" == "10" goto msvc10
-
-call "C:\Program Files (x86)\Microsoft Visual Studio %MSVC_VERSION%.0\VC\vcvarsall.bat" amd64
-goto build
-
-:msvc10
-call "C:\Program Files\Microsoft SDKs\Windows\v7.1\Bin\SetEnv.cmd" /x64
-
-:build
-nmake
-
diff --git a/lib/cmark/tools/make_entities_inc.py b/lib/cmark/tools/make_entities_inc.py
deleted file mode 100644
index 7b8ee41..0000000
--- a/lib/cmark/tools/make_entities_inc.py
+++ /dev/null
@@ -1,32 +0,0 @@
-# Creates C data structures for binary lookup table of entities,
-# using python's html5 entity data.
-# Usage: python3 tools/make_entities_inc.py > src/entities.inc
-
-import html
-
-entities5 = html.entities.html5
-
-# remove keys without semicolons. For some reason the list
-# has duplicates of a few things, like auml, one with and one
-# without a semicolon.
-entities = sorted([(k[:-1], entities5[k].encode('utf-8')) for k in entities5.keys() if k[-1] == ';'])
-
-# Print out the header:
-print("""/* Autogenerated by tools/make_headers_inc.py */
-
-struct cmark_entity_node {
- unsigned char *entity;
- unsigned char bytes[8];
-};
-
-#define CMARK_ENTITY_MIN_LENGTH 2
-#define CMARK_ENTITY_MAX_LENGTH 32""")
-
-print("#define CMARK_NUM_ENTITIES " + str(len(entities)));
-
-print("\nstatic const struct cmark_entity_node cmark_entities[] = {");
-
-for (ent, bs) in entities:
- print('{(unsigned char*)"' + ent + '", {' + ', '.join(map(str, bs)) + ', 0}},')
-
-print("};")
diff --git a/lib/cmark/tools/mkcasefold.pl b/lib/cmark/tools/mkcasefold.pl
deleted file mode 100755
index 740ce77..0000000
--- a/lib/cmark/tools/mkcasefold.pl
+++ /dev/null
@@ -1,22 +0,0 @@
-binmode STDOUT;
-print(" switch (c) {\n");
-my $lastchar = "";
-while (<STDIN>) {
- if (/^[A-F0-9]/ and / [CF]; /) {
- my ($char, $type, $subst) = m/([A-F0-9]+); ([CF]); ([^;]+)/;
- if ($char eq $lastchar) {
- break;
- }
- my @subst = $subst =~ m/(\w+)/g;
- printf(" case 0x%s:\n", $char);
- foreach (@subst) {
- printf(" bufpush(0x%s);\n", $_);
- }
- printf(" break;\n");
- $lastchar = $char;
- }
-}
-printf(" default:\n");
-printf(" bufpush(c);\n");
-print(" }\n");
-
diff --git a/lib/cmark/tools/xml2md.xsl b/lib/cmark/tools/xml2md.xsl
deleted file mode 100644
index 0122e5f..0000000
--- a/lib/cmark/tools/xml2md.xsl
+++ /dev/null
@@ -1,319 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-
-<!--
-
-xml2md.xsl
-==========
-
-This XSLT stylesheet transforms the cmark XML format back to Commonmark.
-Since the XML output is lossy, a lossless MD->XML->MD roundtrip isn't
-possible. The XML->MD->XML roundtrip should produce the original XML,
-though.
-
-Example usage with xsltproc:
-
- cmark -t xml doc.md | xsltproc -novalid xml2md.xsl -
-
--->
-
-<xsl:stylesheet
- version="1.0"
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:md="http://commonmark.org/xml/1.0">
-
-<xsl:output method="text" encoding="utf-8"/>
-
-<!-- Generic templates -->
-
-<xsl:template match="/ | md:document | md:list">
- <xsl:apply-templates select="md:*"/>
-</xsl:template>
-
-<xsl:template match="md:*">
- <xsl:message>Unsupported element '<xsl:value-of select="local-name()"/>'</xsl:message>
-</xsl:template>
-
-<xsl:template match="md:*" mode="indent"/>
-
-<!-- Indent blocks -->
-
-<xsl:template match="md:*" mode="indent-block">
- <xsl:if test="preceding-sibling::md:*">
- <xsl:if test="not(ancestor::md:list[1][@tight='true'])">
- <xsl:apply-templates select="ancestor::md:*" mode="indent"/>
- <xsl:text>&#10;</xsl:text>
- </xsl:if>
- <xsl:apply-templates select="ancestor::md:*" mode="indent"/>
- </xsl:if>
-</xsl:template>
-
-<!-- Heading -->
-
-<xsl:template match="md:heading">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:value-of select="substring('###### ', 7 - @level)"/>
- <xsl:apply-templates select="md:*"/>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<!-- Paragraph -->
-
-<xsl:template match="md:paragraph">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:apply-templates select="md:*"/>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<!-- Thematic break -->
-
-<xsl:template match="md:thematic_break">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:text>***&#10;</xsl:text>
-</xsl:template>
-
-<!-- List -->
-
-<xsl:template match="md:list">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:apply-templates select="md:*"/>
-</xsl:template>
-
-<xsl:template match="md:item">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:choose>
- <xsl:when test="../@type = 'bullet'">-</xsl:when>
- <xsl:when test="../@type = 'ordered'">
- <xsl:value-of select="../@start + position() - 1"/>
- <xsl:choose>
- <xsl:when test="../@delim = 'period'">.</xsl:when>
- <xsl:when test="../@delim = 'paren'">)</xsl:when>
- </xsl:choose>
- </xsl:when>
- </xsl:choose>
- <xsl:text> </xsl:text>
- <xsl:apply-templates select="md:*"/>
-</xsl:template>
-
-<xsl:template match="md:item" mode="indent">
- <xsl:choose>
- <xsl:when test="../@type = 'bullet'">
- <xsl:text> </xsl:text>
- </xsl:when>
- <xsl:when test="../@type = 'ordered'">
- <xsl:text> </xsl:text>
- </xsl:when>
- </xsl:choose>
-</xsl:template>
-
-<!-- Block quote -->
-
-<xsl:template match="md:block_quote">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:text>&gt; </xsl:text>
- <xsl:apply-templates select="md:*"/>
-</xsl:template>
-
-<xsl:template match="md:block_quote" mode="indent">
- <xsl:text>&gt; </xsl:text>
-</xsl:template>
-
-<!-- Code block -->
-
-<xsl:template match="md:code_block">
- <xsl:apply-templates select="." mode="indent-block"/>
-
- <xsl:variable name="t" select="string(.)"/>
- <xsl:variable name="delim">
- <xsl:call-template name="code-delim">
- <xsl:with-param name="text" select="$t"/>
- <xsl:with-param name="delim" select="'```'"/>
- </xsl:call-template>
- </xsl:variable>
-
- <xsl:value-of select="$delim"/>
- <xsl:value-of select="@info"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:call-template name="indent-lines">
- <xsl:with-param name="code" select="$t"/>
- </xsl:call-template>
- <xsl:apply-templates select="ancestor::md:*" mode="indent"/>
- <xsl:value-of select="$delim"/>
- <xsl:text>&#10;</xsl:text>
-</xsl:template>
-
-<!-- Inline HTML -->
-
-<xsl:template match="md:html_block">
- <xsl:apply-templates select="." mode="indent-block"/>
- <xsl:value-of select="substring-before(., '&#10;')"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:call-template name="indent-lines">
- <xsl:with-param name="code" select="substring-after(., '&#10;')"/>
- </xsl:call-template>
-</xsl:template>
-
-<!-- Indent multiple lines -->
-
-<xsl:template name="indent-lines">
- <xsl:param name="code"/>
- <xsl:if test="contains($code, '&#10;')">
- <xsl:apply-templates select="ancestor::md:*" mode="indent"/>
- <xsl:value-of select="substring-before($code, '&#10;')"/>
- <xsl:text>&#10;</xsl:text>
- <xsl:call-template name="indent-lines">
- <xsl:with-param name="code" select="substring-after($code, '&#10;')"/>
- </xsl:call-template>
- </xsl:if>
-</xsl:template>
-
-<!-- Text -->
-
-<xsl:template match="md:text">
- <xsl:variable name="t" select="string(.)"/>
- <xsl:variable name="first" select="substring($t, 1, 1)"/>
- <xsl:variable name="marker-check" select="translate(substring($t, 1, 10), '0123456789', '')"/>
- <xsl:choose>
- <!-- Escape ordered list markers -->
- <xsl:when test="starts-with($marker-check, '.') and $first != '.'">
- <xsl:value-of select="substring-before($t, '.')"/>
- <xsl:text>\.</xsl:text>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="substring-after($t, '.')"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:when test="starts-with($marker-check, ')') and $first != ')'">
- <xsl:value-of select="substring-before($t, ')')"/>
- <xsl:text>\)</xsl:text>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="substring-after($t, ')')"/>
- </xsl:call-template>
- </xsl:when>
- <!-- Escape leading block characters -->
- <xsl:when test="contains('-+>#=~', $first)">
- <xsl:text>\</xsl:text>
- <xsl:value-of select="$first"/>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="substring($t, 2)"/>
- </xsl:call-template>
- </xsl:when>
- <!-- Otherwise -->
- <xsl:otherwise>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="$t"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<!-- Breaks -->
-
-<xsl:template match="md:softbreak">
- <xsl:text>&#10;</xsl:text>
- <xsl:apply-templates select="ancestor::md:*" mode="indent"/>
-</xsl:template>
-
-<xsl:template match="md:linebreak">
- <xsl:text> &#10;</xsl:text>
- <xsl:apply-templates select="ancestor::md:*" mode="indent"/>
-</xsl:template>
-
-<!-- Emphasis -->
-
-<xsl:template match="md:emph">
- <xsl:text>*</xsl:text>
- <xsl:apply-templates select="md:*"/>
- <xsl:text>*</xsl:text>
-</xsl:template>
-
-<xsl:template match="md:strong">
- <xsl:text>**</xsl:text>
- <xsl:apply-templates select="md:*"/>
- <xsl:text>**</xsl:text>
-</xsl:template>
-
-<!-- Inline code -->
-
-<xsl:template match="md:code">
- <xsl:variable name="t" select="string(.)"/>
- <xsl:variable name="delim">
- <xsl:call-template name="code-delim">
- <xsl:with-param name="text" select="$t"/>
- <xsl:with-param name="delim" select="'`'"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:value-of select="$delim"/>
- <xsl:value-of select="$t"/>
- <xsl:value-of select="$delim"/>
-</xsl:template>
-
-<!-- Links and images -->
-
-<xsl:template match="md:link | md:image">
- <xsl:if test="self::md:image">!</xsl:if>
- <xsl:text>[</xsl:text>
- <xsl:apply-templates select="md:*"/>
- <xsl:text>](</xsl:text>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="string(@destination)"/>
- <xsl:with-param name="escape" select="'()'"/>
- </xsl:call-template>
- <xsl:if test="string(@title)">
- <xsl:text> "</xsl:text>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="string(@title)"/>
- <xsl:with-param name="escape" select="'&quot;'"/>
- </xsl:call-template>
- <xsl:text>"</xsl:text>
- </xsl:if>
- <xsl:text>)</xsl:text>
-</xsl:template>
-
-<!-- Inline HTML -->
-
-<xsl:template match="md:html_inline">
- <xsl:value-of select="."/>
-</xsl:template>
-
-<!-- Escaping helpers -->
-
-<xsl:template name="escape-text">
- <xsl:param name="text"/>
- <xsl:param name="escape" select="'*_`&lt;[]&amp;'"/>
-
- <xsl:variable name="trans" select="translate($text, $escape, '\\\\\\\')"/>
- <xsl:choose>
- <xsl:when test="contains($trans, '\')">
- <xsl:variable name="safe" select="substring-before($trans, '\')"/>
- <xsl:variable name="l" select="string-length($safe)"/>
- <xsl:value-of select="$safe"/>
- <xsl:text>\</xsl:text>
- <xsl:value-of select="substring($text, $l + 1, 1)"/>
- <xsl:call-template name="escape-text">
- <xsl:with-param name="text" select="substring($text, $l + 2)"/>
- <xsl:with-param name="escape" select="$escape"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$text"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-<xsl:template name="code-delim">
- <xsl:param name="text"/>
- <xsl:param name="delim"/>
-
- <xsl:choose>
- <xsl:when test="contains($text, $delim)">
- <xsl:call-template name="code-delim">
- <xsl:with-param name="text" select="$text"/>
- <xsl:with-param name="delim" select="concat($delim, '`')"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="$delim"/>
- </xsl:otherwise>
- </xsl:choose>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/lib/cmark/why-cmark-and-not-x.md b/lib/cmark/why-cmark-and-not-x.md
deleted file mode 100644
index 3fdb4e5..0000000
--- a/lib/cmark/why-cmark-and-not-x.md
+++ /dev/null
@@ -1,104 +0,0 @@
-Why use `cmark` and not X?
-==========================
-
-`hoedown`
----------
-
-`hoedown` (which derives from `sundown`) is slightly faster
-than `cmark` in our benchmarks (0.21s vs. 0.29s). But both
-are much faster than any other available implementations.
-
-`hoedown` boasts of including "protection against all possible
-DOS attacks," but there are some chinks in the armor:
-
- % time python -c 'print(("[" * 50000) + "a" + ("]" * 50000))' | cmark
- ...
- user 0m0.073s
- % time python -c 'print(("[" * 50000) + "a" + ("]" * 50000))' | hoedown
- ...
- 0m17.84s
-
-`hoedown` has many parsing bugs. Here is a selection (as of
-v3.0.3):
-
- % hoedown
- - one
- - two
- 1. three
- ^D
- <ul>
- <li>one
-
- <ul>
- <li>two</li>
- <li>three</li>
- </ul></li>
- </ul>
-
-
- % hoedown
- ## hi\###
- ^D
- <h2>hi\</h2>
-
-
- % hoedown
- [ΑΓΩ]: /φου
-
- [αγω]
- ^D
- <p>[αγω]</p>
-
-
- % hoedown
- ```
- [foo]: /url
- ```
-
- [foo]
- ^D
- <p>```</p>
-
- <p>```</p>
-
- <p><a href="/url">foo</a></p>
-
-
- % hoedown
- [foo](url "ti\*tle")
- ^D
- <p><a href="url" title="ti\*tle">foo</a></p>
-
-
- % ./hoedown
- - one
- - two
- - three
- - four
- ^D
- <ul>
- <li>one
-
- <ul>
- <li>two</li>
- <li>three</li>
- <li>four</li>
- </ul></li>
- </ul>
-
-
-`discount`
-----------
-
-`cmark` is about six times faster.
-
-`kramdown`
-----------
-
-`cmark` is about a hundred times faster.
-
-`kramdown` also gets tied in knots by pathological input like
-
- python -c 'print(("[" * 50000) + "a" + ("]" * 50000))'
-
-
diff --git a/lib/cmark/wrappers/wrapper.py b/lib/cmark/wrappers/wrapper.py
deleted file mode 100755
index 98e7f2b..0000000
--- a/lib/cmark/wrappers/wrapper.py
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/usr/bin/env python
-
-# Example for using the shared library from python
-# Will work with either python 2 or python 3
-# Requires cmark library to be installed
-
-from ctypes import CDLL, c_char_p, c_long
-import sys
-import platform
-
-sysname = platform.system()
-
-if sysname == 'Darwin':
- libname = "libcmark.dylib"
-elif sysname == 'Windows':
- libname = "cmark.dll"
-else:
- libname = "libcmark.so"
-cmark = CDLL(libname)
-
-markdown = cmark.cmark_markdown_to_html
-markdown.restype = c_char_p
-markdown.argtypes = [c_char_p, c_long, c_long]
-
-opts = 0 # defaults
-
-def md2html(text):
- if sys.version_info >= (3,0):
- textbytes = text.encode('utf-8')
- textlen = len(textbytes)
- return markdown(textbytes, textlen, opts).decode('utf-8')
- else:
- textbytes = text
- textlen = len(text)
- return markdown(textbytes, textlen, opts)
-
-sys.stdout.write(md2html(sys.stdin.read()))
diff --git a/lib/cmark/wrappers/wrapper.rb b/lib/cmark/wrappers/wrapper.rb
deleted file mode 100755
index 2359366..0000000
--- a/lib/cmark/wrappers/wrapper.rb
+++ /dev/null
@@ -1,15 +0,0 @@
-#!/usr/bin/env ruby
-require 'ffi'
-
-module CMark
- extend FFI::Library
- ffi_lib ['libcmark', 'cmark']
- attach_function :cmark_markdown_to_html, [:string, :int, :int], :string
-end
-
-def markdown_to_html(s)
- len = s.bytesize
- CMark::cmark_markdown_to_html(s, len, 0)
-end
-
-STDOUT.write(markdown_to_html(ARGF.read()))
diff --git a/lib/cmark/wrappers/wrapper.rkt b/lib/cmark/wrappers/wrapper.rkt
deleted file mode 100644
index 1ecce17..0000000
--- a/lib/cmark/wrappers/wrapper.rkt
+++ /dev/null
@@ -1,208 +0,0 @@
-#lang racket/base
-
-;; requires racket >= 5.3 because of submodules
-
-;; Lowlevel interface
-
-(module low-level racket/base
-
- (require ffi/unsafe ffi/unsafe/define)
-
- (provide (all-defined-out))
-
- (define-ffi-definer defcmark (ffi-lib "libcmark"))
-
- (define _cmark_node_type
- (_enum '(;; Error status
- none
- ;; Block
- document block-quote list item code-block
- html-block custom-block
- paragraph heading thematic-break
- ;; ?? first-block = document
- ;; ?? last-block = thematic-break
- ;; Inline
- text softbreak linebreak code html-inline custom-inline
- emph strong link image
- ;; ?? first-inline = text
- ;; ?? last-inline = image
- )))
- (define _cmark_list_type
- (_enum '(no_list bullet_list ordered_list)))
- (define _cmark_delim_type
- (_enum '(no_delim period_delim paren_delim)))
- (define _cmark_opts
- (_bitmask
- '(sourcepos = 2 ; include sourcepos attribute on block elements
- hardbreaks = 4 ; render `softbreak` elements as hard line breaks
- safe = 8 ; suppress raw HTML and unsafe links
- nobreaks = 16 ; render `softbreak` elements as spaces
- normalize = 256 ; legacy (no effect)
- validate-utf8 = 512 ; validate UTF-8 in the input
- smart = 1024 ; straight quotes to curly, ---/-- to em/en dashes
- )))
-
- (define-cpointer-type _node)
-
- (defcmark cmark_markdown_to_html
- (_fun [bs : _bytes] [_int = (bytes-length bs)] _cmark_opts
- -> [r : _bytes] -> (begin0 (bytes->string/utf-8 r) (free r))))
-
- (defcmark cmark_parse_document
- (_fun [bs : _bytes] [_int = (bytes-length bs)] _cmark_opts
- -> _node))
-
- (defcmark cmark_render_html
- (_fun _node _cmark_opts
- -> [r : _bytes] -> (begin0 (bytes->string/utf-8 r) (free r))))
-
- (defcmark cmark_node_new (_fun _cmark_node_type -> _node))
- (defcmark cmark_node_free (_fun _node -> _void))
-
- (defcmark cmark_node_next (_fun _node -> _node/null))
- (defcmark cmark_node_previous (_fun _node -> _node/null))
- (defcmark cmark_node_parent (_fun _node -> _node/null))
- (defcmark cmark_node_first_child (_fun _node -> _node/null))
- (defcmark cmark_node_last_child (_fun _node -> _node/null))
-
- (defcmark cmark_node_get_user_data (_fun _node -> _racket))
- (defcmark cmark_node_set_user_data (_fun _node _racket -> _bool))
- (defcmark cmark_node_get_type (_fun _node -> _cmark_node_type))
- (defcmark cmark_node_get_type_string (_fun _node -> _bytes))
- (defcmark cmark_node_get_literal (_fun _node -> _string))
- (defcmark cmark_node_set_literal (_fun _node _string -> _bool))
- (defcmark cmark_node_get_heading_level (_fun _node -> _int))
- (defcmark cmark_node_set_heading_level (_fun _node _int -> _bool))
- (defcmark cmark_node_get_list_type (_fun _node -> _cmark_list_type))
- (defcmark cmark_node_set_list_type (_fun _node _cmark_list_type -> _bool))
- (defcmark cmark_node_get_list_delim (_fun _node -> _cmark_delim_type))
- (defcmark cmark_node_set_list_delim (_fun _node _cmark_delim_type -> _bool))
- (defcmark cmark_node_get_list_start (_fun _node -> _int))
- (defcmark cmark_node_set_list_start (_fun _node _int -> _bool))
- (defcmark cmark_node_get_list_tight (_fun _node -> _bool))
- (defcmark cmark_node_set_list_tight (_fun _node _bool -> _bool))
- (defcmark cmark_node_get_fence_info (_fun _node -> _string))
- (defcmark cmark_node_set_fence_info (_fun _node _string -> _bool))
- (defcmark cmark_node_get_url (_fun _node -> _string))
- (defcmark cmark_node_set_url (_fun _node _string -> _bool))
- (defcmark cmark_node_get_title (_fun _node -> _string))
- (defcmark cmark_node_set_title (_fun _node _string -> _bool))
- (defcmark cmark_node_get_start_line (_fun _node -> _int))
- (defcmark cmark_node_get_start_column (_fun _node -> _int))
- (defcmark cmark_node_get_end_line (_fun _node -> _int))
- (defcmark cmark_node_get_end_column (_fun _node -> _int))
-
- (defcmark cmark_node_unlink (_fun _node -> _void))
- (defcmark cmark_node_insert_before (_fun _node _node -> _bool))
- (defcmark cmark_node_insert_after (_fun _node _node -> _bool))
- (defcmark cmark_node_prepend_child (_fun _node _node -> _bool))
- (defcmark cmark_node_append_child (_fun _node _node -> _bool))
- (defcmark cmark_consolidate_text_nodes (_fun _node -> _void))
-
- (defcmark cmark_version (_fun -> _int))
- (defcmark cmark_version_string (_fun -> _string))
-
- )
-
-;; Rackety interface
-
-(module high-level racket/base
-
- (require (submod ".." low-level) ffi/unsafe)
-
- (provide cmark-markdown-to-html)
- (define (cmark-markdown-to-html str [options '(normalize smart)])
- (cmark_markdown_to_html (if (bytes? str) str (string->bytes/utf-8 str))
- options))
-
- (require (for-syntax racket/base racket/syntax))
- (define-syntax (make-getter+setter stx)
- (syntax-case stx ()
- [(_ name) (with-syntax ([(getter setter)
- (map (λ(op) (format-id #'name "cmark_node_~a_~a"
- op #'name))
- '(get set))])
- #'(cons getter setter))]))
- (define-syntax-rule (define-getters+setters name [type field ...] ...)
- (define name (list (list 'type (make-getter+setter field) ...) ...)))
- (define-getters+setters getters+setters
- [heading heading_level] [code-block fence_info]
- [link url title] [image url title]
- [list list_type list_delim list_start list_tight])
-
- (provide cmark->sexpr)
- (define (cmark->sexpr node)
- (define text (cmark_node_get_literal node))
- (define type (cmark_node_get_type node))
- (define children
- (let loop ([node (cmark_node_first_child node)])
- (if (not node) '()
- (cons (cmark->sexpr node) (loop (cmark_node_next node))))))
- (define info
- (cond [(assq type getters+setters)
- => (λ(gss) (map (λ(gs) ((car gs) node)) (cdr gss)))]
- [else '()]))
- (define (assert-no what-not b)
- (when b (error 'cmark->sexpr "unexpected ~a in ~s" what-not type)))
- (cond [(memq type '(document paragraph heading block-quote list item
- emph strong link image))
- (assert-no 'text text)
- (list type info children)]
- [(memq type '(text code code-block html-block html-inline
- softbreak linebreak thematic-break))
- (assert-no 'children (pair? children))
- (list type info text)]
- [else (error 'cmark->sexpr "unknown type: ~s" type)]))
-
- (provide sexpr->cmark)
- (define (sexpr->cmark sexpr) ; assumes valid input, as generated by the above
- (define (loop sexpr)
- (define type (car sexpr))
- (define info (cadr sexpr))
- (define data (caddr sexpr))
- (define node (cmark_node_new type))
- (let ([gss (assq type getters+setters)])
- (when gss
- (unless (= (length (cdr gss)) (length info))
- (error 'sexpr->cmark "bad number of info values in ~s" sexpr))
- (for-each (λ(gs x) ((cdr gs) node x)) (cdr gss) info)))
- (cond [(string? data) (cmark_node_set_literal node data)]
- [(not data) (void)]
- [(list? data)
- (for ([child (in-list data)])
- (cmark_node_append_child node (sexpr->cmark child)))]
- [else (error 'sexpr->cmark "bad data in ~s" sexpr)])
- node)
- (define root (loop sexpr))
- (register-finalizer root cmark_node_free)
- root)
-
- ;; Registers a `cmark_node_free` finalizer
- (provide cmark-parse-document)
- (define (cmark-parse-document str [options '(normalize smart)])
- (define root (cmark_parse_document
- (if (bytes? str) str (string->bytes/utf-8 str))
- options))
- (register-finalizer root cmark_node_free)
- root)
-
- (provide cmark-render-html)
- (define (cmark-render-html root [options '(normalize smart)])
- (cmark_render_html root options)))
-
-#; ;; sample use
-(begin
- (require 'high-level racket/string)
- (cmark-render-html
- (cmark-parse-document
- (string-join '("foo"
- "==="
- ""
- "> blah"
- ">"
- "> blah *blah* `bar()` blah:"
- ">"
- "> function foo() {"
- "> bar();"
- "> }")
- "\n"))))