From 674ee308c846f52f07a2382a7c40d5c19825c145 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Wed, 6 Jul 2022 11:02:18 -0400 Subject: [PATCH 01/14] drop submodule --- .gitmodules | 4 ---- .rubocop.yml | 1 - commonmarker.gemspec | 2 +- ext/commonmarker/cmark-upstream | 1 - script/bootstrap | 6 +----- script/cibuild | 2 -- script/update_submodules | 26 -------------------------- 7 files changed, 2 insertions(+), 40 deletions(-) delete mode 160000 ext/commonmarker/cmark-upstream delete mode 100755 script/update_submodules diff --git a/.gitmodules b/.gitmodules index 3eb2afe1..e69de29b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +0,0 @@ -[submodule "ext/commonmarker/cmark-upstream"] - path = ext/commonmarker/cmark-upstream - url = https://github.com/github/cmark-gfm.git - ignore = dirty diff --git a/.rubocop.yml b/.rubocop.yml index e5485141..de8d0a1f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -4,7 +4,6 @@ inherit_gem: - config/minitest.yml AllCops: - TargetRubyVersion: 2.6 Exclude: - "ext/**/*" - "vendor/**/*" diff --git a/commonmarker.gemspec b/commonmarker.gemspec index b2d58847..aacc543b 100644 --- a/commonmarker.gemspec +++ b/commonmarker.gemspec @@ -20,7 +20,7 @@ Gem::Specification.new do |s| s.executables = ["commonmarker"] s.require_paths = ["lib", "ext"] - s.required_ruby_version = [">= 2.6", "< 4.0"] + s.required_ruby_version = [">= 2.7", "< 4.0"] s.metadata["rubygems_mfa_required"] = "true" diff --git a/ext/commonmarker/cmark-upstream b/ext/commonmarker/cmark-upstream deleted file mode 160000 index ef1cfcb8..00000000 --- a/ext/commonmarker/cmark-upstream +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ef1cfcb8a31de72bb951d9259bc4ac89e266975b diff --git a/script/bootstrap b/script/bootstrap index 878a09d2..1497dd92 100755 --- a/script/bootstrap +++ b/script/bootstrap @@ -2,10 +2,6 @@ set -e -echo "==> Initing Git submodules" - -git submodule update --init --recursive - echo "==> Installing gem dependencies…" -bundle install --path vendor/gems --local --standalone --clean "$@" +bundle install diff --git a/script/cibuild b/script/cibuild index 6c9db2f2..5c23ddf0 100755 --- a/script/cibuild +++ b/script/cibuild @@ -2,8 +2,6 @@ set -e -git submodule sync -git submodule update --init bundle bundle exec rake clean bundle exec rake test diff --git a/script/update_submodules b/script/update_submodules deleted file mode 100755 index 69a43e88..00000000 --- a/script/update_submodules +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -set -e - -if [ -z "$1" ]; then - BRANCH="main" -else - BRANCH=$1 -fi - -echo "Using $BRANCH..." - -echo "Checking out cmark-upstream" -echo "---------------------" -cd ext/commonmarker/cmark-upstream -git fetch origin -git checkout $BRANCH && git pull -sha=`git rev-parse HEAD` -cd ../../.. -make -cp ext/commonmarker/cmark-upstream/extensions/*.{c,h} ext/commonmarker -cp ext/commonmarker/cmark-upstream/src/*.{inc,c,h} ext/commonmarker -rm ext/commonmarker/main.c -git add ext/commonmarker/cmark-upstream -git add ext/commonmarker/ -git commit -m "Update cmark-upstream to $(git config submodule.ext/commonmarker/cmark-upstream.url | sed s_.git\$__)/commit/${sha}" From e93c4514898742e370872e7eb945c16a43e6a5c0 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Fri, 15 Jul 2022 15:03:13 -0400 Subject: [PATCH 02/14] Begin process of moving to Rust --- .gitignore | 5 +- README.md | 2 +- Rakefile | 105 +- commonmarker.gemspec | 52 +- ext/commonmarker/arena.c | 103 - ext/commonmarker/autolink.c | 425 - ext/commonmarker/autolink.h | 8 - ext/commonmarker/blocks.c | 1596 --- ext/commonmarker/buffer.c | 278 - ext/commonmarker/buffer.h | 116 - ext/commonmarker/case_fold_switch.inc | 4327 ------- ext/commonmarker/chunk.h | 135 - ext/commonmarker/cmark-gfm-core-extensions.h | 54 - ext/commonmarker/cmark-gfm-extension_api.h | 736 -- .../cmark-gfm-extensions_export.h | 42 - ext/commonmarker/cmark-gfm.h | 817 -- ext/commonmarker/cmark-gfm_export.h | 42 - ext/commonmarker/cmark-gfm_version.h | 7 - ext/commonmarker/cmark.c | 55 - ext/commonmarker/cmark_ctype.c | 44 - ext/commonmarker/cmark_ctype.h | 33 - ext/commonmarker/commonmark.c | 529 - ext/commonmarker/commonmarker.c | 1306 +- ext/commonmarker/commonmarker.h | 4 +- ext/commonmarker/config.h | 76 - ext/commonmarker/core-extensions.c | 27 - ext/commonmarker/entities.inc | 2138 ---- ext/commonmarker/ext_scanners.c | 879 -- ext/commonmarker/ext_scanners.h | 24 - ext/commonmarker/extconf.rb | 72 +- ext/commonmarker/footnotes.c | 63 - ext/commonmarker/footnotes.h | 27 - ext/commonmarker/houdini.h | 57 - ext/commonmarker/houdini_href_e.c | 100 - ext/commonmarker/houdini_html_e.c | 66 - ext/commonmarker/houdini_html_u.c | 149 - ext/commonmarker/html.c | 486 - ext/commonmarker/html.h | 27 - ext/commonmarker/inlines.c | 1691 --- ext/commonmarker/inlines.h | 29 - ext/commonmarker/iterator.c | 159 - ext/commonmarker/iterator.h | 26 - ext/commonmarker/latex.c | 466 - ext/commonmarker/linked_list.c | 37 - ext/commonmarker/man.c | 278 - ext/commonmarker/map.c | 122 - ext/commonmarker/map.h | 41 - ext/commonmarker/node.c | 979 -- ext/commonmarker/node.h | 125 - ext/commonmarker/parser.h | 58 - ext/commonmarker/plaintext.c | 235 - ext/commonmarker/plugin.c | 36 - ext/commonmarker/plugin.h | 34 - ext/commonmarker/references.c | 42 - ext/commonmarker/references.h | 26 - ext/commonmarker/registry.c | 63 - ext/commonmarker/registry.h | 24 - ext/commonmarker/render.c | 205 - ext/commonmarker/render.h | 62 - ext/commonmarker/scanners.c | 10508 ---------------- ext/commonmarker/scanners.h | 62 - ext/commonmarker/scanners.re | 341 - ext/commonmarker/strikethrough.c | 167 - ext/commonmarker/strikethrough.h | 9 - ext/commonmarker/syntax_extension.c | 149 - ext/commonmarker/syntax_extension.h | 34 - ext/commonmarker/table.c | 848 -- ext/commonmarker/table.h | 12 - ext/commonmarker/tagfilter.c | 60 - ext/commonmarker/tagfilter.h | 8 - ext/commonmarker/tasklist.c | 156 - ext/commonmarker/tasklist.h | 8 - ext/commonmarker/utf8.c | 317 - ext/commonmarker/utf8.h | 35 - ext/commonmarker/xml.c | 181 - lib/commonmarker.rb | 41 +- lib/commonmarker/config.rb | 2 +- lib/commonmarker/node.rb | 83 - lib/commonmarker/node/inspect.rb | 47 - lib/commonmarker/renderer.rb | 128 +- lib/commonmarker/renderer/html_renderer.rb | 252 - lib/commonmarker/version.rb | 2 +- rakelib/benchmark.rake | 15 + rakelib/compile.rake | 50 + rakelib/docs.rake | 50 + rakelib/format.rake | 10 + rakelib/test.rake | 17 + test/benchmark.rb | 4 +- test/fixtures/upstream/smart_punct.txt | 177 + test/fixtures/upstream/spec.txt | 9756 ++++++++++++++ test/test_basics.rb | 40 +- test/test_helper.rb | 4 +- 92 files changed, 10234 insertions(+), 33089 deletions(-) delete mode 100644 ext/commonmarker/arena.c delete mode 100644 ext/commonmarker/autolink.c delete mode 100644 ext/commonmarker/autolink.h delete mode 100644 ext/commonmarker/blocks.c delete mode 100644 ext/commonmarker/buffer.c delete mode 100644 ext/commonmarker/buffer.h delete mode 100644 ext/commonmarker/case_fold_switch.inc delete mode 100644 ext/commonmarker/chunk.h delete mode 100644 ext/commonmarker/cmark-gfm-core-extensions.h delete mode 100644 ext/commonmarker/cmark-gfm-extension_api.h delete mode 100644 ext/commonmarker/cmark-gfm-extensions_export.h delete mode 100644 ext/commonmarker/cmark-gfm.h delete mode 100644 ext/commonmarker/cmark-gfm_export.h delete mode 100644 ext/commonmarker/cmark-gfm_version.h delete mode 100644 ext/commonmarker/cmark.c delete mode 100644 ext/commonmarker/cmark_ctype.c delete mode 100644 ext/commonmarker/cmark_ctype.h delete mode 100644 ext/commonmarker/commonmark.c delete mode 100644 ext/commonmarker/config.h delete mode 100644 ext/commonmarker/core-extensions.c delete mode 100644 ext/commonmarker/entities.inc delete mode 100644 ext/commonmarker/ext_scanners.c delete mode 100644 ext/commonmarker/ext_scanners.h delete mode 100644 ext/commonmarker/footnotes.c delete mode 100644 ext/commonmarker/footnotes.h delete mode 100644 ext/commonmarker/houdini.h delete mode 100644 ext/commonmarker/houdini_href_e.c delete mode 100644 ext/commonmarker/houdini_html_e.c delete mode 100644 ext/commonmarker/houdini_html_u.c delete mode 100644 ext/commonmarker/html.c delete mode 100644 ext/commonmarker/html.h delete mode 100644 ext/commonmarker/inlines.c delete mode 100644 ext/commonmarker/inlines.h delete mode 100644 ext/commonmarker/iterator.c delete mode 100644 ext/commonmarker/iterator.h delete mode 100644 ext/commonmarker/latex.c delete mode 100644 ext/commonmarker/linked_list.c delete mode 100644 ext/commonmarker/man.c delete mode 100644 ext/commonmarker/map.c delete mode 100644 ext/commonmarker/map.h delete mode 100644 ext/commonmarker/node.c delete mode 100644 ext/commonmarker/node.h delete mode 100644 ext/commonmarker/parser.h delete mode 100644 ext/commonmarker/plaintext.c delete mode 100644 ext/commonmarker/plugin.c delete mode 100644 ext/commonmarker/plugin.h delete mode 100644 ext/commonmarker/references.c delete mode 100644 ext/commonmarker/references.h delete mode 100644 ext/commonmarker/registry.c delete mode 100644 ext/commonmarker/registry.h delete mode 100644 ext/commonmarker/render.c delete mode 100644 ext/commonmarker/render.h delete mode 100644 ext/commonmarker/scanners.c delete mode 100644 ext/commonmarker/scanners.h delete mode 100644 ext/commonmarker/scanners.re delete mode 100644 ext/commonmarker/strikethrough.c delete mode 100644 ext/commonmarker/strikethrough.h delete mode 100644 ext/commonmarker/syntax_extension.c delete mode 100644 ext/commonmarker/syntax_extension.h delete mode 100644 ext/commonmarker/table.c delete mode 100644 ext/commonmarker/table.h delete mode 100644 ext/commonmarker/tagfilter.c delete mode 100644 ext/commonmarker/tagfilter.h delete mode 100644 ext/commonmarker/tasklist.c delete mode 100644 ext/commonmarker/tasklist.h delete mode 100644 ext/commonmarker/utf8.c delete mode 100644 ext/commonmarker/utf8.h delete mode 100644 ext/commonmarker/xml.c delete mode 100644 lib/commonmarker/node.rb delete mode 100644 lib/commonmarker/node/inspect.rb delete mode 100644 lib/commonmarker/renderer/html_renderer.rb create mode 100644 rakelib/benchmark.rake create mode 100644 rakelib/compile.rake create mode 100644 rakelib/docs.rake create mode 100644 rakelib/format.rake create mode 100644 rakelib/test.rake create mode 100644 test/fixtures/upstream/smart_punct.txt create mode 100644 test/fixtures/upstream/spec.txt diff --git a/.gitignore b/.gitignore index 4e736633..2122c821 100644 --- a/.gitignore +++ b/.gitignore @@ -8,12 +8,13 @@ /InstalledFiles /pkg/ /spec/reports/ -/test/tmp/ /test/version_tmp/ -/tmp/ +tmp/ /vendor/gems /vendor/cache Gemfile.lock +*.log +ports/ ## Specific to RubyMotion: .dat* diff --git a/README.md b/README.md index 84fcd07b..0eeb2058 100644 --- a/README.md +++ b/README.md @@ -187,7 +187,7 @@ The available extensions are: ## Output formats -Like CMark, CommonMarker can generate output in several formats: HTML, XML, plaintext, and commonmark are currently supported. +Like CMark, CommonMarker can generate output in several formats: HTML, XML, plaintext, and CommonMark are currently supported. ### HTML diff --git a/Rakefile b/Rakefile index 4daed669..049a64fe 100644 --- a/Rakefile +++ b/Rakefile @@ -1,109 +1,8 @@ # frozen_string_literal: true -require "date" -require "rake/clean" -require "rake/extensiontask" -require "digest/md5" - -host_os = RbConfig::CONFIG["host_os"] -require "devkit" if host_os == "mingw32" - -task default: [:test] - # Gem Spec -gem_spec = Gem::Specification.load("commonmarker.gemspec") - -# Ruby Extension -Rake::ExtensionTask.new("commonmarker", gem_spec) do |ext| - ext.lib_dir = File.join("lib", "commonmarker") -end +require "bundler" +COMMONMARKER_SPEC = Bundler.load_gemspec("commonmarker.gemspec") # Packaging require "bundler/gem_tasks" - -# Testing -require "rake/testtask" - -Rake::TestTask.new("test:unit") do |t| - t.libs << "lib" - t.libs << "test" - t.pattern = "test/test_*.rb" - t.verbose = true - t.warning = false -end - -desc "Run unit tests" -task "test:unit" => :compile - -desc "Run unit and conformance tests" -task test: ["test:unit"] - -require "rubocop/rake_task" - -RuboCop::RakeTask.new(:rubocop) - -desc "Run benchmarks" -task :benchmark do - if ENV["FETCH_PROGIT"] - %x(rm -rf test/progit) - %x(git clone https://github.com/progit/progit.git test/progit) - langs = ["ar", "az", "be", "ca", "cs", "de", "en", "eo", "es", "es-ni", "fa", "fi", "fr", "hi", "hu", "id", "it", "ja", "ko", "mk", "nl", "no-nb", "pl", "pt-br", "ro", "ru", "sr", "th", "tr", "uk", "vi", "zh", "zh-tw"] - langs.each do |lang| - %x(cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md) - end - end - $LOAD_PATH.unshift("lib") - load "test/benchmark.rb" -end - -desc "Match C style of cmark" -task :format do - sh "clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h" -end - -# Documentation -require "rdoc/task" - -desc "Generate API documentation" -RDoc::Task.new do |rd| - rd.rdoc_dir = "docs" - rd.main = "README.md" - rd.rdoc_files.include("README.md", "lib/**/*.rb", "ext/commonmarker/commonmarker.c") - - rd.options << "--markup tomdoc" - rd.options << "--inline-source" - rd.options << "--line-numbers" - rd.options << "--all" - rd.options << "--fileboxes" -end - -desc "Generate the documentation and run a web server" -task serve: [:rdoc] do - require "webrick" - - puts "Navigate to http://localhost:3000 to see the docs" - - server = WEBrick::HTTPServer.new(Port: 3000) - server.mount("/", WEBrick::HTTPServlet::FileHandler, "docs") - trap("INT") { server.stop } - server.start -end - -desc "Generate and publish docs to gh-pages" -task publish: [:rdoc] do - require "tmpdir" - require "shellwords" - - Dir.mktmpdir do |tmp| - system "mv docs/* #{tmp}" - system "git checkout origin/gh-pages" - system "rm -rf *" - system "mv #{tmp}/* ." - message = Shellwords.escape("Site updated at #{Time.now.utc}") - system "git add ." - system "git commit -am #{message}" - system "git push origin gh-pages --force" - system "git checkout master" - system "echo yolo" - end -end diff --git a/commonmarker.gemspec b/commonmarker.gemspec index aacc543b..dba34d65 100644 --- a/commonmarker.gemspec +++ b/commonmarker.gemspec @@ -4,35 +4,35 @@ lib = File.expand_path("lib", __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require "commonmarker/version" -Gem::Specification.new do |s| - s.name = "commonmarker" - s.version = CommonMarker::VERSION - s.summary = "CommonMark parser and renderer. Written in C, wrapped in Ruby." - s.description = "A fast, safe, extensible parser for CommonMark. This wraps the official libcmark library." - s.authors = ["Garen Torikian", "Ashe Connor"] - s.homepage = "https://github.com/gjtorikian/commonmarker" - s.license = "MIT" +Gem::Specification.new do |spec| + spec.name = "commonmarker" + spec.version = Commonmarker::VERSION + spec.summary = "CommonMark parser and renderer. Written in Rust, wrapped in Ruby." + spec.description = "A fast, safe, extensible parser for CommonMark. This wraps the comrak Rust crate." + spec.authors = ["Garen Torikian", "Ashe Connor"] + spec.homepage = "https://github.com/gjtorikian/commonmarker" + spec.license = "MIT" - s.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec", "bin/commonmarker"] - s.files += Dir.glob("lib/**/*.rb") - s.files += Dir.glob("ext/commonmarker/*.*") - s.extensions = ["ext/commonmarker/extconf.rb"] + spec.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec", "bin/commonmarker"] + spec.files += Dir.glob("lib/**/*.rb") + spec.files += Dir.glob("ext/commonmarker/*.*") + spec.extensions = ["ext/commonmarker/extconf.rb"] - s.executables = ["commonmarker"] - s.require_paths = ["lib", "ext"] - s.required_ruby_version = [">= 2.7", "< 4.0"] + spec.executables = ["commonmarker"] + spec.require_paths = ["lib", "ext"] + spec.required_ruby_version = [">= 2.7", "< 4.0"] - s.metadata["rubygems_mfa_required"] = "true" + spec.metadata["rubygems_mfa_required"] = "true" - s.rdoc_options += ["-x", "ext/commonmarker/cmark/.*"] + spec.add_development_dependency("awesome_print") + spec.add_development_dependency("debug") if "#{RbConfig::CONFIG["MAJOR"]}.#{RbConfig::CONFIG["MINOR"]}".to_f >= 3.1 + spec.add_development_dependency("json", "~> 2.3") + spec.add_development_dependency("minitest", "~> 5.6") + spec.add_development_dependency("minitest-focus", "~> 1.1") + spec.add_development_dependency("rake") + spec.add_development_dependency("rake-compiler", "~> 0.9") + spec.add_development_dependency("rdoc", "~> 6.2") + spec.add_development_dependency("rubocop-standard") - s.add_development_dependency("awesome_print") - s.add_development_dependency("json", "~> 2.3") - s.add_development_dependency("minitest", "~> 5.6") - s.add_development_dependency("minitest-focus", "~> 1.1") - s.add_development_dependency("rake") - s.add_development_dependency("rake-compiler", "~> 0.9") - s.add_development_dependency("rdoc", "~> 6.2") - s.add_development_dependency("rubocop") - s.add_development_dependency("rubocop-standard") + spec.add_runtime_dependency("mini_portile2", "~> 2.8") # keep version in sync with extconf.rb end diff --git a/ext/commonmarker/arena.c b/ext/commonmarker/arena.c deleted file mode 100644 index 83a15255..00000000 --- a/ext/commonmarker/arena.c +++ /dev/null @@ -1,103 +0,0 @@ -#include -#include -#include -#include "cmark-gfm.h" -#include "cmark-gfm-extension_api.h" - -static struct arena_chunk { - size_t sz, used; - uint8_t push_point; - void *ptr; - struct arena_chunk *prev; -} *A = NULL; - -static struct arena_chunk *alloc_arena_chunk(size_t sz, struct arena_chunk *prev) { - struct arena_chunk *c = (struct arena_chunk *)calloc(1, sizeof(*c)); - if (!c) - abort(); - c->sz = sz; - c->ptr = calloc(1, sz); - if (!c->ptr) - abort(); - c->prev = prev; - return c; -} - -void cmark_arena_push(void) { - if (!A) - return; - A->push_point = 1; - A = alloc_arena_chunk(10240, A); -} - -int cmark_arena_pop(void) { - if (!A) - return 0; - while (A && !A->push_point) { - free(A->ptr); - struct arena_chunk *n = A->prev; - free(A); - A = n; - } - if (A) - A->push_point = 0; - return 1; -} - -static void init_arena(void) { - A = alloc_arena_chunk(4 * 1048576, NULL); -} - -void cmark_arena_reset(void) { - while (A) { - free(A->ptr); - struct arena_chunk *n = A->prev; - free(A); - A = n; - } -} - -static void *arena_calloc(size_t nmem, size_t size) { - if (!A) - init_arena(); - - size_t sz = nmem * size + sizeof(size_t); - - // Round allocation sizes to largest integer size to - // ensure returned memory is correctly aligned - const size_t align = sizeof(size_t) - 1; - sz = (sz + align) & ~align; - - if (sz > A->sz) { - A->prev = alloc_arena_chunk(sz, A->prev); - return (uint8_t *) A->prev->ptr + sizeof(size_t); - } - if (sz > A->sz - A->used) { - A = alloc_arena_chunk(A->sz + A->sz / 2, A); - } - void *ptr = (uint8_t *) A->ptr + A->used; - A->used += sz; - *((size_t *) ptr) = sz - sizeof(size_t); - return (uint8_t *) ptr + sizeof(size_t); -} - -static void *arena_realloc(void *ptr, size_t size) { - if (!A) - init_arena(); - - void *new_ptr = arena_calloc(1, size); - if (ptr) - memcpy(new_ptr, ptr, ((size_t *) ptr)[-1]); - return new_ptr; -} - -static void arena_free(void *ptr) { - (void) ptr; - /* no-op */ -} - -cmark_mem CMARK_ARENA_MEM_ALLOCATOR = {arena_calloc, arena_realloc, arena_free}; - -cmark_mem *cmark_get_arena_mem_allocator() { - return &CMARK_ARENA_MEM_ALLOCATOR; -} diff --git a/ext/commonmarker/autolink.c b/ext/commonmarker/autolink.c deleted file mode 100644 index 41564ee4..00000000 --- a/ext/commonmarker/autolink.c +++ /dev/null @@ -1,425 +0,0 @@ -#include "autolink.h" -#include -#include -#include - -#if defined(_WIN32) -#define strncasecmp _strnicmp -#else -#include -#endif - -static int is_valid_hostchar(const uint8_t *link, size_t link_len) { - int32_t ch; - int r = cmark_utf8proc_iterate(link, (bufsize_t)link_len, &ch); - if (r < 0) - return 0; - return !cmark_utf8proc_is_space(ch) && !cmark_utf8proc_is_punctuation(ch); -} - -static int sd_autolink_issafe(const uint8_t *link, size_t link_len) { - static const size_t valid_uris_count = 3; - static const char *valid_uris[] = {"http://", "https://", "ftp://"}; - - size_t i; - - for (i = 0; i < valid_uris_count; ++i) { - size_t len = strlen(valid_uris[i]); - - if (link_len > len && strncasecmp((char *)link, valid_uris[i], len) == 0 && - is_valid_hostchar(link + len, link_len - len)) - return 1; - } - - return 0; -} - -static size_t autolink_delim(uint8_t *data, size_t link_end) { - uint8_t cclose, copen; - size_t i; - - for (i = 0; i < link_end; ++i) - if (data[i] == '<') { - link_end = i; - break; - } - - while (link_end > 0) { - cclose = data[link_end - 1]; - - switch (cclose) { - case ')': - copen = '('; - break; - default: - copen = 0; - } - - if (strchr("?!.,:*_~'\"", data[link_end - 1]) != NULL) - link_end--; - - else if (data[link_end - 1] == ';') { - size_t new_end = link_end - 2; - - while (new_end > 0 && cmark_isalpha(data[new_end])) - new_end--; - - if (new_end < link_end - 2 && data[new_end] == '&') - link_end = new_end; - else - link_end--; - } else if (copen != 0) { - size_t closing = 0; - size_t opening = 0; - i = 0; - - /* Allow any number of matching brackets (as recognised in copen/cclose) - * at the end of the URL. If there is a greater number of closing - * brackets than opening ones, we remove one character from the end of - * the link. - * - * Examples (input text => output linked portion): - * - * http://www.pokemon.com/Pikachu_(Electric) - * => http://www.pokemon.com/Pikachu_(Electric) - * - * http://www.pokemon.com/Pikachu_((Electric) - * => http://www.pokemon.com/Pikachu_((Electric) - * - * http://www.pokemon.com/Pikachu_(Electric)) - * => http://www.pokemon.com/Pikachu_(Electric) - * - * http://www.pokemon.com/Pikachu_((Electric)) - * => http://www.pokemon.com/Pikachu_((Electric)) - */ - - while (i < link_end) { - if (data[i] == copen) - opening++; - else if (data[i] == cclose) - closing++; - - i++; - } - - if (closing <= opening) - break; - - link_end--; - } else - break; - } - - return link_end; -} - -static size_t check_domain(uint8_t *data, size_t size, int allow_short) { - size_t i, np = 0, uscore1 = 0, uscore2 = 0; - - for (i = 1; i < size - 1; i++) { - if (data[i] == '_') - uscore2++; - else if (data[i] == '.') { - uscore1 = uscore2; - uscore2 = 0; - np++; - } else if (!is_valid_hostchar(data + i, size - i) && data[i] != '-') - break; - } - - if (uscore1 > 0 || uscore2 > 0) - return 0; - - if (allow_short) { - /* We don't need a valid domain in the strict sense (with - * least one dot; so just make sure it's composed of valid - * domain characters and return the length of the the valid - * sequence. */ - return i; - } else { - /* a valid domain needs to have at least a dot. - * that's as far as we get */ - return np ? i : 0; - } -} - -static cmark_node *www_match(cmark_parser *parser, cmark_node *parent, - cmark_inline_parser *inline_parser) { - cmark_chunk *chunk = cmark_inline_parser_get_chunk(inline_parser); - size_t max_rewind = cmark_inline_parser_get_offset(inline_parser); - uint8_t *data = chunk->data + max_rewind; - size_t size = chunk->len - max_rewind; - int start = cmark_inline_parser_get_column(inline_parser); - - size_t link_end; - - if (max_rewind > 0 && strchr("*_~(", data[-1]) == NULL && - !cmark_isspace(data[-1])) - return 0; - - if (size < 4 || memcmp(data, "www.", strlen("www.")) != 0) - return 0; - - link_end = check_domain(data, size, 0); - - if (link_end == 0) - return NULL; - - while (link_end < size && !cmark_isspace(data[link_end])) - link_end++; - - link_end = autolink_delim(data, link_end); - - if (link_end == 0) - return NULL; - - cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end)); - - cmark_node *node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem); - - cmark_strbuf buf; - cmark_strbuf_init(parser->mem, &buf, 10); - cmark_strbuf_puts(&buf, "http://"); - cmark_strbuf_put(&buf, data, (bufsize_t)link_end); - node->as.link.url = cmark_chunk_buf_detach(&buf); - - cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem); - text->as.literal = - cmark_chunk_dup(chunk, (bufsize_t)max_rewind, (bufsize_t)link_end); - cmark_node_append_child(node, text); - - node->start_line = text->start_line = - node->end_line = text->end_line = - cmark_inline_parser_get_line(inline_parser); - - node->start_column = text->start_column = start - 1; - node->end_column = text->end_column = cmark_inline_parser_get_column(inline_parser) - 1; - - return node; -} - -static cmark_node *url_match(cmark_parser *parser, cmark_node *parent, - cmark_inline_parser *inline_parser) { - size_t link_end, domain_len; - int rewind = 0; - - cmark_chunk *chunk = cmark_inline_parser_get_chunk(inline_parser); - int max_rewind = cmark_inline_parser_get_offset(inline_parser); - uint8_t *data = chunk->data + max_rewind; - size_t size = chunk->len - max_rewind; - - if (size < 4 || data[1] != '/' || data[2] != '/') - return 0; - - while (rewind < max_rewind && cmark_isalpha(data[-rewind - 1])) - rewind++; - - if (!sd_autolink_issafe(data - rewind, size + rewind)) - return 0; - - link_end = strlen("://"); - - domain_len = check_domain(data + link_end, size - link_end, 1); - - if (domain_len == 0) - return 0; - - link_end += domain_len; - while (link_end < size && !cmark_isspace(data[link_end])) - link_end++; - - link_end = autolink_delim(data, link_end); - - if (link_end == 0) - return NULL; - - cmark_inline_parser_set_offset(inline_parser, (int)(max_rewind + link_end)); - cmark_node_unput(parent, rewind); - - cmark_node *node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem); - - cmark_chunk url = cmark_chunk_dup(chunk, max_rewind - rewind, - (bufsize_t)(link_end + rewind)); - node->as.link.url = url; - - cmark_node *text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem); - text->as.literal = url; - cmark_node_append_child(node, text); - - return node; -} - -static cmark_node *match(cmark_syntax_extension *ext, cmark_parser *parser, - cmark_node *parent, unsigned char c, - cmark_inline_parser *inline_parser) { - if (cmark_inline_parser_in_bracket(inline_parser, false) || - cmark_inline_parser_in_bracket(inline_parser, true)) - return NULL; - - if (c == ':') - return url_match(parser, parent, inline_parser); - - if (c == 'w') - return www_match(parser, parent, inline_parser); - - return NULL; - - // note that we could end up re-consuming something already a - // part of an inline, because we don't track when the last - // inline was finished in inlines.c. -} - -static void postprocess_text(cmark_parser *parser, cmark_node *text, int offset, int depth) { - // postprocess_text can recurse very deeply if there is a very long line of - // '@' only. Stop at a reasonable depth to ensure it cannot crash. - if (depth > 1000) return; - - size_t link_end; - uint8_t *data = text->as.literal.data, - *at; - size_t size = text->as.literal.len; - int rewind, max_rewind, - nb = 0, np = 0, ns = 0; - - if (offset < 0 || (size_t)offset >= size) - return; - - data += offset; - size -= offset; - - at = (uint8_t *)memchr(data, '@', size); - if (!at) - return; - - max_rewind = (int)(at - data); - data += max_rewind; - size -= max_rewind; - - for (rewind = 0; rewind < max_rewind; ++rewind) { - uint8_t c = data[-rewind - 1]; - - if (cmark_isalnum(c)) - continue; - - if (strchr(".+-_", c) != NULL) - continue; - - if (c == '/') - ns++; - - break; - } - - if (rewind == 0 || ns > 0) { - postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1); - return; - } - - for (link_end = 0; link_end < size; ++link_end) { - uint8_t c = data[link_end]; - - if (cmark_isalnum(c)) - continue; - - if (c == '@') - nb++; - else if (c == '.' && link_end < size - 1 && cmark_isalnum(data[link_end + 1])) - np++; - else if (c != '-' && c != '_') - break; - } - - if (link_end < 2 || nb != 1 || np == 0 || - (!cmark_isalpha(data[link_end - 1]) && data[link_end - 1] != '.')) { - postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1); - return; - } - - link_end = autolink_delim(data, link_end); - - if (link_end == 0) { - postprocess_text(parser, text, max_rewind + 1 + offset, depth + 1); - return; - } - - cmark_chunk_to_cstr(parser->mem, &text->as.literal); - - cmark_node *link_node = cmark_node_new_with_mem(CMARK_NODE_LINK, parser->mem); - cmark_strbuf buf; - cmark_strbuf_init(parser->mem, &buf, 10); - cmark_strbuf_puts(&buf, "mailto:"); - cmark_strbuf_put(&buf, data - rewind, (bufsize_t)(link_end + rewind)); - link_node->as.link.url = cmark_chunk_buf_detach(&buf); - - cmark_node *link_text = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem); - cmark_chunk email = cmark_chunk_dup( - &text->as.literal, - offset + max_rewind - rewind, - (bufsize_t)(link_end + rewind)); - cmark_chunk_to_cstr(parser->mem, &email); - link_text->as.literal = email; - cmark_node_append_child(link_node, link_text); - - cmark_node_insert_after(text, link_node); - - cmark_node *post = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem); - post->as.literal = cmark_chunk_dup(&text->as.literal, - (bufsize_t)(offset + max_rewind + link_end), - (bufsize_t)(size - link_end)); - cmark_chunk_to_cstr(parser->mem, &post->as.literal); - - cmark_node_insert_after(link_node, post); - - text->as.literal.len = offset + max_rewind - rewind; - text->as.literal.data[text->as.literal.len] = 0; - - postprocess_text(parser, post, 0, depth + 1); -} - -static cmark_node *postprocess(cmark_syntax_extension *ext, cmark_parser *parser, cmark_node *root) { - cmark_iter *iter; - cmark_event_type ev; - cmark_node *node; - bool in_link = false; - - cmark_consolidate_text_nodes(root); - iter = cmark_iter_new(root); - - while ((ev = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - node = cmark_iter_get_node(iter); - if (in_link) { - if (ev == CMARK_EVENT_EXIT && node->type == CMARK_NODE_LINK) { - in_link = false; - } - continue; - } - - if (ev == CMARK_EVENT_ENTER && node->type == CMARK_NODE_LINK) { - in_link = true; - continue; - } - - if (ev == CMARK_EVENT_ENTER && node->type == CMARK_NODE_TEXT) { - postprocess_text(parser, node, 0, /*depth*/0); - } - } - - cmark_iter_free(iter); - - return root; -} - -cmark_syntax_extension *create_autolink_extension(void) { - cmark_syntax_extension *ext = cmark_syntax_extension_new("autolink"); - cmark_llist *special_chars = NULL; - - cmark_syntax_extension_set_match_inline_func(ext, match); - cmark_syntax_extension_set_postprocess_func(ext, postprocess); - - cmark_mem *mem = cmark_get_default_mem_allocator(); - special_chars = cmark_llist_append(mem, special_chars, (void *)':'); - special_chars = cmark_llist_append(mem, special_chars, (void *)'w'); - cmark_syntax_extension_set_special_inline_chars(ext, special_chars); - - return ext; -} diff --git a/ext/commonmarker/autolink.h b/ext/commonmarker/autolink.h deleted file mode 100644 index 4e179379..00000000 --- a/ext/commonmarker/autolink.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CMARK_GFM_AUTOLINK_H -#define CMARK_GFM_AUTOLINK_H - -#include "cmark-gfm-core-extensions.h" - -cmark_syntax_extension *create_autolink_extension(void); - -#endif diff --git a/ext/commonmarker/blocks.c b/ext/commonmarker/blocks.c deleted file mode 100644 index 812713ed..00000000 --- a/ext/commonmarker/blocks.c +++ /dev/null @@ -1,1596 +0,0 @@ -/** - * Block parsing implementation. - * - * For a high-level overview of the block parsing process, - * see http://spec.commonmark.org/0.24/#phase-1-block-structure - */ - -#include -#include -#include - -#include "cmark_ctype.h" -#include "syntax_extension.h" -#include "config.h" -#include "parser.h" -#include "cmark-gfm.h" -#include "node.h" -#include "references.h" -#include "utf8.h" -#include "scanners.h" -#include "inlines.h" -#include "houdini.h" -#include "buffer.h" -#include "footnotes.h" - -#define CODE_INDENT 4 -#define TAB_STOP 4 - -#ifndef MIN -#define MIN(x, y) ((x < y) ? x : y) -#endif - -#define peek_at(i, n) (i)->data[n] - -static bool S_last_line_blank(const cmark_node *node) { - return (node->flags & CMARK_NODE__LAST_LINE_BLANK) != 0; -} - -static bool S_last_line_checked(const cmark_node *node) { - return (node->flags & CMARK_NODE__LAST_LINE_CHECKED) != 0; -} - -static CMARK_INLINE cmark_node_type S_type(const cmark_node *node) { - return (cmark_node_type)node->type; -} - -static void S_set_last_line_blank(cmark_node *node, bool is_blank) { - if (is_blank) - node->flags |= CMARK_NODE__LAST_LINE_BLANK; - else - node->flags &= ~CMARK_NODE__LAST_LINE_BLANK; -} - -static void S_set_last_line_checked(cmark_node *node) { - node->flags |= CMARK_NODE__LAST_LINE_CHECKED; -} - -static CMARK_INLINE bool S_is_line_end_char(char c) { - return (c == '\n' || c == '\r'); -} - -static CMARK_INLINE bool S_is_space_or_tab(char c) { - return (c == ' ' || c == '\t'); -} - -static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer, - size_t len, bool eof); - -static void S_process_line(cmark_parser *parser, const unsigned char *buffer, - bufsize_t bytes); - -static cmark_node *make_block(cmark_mem *mem, cmark_node_type tag, - int start_line, int start_column) { - cmark_node *e; - - e = (cmark_node *)mem->calloc(1, sizeof(*e)); - cmark_strbuf_init(mem, &e->content, 32); - e->type = (uint16_t)tag; - e->flags = CMARK_NODE__OPEN; - e->start_line = start_line; - e->start_column = start_column; - e->end_line = start_line; - - return e; -} - -// Create a root document node. -static cmark_node *make_document(cmark_mem *mem) { - cmark_node *e = make_block(mem, CMARK_NODE_DOCUMENT, 1, 1); - return e; -} - -int cmark_parser_attach_syntax_extension(cmark_parser *parser, - cmark_syntax_extension *extension) { - parser->syntax_extensions = cmark_llist_append(parser->mem, parser->syntax_extensions, extension); - if (extension->match_inline || extension->insert_inline_from_delim) { - parser->inline_syntax_extensions = cmark_llist_append( - parser->mem, parser->inline_syntax_extensions, extension); - } - - return 1; -} - -static void cmark_parser_dispose(cmark_parser *parser) { - if (parser->root) - cmark_node_free(parser->root); - - if (parser->refmap) - cmark_map_free(parser->refmap); -} - -static void cmark_parser_reset(cmark_parser *parser) { - cmark_llist *saved_exts = parser->syntax_extensions; - cmark_llist *saved_inline_exts = parser->inline_syntax_extensions; - int saved_options = parser->options; - cmark_mem *saved_mem = parser->mem; - - cmark_parser_dispose(parser); - - memset(parser, 0, sizeof(cmark_parser)); - parser->mem = saved_mem; - - cmark_strbuf_init(parser->mem, &parser->curline, 256); - cmark_strbuf_init(parser->mem, &parser->linebuf, 0); - - cmark_node *document = make_document(parser->mem); - - parser->refmap = cmark_reference_map_new(parser->mem); - parser->root = document; - parser->current = document; - - parser->syntax_extensions = saved_exts; - parser->inline_syntax_extensions = saved_inline_exts; - parser->options = saved_options; -} - -cmark_parser *cmark_parser_new_with_mem(int options, cmark_mem *mem) { - cmark_parser *parser = (cmark_parser *)mem->calloc(1, sizeof(cmark_parser)); - parser->mem = mem; - parser->options = options; - cmark_parser_reset(parser); - return parser; -} - -cmark_parser *cmark_parser_new(int options) { - extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR; - return cmark_parser_new_with_mem(options, &CMARK_DEFAULT_MEM_ALLOCATOR); -} - -void cmark_parser_free(cmark_parser *parser) { - cmark_mem *mem = parser->mem; - cmark_parser_dispose(parser); - cmark_strbuf_free(&parser->curline); - cmark_strbuf_free(&parser->linebuf); - cmark_llist_free(parser->mem, parser->syntax_extensions); - cmark_llist_free(parser->mem, parser->inline_syntax_extensions); - mem->free(parser); -} - -static cmark_node *finalize(cmark_parser *parser, cmark_node *b); - -// Returns true if line has only space characters, else false. -static bool is_blank(cmark_strbuf *s, bufsize_t offset) { - while (offset < s->size) { - switch (s->ptr[offset]) { - case '\r': - case '\n': - return true; - case ' ': - offset++; - break; - case '\t': - offset++; - break; - default: - return false; - } - } - - return true; -} - -static CMARK_INLINE bool accepts_lines(cmark_node_type block_type) { - return (block_type == CMARK_NODE_PARAGRAPH || - block_type == CMARK_NODE_HEADING || - block_type == CMARK_NODE_CODE_BLOCK); -} - -static CMARK_INLINE bool contains_inlines(cmark_node *node) { - if (node->extension && node->extension->contains_inlines_func) { - return node->extension->contains_inlines_func(node->extension, node) != 0; - } - - return (node->type == CMARK_NODE_PARAGRAPH || - node->type == CMARK_NODE_HEADING); -} - -static void add_line(cmark_node *node, cmark_chunk *ch, cmark_parser *parser) { - int chars_to_tab; - int i; - assert(node->flags & CMARK_NODE__OPEN); - if (parser->partially_consumed_tab) { - parser->offset += 1; // skip over tab - // add space characters: - chars_to_tab = TAB_STOP - (parser->column % TAB_STOP); - for (i = 0; i < chars_to_tab; i++) { - cmark_strbuf_putc(&node->content, ' '); - } - } - cmark_strbuf_put(&node->content, ch->data + parser->offset, - ch->len - parser->offset); -} - -static void remove_trailing_blank_lines(cmark_strbuf *ln) { - bufsize_t i; - unsigned char c; - - for (i = ln->size - 1; i >= 0; --i) { - c = ln->ptr[i]; - - if (c != ' ' && c != '\t' && !S_is_line_end_char(c)) - break; - } - - if (i < 0) { - cmark_strbuf_clear(ln); - return; - } - - for (; i < ln->size; ++i) { - c = ln->ptr[i]; - - if (!S_is_line_end_char(c)) - continue; - - cmark_strbuf_truncate(ln, i); - break; - } -} - -// Check to see if a node ends with a blank line, descending -// if needed into lists and sublists. -static bool S_ends_with_blank_line(cmark_node *node) { - if (S_last_line_checked(node)) { - return(S_last_line_blank(node)); - } else if ((S_type(node) == CMARK_NODE_LIST || - S_type(node) == CMARK_NODE_ITEM) && node->last_child) { - S_set_last_line_checked(node); - return(S_ends_with_blank_line(node->last_child)); - } else { - S_set_last_line_checked(node); - return (S_last_line_blank(node)); - } -} - -// returns true if content remains after link defs are resolved. -static bool resolve_reference_link_definitions( - cmark_parser *parser, - cmark_node *b) { - bufsize_t pos; - cmark_strbuf *node_content = &b->content; - cmark_chunk chunk = {node_content->ptr, node_content->size, 0}; - while (chunk.len && chunk.data[0] == '[' && - (pos = cmark_parse_reference_inline(parser->mem, &chunk, - parser->refmap))) { - - chunk.data += pos; - chunk.len -= pos; - } - cmark_strbuf_drop(node_content, (node_content->size - chunk.len)); - return !is_blank(&b->content, 0); -} - -static cmark_node *finalize(cmark_parser *parser, cmark_node *b) { - bufsize_t pos; - cmark_node *item; - cmark_node *subitem; - cmark_node *parent; - bool has_content; - - parent = b->parent; - assert(b->flags & - CMARK_NODE__OPEN); // shouldn't call finalize on closed blocks - b->flags &= ~CMARK_NODE__OPEN; - - if (parser->curline.size == 0) { - // end of input - line number has not been incremented - b->end_line = parser->line_number; - b->end_column = parser->last_line_length; - } else if (S_type(b) == CMARK_NODE_DOCUMENT || - (S_type(b) == CMARK_NODE_CODE_BLOCK && b->as.code.fenced) || - (S_type(b) == CMARK_NODE_HEADING && b->as.heading.setext)) { - b->end_line = parser->line_number; - b->end_column = parser->curline.size; - if (b->end_column && parser->curline.ptr[b->end_column - 1] == '\n') - b->end_column -= 1; - if (b->end_column && parser->curline.ptr[b->end_column - 1] == '\r') - b->end_column -= 1; - } else { - b->end_line = parser->line_number - 1; - b->end_column = parser->last_line_length; - } - - cmark_strbuf *node_content = &b->content; - - switch (S_type(b)) { - case CMARK_NODE_PARAGRAPH: - { - has_content = resolve_reference_link_definitions(parser, b); - if (!has_content) { - // remove blank node (former reference def) - cmark_node_free(b); - } - break; - } - - case CMARK_NODE_CODE_BLOCK: - if (!b->as.code.fenced) { // indented code - remove_trailing_blank_lines(node_content); - cmark_strbuf_putc(node_content, '\n'); - } else { - // first line of contents becomes info - for (pos = 0; pos < node_content->size; ++pos) { - if (S_is_line_end_char(node_content->ptr[pos])) - break; - } - assert(pos < node_content->size); - - cmark_strbuf tmp = CMARK_BUF_INIT(parser->mem); - houdini_unescape_html_f(&tmp, node_content->ptr, pos); - cmark_strbuf_trim(&tmp); - cmark_strbuf_unescape(&tmp); - b->as.code.info = cmark_chunk_buf_detach(&tmp); - - if (node_content->ptr[pos] == '\r') - pos += 1; - if (node_content->ptr[pos] == '\n') - pos += 1; - cmark_strbuf_drop(node_content, pos); - } - b->as.code.literal = cmark_chunk_buf_detach(node_content); - break; - - case CMARK_NODE_HTML_BLOCK: - b->as.literal = cmark_chunk_buf_detach(node_content); - break; - - case CMARK_NODE_LIST: // determine tight/loose status - b->as.list.tight = true; // tight by default - item = b->first_child; - - while (item) { - // check for non-final non-empty list item ending with blank line: - if (S_last_line_blank(item) && item->next) { - b->as.list.tight = false; - break; - } - // recurse into children of list item, to see if there are - // spaces between them: - subitem = item->first_child; - while (subitem) { - if ((item->next || subitem->next) && - S_ends_with_blank_line(subitem)) { - b->as.list.tight = false; - break; - } - subitem = subitem->next; - } - if (!(b->as.list.tight)) { - break; - } - item = item->next; - } - - break; - - default: - break; - } - - return parent; -} - -// Add a node as child of another. Return pointer to child. -static cmark_node *add_child(cmark_parser *parser, cmark_node *parent, - cmark_node_type block_type, int start_column) { - assert(parent); - - // if 'parent' isn't the kind of node that can accept this child, - // then back up til we hit a node that can. - while (!cmark_node_can_contain_type(parent, block_type)) { - parent = finalize(parser, parent); - } - - cmark_node *child = - make_block(parser->mem, block_type, parser->line_number, start_column); - child->parent = parent; - - if (parent->last_child) { - parent->last_child->next = child; - child->prev = parent->last_child; - } else { - parent->first_child = child; - child->prev = NULL; - } - parent->last_child = child; - return child; -} - -void cmark_manage_extensions_special_characters(cmark_parser *parser, int add) { - cmark_llist *tmp_ext; - - for (tmp_ext = parser->inline_syntax_extensions; tmp_ext; tmp_ext=tmp_ext->next) { - cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp_ext->data; - cmark_llist *tmp_char; - for (tmp_char = ext->special_inline_chars; tmp_char; tmp_char=tmp_char->next) { - unsigned char c = (unsigned char)(size_t)tmp_char->data; - if (add) - cmark_inlines_add_special_character(c, ext->emphasis); - else - cmark_inlines_remove_special_character(c, ext->emphasis); - } - } -} - -// Walk through node and all children, recursively, parsing -// string content into inline content where appropriate. -static void process_inlines(cmark_parser *parser, - cmark_map *refmap, int options) { - cmark_iter *iter = cmark_iter_new(parser->root); - cmark_node *cur; - cmark_event_type ev_type; - - cmark_manage_extensions_special_characters(parser, true); - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - if (ev_type == CMARK_EVENT_ENTER) { - if (contains_inlines(cur)) { - cmark_parse_inlines(parser, cur, refmap, options); - } - } - } - - cmark_manage_extensions_special_characters(parser, false); - - cmark_iter_free(iter); -} - -static int sort_footnote_by_ix(const void *_a, const void *_b) { - cmark_footnote *a = *(cmark_footnote **)_a; - cmark_footnote *b = *(cmark_footnote **)_b; - return (int)a->ix - (int)b->ix; -} - -static void process_footnotes(cmark_parser *parser) { - // * Collect definitions in a map. - // * Iterate the references in the document in order, assigning indices to - // definitions in the order they're seen. - // * Write out the footnotes at the bottom of the document in index order. - - cmark_map *map = cmark_footnote_map_new(parser->mem); - - cmark_iter *iter = cmark_iter_new(parser->root); - cmark_node *cur; - cmark_event_type ev_type; - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - if (ev_type == CMARK_EVENT_EXIT && cur->type == CMARK_NODE_FOOTNOTE_DEFINITION) { - cmark_footnote_create(map, cur); - } - } - - cmark_iter_free(iter); - iter = cmark_iter_new(parser->root); - unsigned int ix = 0; - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - if (ev_type == CMARK_EVENT_EXIT && cur->type == CMARK_NODE_FOOTNOTE_REFERENCE) { - cmark_footnote *footnote = (cmark_footnote *)cmark_map_lookup(map, &cur->as.literal); - if (footnote) { - if (!footnote->ix) - footnote->ix = ++ix; - - // store a reference to this footnote reference's footnote definition - // this is used by renderers when generating label ids - cur->parent_footnote_def = footnote->node; - - // keep track of a) count of how many times this footnote def has been - // referenced, and b) which reference index this footnote ref is at. - // this is used by renderers when generating links and backreferences. - cur->footnote.ref_ix = ++footnote->node->footnote.def_count; - - char n[32]; - snprintf(n, sizeof(n), "%d", footnote->ix); - cmark_chunk_free(parser->mem, &cur->as.literal); - cmark_strbuf buf = CMARK_BUF_INIT(parser->mem); - cmark_strbuf_puts(&buf, n); - - cur->as.literal = cmark_chunk_buf_detach(&buf); - } else { - cmark_node *text = (cmark_node *)parser->mem->calloc(1, sizeof(*text)); - cmark_strbuf_init(parser->mem, &text->content, 0); - text->type = (uint16_t) CMARK_NODE_TEXT; - - cmark_strbuf buf = CMARK_BUF_INIT(parser->mem); - cmark_strbuf_puts(&buf, "[^"); - cmark_strbuf_put(&buf, cur->as.literal.data, cur->as.literal.len); - cmark_strbuf_putc(&buf, ']'); - - text->as.literal = cmark_chunk_buf_detach(&buf); - cmark_node_insert_after(cur, text); - cmark_node_free(cur); - } - } - } - - cmark_iter_free(iter); - - if (map->sorted) { - qsort(map->sorted, map->size, sizeof(cmark_map_entry *), sort_footnote_by_ix); - for (unsigned int i = 0; i < map->size; ++i) { - cmark_footnote *footnote = (cmark_footnote *)map->sorted[i]; - if (!footnote->ix) { - cmark_node_unlink(footnote->node); - continue; - } - cmark_node_append_child(parser->root, footnote->node); - footnote->node = NULL; - } - } - - cmark_unlink_footnotes_map(map); - cmark_map_free(map); -} - -// Attempts to parse a list item marker (bullet or enumerated). -// On success, returns length of the marker, and populates -// data with the details. On failure, returns 0. -static bufsize_t parse_list_marker(cmark_mem *mem, cmark_chunk *input, - bufsize_t pos, bool interrupts_paragraph, - cmark_list **dataptr) { - unsigned char c; - bufsize_t startpos; - cmark_list *data; - bufsize_t i; - - startpos = pos; - c = peek_at(input, pos); - - if (c == '*' || c == '-' || c == '+') { - pos++; - if (!cmark_isspace(peek_at(input, pos))) { - return 0; - } - - if (interrupts_paragraph) { - i = pos; - // require non-blank content after list marker: - while (S_is_space_or_tab(peek_at(input, i))) { - i++; - } - if (peek_at(input, i) == '\n') { - return 0; - } - } - - data = (cmark_list *)mem->calloc(1, sizeof(*data)); - data->marker_offset = 0; // will be adjusted later - data->list_type = CMARK_BULLET_LIST; - data->bullet_char = c; - data->start = 0; - data->delimiter = CMARK_NO_DELIM; - data->tight = false; - } else if (cmark_isdigit(c)) { - int start = 0; - int digits = 0; - - do { - start = (10 * start) + (peek_at(input, pos) - '0'); - pos++; - digits++; - // We limit to 9 digits to avoid overflow, - // assuming max int is 2^31 - 1 - // This also seems to be the limit for 'start' in some browsers. - } while (digits < 9 && cmark_isdigit(peek_at(input, pos))); - - if (interrupts_paragraph && start != 1) { - return 0; - } - c = peek_at(input, pos); - if (c == '.' || c == ')') { - pos++; - if (!cmark_isspace(peek_at(input, pos))) { - return 0; - } - if (interrupts_paragraph) { - // require non-blank content after list marker: - i = pos; - while (S_is_space_or_tab(peek_at(input, i))) { - i++; - } - if (S_is_line_end_char(peek_at(input, i))) { - return 0; - } - } - - data = (cmark_list *)mem->calloc(1, sizeof(*data)); - data->marker_offset = 0; // will be adjusted later - data->list_type = CMARK_ORDERED_LIST; - data->bullet_char = 0; - data->start = start; - data->delimiter = (c == '.' ? CMARK_PERIOD_DELIM : CMARK_PAREN_DELIM); - data->tight = false; - } else { - return 0; - } - } else { - return 0; - } - - *dataptr = data; - return (pos - startpos); -} - -// Return 1 if list item belongs in list, else 0. -static int lists_match(cmark_list *list_data, cmark_list *item_data) { - return (list_data->list_type == item_data->list_type && - list_data->delimiter == item_data->delimiter && - // list_data->marker_offset == item_data.marker_offset && - list_data->bullet_char == item_data->bullet_char); -} - -static cmark_node *finalize_document(cmark_parser *parser) { - while (parser->current != parser->root) { - parser->current = finalize(parser, parser->current); - } - - finalize(parser, parser->root); - process_inlines(parser, parser->refmap, parser->options); - if (parser->options & CMARK_OPT_FOOTNOTES) - process_footnotes(parser); - - return parser->root; -} - -cmark_node *cmark_parse_file(FILE *f, int options) { - unsigned char buffer[4096]; - cmark_parser *parser = cmark_parser_new(options); - size_t bytes; - cmark_node *document; - - while ((bytes = fread(buffer, 1, sizeof(buffer), f)) > 0) { - bool eof = bytes < sizeof(buffer); - S_parser_feed(parser, buffer, bytes, eof); - if (eof) { - break; - } - } - - document = cmark_parser_finish(parser); - cmark_parser_free(parser); - return document; -} - -cmark_node *cmark_parse_document(const char *buffer, size_t len, int options) { - cmark_parser *parser = cmark_parser_new(options); - cmark_node *document; - - S_parser_feed(parser, (const unsigned char *)buffer, len, true); - - document = cmark_parser_finish(parser); - cmark_parser_free(parser); - return document; -} - -void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len) { - S_parser_feed(parser, (const unsigned char *)buffer, len, false); -} - -void cmark_parser_feed_reentrant(cmark_parser *parser, const char *buffer, size_t len) { - cmark_strbuf saved_linebuf; - - cmark_strbuf_init(parser->mem, &saved_linebuf, 0); - cmark_strbuf_puts(&saved_linebuf, cmark_strbuf_cstr(&parser->linebuf)); - cmark_strbuf_clear(&parser->linebuf); - - S_parser_feed(parser, (const unsigned char *)buffer, len, true); - - cmark_strbuf_sets(&parser->linebuf, cmark_strbuf_cstr(&saved_linebuf)); - cmark_strbuf_free(&saved_linebuf); -} - -static void S_parser_feed(cmark_parser *parser, const unsigned char *buffer, - size_t len, bool eof) { - const unsigned char *end = buffer + len; - static const uint8_t repl[] = {239, 191, 189}; - - if (parser->last_buffer_ended_with_cr && *buffer == '\n') { - // skip NL if last buffer ended with CR ; see #117 - buffer++; - } - parser->last_buffer_ended_with_cr = false; - while (buffer < end) { - const unsigned char *eol; - bufsize_t chunk_len; - bool process = false; - for (eol = buffer; eol < end; ++eol) { - if (S_is_line_end_char(*eol)) { - process = true; - break; - } - if (*eol == '\0' && eol < end) { - break; - } - } - if (eol >= end && eof) { - process = true; - } - - chunk_len = (bufsize_t)(eol - buffer); - if (process) { - if (parser->linebuf.size > 0) { - cmark_strbuf_put(&parser->linebuf, buffer, chunk_len); - S_process_line(parser, parser->linebuf.ptr, parser->linebuf.size); - cmark_strbuf_clear(&parser->linebuf); - } else { - S_process_line(parser, buffer, chunk_len); - } - } else { - if (eol < end && *eol == '\0') { - // omit NULL byte - cmark_strbuf_put(&parser->linebuf, buffer, chunk_len); - // add replacement character - cmark_strbuf_put(&parser->linebuf, repl, 3); - } else { - cmark_strbuf_put(&parser->linebuf, buffer, chunk_len); - } - } - - buffer += chunk_len; - if (buffer < end) { - if (*buffer == '\0') { - // skip over NULL - buffer++; - } else { - // skip over line ending characters - if (*buffer == '\r') { - buffer++; - if (buffer == end) - parser->last_buffer_ended_with_cr = true; - } - if (buffer < end && *buffer == '\n') - buffer++; - } - } - } -} - -static void chop_trailing_hashtags(cmark_chunk *ch) { - bufsize_t n, orig_n; - - cmark_chunk_rtrim(ch); - orig_n = n = ch->len - 1; - - // if string ends in space followed by #s, remove these: - while (n >= 0 && peek_at(ch, n) == '#') - n--; - - // Check for a space before the final #s: - if (n != orig_n && n >= 0 && S_is_space_or_tab(peek_at(ch, n))) { - ch->len = n; - cmark_chunk_rtrim(ch); - } -} - -// Check for thematic break. On failure, return 0 and update -// thematic_break_kill_pos with the index at which the -// parse fails. On success, return length of match. -// "...three or more hyphens, asterisks, -// or underscores on a line by themselves. If you wish, you may use -// spaces between the hyphens or asterisks." -static int S_scan_thematic_break(cmark_parser *parser, cmark_chunk *input, - bufsize_t offset) { - bufsize_t i; - char c; - char nextc = '\0'; - int count; - i = offset; - c = peek_at(input, i); - if (!(c == '*' || c == '_' || c == '-')) { - parser->thematic_break_kill_pos = i; - return 0; - } - count = 1; - while ((nextc = peek_at(input, ++i))) { - if (nextc == c) { - count++; - } else if (nextc != ' ' && nextc != '\t') { - break; - } - } - if (count >= 3 && (nextc == '\r' || nextc == '\n')) { - return (i - offset) + 1; - } else { - parser->thematic_break_kill_pos = i; - return 0; - } -} - -// Find first nonspace character from current offset, setting -// parser->first_nonspace, parser->first_nonspace_column, -// parser->indent, and parser->blank. Does not advance parser->offset. -static void S_find_first_nonspace(cmark_parser *parser, cmark_chunk *input) { - char c; - int chars_to_tab = TAB_STOP - (parser->column % TAB_STOP); - - if (parser->first_nonspace <= parser->offset) { - parser->first_nonspace = parser->offset; - parser->first_nonspace_column = parser->column; - while ((c = peek_at(input, parser->first_nonspace))) { - if (c == ' ') { - parser->first_nonspace += 1; - parser->first_nonspace_column += 1; - chars_to_tab = chars_to_tab - 1; - if (chars_to_tab == 0) { - chars_to_tab = TAB_STOP; - } - } else if (c == '\t') { - parser->first_nonspace += 1; - parser->first_nonspace_column += chars_to_tab; - chars_to_tab = TAB_STOP; - } else { - break; - } - } - } - - parser->indent = parser->first_nonspace_column - parser->column; - parser->blank = S_is_line_end_char(peek_at(input, parser->first_nonspace)); -} - -// Advance parser->offset and parser->column. parser->offset is the -// byte position in input; parser->column is a virtual column number -// that takes into account tabs. (Multibyte characters are not taken -// into account, because the Markdown line prefixes we are interested in -// analyzing are entirely ASCII.) The count parameter indicates -// how far to advance the offset. If columns is true, then count -// indicates a number of columns; otherwise, a number of bytes. -// If advancing a certain number of columns partially consumes -// a tab character, parser->partially_consumed_tab is set to true. -static void S_advance_offset(cmark_parser *parser, cmark_chunk *input, - bufsize_t count, bool columns) { - char c; - int chars_to_tab; - int chars_to_advance; - while (count > 0 && (c = peek_at(input, parser->offset))) { - if (c == '\t') { - chars_to_tab = TAB_STOP - (parser->column % TAB_STOP); - if (columns) { - parser->partially_consumed_tab = chars_to_tab > count; - chars_to_advance = MIN(count, chars_to_tab); - parser->column += chars_to_advance; - parser->offset += (parser->partially_consumed_tab ? 0 : 1); - count -= chars_to_advance; - } else { - parser->partially_consumed_tab = false; - parser->column += chars_to_tab; - parser->offset += 1; - count -= 1; - } - } else { - parser->partially_consumed_tab = false; - parser->offset += 1; - parser->column += 1; // assume ascii; block starts are ascii - count -= 1; - } - } -} - -static bool S_last_child_is_open(cmark_node *container) { - return container->last_child && - (container->last_child->flags & CMARK_NODE__OPEN); -} - -static bool parse_block_quote_prefix(cmark_parser *parser, cmark_chunk *input) { - bool res = false; - bufsize_t matched = 0; - - matched = - parser->indent <= 3 && peek_at(input, parser->first_nonspace) == '>'; - if (matched) { - - S_advance_offset(parser, input, parser->indent + 1, true); - - if (S_is_space_or_tab(peek_at(input, parser->offset))) { - S_advance_offset(parser, input, 1, true); - } - - res = true; - } - return res; -} - -static bool parse_footnote_definition_block_prefix(cmark_parser *parser, cmark_chunk *input, - cmark_node *container) { - if (parser->indent >= 4) { - S_advance_offset(parser, input, 4, true); - return true; - } else if (input->len > 0 && (input->data[0] == '\n' || (input->data[0] == '\r' && input->data[1] == '\n'))) { - return true; - } - - return false; -} - -static bool parse_node_item_prefix(cmark_parser *parser, cmark_chunk *input, - cmark_node *container) { - bool res = false; - - if (parser->indent >= - container->as.list.marker_offset + container->as.list.padding) { - S_advance_offset(parser, input, container->as.list.marker_offset + - container->as.list.padding, - true); - res = true; - } else if (parser->blank && container->first_child != NULL) { - // if container->first_child is NULL, then the opening line - // of the list item was blank after the list marker; in this - // case, we are done with the list item. - S_advance_offset(parser, input, parser->first_nonspace - parser->offset, - false); - res = true; - } - return res; -} - -static bool parse_code_block_prefix(cmark_parser *parser, cmark_chunk *input, - cmark_node *container, - bool *should_continue) { - bool res = false; - - if (!container->as.code.fenced) { // indented - if (parser->indent >= CODE_INDENT) { - S_advance_offset(parser, input, CODE_INDENT, true); - res = true; - } else if (parser->blank) { - S_advance_offset(parser, input, parser->first_nonspace - parser->offset, - false); - res = true; - } - } else { // fenced - bufsize_t matched = 0; - - if (parser->indent <= 3 && (peek_at(input, parser->first_nonspace) == - container->as.code.fence_char)) { - matched = scan_close_code_fence(input, parser->first_nonspace); - } - - if (matched >= container->as.code.fence_length) { - // closing fence - and since we're at - // the end of a line, we can stop processing it: - *should_continue = false; - S_advance_offset(parser, input, matched, false); - parser->current = finalize(parser, container); - } else { - // skip opt. spaces of fence parser->offset - int i = container->as.code.fence_offset; - - while (i > 0 && S_is_space_or_tab(peek_at(input, parser->offset))) { - S_advance_offset(parser, input, 1, true); - i--; - } - res = true; - } - } - - return res; -} - -static bool parse_html_block_prefix(cmark_parser *parser, - cmark_node *container) { - bool res = false; - int html_block_type = container->as.html_block_type; - - assert(html_block_type >= 1 && html_block_type <= 7); - switch (html_block_type) { - case 1: - case 2: - case 3: - case 4: - case 5: - // these types of blocks can accept blanks - res = true; - break; - case 6: - case 7: - res = !parser->blank; - break; - } - - return res; -} - -static bool parse_extension_block(cmark_parser *parser, - cmark_node *container, - cmark_chunk *input) -{ - bool res = false; - - if (container->extension->last_block_matches) { - if (container->extension->last_block_matches( - container->extension, parser, input->data, input->len, container)) - res = true; - } - - return res; -} - -/** - * For each containing node, try to parse the associated line start. - * - * Will not close unmatched blocks, as we may have a lazy continuation - * line -> http://spec.commonmark.org/0.24/#lazy-continuation-line - * - * Returns: The last matching node, or NULL - */ -static cmark_node *check_open_blocks(cmark_parser *parser, cmark_chunk *input, - bool *all_matched) { - bool should_continue = true; - *all_matched = false; - cmark_node *container = parser->root; - cmark_node_type cont_type; - - while (S_last_child_is_open(container)) { - container = container->last_child; - cont_type = S_type(container); - - S_find_first_nonspace(parser, input); - - if (container->extension) { - if (!parse_extension_block(parser, container, input)) - goto done; - continue; - } - - switch (cont_type) { - case CMARK_NODE_BLOCK_QUOTE: - if (!parse_block_quote_prefix(parser, input)) - goto done; - break; - case CMARK_NODE_ITEM: - if (!parse_node_item_prefix(parser, input, container)) - goto done; - break; - case CMARK_NODE_CODE_BLOCK: - if (!parse_code_block_prefix(parser, input, container, &should_continue)) - goto done; - break; - case CMARK_NODE_HEADING: - // a heading can never contain more than one line - goto done; - case CMARK_NODE_HTML_BLOCK: - if (!parse_html_block_prefix(parser, container)) - goto done; - break; - case CMARK_NODE_PARAGRAPH: - if (parser->blank) - goto done; - break; - case CMARK_NODE_FOOTNOTE_DEFINITION: - if (!parse_footnote_definition_block_prefix(parser, input, container)) - goto done; - break; - default: - break; - } - } - - *all_matched = true; - -done: - if (!*all_matched) { - container = container->parent; // back up to last matching node - } - - if (!should_continue) { - container = NULL; - } - - return container; -} - -static void open_new_blocks(cmark_parser *parser, cmark_node **container, - cmark_chunk *input, bool all_matched) { - bool indented; - cmark_list *data = NULL; - bool maybe_lazy = S_type(parser->current) == CMARK_NODE_PARAGRAPH; - cmark_node_type cont_type = S_type(*container); - bufsize_t matched = 0; - int lev = 0; - bool save_partially_consumed_tab; - bool has_content; - int save_offset; - int save_column; - - while (cont_type != CMARK_NODE_CODE_BLOCK && - cont_type != CMARK_NODE_HTML_BLOCK) { - - S_find_first_nonspace(parser, input); - indented = parser->indent >= CODE_INDENT; - - if (!indented && peek_at(input, parser->first_nonspace) == '>') { - - bufsize_t blockquote_startpos = parser->first_nonspace; - - S_advance_offset(parser, input, - parser->first_nonspace + 1 - parser->offset, false); - // optional following character - if (S_is_space_or_tab(peek_at(input, parser->offset))) { - S_advance_offset(parser, input, 1, true); - } - *container = add_child(parser, *container, CMARK_NODE_BLOCK_QUOTE, - blockquote_startpos + 1); - - } else if (!indented && (matched = scan_atx_heading_start( - input, parser->first_nonspace))) { - bufsize_t hashpos; - int level = 0; - bufsize_t heading_startpos = parser->first_nonspace; - - S_advance_offset(parser, input, - parser->first_nonspace + matched - parser->offset, - false); - *container = add_child(parser, *container, CMARK_NODE_HEADING, - heading_startpos + 1); - - hashpos = cmark_chunk_strchr(input, '#', parser->first_nonspace); - - while (peek_at(input, hashpos) == '#') { - level++; - hashpos++; - } - - (*container)->as.heading.level = level; - (*container)->as.heading.setext = false; - (*container)->internal_offset = matched; - - } else if (!indented && (matched = scan_open_code_fence( - input, parser->first_nonspace))) { - *container = add_child(parser, *container, CMARK_NODE_CODE_BLOCK, - parser->first_nonspace + 1); - (*container)->as.code.fenced = true; - (*container)->as.code.fence_char = peek_at(input, parser->first_nonspace); - (*container)->as.code.fence_length = (matched > 255) ? 255 : (uint8_t)matched; - (*container)->as.code.fence_offset = - (int8_t)(parser->first_nonspace - parser->offset); - (*container)->as.code.info = cmark_chunk_literal(""); - S_advance_offset(parser, input, - parser->first_nonspace + matched - parser->offset, - false); - - } else if (!indented && ((matched = scan_html_block_start( - input, parser->first_nonspace)) || - (cont_type != CMARK_NODE_PARAGRAPH && - (matched = scan_html_block_start_7( - input, parser->first_nonspace))))) { - *container = add_child(parser, *container, CMARK_NODE_HTML_BLOCK, - parser->first_nonspace + 1); - (*container)->as.html_block_type = matched; - // note, we don't adjust parser->offset because the tag is part of the - // text - } else if (!indented && cont_type == CMARK_NODE_PARAGRAPH && - (lev = - scan_setext_heading_line(input, parser->first_nonspace))) { - // finalize paragraph, resolving reference links - has_content = resolve_reference_link_definitions(parser, *container); - - if (has_content) { - - (*container)->type = (uint16_t)CMARK_NODE_HEADING; - (*container)->as.heading.level = lev; - (*container)->as.heading.setext = true; - S_advance_offset(parser, input, input->len - 1 - parser->offset, false); - } - } else if (!indented && - !(cont_type == CMARK_NODE_PARAGRAPH && !all_matched) && - (parser->thematic_break_kill_pos <= parser->first_nonspace) && - (matched = S_scan_thematic_break(parser, input, parser->first_nonspace))) { - // it's only now that we know the line is not part of a setext heading: - *container = add_child(parser, *container, CMARK_NODE_THEMATIC_BREAK, - parser->first_nonspace + 1); - S_advance_offset(parser, input, input->len - 1 - parser->offset, false); - } else if (!indented && - parser->options & CMARK_OPT_FOOTNOTES && - (matched = scan_footnote_definition(input, parser->first_nonspace))) { - cmark_chunk c = cmark_chunk_dup(input, parser->first_nonspace + 2, matched - 2); - cmark_chunk_to_cstr(parser->mem, &c); - - while (c.data[c.len - 1] != ']') - --c.len; - --c.len; - - S_advance_offset(parser, input, parser->first_nonspace + matched - parser->offset, false); - *container = add_child(parser, *container, CMARK_NODE_FOOTNOTE_DEFINITION, parser->first_nonspace + matched + 1); - (*container)->as.literal = c; - - (*container)->internal_offset = matched; - } else if ((!indented || cont_type == CMARK_NODE_LIST) && - parser->indent < 4 && - (matched = parse_list_marker( - parser->mem, input, parser->first_nonspace, - (*container)->type == CMARK_NODE_PARAGRAPH, &data))) { - - // Note that we can have new list items starting with >= 4 - // spaces indent, as long as the list container is still open. - int i = 0; - - // compute padding: - S_advance_offset(parser, input, - parser->first_nonspace + matched - parser->offset, - false); - - save_partially_consumed_tab = parser->partially_consumed_tab; - save_offset = parser->offset; - save_column = parser->column; - - while (parser->column - save_column <= 5 && - S_is_space_or_tab(peek_at(input, parser->offset))) { - S_advance_offset(parser, input, 1, true); - } - - i = parser->column - save_column; - if (i >= 5 || i < 1 || - // only spaces after list marker: - S_is_line_end_char(peek_at(input, parser->offset))) { - data->padding = matched + 1; - parser->offset = save_offset; - parser->column = save_column; - parser->partially_consumed_tab = save_partially_consumed_tab; - if (i > 0) { - S_advance_offset(parser, input, 1, true); - } - } else { - data->padding = matched + i; - } - - // check container; if it's a list, see if this list item - // can continue the list; otherwise, create a list container. - - data->marker_offset = parser->indent; - - if (cont_type != CMARK_NODE_LIST || - !lists_match(&((*container)->as.list), data)) { - *container = add_child(parser, *container, CMARK_NODE_LIST, - parser->first_nonspace + 1); - - memcpy(&((*container)->as.list), data, sizeof(*data)); - } - - // add the list item - *container = add_child(parser, *container, CMARK_NODE_ITEM, - parser->first_nonspace + 1); - /* TODO: static */ - memcpy(&((*container)->as.list), data, sizeof(*data)); - parser->mem->free(data); - } else if (indented && !maybe_lazy && !parser->blank) { - S_advance_offset(parser, input, CODE_INDENT, true); - *container = add_child(parser, *container, CMARK_NODE_CODE_BLOCK, - parser->offset + 1); - (*container)->as.code.fenced = false; - (*container)->as.code.fence_char = 0; - (*container)->as.code.fence_length = 0; - (*container)->as.code.fence_offset = 0; - (*container)->as.code.info = cmark_chunk_literal(""); - } else { - cmark_llist *tmp; - cmark_node *new_container = NULL; - - for (tmp = parser->syntax_extensions; tmp; tmp=tmp->next) { - cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp->data; - - if (ext->try_opening_block) { - new_container = ext->try_opening_block( - ext, indented, parser, *container, input->data, input->len); - - if (new_container) { - *container = new_container; - break; - } - } - } - - if (!new_container) { - break; - } - } - - if (accepts_lines(S_type(*container))) { - // if it's a line container, it can't contain other containers - break; - } - - cont_type = S_type(*container); - maybe_lazy = false; - } -} - -static void add_text_to_container(cmark_parser *parser, cmark_node *container, - cmark_node *last_matched_container, - cmark_chunk *input) { - cmark_node *tmp; - // what remains at parser->offset is a text line. add the text to the - // appropriate container. - - S_find_first_nonspace(parser, input); - - if (parser->blank && container->last_child) - S_set_last_line_blank(container->last_child, true); - - // block quote lines are never blank as they start with > - // and we don't count blanks in fenced code for purposes of tight/loose - // lists or breaking out of lists. we also don't set last_line_blank - // on an empty list item. - const cmark_node_type ctype = S_type(container); - const bool last_line_blank = - (parser->blank && ctype != CMARK_NODE_BLOCK_QUOTE && - ctype != CMARK_NODE_HEADING && ctype != CMARK_NODE_THEMATIC_BREAK && - !(ctype == CMARK_NODE_CODE_BLOCK && container->as.code.fenced) && - !(ctype == CMARK_NODE_ITEM && container->first_child == NULL && - container->start_line == parser->line_number)); - - S_set_last_line_blank(container, last_line_blank); - - tmp = container; - while (tmp->parent) { - S_set_last_line_blank(tmp->parent, false); - tmp = tmp->parent; - } - - // If the last line processed belonged to a paragraph node, - // and we didn't match all of the line prefixes for the open containers, - // and we didn't start any new containers, - // and the line isn't blank, - // then treat this as a "lazy continuation line" and add it to - // the open paragraph. - if (parser->current != last_matched_container && - container == last_matched_container && !parser->blank && - S_type(parser->current) == CMARK_NODE_PARAGRAPH) { - add_line(parser->current, input, parser); - } else { // not a lazy continuation - // Finalize any blocks that were not matched and set cur to container: - while (parser->current != last_matched_container) { - parser->current = finalize(parser, parser->current); - assert(parser->current != NULL); - } - - if (S_type(container) == CMARK_NODE_CODE_BLOCK) { - add_line(container, input, parser); - } else if (S_type(container) == CMARK_NODE_HTML_BLOCK) { - add_line(container, input, parser); - - int matches_end_condition; - switch (container->as.html_block_type) { - case 1: - // , , - matches_end_condition = - scan_html_block_end_1(input, parser->first_nonspace); - break; - case 2: - // --> - matches_end_condition = - scan_html_block_end_2(input, parser->first_nonspace); - break; - case 3: - // ?> - matches_end_condition = - scan_html_block_end_3(input, parser->first_nonspace); - break; - case 4: - // > - matches_end_condition = - scan_html_block_end_4(input, parser->first_nonspace); - break; - case 5: - // ]]> - matches_end_condition = - scan_html_block_end_5(input, parser->first_nonspace); - break; - default: - matches_end_condition = 0; - break; - } - - if (matches_end_condition) { - container = finalize(parser, container); - assert(parser->current != NULL); - } - } else if (parser->blank) { - // ??? do nothing - } else if (accepts_lines(S_type(container))) { - if (S_type(container) == CMARK_NODE_HEADING && - container->as.heading.setext == false) { - chop_trailing_hashtags(input); - } - S_advance_offset(parser, input, parser->first_nonspace - parser->offset, - false); - add_line(container, input, parser); - } else { - // create paragraph container for line - container = add_child(parser, container, CMARK_NODE_PARAGRAPH, - parser->first_nonspace + 1); - S_advance_offset(parser, input, parser->first_nonspace - parser->offset, - false); - add_line(container, input, parser); - } - - parser->current = container; - } -} - -/* See http://spec.commonmark.org/0.24/#phase-1-block-structure */ -static void S_process_line(cmark_parser *parser, const unsigned char *buffer, - bufsize_t bytes) { - cmark_node *last_matched_container; - bool all_matched = true; - cmark_node *container; - cmark_chunk input; - cmark_node *current; - - cmark_strbuf_clear(&parser->curline); - - if (parser->options & CMARK_OPT_VALIDATE_UTF8) - cmark_utf8proc_check(&parser->curline, buffer, bytes); - else - cmark_strbuf_put(&parser->curline, buffer, bytes); - - bytes = parser->curline.size; - - // ensure line ends with a newline: - if (bytes == 0 || !S_is_line_end_char(parser->curline.ptr[bytes - 1])) - cmark_strbuf_putc(&parser->curline, '\n'); - - parser->offset = 0; - parser->column = 0; - parser->first_nonspace = 0; - parser->first_nonspace_column = 0; - parser->thematic_break_kill_pos = 0; - parser->indent = 0; - parser->blank = false; - parser->partially_consumed_tab = false; - - input.data = parser->curline.ptr; - input.len = parser->curline.size; - input.alloc = 0; - - // Skip UTF-8 BOM. - if (parser->line_number == 0 && - input.len >= 3 && - memcmp(input.data, "\xef\xbb\xbf", 3) == 0) - parser->offset += 3; - - parser->line_number++; - - last_matched_container = check_open_blocks(parser, &input, &all_matched); - - if (!last_matched_container) - goto finished; - - container = last_matched_container; - - current = parser->current; - - open_new_blocks(parser, &container, &input, all_matched); - - /* parser->current might have changed if feed_reentrant was called */ - if (current == parser->current) - add_text_to_container(parser, container, last_matched_container, &input); - -finished: - parser->last_line_length = input.len; - if (parser->last_line_length && - input.data[parser->last_line_length - 1] == '\n') - parser->last_line_length -= 1; - if (parser->last_line_length && - input.data[parser->last_line_length - 1] == '\r') - parser->last_line_length -= 1; - - cmark_strbuf_clear(&parser->curline); -} - -cmark_node *cmark_parser_finish(cmark_parser *parser) { - cmark_node *res; - cmark_llist *extensions; - - /* Parser was already finished once */ - if (parser->root == NULL) - return NULL; - - if (parser->linebuf.size) { - S_process_line(parser, parser->linebuf.ptr, parser->linebuf.size); - cmark_strbuf_clear(&parser->linebuf); - } - - finalize_document(parser); - - cmark_consolidate_text_nodes(parser->root); - - cmark_strbuf_free(&parser->curline); - cmark_strbuf_free(&parser->linebuf); - -#if CMARK_DEBUG_NODES - if (cmark_node_check(parser->root, stderr)) { - abort(); - } -#endif - - for (extensions = parser->syntax_extensions; extensions; extensions = extensions->next) { - cmark_syntax_extension *ext = (cmark_syntax_extension *) extensions->data; - if (ext->postprocess_func) { - cmark_node *processed = ext->postprocess_func(ext, parser, parser->root); - if (processed) - parser->root = processed; - } - } - - res = parser->root; - parser->root = NULL; - - cmark_parser_reset(parser); - - return res; -} - -int cmark_parser_get_line_number(cmark_parser *parser) { - return parser->line_number; -} - -bufsize_t cmark_parser_get_offset(cmark_parser *parser) { - return parser->offset; -} - -bufsize_t cmark_parser_get_column(cmark_parser *parser) { - return parser->column; -} - -int cmark_parser_get_first_nonspace(cmark_parser *parser) { - return parser->first_nonspace; -} - -int cmark_parser_get_first_nonspace_column(cmark_parser *parser) { - return parser->first_nonspace_column; -} - -int cmark_parser_get_indent(cmark_parser *parser) { - return parser->indent; -} - -int cmark_parser_is_blank(cmark_parser *parser) { - return parser->blank; -} - -int cmark_parser_has_partially_consumed_tab(cmark_parser *parser) { - return parser->partially_consumed_tab; -} - -int cmark_parser_get_last_line_length(cmark_parser *parser) { - return parser->last_line_length; -} - -cmark_node *cmark_parser_add_child(cmark_parser *parser, - cmark_node *parent, - cmark_node_type block_type, - int start_column) { - return add_child(parser, parent, block_type, start_column); -} - -void cmark_parser_advance_offset(cmark_parser *parser, - const char *input, - int count, - int columns) { - cmark_chunk input_chunk = cmark_chunk_literal(input); - - S_advance_offset(parser, &input_chunk, count, columns != 0); -} - -void cmark_parser_set_backslash_ispunct_func(cmark_parser *parser, - cmark_ispunct_func func) { - parser->backslash_ispunct = func; -} - -cmark_llist *cmark_parser_get_syntax_extensions(cmark_parser *parser) { - return parser->syntax_extensions; -} diff --git a/ext/commonmarker/buffer.c b/ext/commonmarker/buffer.c deleted file mode 100644 index c7934e57..00000000 --- a/ext/commonmarker/buffer.c +++ /dev/null @@ -1,278 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include - -#include "config.h" -#include "cmark_ctype.h" -#include "buffer.h" - -/* Used as default value for cmark_strbuf->ptr so that people can always - * assume ptr is non-NULL and zero terminated even for new cmark_strbufs. - */ -unsigned char cmark_strbuf__initbuf[1]; - -#ifndef MIN -#define MIN(x, y) ((x < y) ? x : y) -#endif - -void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf, - bufsize_t initial_size) { - buf->mem = mem; - buf->asize = 0; - buf->size = 0; - buf->ptr = cmark_strbuf__initbuf; - - if (initial_size > 0) - cmark_strbuf_grow(buf, initial_size); -} - -static CMARK_INLINE void S_strbuf_grow_by(cmark_strbuf *buf, bufsize_t add) { - cmark_strbuf_grow(buf, buf->size + add); -} - -void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size) { - assert(target_size > 0); - - if (target_size < buf->asize) - return; - - if (target_size > (bufsize_t)(INT32_MAX / 2)) { - fprintf(stderr, - "[cmark] cmark_strbuf_grow requests buffer with size > %d, aborting\n", - (INT32_MAX / 2)); - abort(); - } - - /* Oversize the buffer by 50% to guarantee amortized linear time - * complexity on append operations. */ - bufsize_t new_size = target_size + target_size / 2; - new_size += 1; - new_size = (new_size + 7) & ~7; - - buf->ptr = (unsigned char *)buf->mem->realloc(buf->asize ? buf->ptr : NULL, - new_size); - buf->asize = new_size; -} - -bufsize_t cmark_strbuf_len(const cmark_strbuf *buf) { return buf->size; } - -void cmark_strbuf_free(cmark_strbuf *buf) { - if (!buf) - return; - - if (buf->ptr != cmark_strbuf__initbuf) - buf->mem->free(buf->ptr); - - cmark_strbuf_init(buf->mem, buf, 0); -} - -void cmark_strbuf_clear(cmark_strbuf *buf) { - buf->size = 0; - - if (buf->asize > 0) - buf->ptr[0] = '\0'; -} - -void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, - bufsize_t len) { - if (len <= 0 || data == NULL) { - cmark_strbuf_clear(buf); - } else { - if (data != buf->ptr) { - if (len >= buf->asize) - cmark_strbuf_grow(buf, len); - memmove(buf->ptr, data, len); - } - buf->size = len; - buf->ptr[buf->size] = '\0'; - } -} - -void cmark_strbuf_sets(cmark_strbuf *buf, const char *string) { - cmark_strbuf_set(buf, (const unsigned char *)string, - string ? (bufsize_t)strlen(string) : 0); -} - -void cmark_strbuf_putc(cmark_strbuf *buf, int c) { - S_strbuf_grow_by(buf, 1); - buf->ptr[buf->size++] = (unsigned char)(c & 0xFF); - buf->ptr[buf->size] = '\0'; -} - -void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, - bufsize_t len) { - if (len <= 0) - return; - - S_strbuf_grow_by(buf, len); - memmove(buf->ptr + buf->size, data, len); - buf->size += len; - buf->ptr[buf->size] = '\0'; -} - -void cmark_strbuf_puts(cmark_strbuf *buf, const char *string) { - cmark_strbuf_put(buf, (const unsigned char *)string, (bufsize_t)strlen(string)); -} - -void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize, - const cmark_strbuf *buf) { - bufsize_t copylen; - - assert(buf); - if (!data || datasize <= 0) - return; - - data[0] = '\0'; - - if (buf->size == 0 || buf->asize <= 0) - return; - - copylen = buf->size; - if (copylen > datasize - 1) - copylen = datasize - 1; - memmove(data, buf->ptr, copylen); - data[copylen] = '\0'; -} - -void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b) { - cmark_strbuf t = *buf_a; - *buf_a = *buf_b; - *buf_b = t; -} - -unsigned char *cmark_strbuf_detach(cmark_strbuf *buf) { - unsigned char *data = buf->ptr; - - if (buf->asize == 0) { - /* return an empty string */ - return (unsigned char *)buf->mem->calloc(1, 1); - } - - cmark_strbuf_init(buf->mem, buf, 0); - return data; -} - -int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b) { - int result = memcmp(a->ptr, b->ptr, MIN(a->size, b->size)); - return (result != 0) ? result - : (a->size < b->size) ? -1 : (a->size > b->size) ? 1 : 0; -} - -bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos) { - if (pos >= buf->size) - return -1; - if (pos < 0) - pos = 0; - - const unsigned char *p = - (unsigned char *)memchr(buf->ptr + pos, c, buf->size - pos); - if (!p) - return -1; - - return (bufsize_t)(p - (const unsigned char *)buf->ptr); -} - -bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos) { - if (pos < 0 || buf->size == 0) - return -1; - if (pos >= buf->size) - pos = buf->size - 1; - - bufsize_t i; - for (i = pos; i >= 0; i--) { - if (buf->ptr[i] == (unsigned char)c) - return i; - } - - return -1; -} - -void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len) { - if (len < 0) - len = 0; - - if (len < buf->size) { - buf->size = len; - buf->ptr[buf->size] = '\0'; - } -} - -void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n) { - if (n > 0) { - if (n > buf->size) - n = buf->size; - buf->size = buf->size - n; - if (buf->size) - memmove(buf->ptr, buf->ptr + n, buf->size); - - buf->ptr[buf->size] = '\0'; - } -} - -void cmark_strbuf_rtrim(cmark_strbuf *buf) { - if (!buf->size) - return; - - while (buf->size > 0) { - if (!cmark_isspace(buf->ptr[buf->size - 1])) - break; - - buf->size--; - } - - buf->ptr[buf->size] = '\0'; -} - -void cmark_strbuf_trim(cmark_strbuf *buf) { - bufsize_t i = 0; - - if (!buf->size) - return; - - while (i < buf->size && cmark_isspace(buf->ptr[i])) - i++; - - cmark_strbuf_drop(buf, i); - - cmark_strbuf_rtrim(buf); -} - -// Destructively modify string, collapsing consecutive -// space and newline characters into a single space. -void cmark_strbuf_normalize_whitespace(cmark_strbuf *s) { - bool last_char_was_space = false; - bufsize_t r, w; - - for (r = 0, w = 0; r < s->size; ++r) { - if (cmark_isspace(s->ptr[r])) { - if (!last_char_was_space) { - s->ptr[w++] = ' '; - last_char_was_space = true; - } - } else { - s->ptr[w++] = s->ptr[r]; - last_char_was_space = false; - } - } - - cmark_strbuf_truncate(s, w); -} - -// Destructively unescape a string: remove backslashes before punctuation chars. -extern void cmark_strbuf_unescape(cmark_strbuf *buf) { - bufsize_t r, w; - - for (r = 0, w = 0; r < buf->size; ++r) { - if (buf->ptr[r] == '\\' && cmark_ispunct(buf->ptr[r + 1])) - r++; - - buf->ptr[w++] = buf->ptr[r]; - } - - cmark_strbuf_truncate(buf, w); -} diff --git a/ext/commonmarker/buffer.h b/ext/commonmarker/buffer.h deleted file mode 100644 index b85bb440..00000000 --- a/ext/commonmarker/buffer.h +++ /dev/null @@ -1,116 +0,0 @@ -#ifndef CMARK_BUFFER_H -#define CMARK_BUFFER_H - -#include -#include -#include -#include -#include -#include "config.h" -#include "cmark-gfm.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - cmark_mem *mem; - unsigned char *ptr; - bufsize_t asize, size; -} cmark_strbuf; - -extern unsigned char cmark_strbuf__initbuf[]; - -#define CMARK_BUF_INIT(mem) \ - { mem, cmark_strbuf__initbuf, 0, 0 } - -/** - * Initialize a cmark_strbuf structure. - * - * For the cases where CMARK_BUF_INIT cannot be used to do static - * initialization. - */ -CMARK_GFM_EXPORT -void cmark_strbuf_init(cmark_mem *mem, cmark_strbuf *buf, - bufsize_t initial_size); - -/** - * Grow the buffer to hold at least `target_size` bytes. - */ -CMARK_GFM_EXPORT -void cmark_strbuf_grow(cmark_strbuf *buf, bufsize_t target_size); - -CMARK_GFM_EXPORT -void cmark_strbuf_free(cmark_strbuf *buf); - -CMARK_GFM_EXPORT -void cmark_strbuf_swap(cmark_strbuf *buf_a, cmark_strbuf *buf_b); - -CMARK_GFM_EXPORT -bufsize_t cmark_strbuf_len(const cmark_strbuf *buf); - -CMARK_GFM_EXPORT -int cmark_strbuf_cmp(const cmark_strbuf *a, const cmark_strbuf *b); - -CMARK_GFM_EXPORT -unsigned char *cmark_strbuf_detach(cmark_strbuf *buf); - -CMARK_GFM_EXPORT -void cmark_strbuf_copy_cstr(char *data, bufsize_t datasize, - const cmark_strbuf *buf); - -static CMARK_INLINE const char *cmark_strbuf_cstr(const cmark_strbuf *buf) { - return (char *)buf->ptr; -} - -#define cmark_strbuf_at(buf, n) ((buf)->ptr[n]) - -CMARK_GFM_EXPORT -void cmark_strbuf_set(cmark_strbuf *buf, const unsigned char *data, - bufsize_t len); - -CMARK_GFM_EXPORT -void cmark_strbuf_sets(cmark_strbuf *buf, const char *string); - -CMARK_GFM_EXPORT -void cmark_strbuf_putc(cmark_strbuf *buf, int c); - -CMARK_GFM_EXPORT -void cmark_strbuf_put(cmark_strbuf *buf, const unsigned char *data, - bufsize_t len); - -CMARK_GFM_EXPORT -void cmark_strbuf_puts(cmark_strbuf *buf, const char *string); - -CMARK_GFM_EXPORT -void cmark_strbuf_clear(cmark_strbuf *buf); - -CMARK_GFM_EXPORT -bufsize_t cmark_strbuf_strchr(const cmark_strbuf *buf, int c, bufsize_t pos); - -CMARK_GFM_EXPORT -bufsize_t cmark_strbuf_strrchr(const cmark_strbuf *buf, int c, bufsize_t pos); - -CMARK_GFM_EXPORT -void cmark_strbuf_drop(cmark_strbuf *buf, bufsize_t n); - -CMARK_GFM_EXPORT -void cmark_strbuf_truncate(cmark_strbuf *buf, bufsize_t len); - -CMARK_GFM_EXPORT -void cmark_strbuf_rtrim(cmark_strbuf *buf); - -CMARK_GFM_EXPORT -void cmark_strbuf_trim(cmark_strbuf *buf); - -CMARK_GFM_EXPORT -void cmark_strbuf_normalize_whitespace(cmark_strbuf *s); - -CMARK_GFM_EXPORT -void cmark_strbuf_unescape(cmark_strbuf *s); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/case_fold_switch.inc b/ext/commonmarker/case_fold_switch.inc deleted file mode 100644 index 28e223e1..00000000 --- a/ext/commonmarker/case_fold_switch.inc +++ /dev/null @@ -1,4327 +0,0 @@ - switch (c) { - case 0x0041: - bufpush(0x0061); - break; - case 0x0042: - bufpush(0x0062); - break; - case 0x0043: - bufpush(0x0063); - break; - case 0x0044: - bufpush(0x0064); - break; - case 0x0045: - bufpush(0x0065); - break; - case 0x0046: - bufpush(0x0066); - break; - case 0x0047: - bufpush(0x0067); - break; - case 0x0048: - bufpush(0x0068); - break; - case 0x0049: - bufpush(0x0069); - break; - case 0x004A: - bufpush(0x006A); - break; - case 0x004B: - bufpush(0x006B); - break; - case 0x004C: - bufpush(0x006C); - break; - case 0x004D: - bufpush(0x006D); - break; - case 0x004E: - bufpush(0x006E); - break; - case 0x004F: - bufpush(0x006F); - break; - case 0x0050: - bufpush(0x0070); - break; - case 0x0051: - bufpush(0x0071); - break; - case 0x0052: - bufpush(0x0072); - break; - case 0x0053: - bufpush(0x0073); - break; - case 0x0054: - bufpush(0x0074); - break; - case 0x0055: - bufpush(0x0075); - break; - case 0x0056: - bufpush(0x0076); - break; - case 0x0057: - bufpush(0x0077); - break; - case 0x0058: - bufpush(0x0078); - break; - case 0x0059: - bufpush(0x0079); - break; - case 0x005A: - bufpush(0x007A); - break; - case 0x00B5: - bufpush(0x03BC); - break; - case 0x00C0: - bufpush(0x00E0); - break; - case 0x00C1: - bufpush(0x00E1); - break; - case 0x00C2: - bufpush(0x00E2); - break; - case 0x00C3: - bufpush(0x00E3); - break; - case 0x00C4: - bufpush(0x00E4); - break; - case 0x00C5: - bufpush(0x00E5); - break; - case 0x00C6: - bufpush(0x00E6); - break; - case 0x00C7: - bufpush(0x00E7); - break; - case 0x00C8: - bufpush(0x00E8); - break; - case 0x00C9: - bufpush(0x00E9); - break; - case 0x00CA: - bufpush(0x00EA); - break; - case 0x00CB: - bufpush(0x00EB); - break; - case 0x00CC: - bufpush(0x00EC); - break; - case 0x00CD: - bufpush(0x00ED); - break; - case 0x00CE: - bufpush(0x00EE); - break; - case 0x00CF: - bufpush(0x00EF); - break; - case 0x00D0: - bufpush(0x00F0); - break; - case 0x00D1: - bufpush(0x00F1); - break; - case 0x00D2: - bufpush(0x00F2); - break; - case 0x00D3: - bufpush(0x00F3); - break; - case 0x00D4: - bufpush(0x00F4); - break; - case 0x00D5: - bufpush(0x00F5); - break; - case 0x00D6: - bufpush(0x00F6); - break; - case 0x00D8: - bufpush(0x00F8); - break; - case 0x00D9: - bufpush(0x00F9); - break; - case 0x00DA: - bufpush(0x00FA); - break; - case 0x00DB: - bufpush(0x00FB); - break; - case 0x00DC: - bufpush(0x00FC); - break; - case 0x00DD: - bufpush(0x00FD); - break; - case 0x00DE: - bufpush(0x00FE); - break; - case 0x00DF: - bufpush(0x0073); - bufpush(0x0073); - break; - case 0x0100: - bufpush(0x0101); - break; - case 0x0102: - bufpush(0x0103); - break; - case 0x0104: - bufpush(0x0105); - break; - case 0x0106: - bufpush(0x0107); - break; - case 0x0108: - bufpush(0x0109); - break; - case 0x010A: - bufpush(0x010B); - break; - case 0x010C: - bufpush(0x010D); - break; - case 0x010E: - bufpush(0x010F); - break; - case 0x0110: - bufpush(0x0111); - break; - case 0x0112: - bufpush(0x0113); - break; - case 0x0114: - bufpush(0x0115); - break; - case 0x0116: - bufpush(0x0117); - break; - case 0x0118: - bufpush(0x0119); - break; - case 0x011A: - bufpush(0x011B); - break; - case 0x011C: - bufpush(0x011D); - break; - case 0x011E: - bufpush(0x011F); - break; - case 0x0120: - bufpush(0x0121); - break; - case 0x0122: - bufpush(0x0123); - break; - case 0x0124: - bufpush(0x0125); - break; - case 0x0126: - bufpush(0x0127); - break; - case 0x0128: - bufpush(0x0129); - break; - case 0x012A: - bufpush(0x012B); - break; - case 0x012C: - bufpush(0x012D); - break; - case 0x012E: - bufpush(0x012F); - break; - case 0x0130: - bufpush(0x0069); - bufpush(0x0307); - break; - case 0x0132: - bufpush(0x0133); - break; - case 0x0134: - bufpush(0x0135); - break; - case 0x0136: - bufpush(0x0137); - break; - case 0x0139: - bufpush(0x013A); - break; - case 0x013B: - bufpush(0x013C); - break; - case 0x013D: - bufpush(0x013E); - break; - case 0x013F: - bufpush(0x0140); - break; - case 0x0141: - bufpush(0x0142); - break; - case 0x0143: - bufpush(0x0144); - break; - case 0x0145: - bufpush(0x0146); - break; - case 0x0147: - bufpush(0x0148); - break; - case 0x0149: - bufpush(0x02BC); - bufpush(0x006E); - break; - case 0x014A: - bufpush(0x014B); - break; - case 0x014C: - bufpush(0x014D); - break; - case 0x014E: - bufpush(0x014F); - break; - case 0x0150: - bufpush(0x0151); - break; - case 0x0152: - bufpush(0x0153); - break; - case 0x0154: - bufpush(0x0155); - break; - case 0x0156: - bufpush(0x0157); - break; - case 0x0158: - bufpush(0x0159); - break; - case 0x015A: - bufpush(0x015B); - break; - case 0x015C: - bufpush(0x015D); - break; - case 0x015E: - bufpush(0x015F); - break; - case 0x0160: - bufpush(0x0161); - break; - case 0x0162: - bufpush(0x0163); - break; - case 0x0164: - bufpush(0x0165); - break; - case 0x0166: - bufpush(0x0167); - break; - case 0x0168: - bufpush(0x0169); - break; - case 0x016A: - bufpush(0x016B); - break; - case 0x016C: - bufpush(0x016D); - break; - case 0x016E: - bufpush(0x016F); - break; - case 0x0170: - bufpush(0x0171); - break; - case 0x0172: - bufpush(0x0173); - break; - case 0x0174: - bufpush(0x0175); - break; - case 0x0176: - bufpush(0x0177); - break; - case 0x0178: - bufpush(0x00FF); - break; - case 0x0179: - bufpush(0x017A); - break; - case 0x017B: - bufpush(0x017C); - break; - case 0x017D: - bufpush(0x017E); - break; - case 0x017F: - bufpush(0x0073); - break; - case 0x0181: - bufpush(0x0253); - break; - case 0x0182: - bufpush(0x0183); - break; - case 0x0184: - bufpush(0x0185); - break; - case 0x0186: - bufpush(0x0254); - break; - case 0x0187: - bufpush(0x0188); - break; - case 0x0189: - bufpush(0x0256); - break; - case 0x018A: - bufpush(0x0257); - break; - case 0x018B: - bufpush(0x018C); - break; - case 0x018E: - bufpush(0x01DD); - break; - case 0x018F: - bufpush(0x0259); - break; - case 0x0190: - bufpush(0x025B); - break; - case 0x0191: - bufpush(0x0192); - break; - case 0x0193: - bufpush(0x0260); - break; - case 0x0194: - bufpush(0x0263); - break; - case 0x0196: - bufpush(0x0269); - break; - case 0x0197: - bufpush(0x0268); - break; - case 0x0198: - bufpush(0x0199); - break; - case 0x019C: - bufpush(0x026F); - break; - case 0x019D: - bufpush(0x0272); - break; - case 0x019F: - bufpush(0x0275); - break; - case 0x01A0: - bufpush(0x01A1); - break; - case 0x01A2: - bufpush(0x01A3); - break; - case 0x01A4: - bufpush(0x01A5); - break; - case 0x01A6: - bufpush(0x0280); - break; - case 0x01A7: - bufpush(0x01A8); - break; - case 0x01A9: - bufpush(0x0283); - break; - case 0x01AC: - bufpush(0x01AD); - break; - case 0x01AE: - bufpush(0x0288); - break; - case 0x01AF: - bufpush(0x01B0); - break; - case 0x01B1: - bufpush(0x028A); - break; - case 0x01B2: - bufpush(0x028B); - break; - case 0x01B3: - bufpush(0x01B4); - break; - case 0x01B5: - bufpush(0x01B6); - break; - case 0x01B7: - bufpush(0x0292); - break; - case 0x01B8: - bufpush(0x01B9); - break; - case 0x01BC: - bufpush(0x01BD); - break; - case 0x01C4: - bufpush(0x01C6); - break; - case 0x01C5: - bufpush(0x01C6); - break; - case 0x01C7: - bufpush(0x01C9); - break; - case 0x01C8: - bufpush(0x01C9); - break; - case 0x01CA: - bufpush(0x01CC); - break; - case 0x01CB: - bufpush(0x01CC); - break; - case 0x01CD: - bufpush(0x01CE); - break; - case 0x01CF: - bufpush(0x01D0); - break; - case 0x01D1: - bufpush(0x01D2); - break; - case 0x01D3: - bufpush(0x01D4); - break; - case 0x01D5: - bufpush(0x01D6); - break; - case 0x01D7: - bufpush(0x01D8); - break; - case 0x01D9: - bufpush(0x01DA); - break; - case 0x01DB: - bufpush(0x01DC); - break; - case 0x01DE: - bufpush(0x01DF); - break; - case 0x01E0: - bufpush(0x01E1); - break; - case 0x01E2: - bufpush(0x01E3); - break; - case 0x01E4: - bufpush(0x01E5); - break; - case 0x01E6: - bufpush(0x01E7); - break; - case 0x01E8: - bufpush(0x01E9); - break; - case 0x01EA: - bufpush(0x01EB); - break; - case 0x01EC: - bufpush(0x01ED); - break; - case 0x01EE: - bufpush(0x01EF); - break; - case 0x01F0: - bufpush(0x006A); - bufpush(0x030C); - break; - case 0x01F1: - bufpush(0x01F3); - break; - case 0x01F2: - bufpush(0x01F3); - break; - case 0x01F4: - bufpush(0x01F5); - break; - case 0x01F6: - bufpush(0x0195); - break; - case 0x01F7: - bufpush(0x01BF); - break; - case 0x01F8: - bufpush(0x01F9); - break; - case 0x01FA: - bufpush(0x01FB); - break; - case 0x01FC: - bufpush(0x01FD); - break; - case 0x01FE: - bufpush(0x01FF); - break; - case 0x0200: - bufpush(0x0201); - break; - case 0x0202: - bufpush(0x0203); - break; - case 0x0204: - bufpush(0x0205); - break; - case 0x0206: - bufpush(0x0207); - break; - case 0x0208: - bufpush(0x0209); - break; - case 0x020A: - bufpush(0x020B); - break; - case 0x020C: - bufpush(0x020D); - break; - case 0x020E: - bufpush(0x020F); - break; - case 0x0210: - bufpush(0x0211); - break; - case 0x0212: - bufpush(0x0213); - break; - case 0x0214: - bufpush(0x0215); - break; - case 0x0216: - bufpush(0x0217); - break; - case 0x0218: - bufpush(0x0219); - break; - case 0x021A: - bufpush(0x021B); - break; - case 0x021C: - bufpush(0x021D); - break; - case 0x021E: - bufpush(0x021F); - break; - case 0x0220: - bufpush(0x019E); - break; - case 0x0222: - bufpush(0x0223); - break; - case 0x0224: - bufpush(0x0225); - break; - case 0x0226: - bufpush(0x0227); - break; - case 0x0228: - bufpush(0x0229); - break; - case 0x022A: - bufpush(0x022B); - break; - case 0x022C: - bufpush(0x022D); - break; - case 0x022E: - bufpush(0x022F); - break; - case 0x0230: - bufpush(0x0231); - break; - case 0x0232: - bufpush(0x0233); - break; - case 0x023A: - bufpush(0x2C65); - break; - case 0x023B: - bufpush(0x023C); - break; - case 0x023D: - bufpush(0x019A); - break; - case 0x023E: - bufpush(0x2C66); - break; - case 0x0241: - bufpush(0x0242); - break; - case 0x0243: - bufpush(0x0180); - break; - case 0x0244: - bufpush(0x0289); - break; - case 0x0245: - bufpush(0x028C); - break; - case 0x0246: - bufpush(0x0247); - break; - case 0x0248: - bufpush(0x0249); - break; - case 0x024A: - bufpush(0x024B); - break; - case 0x024C: - bufpush(0x024D); - break; - case 0x024E: - bufpush(0x024F); - break; - case 0x0345: - bufpush(0x03B9); - break; - case 0x0370: - bufpush(0x0371); - break; - case 0x0372: - bufpush(0x0373); - break; - case 0x0376: - bufpush(0x0377); - break; - case 0x037F: - bufpush(0x03F3); - break; - case 0x0386: - bufpush(0x03AC); - break; - case 0x0388: - bufpush(0x03AD); - break; - case 0x0389: - bufpush(0x03AE); - break; - case 0x038A: - bufpush(0x03AF); - break; - case 0x038C: - bufpush(0x03CC); - break; - case 0x038E: - bufpush(0x03CD); - break; - case 0x038F: - bufpush(0x03CE); - break; - case 0x0390: - bufpush(0x03B9); - bufpush(0x0308); - bufpush(0x0301); - break; - case 0x0391: - bufpush(0x03B1); - break; - case 0x0392: - bufpush(0x03B2); - break; - case 0x0393: - bufpush(0x03B3); - break; - case 0x0394: - bufpush(0x03B4); - break; - case 0x0395: - bufpush(0x03B5); - break; - case 0x0396: - bufpush(0x03B6); - break; - case 0x0397: - bufpush(0x03B7); - break; - case 0x0398: - bufpush(0x03B8); - break; - case 0x0399: - bufpush(0x03B9); - break; - case 0x039A: - bufpush(0x03BA); - break; - case 0x039B: - bufpush(0x03BB); - break; - case 0x039C: - bufpush(0x03BC); - break; - case 0x039D: - bufpush(0x03BD); - break; - case 0x039E: - bufpush(0x03BE); - break; - case 0x039F: - bufpush(0x03BF); - break; - case 0x03A0: - bufpush(0x03C0); - break; - case 0x03A1: - bufpush(0x03C1); - break; - case 0x03A3: - bufpush(0x03C3); - break; - case 0x03A4: - bufpush(0x03C4); - break; - case 0x03A5: - bufpush(0x03C5); - break; - case 0x03A6: - bufpush(0x03C6); - break; - case 0x03A7: - bufpush(0x03C7); - break; - case 0x03A8: - bufpush(0x03C8); - break; - case 0x03A9: - bufpush(0x03C9); - break; - case 0x03AA: - bufpush(0x03CA); - break; - case 0x03AB: - bufpush(0x03CB); - break; - case 0x03B0: - bufpush(0x03C5); - bufpush(0x0308); - bufpush(0x0301); - break; - case 0x03C2: - bufpush(0x03C3); - break; - case 0x03CF: - bufpush(0x03D7); - break; - case 0x03D0: - bufpush(0x03B2); - break; - case 0x03D1: - bufpush(0x03B8); - break; - case 0x03D5: - bufpush(0x03C6); - break; - case 0x03D6: - bufpush(0x03C0); - break; - case 0x03D8: - bufpush(0x03D9); - break; - case 0x03DA: - bufpush(0x03DB); - break; - case 0x03DC: - bufpush(0x03DD); - break; - case 0x03DE: - bufpush(0x03DF); - break; - case 0x03E0: - bufpush(0x03E1); - break; - case 0x03E2: - bufpush(0x03E3); - break; - case 0x03E4: - bufpush(0x03E5); - break; - case 0x03E6: - bufpush(0x03E7); - break; - case 0x03E8: - bufpush(0x03E9); - break; - case 0x03EA: - bufpush(0x03EB); - break; - case 0x03EC: - bufpush(0x03ED); - break; - case 0x03EE: - bufpush(0x03EF); - break; - case 0x03F0: - bufpush(0x03BA); - break; - case 0x03F1: - bufpush(0x03C1); - break; - case 0x03F4: - bufpush(0x03B8); - break; - case 0x03F5: - bufpush(0x03B5); - break; - case 0x03F7: - bufpush(0x03F8); - break; - case 0x03F9: - bufpush(0x03F2); - break; - case 0x03FA: - bufpush(0x03FB); - break; - case 0x03FD: - bufpush(0x037B); - break; - case 0x03FE: - bufpush(0x037C); - break; - case 0x03FF: - bufpush(0x037D); - break; - case 0x0400: - bufpush(0x0450); - break; - case 0x0401: - bufpush(0x0451); - break; - case 0x0402: - bufpush(0x0452); - break; - case 0x0403: - bufpush(0x0453); - break; - case 0x0404: - bufpush(0x0454); - break; - case 0x0405: - bufpush(0x0455); - break; - case 0x0406: - bufpush(0x0456); - break; - case 0x0407: - bufpush(0x0457); - break; - case 0x0408: - bufpush(0x0458); - break; - case 0x0409: - bufpush(0x0459); - break; - case 0x040A: - bufpush(0x045A); - break; - case 0x040B: - bufpush(0x045B); - break; - case 0x040C: - bufpush(0x045C); - break; - case 0x040D: - bufpush(0x045D); - break; - case 0x040E: - bufpush(0x045E); - break; - case 0x040F: - bufpush(0x045F); - break; - case 0x0410: - bufpush(0x0430); - break; - case 0x0411: - bufpush(0x0431); - break; - case 0x0412: - bufpush(0x0432); - break; - case 0x0413: - bufpush(0x0433); - break; - case 0x0414: - bufpush(0x0434); - break; - case 0x0415: - bufpush(0x0435); - break; - case 0x0416: - bufpush(0x0436); - break; - case 0x0417: - bufpush(0x0437); - break; - case 0x0418: - bufpush(0x0438); - break; - case 0x0419: - bufpush(0x0439); - break; - case 0x041A: - bufpush(0x043A); - break; - case 0x041B: - bufpush(0x043B); - break; - case 0x041C: - bufpush(0x043C); - break; - case 0x041D: - bufpush(0x043D); - break; - case 0x041E: - bufpush(0x043E); - break; - case 0x041F: - bufpush(0x043F); - break; - case 0x0420: - bufpush(0x0440); - break; - case 0x0421: - bufpush(0x0441); - break; - case 0x0422: - bufpush(0x0442); - break; - case 0x0423: - bufpush(0x0443); - break; - case 0x0424: - bufpush(0x0444); - break; - case 0x0425: - bufpush(0x0445); - break; - case 0x0426: - bufpush(0x0446); - break; - case 0x0427: - bufpush(0x0447); - break; - case 0x0428: - bufpush(0x0448); - break; - case 0x0429: - bufpush(0x0449); - break; - case 0x042A: - bufpush(0x044A); - break; - case 0x042B: - bufpush(0x044B); - break; - case 0x042C: - bufpush(0x044C); - break; - case 0x042D: - bufpush(0x044D); - break; - case 0x042E: - bufpush(0x044E); - break; - case 0x042F: - bufpush(0x044F); - break; - case 0x0460: - bufpush(0x0461); - break; - case 0x0462: - bufpush(0x0463); - break; - case 0x0464: - bufpush(0x0465); - break; - case 0x0466: - bufpush(0x0467); - break; - case 0x0468: - bufpush(0x0469); - break; - case 0x046A: - bufpush(0x046B); - break; - case 0x046C: - bufpush(0x046D); - break; - case 0x046E: - bufpush(0x046F); - break; - case 0x0470: - bufpush(0x0471); - break; - case 0x0472: - bufpush(0x0473); - break; - case 0x0474: - bufpush(0x0475); - break; - case 0x0476: - bufpush(0x0477); - break; - case 0x0478: - bufpush(0x0479); - break; - case 0x047A: - bufpush(0x047B); - break; - case 0x047C: - bufpush(0x047D); - break; - case 0x047E: - bufpush(0x047F); - break; - case 0x0480: - bufpush(0x0481); - break; - case 0x048A: - bufpush(0x048B); - break; - case 0x048C: - bufpush(0x048D); - break; - case 0x048E: - bufpush(0x048F); - break; - case 0x0490: - bufpush(0x0491); - break; - case 0x0492: - bufpush(0x0493); - break; - case 0x0494: - bufpush(0x0495); - break; - case 0x0496: - bufpush(0x0497); - break; - case 0x0498: - bufpush(0x0499); - break; - case 0x049A: - bufpush(0x049B); - break; - case 0x049C: - bufpush(0x049D); - break; - case 0x049E: - bufpush(0x049F); - break; - case 0x04A0: - bufpush(0x04A1); - break; - case 0x04A2: - bufpush(0x04A3); - break; - case 0x04A4: - bufpush(0x04A5); - break; - case 0x04A6: - bufpush(0x04A7); - break; - case 0x04A8: - bufpush(0x04A9); - break; - case 0x04AA: - bufpush(0x04AB); - break; - case 0x04AC: - bufpush(0x04AD); - break; - case 0x04AE: - bufpush(0x04AF); - break; - case 0x04B0: - bufpush(0x04B1); - break; - case 0x04B2: - bufpush(0x04B3); - break; - case 0x04B4: - bufpush(0x04B5); - break; - case 0x04B6: - bufpush(0x04B7); - break; - case 0x04B8: - bufpush(0x04B9); - break; - case 0x04BA: - bufpush(0x04BB); - break; - case 0x04BC: - bufpush(0x04BD); - break; - case 0x04BE: - bufpush(0x04BF); - break; - case 0x04C0: - bufpush(0x04CF); - break; - case 0x04C1: - bufpush(0x04C2); - break; - case 0x04C3: - bufpush(0x04C4); - break; - case 0x04C5: - bufpush(0x04C6); - break; - case 0x04C7: - bufpush(0x04C8); - break; - case 0x04C9: - bufpush(0x04CA); - break; - case 0x04CB: - bufpush(0x04CC); - break; - case 0x04CD: - bufpush(0x04CE); - break; - case 0x04D0: - bufpush(0x04D1); - break; - case 0x04D2: - bufpush(0x04D3); - break; - case 0x04D4: - bufpush(0x04D5); - break; - case 0x04D6: - bufpush(0x04D7); - break; - case 0x04D8: - bufpush(0x04D9); - break; - case 0x04DA: - bufpush(0x04DB); - break; - case 0x04DC: - bufpush(0x04DD); - break; - case 0x04DE: - bufpush(0x04DF); - break; - case 0x04E0: - bufpush(0x04E1); - break; - case 0x04E2: - bufpush(0x04E3); - break; - case 0x04E4: - bufpush(0x04E5); - break; - case 0x04E6: - bufpush(0x04E7); - break; - case 0x04E8: - bufpush(0x04E9); - break; - case 0x04EA: - bufpush(0x04EB); - break; - case 0x04EC: - bufpush(0x04ED); - break; - case 0x04EE: - bufpush(0x04EF); - break; - case 0x04F0: - bufpush(0x04F1); - break; - case 0x04F2: - bufpush(0x04F3); - break; - case 0x04F4: - bufpush(0x04F5); - break; - case 0x04F6: - bufpush(0x04F7); - break; - case 0x04F8: - bufpush(0x04F9); - break; - case 0x04FA: - bufpush(0x04FB); - break; - case 0x04FC: - bufpush(0x04FD); - break; - case 0x04FE: - bufpush(0x04FF); - break; - case 0x0500: - bufpush(0x0501); - break; - case 0x0502: - bufpush(0x0503); - break; - case 0x0504: - bufpush(0x0505); - break; - case 0x0506: - bufpush(0x0507); - break; - case 0x0508: - bufpush(0x0509); - break; - case 0x050A: - bufpush(0x050B); - break; - case 0x050C: - bufpush(0x050D); - break; - case 0x050E: - bufpush(0x050F); - break; - case 0x0510: - bufpush(0x0511); - break; - case 0x0512: - bufpush(0x0513); - break; - case 0x0514: - bufpush(0x0515); - break; - case 0x0516: - bufpush(0x0517); - break; - case 0x0518: - bufpush(0x0519); - break; - case 0x051A: - bufpush(0x051B); - break; - case 0x051C: - bufpush(0x051D); - break; - case 0x051E: - bufpush(0x051F); - break; - case 0x0520: - bufpush(0x0521); - break; - case 0x0522: - bufpush(0x0523); - break; - case 0x0524: - bufpush(0x0525); - break; - case 0x0526: - bufpush(0x0527); - break; - case 0x0528: - bufpush(0x0529); - break; - case 0x052A: - bufpush(0x052B); - break; - case 0x052C: - bufpush(0x052D); - break; - case 0x052E: - bufpush(0x052F); - break; - case 0x0531: - bufpush(0x0561); - break; - case 0x0532: - bufpush(0x0562); - break; - case 0x0533: - bufpush(0x0563); - break; - case 0x0534: - bufpush(0x0564); - break; - case 0x0535: - bufpush(0x0565); - break; - case 0x0536: - bufpush(0x0566); - break; - case 0x0537: - bufpush(0x0567); - break; - case 0x0538: - bufpush(0x0568); - break; - case 0x0539: - bufpush(0x0569); - break; - case 0x053A: - bufpush(0x056A); - break; - case 0x053B: - bufpush(0x056B); - break; - case 0x053C: - bufpush(0x056C); - break; - case 0x053D: - bufpush(0x056D); - break; - case 0x053E: - bufpush(0x056E); - break; - case 0x053F: - bufpush(0x056F); - break; - case 0x0540: - bufpush(0x0570); - break; - case 0x0541: - bufpush(0x0571); - break; - case 0x0542: - bufpush(0x0572); - break; - case 0x0543: - bufpush(0x0573); - break; - case 0x0544: - bufpush(0x0574); - break; - case 0x0545: - bufpush(0x0575); - break; - case 0x0546: - bufpush(0x0576); - break; - case 0x0547: - bufpush(0x0577); - break; - case 0x0548: - bufpush(0x0578); - break; - case 0x0549: - bufpush(0x0579); - break; - case 0x054A: - bufpush(0x057A); - break; - case 0x054B: - bufpush(0x057B); - break; - case 0x054C: - bufpush(0x057C); - break; - case 0x054D: - bufpush(0x057D); - break; - case 0x054E: - bufpush(0x057E); - break; - case 0x054F: - bufpush(0x057F); - break; - case 0x0550: - bufpush(0x0580); - break; - case 0x0551: - bufpush(0x0581); - break; - case 0x0552: - bufpush(0x0582); - break; - case 0x0553: - bufpush(0x0583); - break; - case 0x0554: - bufpush(0x0584); - break; - case 0x0555: - bufpush(0x0585); - break; - case 0x0556: - bufpush(0x0586); - break; - case 0x0587: - bufpush(0x0565); - bufpush(0x0582); - break; - case 0x10A0: - bufpush(0x2D00); - break; - case 0x10A1: - bufpush(0x2D01); - break; - case 0x10A2: - bufpush(0x2D02); - break; - case 0x10A3: - bufpush(0x2D03); - break; - case 0x10A4: - bufpush(0x2D04); - break; - case 0x10A5: - bufpush(0x2D05); - break; - case 0x10A6: - bufpush(0x2D06); - break; - case 0x10A7: - bufpush(0x2D07); - break; - case 0x10A8: - bufpush(0x2D08); - break; - case 0x10A9: - bufpush(0x2D09); - break; - case 0x10AA: - bufpush(0x2D0A); - break; - case 0x10AB: - bufpush(0x2D0B); - break; - case 0x10AC: - bufpush(0x2D0C); - break; - case 0x10AD: - bufpush(0x2D0D); - break; - case 0x10AE: - bufpush(0x2D0E); - break; - case 0x10AF: - bufpush(0x2D0F); - break; - case 0x10B0: - bufpush(0x2D10); - break; - case 0x10B1: - bufpush(0x2D11); - break; - case 0x10B2: - bufpush(0x2D12); - break; - case 0x10B3: - bufpush(0x2D13); - break; - case 0x10B4: - bufpush(0x2D14); - break; - case 0x10B5: - bufpush(0x2D15); - break; - case 0x10B6: - bufpush(0x2D16); - break; - case 0x10B7: - bufpush(0x2D17); - break; - case 0x10B8: - bufpush(0x2D18); - break; - case 0x10B9: - bufpush(0x2D19); - break; - case 0x10BA: - bufpush(0x2D1A); - break; - case 0x10BB: - bufpush(0x2D1B); - break; - case 0x10BC: - bufpush(0x2D1C); - break; - case 0x10BD: - bufpush(0x2D1D); - break; - case 0x10BE: - bufpush(0x2D1E); - break; - case 0x10BF: - bufpush(0x2D1F); - break; - case 0x10C0: - bufpush(0x2D20); - break; - case 0x10C1: - bufpush(0x2D21); - break; - case 0x10C2: - bufpush(0x2D22); - break; - case 0x10C3: - bufpush(0x2D23); - break; - case 0x10C4: - bufpush(0x2D24); - break; - case 0x10C5: - bufpush(0x2D25); - break; - case 0x10C7: - bufpush(0x2D27); - break; - case 0x10CD: - bufpush(0x2D2D); - break; - case 0x13F8: - bufpush(0x13F0); - break; - case 0x13F9: - bufpush(0x13F1); - break; - case 0x13FA: - bufpush(0x13F2); - break; - case 0x13FB: - bufpush(0x13F3); - break; - case 0x13FC: - bufpush(0x13F4); - break; - case 0x13FD: - bufpush(0x13F5); - break; - case 0x1C80: - bufpush(0x0432); - break; - case 0x1C81: - bufpush(0x0434); - break; - case 0x1C82: - bufpush(0x043E); - break; - case 0x1C83: - bufpush(0x0441); - break; - case 0x1C84: - bufpush(0x0442); - break; - case 0x1C85: - bufpush(0x0442); - break; - case 0x1C86: - bufpush(0x044A); - break; - case 0x1C87: - bufpush(0x0463); - break; - case 0x1C88: - bufpush(0xA64B); - break; - case 0x1E00: - bufpush(0x1E01); - break; - case 0x1E02: - bufpush(0x1E03); - break; - case 0x1E04: - bufpush(0x1E05); - break; - case 0x1E06: - bufpush(0x1E07); - break; - case 0x1E08: - bufpush(0x1E09); - break; - case 0x1E0A: - bufpush(0x1E0B); - break; - case 0x1E0C: - bufpush(0x1E0D); - break; - case 0x1E0E: - bufpush(0x1E0F); - break; - case 0x1E10: - bufpush(0x1E11); - break; - case 0x1E12: - bufpush(0x1E13); - break; - case 0x1E14: - bufpush(0x1E15); - break; - case 0x1E16: - bufpush(0x1E17); - break; - case 0x1E18: - bufpush(0x1E19); - break; - case 0x1E1A: - bufpush(0x1E1B); - break; - case 0x1E1C: - bufpush(0x1E1D); - break; - case 0x1E1E: - bufpush(0x1E1F); - break; - case 0x1E20: - bufpush(0x1E21); - break; - case 0x1E22: - bufpush(0x1E23); - break; - case 0x1E24: - bufpush(0x1E25); - break; - case 0x1E26: - bufpush(0x1E27); - break; - case 0x1E28: - bufpush(0x1E29); - break; - case 0x1E2A: - bufpush(0x1E2B); - break; - case 0x1E2C: - bufpush(0x1E2D); - break; - case 0x1E2E: - bufpush(0x1E2F); - break; - case 0x1E30: - bufpush(0x1E31); - break; - case 0x1E32: - bufpush(0x1E33); - break; - case 0x1E34: - bufpush(0x1E35); - break; - case 0x1E36: - bufpush(0x1E37); - break; - case 0x1E38: - bufpush(0x1E39); - break; - case 0x1E3A: - bufpush(0x1E3B); - break; - case 0x1E3C: - bufpush(0x1E3D); - break; - case 0x1E3E: - bufpush(0x1E3F); - break; - case 0x1E40: - bufpush(0x1E41); - break; - case 0x1E42: - bufpush(0x1E43); - break; - case 0x1E44: - bufpush(0x1E45); - break; - case 0x1E46: - bufpush(0x1E47); - break; - case 0x1E48: - bufpush(0x1E49); - break; - case 0x1E4A: - bufpush(0x1E4B); - break; - case 0x1E4C: - bufpush(0x1E4D); - break; - case 0x1E4E: - bufpush(0x1E4F); - break; - case 0x1E50: - bufpush(0x1E51); - break; - case 0x1E52: - bufpush(0x1E53); - break; - case 0x1E54: - bufpush(0x1E55); - break; - case 0x1E56: - bufpush(0x1E57); - break; - case 0x1E58: - bufpush(0x1E59); - break; - case 0x1E5A: - bufpush(0x1E5B); - break; - case 0x1E5C: - bufpush(0x1E5D); - break; - case 0x1E5E: - bufpush(0x1E5F); - break; - case 0x1E60: - bufpush(0x1E61); - break; - case 0x1E62: - bufpush(0x1E63); - break; - case 0x1E64: - bufpush(0x1E65); - break; - case 0x1E66: - bufpush(0x1E67); - break; - case 0x1E68: - bufpush(0x1E69); - break; - case 0x1E6A: - bufpush(0x1E6B); - break; - case 0x1E6C: - bufpush(0x1E6D); - break; - case 0x1E6E: - bufpush(0x1E6F); - break; - case 0x1E70: - bufpush(0x1E71); - break; - case 0x1E72: - bufpush(0x1E73); - break; - case 0x1E74: - bufpush(0x1E75); - break; - case 0x1E76: - bufpush(0x1E77); - break; - case 0x1E78: - bufpush(0x1E79); - break; - case 0x1E7A: - bufpush(0x1E7B); - break; - case 0x1E7C: - bufpush(0x1E7D); - break; - case 0x1E7E: - bufpush(0x1E7F); - break; - case 0x1E80: - bufpush(0x1E81); - break; - case 0x1E82: - bufpush(0x1E83); - break; - case 0x1E84: - bufpush(0x1E85); - break; - case 0x1E86: - bufpush(0x1E87); - break; - case 0x1E88: - bufpush(0x1E89); - break; - case 0x1E8A: - bufpush(0x1E8B); - break; - case 0x1E8C: - bufpush(0x1E8D); - break; - case 0x1E8E: - bufpush(0x1E8F); - break; - case 0x1E90: - bufpush(0x1E91); - break; - case 0x1E92: - bufpush(0x1E93); - break; - case 0x1E94: - bufpush(0x1E95); - break; - case 0x1E96: - bufpush(0x0068); - bufpush(0x0331); - break; - case 0x1E97: - bufpush(0x0074); - bufpush(0x0308); - break; - case 0x1E98: - bufpush(0x0077); - bufpush(0x030A); - break; - case 0x1E99: - bufpush(0x0079); - bufpush(0x030A); - break; - case 0x1E9A: - bufpush(0x0061); - bufpush(0x02BE); - break; - case 0x1E9B: - bufpush(0x1E61); - break; - case 0x1E9E: - bufpush(0x0073); - bufpush(0x0073); - break; - case 0x1EA0: - bufpush(0x1EA1); - break; - case 0x1EA2: - bufpush(0x1EA3); - break; - case 0x1EA4: - bufpush(0x1EA5); - break; - case 0x1EA6: - bufpush(0x1EA7); - break; - case 0x1EA8: - bufpush(0x1EA9); - break; - case 0x1EAA: - bufpush(0x1EAB); - break; - case 0x1EAC: - bufpush(0x1EAD); - break; - case 0x1EAE: - bufpush(0x1EAF); - break; - case 0x1EB0: - bufpush(0x1EB1); - break; - case 0x1EB2: - bufpush(0x1EB3); - break; - case 0x1EB4: - bufpush(0x1EB5); - break; - case 0x1EB6: - bufpush(0x1EB7); - break; - case 0x1EB8: - bufpush(0x1EB9); - break; - case 0x1EBA: - bufpush(0x1EBB); - break; - case 0x1EBC: - bufpush(0x1EBD); - break; - case 0x1EBE: - bufpush(0x1EBF); - break; - case 0x1EC0: - bufpush(0x1EC1); - break; - case 0x1EC2: - bufpush(0x1EC3); - break; - case 0x1EC4: - bufpush(0x1EC5); - break; - case 0x1EC6: - bufpush(0x1EC7); - break; - case 0x1EC8: - bufpush(0x1EC9); - break; - case 0x1ECA: - bufpush(0x1ECB); - break; - case 0x1ECC: - bufpush(0x1ECD); - break; - case 0x1ECE: - bufpush(0x1ECF); - break; - case 0x1ED0: - bufpush(0x1ED1); - break; - case 0x1ED2: - bufpush(0x1ED3); - break; - case 0x1ED4: - bufpush(0x1ED5); - break; - case 0x1ED6: - bufpush(0x1ED7); - break; - case 0x1ED8: - bufpush(0x1ED9); - break; - case 0x1EDA: - bufpush(0x1EDB); - break; - case 0x1EDC: - bufpush(0x1EDD); - break; - case 0x1EDE: - bufpush(0x1EDF); - break; - case 0x1EE0: - bufpush(0x1EE1); - break; - case 0x1EE2: - bufpush(0x1EE3); - break; - case 0x1EE4: - bufpush(0x1EE5); - break; - case 0x1EE6: - bufpush(0x1EE7); - break; - case 0x1EE8: - bufpush(0x1EE9); - break; - case 0x1EEA: - bufpush(0x1EEB); - break; - case 0x1EEC: - bufpush(0x1EED); - break; - case 0x1EEE: - bufpush(0x1EEF); - break; - case 0x1EF0: - bufpush(0x1EF1); - break; - case 0x1EF2: - bufpush(0x1EF3); - break; - case 0x1EF4: - bufpush(0x1EF5); - break; - case 0x1EF6: - bufpush(0x1EF7); - break; - case 0x1EF8: - bufpush(0x1EF9); - break; - case 0x1EFA: - bufpush(0x1EFB); - break; - case 0x1EFC: - bufpush(0x1EFD); - break; - case 0x1EFE: - bufpush(0x1EFF); - break; - case 0x1F08: - bufpush(0x1F00); - break; - case 0x1F09: - bufpush(0x1F01); - break; - case 0x1F0A: - bufpush(0x1F02); - break; - case 0x1F0B: - bufpush(0x1F03); - break; - case 0x1F0C: - bufpush(0x1F04); - break; - case 0x1F0D: - bufpush(0x1F05); - break; - case 0x1F0E: - bufpush(0x1F06); - break; - case 0x1F0F: - bufpush(0x1F07); - break; - case 0x1F18: - bufpush(0x1F10); - break; - case 0x1F19: - bufpush(0x1F11); - break; - case 0x1F1A: - bufpush(0x1F12); - break; - case 0x1F1B: - bufpush(0x1F13); - break; - case 0x1F1C: - bufpush(0x1F14); - break; - case 0x1F1D: - bufpush(0x1F15); - break; - case 0x1F28: - bufpush(0x1F20); - break; - case 0x1F29: - bufpush(0x1F21); - break; - case 0x1F2A: - bufpush(0x1F22); - break; - case 0x1F2B: - bufpush(0x1F23); - break; - case 0x1F2C: - bufpush(0x1F24); - break; - case 0x1F2D: - bufpush(0x1F25); - break; - case 0x1F2E: - bufpush(0x1F26); - break; - case 0x1F2F: - bufpush(0x1F27); - break; - case 0x1F38: - bufpush(0x1F30); - break; - case 0x1F39: - bufpush(0x1F31); - break; - case 0x1F3A: - bufpush(0x1F32); - break; - case 0x1F3B: - bufpush(0x1F33); - break; - case 0x1F3C: - bufpush(0x1F34); - break; - case 0x1F3D: - bufpush(0x1F35); - break; - case 0x1F3E: - bufpush(0x1F36); - break; - case 0x1F3F: - bufpush(0x1F37); - break; - case 0x1F48: - bufpush(0x1F40); - break; - case 0x1F49: - bufpush(0x1F41); - break; - case 0x1F4A: - bufpush(0x1F42); - break; - case 0x1F4B: - bufpush(0x1F43); - break; - case 0x1F4C: - bufpush(0x1F44); - break; - case 0x1F4D: - bufpush(0x1F45); - break; - case 0x1F50: - bufpush(0x03C5); - bufpush(0x0313); - break; - case 0x1F52: - bufpush(0x03C5); - bufpush(0x0313); - bufpush(0x0300); - break; - case 0x1F54: - bufpush(0x03C5); - bufpush(0x0313); - bufpush(0x0301); - break; - case 0x1F56: - bufpush(0x03C5); - bufpush(0x0313); - bufpush(0x0342); - break; - case 0x1F59: - bufpush(0x1F51); - break; - case 0x1F5B: - bufpush(0x1F53); - break; - case 0x1F5D: - bufpush(0x1F55); - break; - case 0x1F5F: - bufpush(0x1F57); - break; - case 0x1F68: - bufpush(0x1F60); - break; - case 0x1F69: - bufpush(0x1F61); - break; - case 0x1F6A: - bufpush(0x1F62); - break; - case 0x1F6B: - bufpush(0x1F63); - break; - case 0x1F6C: - bufpush(0x1F64); - break; - case 0x1F6D: - bufpush(0x1F65); - break; - case 0x1F6E: - bufpush(0x1F66); - break; - case 0x1F6F: - bufpush(0x1F67); - break; - case 0x1F80: - bufpush(0x1F00); - bufpush(0x03B9); - break; - case 0x1F81: - bufpush(0x1F01); - bufpush(0x03B9); - break; - case 0x1F82: - bufpush(0x1F02); - bufpush(0x03B9); - break; - case 0x1F83: - bufpush(0x1F03); - bufpush(0x03B9); - break; - case 0x1F84: - bufpush(0x1F04); - bufpush(0x03B9); - break; - case 0x1F85: - bufpush(0x1F05); - bufpush(0x03B9); - break; - case 0x1F86: - bufpush(0x1F06); - bufpush(0x03B9); - break; - case 0x1F87: - bufpush(0x1F07); - bufpush(0x03B9); - break; - case 0x1F88: - bufpush(0x1F00); - bufpush(0x03B9); - break; - case 0x1F89: - bufpush(0x1F01); - bufpush(0x03B9); - break; - case 0x1F8A: - bufpush(0x1F02); - bufpush(0x03B9); - break; - case 0x1F8B: - bufpush(0x1F03); - bufpush(0x03B9); - break; - case 0x1F8C: - bufpush(0x1F04); - bufpush(0x03B9); - break; - case 0x1F8D: - bufpush(0x1F05); - bufpush(0x03B9); - break; - case 0x1F8E: - bufpush(0x1F06); - bufpush(0x03B9); - break; - case 0x1F8F: - bufpush(0x1F07); - bufpush(0x03B9); - break; - case 0x1F90: - bufpush(0x1F20); - bufpush(0x03B9); - break; - case 0x1F91: - bufpush(0x1F21); - bufpush(0x03B9); - break; - case 0x1F92: - bufpush(0x1F22); - bufpush(0x03B9); - break; - case 0x1F93: - bufpush(0x1F23); - bufpush(0x03B9); - break; - case 0x1F94: - bufpush(0x1F24); - bufpush(0x03B9); - break; - case 0x1F95: - bufpush(0x1F25); - bufpush(0x03B9); - break; - case 0x1F96: - bufpush(0x1F26); - bufpush(0x03B9); - break; - case 0x1F97: - bufpush(0x1F27); - bufpush(0x03B9); - break; - case 0x1F98: - bufpush(0x1F20); - bufpush(0x03B9); - break; - case 0x1F99: - bufpush(0x1F21); - bufpush(0x03B9); - break; - case 0x1F9A: - bufpush(0x1F22); - bufpush(0x03B9); - break; - case 0x1F9B: - bufpush(0x1F23); - bufpush(0x03B9); - break; - case 0x1F9C: - bufpush(0x1F24); - bufpush(0x03B9); - break; - case 0x1F9D: - bufpush(0x1F25); - bufpush(0x03B9); - break; - case 0x1F9E: - bufpush(0x1F26); - bufpush(0x03B9); - break; - case 0x1F9F: - bufpush(0x1F27); - bufpush(0x03B9); - break; - case 0x1FA0: - bufpush(0x1F60); - bufpush(0x03B9); - break; - case 0x1FA1: - bufpush(0x1F61); - bufpush(0x03B9); - break; - case 0x1FA2: - bufpush(0x1F62); - bufpush(0x03B9); - break; - case 0x1FA3: - bufpush(0x1F63); - bufpush(0x03B9); - break; - case 0x1FA4: - bufpush(0x1F64); - bufpush(0x03B9); - break; - case 0x1FA5: - bufpush(0x1F65); - bufpush(0x03B9); - break; - case 0x1FA6: - bufpush(0x1F66); - bufpush(0x03B9); - break; - case 0x1FA7: - bufpush(0x1F67); - bufpush(0x03B9); - break; - case 0x1FA8: - bufpush(0x1F60); - bufpush(0x03B9); - break; - case 0x1FA9: - bufpush(0x1F61); - bufpush(0x03B9); - break; - case 0x1FAA: - bufpush(0x1F62); - bufpush(0x03B9); - break; - case 0x1FAB: - bufpush(0x1F63); - bufpush(0x03B9); - break; - case 0x1FAC: - bufpush(0x1F64); - bufpush(0x03B9); - break; - case 0x1FAD: - bufpush(0x1F65); - bufpush(0x03B9); - break; - case 0x1FAE: - bufpush(0x1F66); - bufpush(0x03B9); - break; - case 0x1FAF: - bufpush(0x1F67); - bufpush(0x03B9); - break; - case 0x1FB2: - bufpush(0x1F70); - bufpush(0x03B9); - break; - case 0x1FB3: - bufpush(0x03B1); - bufpush(0x03B9); - break; - case 0x1FB4: - bufpush(0x03AC); - bufpush(0x03B9); - break; - case 0x1FB6: - bufpush(0x03B1); - bufpush(0x0342); - break; - case 0x1FB7: - bufpush(0x03B1); - bufpush(0x0342); - bufpush(0x03B9); - break; - case 0x1FB8: - bufpush(0x1FB0); - break; - case 0x1FB9: - bufpush(0x1FB1); - break; - case 0x1FBA: - bufpush(0x1F70); - break; - case 0x1FBB: - bufpush(0x1F71); - break; - case 0x1FBC: - bufpush(0x03B1); - bufpush(0x03B9); - break; - case 0x1FBE: - bufpush(0x03B9); - break; - case 0x1FC2: - bufpush(0x1F74); - bufpush(0x03B9); - break; - case 0x1FC3: - bufpush(0x03B7); - bufpush(0x03B9); - break; - case 0x1FC4: - bufpush(0x03AE); - bufpush(0x03B9); - break; - case 0x1FC6: - bufpush(0x03B7); - bufpush(0x0342); - break; - case 0x1FC7: - bufpush(0x03B7); - bufpush(0x0342); - bufpush(0x03B9); - break; - case 0x1FC8: - bufpush(0x1F72); - break; - case 0x1FC9: - bufpush(0x1F73); - break; - case 0x1FCA: - bufpush(0x1F74); - break; - case 0x1FCB: - bufpush(0x1F75); - break; - case 0x1FCC: - bufpush(0x03B7); - bufpush(0x03B9); - break; - case 0x1FD2: - bufpush(0x03B9); - bufpush(0x0308); - bufpush(0x0300); - break; - case 0x1FD3: - bufpush(0x03B9); - bufpush(0x0308); - bufpush(0x0301); - break; - case 0x1FD6: - bufpush(0x03B9); - bufpush(0x0342); - break; - case 0x1FD7: - bufpush(0x03B9); - bufpush(0x0308); - bufpush(0x0342); - break; - case 0x1FD8: - bufpush(0x1FD0); - break; - case 0x1FD9: - bufpush(0x1FD1); - break; - case 0x1FDA: - bufpush(0x1F76); - break; - case 0x1FDB: - bufpush(0x1F77); - break; - case 0x1FE2: - bufpush(0x03C5); - bufpush(0x0308); - bufpush(0x0300); - break; - case 0x1FE3: - bufpush(0x03C5); - bufpush(0x0308); - bufpush(0x0301); - break; - case 0x1FE4: - bufpush(0x03C1); - bufpush(0x0313); - break; - case 0x1FE6: - bufpush(0x03C5); - bufpush(0x0342); - break; - case 0x1FE7: - bufpush(0x03C5); - bufpush(0x0308); - bufpush(0x0342); - break; - case 0x1FE8: - bufpush(0x1FE0); - break; - case 0x1FE9: - bufpush(0x1FE1); - break; - case 0x1FEA: - bufpush(0x1F7A); - break; - case 0x1FEB: - bufpush(0x1F7B); - break; - case 0x1FEC: - bufpush(0x1FE5); - break; - case 0x1FF2: - bufpush(0x1F7C); - bufpush(0x03B9); - break; - case 0x1FF3: - bufpush(0x03C9); - bufpush(0x03B9); - break; - case 0x1FF4: - bufpush(0x03CE); - bufpush(0x03B9); - break; - case 0x1FF6: - bufpush(0x03C9); - bufpush(0x0342); - break; - case 0x1FF7: - bufpush(0x03C9); - bufpush(0x0342); - bufpush(0x03B9); - break; - case 0x1FF8: - bufpush(0x1F78); - break; - case 0x1FF9: - bufpush(0x1F79); - break; - case 0x1FFA: - bufpush(0x1F7C); - break; - case 0x1FFB: - bufpush(0x1F7D); - break; - case 0x1FFC: - bufpush(0x03C9); - bufpush(0x03B9); - break; - case 0x2126: - bufpush(0x03C9); - break; - case 0x212A: - bufpush(0x006B); - break; - case 0x212B: - bufpush(0x00E5); - break; - case 0x2132: - bufpush(0x214E); - break; - case 0x2160: - bufpush(0x2170); - break; - case 0x2161: - bufpush(0x2171); - break; - case 0x2162: - bufpush(0x2172); - break; - case 0x2163: - bufpush(0x2173); - break; - case 0x2164: - bufpush(0x2174); - break; - case 0x2165: - bufpush(0x2175); - break; - case 0x2166: - bufpush(0x2176); - break; - case 0x2167: - bufpush(0x2177); - break; - case 0x2168: - bufpush(0x2178); - break; - case 0x2169: - bufpush(0x2179); - break; - case 0x216A: - bufpush(0x217A); - break; - case 0x216B: - bufpush(0x217B); - break; - case 0x216C: - bufpush(0x217C); - break; - case 0x216D: - bufpush(0x217D); - break; - case 0x216E: - bufpush(0x217E); - break; - case 0x216F: - bufpush(0x217F); - break; - case 0x2183: - bufpush(0x2184); - break; - case 0x24B6: - bufpush(0x24D0); - break; - case 0x24B7: - bufpush(0x24D1); - break; - case 0x24B8: - bufpush(0x24D2); - break; - case 0x24B9: - bufpush(0x24D3); - break; - case 0x24BA: - bufpush(0x24D4); - break; - case 0x24BB: - bufpush(0x24D5); - break; - case 0x24BC: - bufpush(0x24D6); - break; - case 0x24BD: - bufpush(0x24D7); - break; - case 0x24BE: - bufpush(0x24D8); - break; - case 0x24BF: - bufpush(0x24D9); - break; - case 0x24C0: - bufpush(0x24DA); - break; - case 0x24C1: - bufpush(0x24DB); - break; - case 0x24C2: - bufpush(0x24DC); - break; - case 0x24C3: - bufpush(0x24DD); - break; - case 0x24C4: - bufpush(0x24DE); - break; - case 0x24C5: - bufpush(0x24DF); - break; - case 0x24C6: - bufpush(0x24E0); - break; - case 0x24C7: - bufpush(0x24E1); - break; - case 0x24C8: - bufpush(0x24E2); - break; - case 0x24C9: - bufpush(0x24E3); - break; - case 0x24CA: - bufpush(0x24E4); - break; - case 0x24CB: - bufpush(0x24E5); - break; - case 0x24CC: - bufpush(0x24E6); - break; - case 0x24CD: - bufpush(0x24E7); - break; - case 0x24CE: - bufpush(0x24E8); - break; - case 0x24CF: - bufpush(0x24E9); - break; - case 0x2C00: - bufpush(0x2C30); - break; - case 0x2C01: - bufpush(0x2C31); - break; - case 0x2C02: - bufpush(0x2C32); - break; - case 0x2C03: - bufpush(0x2C33); - break; - case 0x2C04: - bufpush(0x2C34); - break; - case 0x2C05: - bufpush(0x2C35); - break; - case 0x2C06: - bufpush(0x2C36); - break; - case 0x2C07: - bufpush(0x2C37); - break; - case 0x2C08: - bufpush(0x2C38); - break; - case 0x2C09: - bufpush(0x2C39); - break; - case 0x2C0A: - bufpush(0x2C3A); - break; - case 0x2C0B: - bufpush(0x2C3B); - break; - case 0x2C0C: - bufpush(0x2C3C); - break; - case 0x2C0D: - bufpush(0x2C3D); - break; - case 0x2C0E: - bufpush(0x2C3E); - break; - case 0x2C0F: - bufpush(0x2C3F); - break; - case 0x2C10: - bufpush(0x2C40); - break; - case 0x2C11: - bufpush(0x2C41); - break; - case 0x2C12: - bufpush(0x2C42); - break; - case 0x2C13: - bufpush(0x2C43); - break; - case 0x2C14: - bufpush(0x2C44); - break; - case 0x2C15: - bufpush(0x2C45); - break; - case 0x2C16: - bufpush(0x2C46); - break; - case 0x2C17: - bufpush(0x2C47); - break; - case 0x2C18: - bufpush(0x2C48); - break; - case 0x2C19: - bufpush(0x2C49); - break; - case 0x2C1A: - bufpush(0x2C4A); - break; - case 0x2C1B: - bufpush(0x2C4B); - break; - case 0x2C1C: - bufpush(0x2C4C); - break; - case 0x2C1D: - bufpush(0x2C4D); - break; - case 0x2C1E: - bufpush(0x2C4E); - break; - case 0x2C1F: - bufpush(0x2C4F); - break; - case 0x2C20: - bufpush(0x2C50); - break; - case 0x2C21: - bufpush(0x2C51); - break; - case 0x2C22: - bufpush(0x2C52); - break; - case 0x2C23: - bufpush(0x2C53); - break; - case 0x2C24: - bufpush(0x2C54); - break; - case 0x2C25: - bufpush(0x2C55); - break; - case 0x2C26: - bufpush(0x2C56); - break; - case 0x2C27: - bufpush(0x2C57); - break; - case 0x2C28: - bufpush(0x2C58); - break; - case 0x2C29: - bufpush(0x2C59); - break; - case 0x2C2A: - bufpush(0x2C5A); - break; - case 0x2C2B: - bufpush(0x2C5B); - break; - case 0x2C2C: - bufpush(0x2C5C); - break; - case 0x2C2D: - bufpush(0x2C5D); - break; - case 0x2C2E: - bufpush(0x2C5E); - break; - case 0x2C60: - bufpush(0x2C61); - break; - case 0x2C62: - bufpush(0x026B); - break; - case 0x2C63: - bufpush(0x1D7D); - break; - case 0x2C64: - bufpush(0x027D); - break; - case 0x2C67: - bufpush(0x2C68); - break; - case 0x2C69: - bufpush(0x2C6A); - break; - case 0x2C6B: - bufpush(0x2C6C); - break; - case 0x2C6D: - bufpush(0x0251); - break; - case 0x2C6E: - bufpush(0x0271); - break; - case 0x2C6F: - bufpush(0x0250); - break; - case 0x2C70: - bufpush(0x0252); - break; - case 0x2C72: - bufpush(0x2C73); - break; - case 0x2C75: - bufpush(0x2C76); - break; - case 0x2C7E: - bufpush(0x023F); - break; - case 0x2C7F: - bufpush(0x0240); - break; - case 0x2C80: - bufpush(0x2C81); - break; - case 0x2C82: - bufpush(0x2C83); - break; - case 0x2C84: - bufpush(0x2C85); - break; - case 0x2C86: - bufpush(0x2C87); - break; - case 0x2C88: - bufpush(0x2C89); - break; - case 0x2C8A: - bufpush(0x2C8B); - break; - case 0x2C8C: - bufpush(0x2C8D); - break; - case 0x2C8E: - bufpush(0x2C8F); - break; - case 0x2C90: - bufpush(0x2C91); - break; - case 0x2C92: - bufpush(0x2C93); - break; - case 0x2C94: - bufpush(0x2C95); - break; - case 0x2C96: - bufpush(0x2C97); - break; - case 0x2C98: - bufpush(0x2C99); - break; - case 0x2C9A: - bufpush(0x2C9B); - break; - case 0x2C9C: - bufpush(0x2C9D); - break; - case 0x2C9E: - bufpush(0x2C9F); - break; - case 0x2CA0: - bufpush(0x2CA1); - break; - case 0x2CA2: - bufpush(0x2CA3); - break; - case 0x2CA4: - bufpush(0x2CA5); - break; - case 0x2CA6: - bufpush(0x2CA7); - break; - case 0x2CA8: - bufpush(0x2CA9); - break; - case 0x2CAA: - bufpush(0x2CAB); - break; - case 0x2CAC: - bufpush(0x2CAD); - break; - case 0x2CAE: - bufpush(0x2CAF); - break; - case 0x2CB0: - bufpush(0x2CB1); - break; - case 0x2CB2: - bufpush(0x2CB3); - break; - case 0x2CB4: - bufpush(0x2CB5); - break; - case 0x2CB6: - bufpush(0x2CB7); - break; - case 0x2CB8: - bufpush(0x2CB9); - break; - case 0x2CBA: - bufpush(0x2CBB); - break; - case 0x2CBC: - bufpush(0x2CBD); - break; - case 0x2CBE: - bufpush(0x2CBF); - break; - case 0x2CC0: - bufpush(0x2CC1); - break; - case 0x2CC2: - bufpush(0x2CC3); - break; - case 0x2CC4: - bufpush(0x2CC5); - break; - case 0x2CC6: - bufpush(0x2CC7); - break; - case 0x2CC8: - bufpush(0x2CC9); - break; - case 0x2CCA: - bufpush(0x2CCB); - break; - case 0x2CCC: - bufpush(0x2CCD); - break; - case 0x2CCE: - bufpush(0x2CCF); - break; - case 0x2CD0: - bufpush(0x2CD1); - break; - case 0x2CD2: - bufpush(0x2CD3); - break; - case 0x2CD4: - bufpush(0x2CD5); - break; - case 0x2CD6: - bufpush(0x2CD7); - break; - case 0x2CD8: - bufpush(0x2CD9); - break; - case 0x2CDA: - bufpush(0x2CDB); - break; - case 0x2CDC: - bufpush(0x2CDD); - break; - case 0x2CDE: - bufpush(0x2CDF); - break; - case 0x2CE0: - bufpush(0x2CE1); - break; - case 0x2CE2: - bufpush(0x2CE3); - break; - case 0x2CEB: - bufpush(0x2CEC); - break; - case 0x2CED: - bufpush(0x2CEE); - break; - case 0x2CF2: - bufpush(0x2CF3); - break; - case 0xA640: - bufpush(0xA641); - break; - case 0xA642: - bufpush(0xA643); - break; - case 0xA644: - bufpush(0xA645); - break; - case 0xA646: - bufpush(0xA647); - break; - case 0xA648: - bufpush(0xA649); - break; - case 0xA64A: - bufpush(0xA64B); - break; - case 0xA64C: - bufpush(0xA64D); - break; - case 0xA64E: - bufpush(0xA64F); - break; - case 0xA650: - bufpush(0xA651); - break; - case 0xA652: - bufpush(0xA653); - break; - case 0xA654: - bufpush(0xA655); - break; - case 0xA656: - bufpush(0xA657); - break; - case 0xA658: - bufpush(0xA659); - break; - case 0xA65A: - bufpush(0xA65B); - break; - case 0xA65C: - bufpush(0xA65D); - break; - case 0xA65E: - bufpush(0xA65F); - break; - case 0xA660: - bufpush(0xA661); - break; - case 0xA662: - bufpush(0xA663); - break; - case 0xA664: - bufpush(0xA665); - break; - case 0xA666: - bufpush(0xA667); - break; - case 0xA668: - bufpush(0xA669); - break; - case 0xA66A: - bufpush(0xA66B); - break; - case 0xA66C: - bufpush(0xA66D); - break; - case 0xA680: - bufpush(0xA681); - break; - case 0xA682: - bufpush(0xA683); - break; - case 0xA684: - bufpush(0xA685); - break; - case 0xA686: - bufpush(0xA687); - break; - case 0xA688: - bufpush(0xA689); - break; - case 0xA68A: - bufpush(0xA68B); - break; - case 0xA68C: - bufpush(0xA68D); - break; - case 0xA68E: - bufpush(0xA68F); - break; - case 0xA690: - bufpush(0xA691); - break; - case 0xA692: - bufpush(0xA693); - break; - case 0xA694: - bufpush(0xA695); - break; - case 0xA696: - bufpush(0xA697); - break; - case 0xA698: - bufpush(0xA699); - break; - case 0xA69A: - bufpush(0xA69B); - break; - case 0xA722: - bufpush(0xA723); - break; - case 0xA724: - bufpush(0xA725); - break; - case 0xA726: - bufpush(0xA727); - break; - case 0xA728: - bufpush(0xA729); - break; - case 0xA72A: - bufpush(0xA72B); - break; - case 0xA72C: - bufpush(0xA72D); - break; - case 0xA72E: - bufpush(0xA72F); - break; - case 0xA732: - bufpush(0xA733); - break; - case 0xA734: - bufpush(0xA735); - break; - case 0xA736: - bufpush(0xA737); - break; - case 0xA738: - bufpush(0xA739); - break; - case 0xA73A: - bufpush(0xA73B); - break; - case 0xA73C: - bufpush(0xA73D); - break; - case 0xA73E: - bufpush(0xA73F); - break; - case 0xA740: - bufpush(0xA741); - break; - case 0xA742: - bufpush(0xA743); - break; - case 0xA744: - bufpush(0xA745); - break; - case 0xA746: - bufpush(0xA747); - break; - case 0xA748: - bufpush(0xA749); - break; - case 0xA74A: - bufpush(0xA74B); - break; - case 0xA74C: - bufpush(0xA74D); - break; - case 0xA74E: - bufpush(0xA74F); - break; - case 0xA750: - bufpush(0xA751); - break; - case 0xA752: - bufpush(0xA753); - break; - case 0xA754: - bufpush(0xA755); - break; - case 0xA756: - bufpush(0xA757); - break; - case 0xA758: - bufpush(0xA759); - break; - case 0xA75A: - bufpush(0xA75B); - break; - case 0xA75C: - bufpush(0xA75D); - break; - case 0xA75E: - bufpush(0xA75F); - break; - case 0xA760: - bufpush(0xA761); - break; - case 0xA762: - bufpush(0xA763); - break; - case 0xA764: - bufpush(0xA765); - break; - case 0xA766: - bufpush(0xA767); - break; - case 0xA768: - bufpush(0xA769); - break; - case 0xA76A: - bufpush(0xA76B); - break; - case 0xA76C: - bufpush(0xA76D); - break; - case 0xA76E: - bufpush(0xA76F); - break; - case 0xA779: - bufpush(0xA77A); - break; - case 0xA77B: - bufpush(0xA77C); - break; - case 0xA77D: - bufpush(0x1D79); - break; - case 0xA77E: - bufpush(0xA77F); - break; - case 0xA780: - bufpush(0xA781); - break; - case 0xA782: - bufpush(0xA783); - break; - case 0xA784: - bufpush(0xA785); - break; - case 0xA786: - bufpush(0xA787); - break; - case 0xA78B: - bufpush(0xA78C); - break; - case 0xA78D: - bufpush(0x0265); - break; - case 0xA790: - bufpush(0xA791); - break; - case 0xA792: - bufpush(0xA793); - break; - case 0xA796: - bufpush(0xA797); - break; - case 0xA798: - bufpush(0xA799); - break; - case 0xA79A: - bufpush(0xA79B); - break; - case 0xA79C: - bufpush(0xA79D); - break; - case 0xA79E: - bufpush(0xA79F); - break; - case 0xA7A0: - bufpush(0xA7A1); - break; - case 0xA7A2: - bufpush(0xA7A3); - break; - case 0xA7A4: - bufpush(0xA7A5); - break; - case 0xA7A6: - bufpush(0xA7A7); - break; - case 0xA7A8: - bufpush(0xA7A9); - break; - case 0xA7AA: - bufpush(0x0266); - break; - case 0xA7AB: - bufpush(0x025C); - break; - case 0xA7AC: - bufpush(0x0261); - break; - case 0xA7AD: - bufpush(0x026C); - break; - case 0xA7AE: - bufpush(0x026A); - break; - case 0xA7B0: - bufpush(0x029E); - break; - case 0xA7B1: - bufpush(0x0287); - break; - case 0xA7B2: - bufpush(0x029D); - break; - case 0xA7B3: - bufpush(0xAB53); - break; - case 0xA7B4: - bufpush(0xA7B5); - break; - case 0xA7B6: - bufpush(0xA7B7); - break; - case 0xAB70: - bufpush(0x13A0); - break; - case 0xAB71: - bufpush(0x13A1); - break; - case 0xAB72: - bufpush(0x13A2); - break; - case 0xAB73: - bufpush(0x13A3); - break; - case 0xAB74: - bufpush(0x13A4); - break; - case 0xAB75: - bufpush(0x13A5); - break; - case 0xAB76: - bufpush(0x13A6); - break; - case 0xAB77: - bufpush(0x13A7); - break; - case 0xAB78: - bufpush(0x13A8); - break; - case 0xAB79: - bufpush(0x13A9); - break; - case 0xAB7A: - bufpush(0x13AA); - break; - case 0xAB7B: - bufpush(0x13AB); - break; - case 0xAB7C: - bufpush(0x13AC); - break; - case 0xAB7D: - bufpush(0x13AD); - break; - case 0xAB7E: - bufpush(0x13AE); - break; - case 0xAB7F: - bufpush(0x13AF); - break; - case 0xAB80: - bufpush(0x13B0); - break; - case 0xAB81: - bufpush(0x13B1); - break; - case 0xAB82: - bufpush(0x13B2); - break; - case 0xAB83: - bufpush(0x13B3); - break; - case 0xAB84: - bufpush(0x13B4); - break; - case 0xAB85: - bufpush(0x13B5); - break; - case 0xAB86: - bufpush(0x13B6); - break; - case 0xAB87: - bufpush(0x13B7); - break; - case 0xAB88: - bufpush(0x13B8); - break; - case 0xAB89: - bufpush(0x13B9); - break; - case 0xAB8A: - bufpush(0x13BA); - break; - case 0xAB8B: - bufpush(0x13BB); - break; - case 0xAB8C: - bufpush(0x13BC); - break; - case 0xAB8D: - bufpush(0x13BD); - break; - case 0xAB8E: - bufpush(0x13BE); - break; - case 0xAB8F: - bufpush(0x13BF); - break; - case 0xAB90: - bufpush(0x13C0); - break; - case 0xAB91: - bufpush(0x13C1); - break; - case 0xAB92: - bufpush(0x13C2); - break; - case 0xAB93: - bufpush(0x13C3); - break; - case 0xAB94: - bufpush(0x13C4); - break; - case 0xAB95: - bufpush(0x13C5); - break; - case 0xAB96: - bufpush(0x13C6); - break; - case 0xAB97: - bufpush(0x13C7); - break; - case 0xAB98: - bufpush(0x13C8); - break; - case 0xAB99: - bufpush(0x13C9); - break; - case 0xAB9A: - bufpush(0x13CA); - break; - case 0xAB9B: - bufpush(0x13CB); - break; - case 0xAB9C: - bufpush(0x13CC); - break; - case 0xAB9D: - bufpush(0x13CD); - break; - case 0xAB9E: - bufpush(0x13CE); - break; - case 0xAB9F: - bufpush(0x13CF); - break; - case 0xABA0: - bufpush(0x13D0); - break; - case 0xABA1: - bufpush(0x13D1); - break; - case 0xABA2: - bufpush(0x13D2); - break; - case 0xABA3: - bufpush(0x13D3); - break; - case 0xABA4: - bufpush(0x13D4); - break; - case 0xABA5: - bufpush(0x13D5); - break; - case 0xABA6: - bufpush(0x13D6); - break; - case 0xABA7: - bufpush(0x13D7); - break; - case 0xABA8: - bufpush(0x13D8); - break; - case 0xABA9: - bufpush(0x13D9); - break; - case 0xABAA: - bufpush(0x13DA); - break; - case 0xABAB: - bufpush(0x13DB); - break; - case 0xABAC: - bufpush(0x13DC); - break; - case 0xABAD: - bufpush(0x13DD); - break; - case 0xABAE: - bufpush(0x13DE); - break; - case 0xABAF: - bufpush(0x13DF); - break; - case 0xABB0: - bufpush(0x13E0); - break; - case 0xABB1: - bufpush(0x13E1); - break; - case 0xABB2: - bufpush(0x13E2); - break; - case 0xABB3: - bufpush(0x13E3); - break; - case 0xABB4: - bufpush(0x13E4); - break; - case 0xABB5: - bufpush(0x13E5); - break; - case 0xABB6: - bufpush(0x13E6); - break; - case 0xABB7: - bufpush(0x13E7); - break; - case 0xABB8: - bufpush(0x13E8); - break; - case 0xABB9: - bufpush(0x13E9); - break; - case 0xABBA: - bufpush(0x13EA); - break; - case 0xABBB: - bufpush(0x13EB); - break; - case 0xABBC: - bufpush(0x13EC); - break; - case 0xABBD: - bufpush(0x13ED); - break; - case 0xABBE: - bufpush(0x13EE); - break; - case 0xABBF: - bufpush(0x13EF); - break; - case 0xFB00: - bufpush(0x0066); - bufpush(0x0066); - break; - case 0xFB01: - bufpush(0x0066); - bufpush(0x0069); - break; - case 0xFB02: - bufpush(0x0066); - bufpush(0x006C); - break; - case 0xFB03: - bufpush(0x0066); - bufpush(0x0066); - bufpush(0x0069); - break; - case 0xFB04: - bufpush(0x0066); - bufpush(0x0066); - bufpush(0x006C); - break; - case 0xFB05: - bufpush(0x0073); - bufpush(0x0074); - break; - case 0xFB06: - bufpush(0x0073); - bufpush(0x0074); - break; - case 0xFB13: - bufpush(0x0574); - bufpush(0x0576); - break; - case 0xFB14: - bufpush(0x0574); - bufpush(0x0565); - break; - case 0xFB15: - bufpush(0x0574); - bufpush(0x056B); - break; - case 0xFB16: - bufpush(0x057E); - bufpush(0x0576); - break; - case 0xFB17: - bufpush(0x0574); - bufpush(0x056D); - break; - case 0xFF21: - bufpush(0xFF41); - break; - case 0xFF22: - bufpush(0xFF42); - break; - case 0xFF23: - bufpush(0xFF43); - break; - case 0xFF24: - bufpush(0xFF44); - break; - case 0xFF25: - bufpush(0xFF45); - break; - case 0xFF26: - bufpush(0xFF46); - break; - case 0xFF27: - bufpush(0xFF47); - break; - case 0xFF28: - bufpush(0xFF48); - break; - case 0xFF29: - bufpush(0xFF49); - break; - case 0xFF2A: - bufpush(0xFF4A); - break; - case 0xFF2B: - bufpush(0xFF4B); - break; - case 0xFF2C: - bufpush(0xFF4C); - break; - case 0xFF2D: - bufpush(0xFF4D); - break; - case 0xFF2E: - bufpush(0xFF4E); - break; - case 0xFF2F: - bufpush(0xFF4F); - break; - case 0xFF30: - bufpush(0xFF50); - break; - case 0xFF31: - bufpush(0xFF51); - break; - case 0xFF32: - bufpush(0xFF52); - break; - case 0xFF33: - bufpush(0xFF53); - break; - case 0xFF34: - bufpush(0xFF54); - break; - case 0xFF35: - bufpush(0xFF55); - break; - case 0xFF36: - bufpush(0xFF56); - break; - case 0xFF37: - bufpush(0xFF57); - break; - case 0xFF38: - bufpush(0xFF58); - break; - case 0xFF39: - bufpush(0xFF59); - break; - case 0xFF3A: - bufpush(0xFF5A); - break; - case 0x10400: - bufpush(0x10428); - break; - case 0x10401: - bufpush(0x10429); - break; - case 0x10402: - bufpush(0x1042A); - break; - case 0x10403: - bufpush(0x1042B); - break; - case 0x10404: - bufpush(0x1042C); - break; - case 0x10405: - bufpush(0x1042D); - break; - case 0x10406: - bufpush(0x1042E); - break; - case 0x10407: - bufpush(0x1042F); - break; - case 0x10408: - bufpush(0x10430); - break; - case 0x10409: - bufpush(0x10431); - break; - case 0x1040A: - bufpush(0x10432); - break; - case 0x1040B: - bufpush(0x10433); - break; - case 0x1040C: - bufpush(0x10434); - break; - case 0x1040D: - bufpush(0x10435); - break; - case 0x1040E: - bufpush(0x10436); - break; - case 0x1040F: - bufpush(0x10437); - break; - case 0x10410: - bufpush(0x10438); - break; - case 0x10411: - bufpush(0x10439); - break; - case 0x10412: - bufpush(0x1043A); - break; - case 0x10413: - bufpush(0x1043B); - break; - case 0x10414: - bufpush(0x1043C); - break; - case 0x10415: - bufpush(0x1043D); - break; - case 0x10416: - bufpush(0x1043E); - break; - case 0x10417: - bufpush(0x1043F); - break; - case 0x10418: - bufpush(0x10440); - break; - case 0x10419: - bufpush(0x10441); - break; - case 0x1041A: - bufpush(0x10442); - break; - case 0x1041B: - bufpush(0x10443); - break; - case 0x1041C: - bufpush(0x10444); - break; - case 0x1041D: - bufpush(0x10445); - break; - case 0x1041E: - bufpush(0x10446); - break; - case 0x1041F: - bufpush(0x10447); - break; - case 0x10420: - bufpush(0x10448); - break; - case 0x10421: - bufpush(0x10449); - break; - case 0x10422: - bufpush(0x1044A); - break; - case 0x10423: - bufpush(0x1044B); - break; - case 0x10424: - bufpush(0x1044C); - break; - case 0x10425: - bufpush(0x1044D); - break; - case 0x10426: - bufpush(0x1044E); - break; - case 0x10427: - bufpush(0x1044F); - break; - case 0x104B0: - bufpush(0x104D8); - break; - case 0x104B1: - bufpush(0x104D9); - break; - case 0x104B2: - bufpush(0x104DA); - break; - case 0x104B3: - bufpush(0x104DB); - break; - case 0x104B4: - bufpush(0x104DC); - break; - case 0x104B5: - bufpush(0x104DD); - break; - case 0x104B6: - bufpush(0x104DE); - break; - case 0x104B7: - bufpush(0x104DF); - break; - case 0x104B8: - bufpush(0x104E0); - break; - case 0x104B9: - bufpush(0x104E1); - break; - case 0x104BA: - bufpush(0x104E2); - break; - case 0x104BB: - bufpush(0x104E3); - break; - case 0x104BC: - bufpush(0x104E4); - break; - case 0x104BD: - bufpush(0x104E5); - break; - case 0x104BE: - bufpush(0x104E6); - break; - case 0x104BF: - bufpush(0x104E7); - break; - case 0x104C0: - bufpush(0x104E8); - break; - case 0x104C1: - bufpush(0x104E9); - break; - case 0x104C2: - bufpush(0x104EA); - break; - case 0x104C3: - bufpush(0x104EB); - break; - case 0x104C4: - bufpush(0x104EC); - break; - case 0x104C5: - bufpush(0x104ED); - break; - case 0x104C6: - bufpush(0x104EE); - break; - case 0x104C7: - bufpush(0x104EF); - break; - case 0x104C8: - bufpush(0x104F0); - break; - case 0x104C9: - bufpush(0x104F1); - break; - case 0x104CA: - bufpush(0x104F2); - break; - case 0x104CB: - bufpush(0x104F3); - break; - case 0x104CC: - bufpush(0x104F4); - break; - case 0x104CD: - bufpush(0x104F5); - break; - case 0x104CE: - bufpush(0x104F6); - break; - case 0x104CF: - bufpush(0x104F7); - break; - case 0x104D0: - bufpush(0x104F8); - break; - case 0x104D1: - bufpush(0x104F9); - break; - case 0x104D2: - bufpush(0x104FA); - break; - case 0x104D3: - bufpush(0x104FB); - break; - case 0x10C80: - bufpush(0x10CC0); - break; - case 0x10C81: - bufpush(0x10CC1); - break; - case 0x10C82: - bufpush(0x10CC2); - break; - case 0x10C83: - bufpush(0x10CC3); - break; - case 0x10C84: - bufpush(0x10CC4); - break; - case 0x10C85: - bufpush(0x10CC5); - break; - case 0x10C86: - bufpush(0x10CC6); - break; - case 0x10C87: - bufpush(0x10CC7); - break; - case 0x10C88: - bufpush(0x10CC8); - break; - case 0x10C89: - bufpush(0x10CC9); - break; - case 0x10C8A: - bufpush(0x10CCA); - break; - case 0x10C8B: - bufpush(0x10CCB); - break; - case 0x10C8C: - bufpush(0x10CCC); - break; - case 0x10C8D: - bufpush(0x10CCD); - break; - case 0x10C8E: - bufpush(0x10CCE); - break; - case 0x10C8F: - bufpush(0x10CCF); - break; - case 0x10C90: - bufpush(0x10CD0); - break; - case 0x10C91: - bufpush(0x10CD1); - break; - case 0x10C92: - bufpush(0x10CD2); - break; - case 0x10C93: - bufpush(0x10CD3); - break; - case 0x10C94: - bufpush(0x10CD4); - break; - case 0x10C95: - bufpush(0x10CD5); - break; - case 0x10C96: - bufpush(0x10CD6); - break; - case 0x10C97: - bufpush(0x10CD7); - break; - case 0x10C98: - bufpush(0x10CD8); - break; - case 0x10C99: - bufpush(0x10CD9); - break; - case 0x10C9A: - bufpush(0x10CDA); - break; - case 0x10C9B: - bufpush(0x10CDB); - break; - case 0x10C9C: - bufpush(0x10CDC); - break; - case 0x10C9D: - bufpush(0x10CDD); - break; - case 0x10C9E: - bufpush(0x10CDE); - break; - case 0x10C9F: - bufpush(0x10CDF); - break; - case 0x10CA0: - bufpush(0x10CE0); - break; - case 0x10CA1: - bufpush(0x10CE1); - break; - case 0x10CA2: - bufpush(0x10CE2); - break; - case 0x10CA3: - bufpush(0x10CE3); - break; - case 0x10CA4: - bufpush(0x10CE4); - break; - case 0x10CA5: - bufpush(0x10CE5); - break; - case 0x10CA6: - bufpush(0x10CE6); - break; - case 0x10CA7: - bufpush(0x10CE7); - break; - case 0x10CA8: - bufpush(0x10CE8); - break; - case 0x10CA9: - bufpush(0x10CE9); - break; - case 0x10CAA: - bufpush(0x10CEA); - break; - case 0x10CAB: - bufpush(0x10CEB); - break; - case 0x10CAC: - bufpush(0x10CEC); - break; - case 0x10CAD: - bufpush(0x10CED); - break; - case 0x10CAE: - bufpush(0x10CEE); - break; - case 0x10CAF: - bufpush(0x10CEF); - break; - case 0x10CB0: - bufpush(0x10CF0); - break; - case 0x10CB1: - bufpush(0x10CF1); - break; - case 0x10CB2: - bufpush(0x10CF2); - break; - case 0x118A0: - bufpush(0x118C0); - break; - case 0x118A1: - bufpush(0x118C1); - break; - case 0x118A2: - bufpush(0x118C2); - break; - case 0x118A3: - bufpush(0x118C3); - break; - case 0x118A4: - bufpush(0x118C4); - break; - case 0x118A5: - bufpush(0x118C5); - break; - case 0x118A6: - bufpush(0x118C6); - break; - case 0x118A7: - bufpush(0x118C7); - break; - case 0x118A8: - bufpush(0x118C8); - break; - case 0x118A9: - bufpush(0x118C9); - break; - case 0x118AA: - bufpush(0x118CA); - break; - case 0x118AB: - bufpush(0x118CB); - break; - case 0x118AC: - bufpush(0x118CC); - break; - case 0x118AD: - bufpush(0x118CD); - break; - case 0x118AE: - bufpush(0x118CE); - break; - case 0x118AF: - bufpush(0x118CF); - break; - case 0x118B0: - bufpush(0x118D0); - break; - case 0x118B1: - bufpush(0x118D1); - break; - case 0x118B2: - bufpush(0x118D2); - break; - case 0x118B3: - bufpush(0x118D3); - break; - case 0x118B4: - bufpush(0x118D4); - break; - case 0x118B5: - bufpush(0x118D5); - break; - case 0x118B6: - bufpush(0x118D6); - break; - case 0x118B7: - bufpush(0x118D7); - break; - case 0x118B8: - bufpush(0x118D8); - break; - case 0x118B9: - bufpush(0x118D9); - break; - case 0x118BA: - bufpush(0x118DA); - break; - case 0x118BB: - bufpush(0x118DB); - break; - case 0x118BC: - bufpush(0x118DC); - break; - case 0x118BD: - bufpush(0x118DD); - break; - case 0x118BE: - bufpush(0x118DE); - break; - case 0x118BF: - bufpush(0x118DF); - break; - case 0x1E900: - bufpush(0x1E922); - break; - case 0x1E901: - bufpush(0x1E923); - break; - case 0x1E902: - bufpush(0x1E924); - break; - case 0x1E903: - bufpush(0x1E925); - break; - case 0x1E904: - bufpush(0x1E926); - break; - case 0x1E905: - bufpush(0x1E927); - break; - case 0x1E906: - bufpush(0x1E928); - break; - case 0x1E907: - bufpush(0x1E929); - break; - case 0x1E908: - bufpush(0x1E92A); - break; - case 0x1E909: - bufpush(0x1E92B); - break; - case 0x1E90A: - bufpush(0x1E92C); - break; - case 0x1E90B: - bufpush(0x1E92D); - break; - case 0x1E90C: - bufpush(0x1E92E); - break; - case 0x1E90D: - bufpush(0x1E92F); - break; - case 0x1E90E: - bufpush(0x1E930); - break; - case 0x1E90F: - bufpush(0x1E931); - break; - case 0x1E910: - bufpush(0x1E932); - break; - case 0x1E911: - bufpush(0x1E933); - break; - case 0x1E912: - bufpush(0x1E934); - break; - case 0x1E913: - bufpush(0x1E935); - break; - case 0x1E914: - bufpush(0x1E936); - break; - case 0x1E915: - bufpush(0x1E937); - break; - case 0x1E916: - bufpush(0x1E938); - break; - case 0x1E917: - bufpush(0x1E939); - break; - case 0x1E918: - bufpush(0x1E93A); - break; - case 0x1E919: - bufpush(0x1E93B); - break; - case 0x1E91A: - bufpush(0x1E93C); - break; - case 0x1E91B: - bufpush(0x1E93D); - break; - case 0x1E91C: - bufpush(0x1E93E); - break; - case 0x1E91D: - bufpush(0x1E93F); - break; - case 0x1E91E: - bufpush(0x1E940); - break; - case 0x1E91F: - bufpush(0x1E941); - break; - case 0x1E920: - bufpush(0x1E942); - break; - case 0x1E921: - bufpush(0x1E943); - break; - default: - bufpush(c); - } diff --git a/ext/commonmarker/chunk.h b/ext/commonmarker/chunk.h deleted file mode 100644 index c411c04a..00000000 --- a/ext/commonmarker/chunk.h +++ /dev/null @@ -1,135 +0,0 @@ -#ifndef CMARK_CHUNK_H -#define CMARK_CHUNK_H - -#include -#include -#include -#include "cmark-gfm.h" -#include "buffer.h" -#include "cmark_ctype.h" - -#define CMARK_CHUNK_EMPTY \ - { NULL, 0, 0 } - -typedef struct cmark_chunk { - unsigned char *data; - bufsize_t len; - bufsize_t alloc; // also implies a NULL-terminated string -} cmark_chunk; - -static CMARK_INLINE void cmark_chunk_free(cmark_mem *mem, cmark_chunk *c) { - if (c->alloc) - mem->free(c->data); - - c->data = NULL; - c->alloc = 0; - c->len = 0; -} - -static CMARK_INLINE void cmark_chunk_ltrim(cmark_chunk *c) { - assert(!c->alloc); - - while (c->len && cmark_isspace(c->data[0])) { - c->data++; - c->len--; - } -} - -static CMARK_INLINE void cmark_chunk_rtrim(cmark_chunk *c) { - assert(!c->alloc); - - while (c->len > 0) { - if (!cmark_isspace(c->data[c->len - 1])) - break; - - c->len--; - } -} - -static CMARK_INLINE void cmark_chunk_trim(cmark_chunk *c) { - cmark_chunk_ltrim(c); - cmark_chunk_rtrim(c); -} - -static CMARK_INLINE bufsize_t cmark_chunk_strchr(cmark_chunk *ch, int c, - bufsize_t offset) { - const unsigned char *p = - (unsigned char *)memchr(ch->data + offset, c, ch->len - offset); - return p ? (bufsize_t)(p - ch->data) : ch->len; -} - -static CMARK_INLINE const char *cmark_chunk_to_cstr(cmark_mem *mem, - cmark_chunk *c) { - unsigned char *str; - - if (c->alloc) { - return (char *)c->data; - } - str = (unsigned char *)mem->calloc(c->len + 1, 1); - if (c->len > 0) { - memcpy(str, c->data, c->len); - } - str[c->len] = 0; - c->data = str; - c->alloc = 1; - - return (char *)str; -} - -static CMARK_INLINE void cmark_chunk_set_cstr(cmark_mem *mem, cmark_chunk *c, - const char *str) { - unsigned char *old = c->alloc ? c->data : NULL; - if (str == NULL) { - c->len = 0; - c->data = NULL; - c->alloc = 0; - } else { - c->len = (bufsize_t)strlen(str); - c->data = (unsigned char *)mem->calloc(c->len + 1, 1); - c->alloc = 1; - memcpy(c->data, str, c->len + 1); - } - if (old != NULL) { - mem->free(old); - } -} - -static CMARK_INLINE cmark_chunk cmark_chunk_literal(const char *data) { - bufsize_t len = data ? (bufsize_t)strlen(data) : 0; - cmark_chunk c = {(unsigned char *)data, len, 0}; - return c; -} - -static CMARK_INLINE cmark_chunk cmark_chunk_dup(const cmark_chunk *ch, - bufsize_t pos, bufsize_t len) { - cmark_chunk c = {ch->data + pos, len, 0}; - return c; -} - -static CMARK_INLINE cmark_chunk cmark_chunk_buf_detach(cmark_strbuf *buf) { - cmark_chunk c; - - c.len = buf->size; - c.data = cmark_strbuf_detach(buf); - c.alloc = 1; - - return c; -} - -/* trim_new variants are to be used when the source chunk may or may not be - * allocated; forces a newly allocated chunk. */ -static CMARK_INLINE cmark_chunk cmark_chunk_ltrim_new(cmark_mem *mem, cmark_chunk *c) { - cmark_chunk r = cmark_chunk_dup(c, 0, c->len); - cmark_chunk_ltrim(&r); - cmark_chunk_to_cstr(mem, &r); - return r; -} - -static CMARK_INLINE cmark_chunk cmark_chunk_rtrim_new(cmark_mem *mem, cmark_chunk *c) { - cmark_chunk r = cmark_chunk_dup(c, 0, c->len); - cmark_chunk_rtrim(&r); - cmark_chunk_to_cstr(mem, &r); - return r; -} - -#endif diff --git a/ext/commonmarker/cmark-gfm-core-extensions.h b/ext/commonmarker/cmark-gfm-core-extensions.h deleted file mode 100644 index 0645915f..00000000 --- a/ext/commonmarker/cmark-gfm-core-extensions.h +++ /dev/null @@ -1,54 +0,0 @@ -#ifndef CMARK_GFM_CORE_EXTENSIONS_H -#define CMARK_GFM_CORE_EXTENSIONS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmark-gfm-extension_api.h" -#include "cmark-gfm-extensions_export.h" -#include "config.h" // for bool -#include - -CMARK_GFM_EXTENSIONS_EXPORT -void cmark_gfm_core_extensions_ensure_registered(void); - -CMARK_GFM_EXTENSIONS_EXPORT -uint16_t cmark_gfm_extensions_get_table_columns(cmark_node *node); - -/** Sets the number of columns for the table, returning 1 on success and 0 on error. - */ -CMARK_GFM_EXTENSIONS_EXPORT -int cmark_gfm_extensions_set_table_columns(cmark_node *node, uint16_t n_columns); - -CMARK_GFM_EXTENSIONS_EXPORT -uint8_t *cmark_gfm_extensions_get_table_alignments(cmark_node *node); - -/** Sets the alignments for the table, returning 1 on success and 0 on error. - */ -CMARK_GFM_EXTENSIONS_EXPORT -int cmark_gfm_extensions_set_table_alignments(cmark_node *node, uint16_t ncols, uint8_t *alignments); - -CMARK_GFM_EXTENSIONS_EXPORT -int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node); - -/** Sets whether the node is a table header row, returning 1 on success and 0 on error. - */ -CMARK_GFM_EXTENSIONS_EXPORT -int cmark_gfm_extensions_set_table_row_is_header(cmark_node *node, int is_header); - -CMARK_GFM_EXTENSIONS_EXPORT -bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node); -/* For backwards compatibility */ -#define cmark_gfm_extensions_tasklist_is_checked cmark_gfm_extensions_get_tasklist_item_checked - -/** Sets whether a tasklist item is "checked" (completed), returning 1 on success and 0 on error. - */ -CMARK_GFM_EXTENSIONS_EXPORT -int cmark_gfm_extensions_set_tasklist_item_checked(cmark_node *node, bool is_checked); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/cmark-gfm-extension_api.h b/ext/commonmarker/cmark-gfm-extension_api.h deleted file mode 100644 index 9403c4f0..00000000 --- a/ext/commonmarker/cmark-gfm-extension_api.h +++ /dev/null @@ -1,736 +0,0 @@ -#ifndef CMARK_GFM_EXTENSION_API_H -#define CMARK_GFM_EXTENSION_API_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmark-gfm.h" - -struct cmark_renderer; -struct cmark_html_renderer; -struct cmark_chunk; - -/** - * ## Extension Support - * - * While the "core" of libcmark is strictly compliant with the - * specification, an API is provided for extension writers to - * hook into the parsing process. - * - * It should be noted that the cmark_node API already offers - * room for customization, with methods offered to traverse and - * modify the AST, and even define custom blocks. - * When the desired customization is achievable in an error-proof - * way using that API, it should be the preferred method. - * - * The following API requires a more in-depth understanding - * of libcmark's parsing strategy, which is exposed - * [here](http://spec.commonmark.org/0.24/#appendix-a-parsing-strategy). - * - * It should be used when "a posteriori" modification of the AST - * proves to be too difficult / impossible to implement correctly. - * - * It can also serve as an intermediary step before extending - * the specification, as an extension implemented using this API - * will be trivially integrated in the core if it proves to be - * desirable. - */ - -typedef struct cmark_plugin cmark_plugin; - -/** A syntax extension that can be attached to a cmark_parser - * with cmark_parser_attach_syntax_extension(). - * - * Extension writers should assign functions matching - * the signature of the following 'virtual methods' to - * implement new functionality. - * - * Their calling order and expected behaviour match the procedure outlined - * at : - * - * During step 1, cmark will call the function provided through - * 'cmark_syntax_extension_set_match_block_func' when it - * iterates over an open block created by this extension, - * to determine whether it could contain the new line. - * If no function was provided, cmark will close the block. - * - * During step 2, if and only if the new line doesn't match any - * of the standard syntax rules, cmark will call the function - * provided through 'cmark_syntax_extension_set_open_block_func' - * to let the extension determine whether that new line matches - * one of its syntax rules. - * It is the responsibility of the parser to create and add the - * new block with cmark_parser_make_block and cmark_parser_add_child. - * If no function was provided is NULL, the extension will have - * no effect at all on the final block structure of the AST. - * - * #### Inline parsing phase hooks - * - * For each character provided by the extension through - * 'cmark_syntax_extension_set_special_inline_chars', - * the function provided by the extension through - * 'cmark_syntax_extension_set_match_inline_func' - * will get called, it is the responsibility of the extension - * to scan the characters located at the current inline parsing offset - * with the cmark_inline_parser API. - * - * Depending on the type of the extension, it can either: - * - * * Scan forward, determine that the syntax matches and return - * a newly-created inline node with the appropriate type. - * This is the technique that would be used if inline code - * (with backticks) was implemented as an extension. - * * Scan only the character(s) that its syntax rules require - * for opening and closing nodes, push a delimiter on the - * delimiter stack, and return a simple text node with its - * contents set to the character(s) consumed. - * This is the technique that would be used if emphasis - * inlines were implemented as an extension. - * - * When an extension has pushed delimiters on the stack, - * the function provided through - * 'cmark_syntax_extension_set_inline_from_delim_func' - * will get called in a latter phase, - * when the inline parser has matched opener and closer delimiters - * created by the extension together. - * - * It is then the responsibility of the extension to modify - * and populate the opener inline text node, and to remove - * the necessary delimiters from the delimiter stack. - * - * Finally, the extension should return NULL if its scan didn't - * match its syntax rules. - * - * The extension can store whatever private data it might need - * with 'cmark_syntax_extension_set_private', - * and optionally define a free function for this data. - */ -typedef struct subject cmark_inline_parser; - -/** Exposed raw for now */ - -typedef struct delimiter { - struct delimiter *previous; - struct delimiter *next; - cmark_node *inl_text; - bufsize_t length; - unsigned char delim_char; - int can_open; - int can_close; -} delimiter; - -/** - * ### Plugin API. - * - * Extensions should be distributed as dynamic libraries, - * with a single exported function named after the distributed - * filename. - * - * When discovering extensions (see cmark_init), cmark will - * try to load a symbol named "init_{{filename}}" in all the - * dynamic libraries it encounters. - * - * For example, given a dynamic library named myextension.so - * (or myextension.dll), cmark will try to load the symbol - * named "init_myextension". This means that the filename - * must lend itself to forming a valid C identifier, with - * the notable exception of dashes, which will be translated - * to underscores, which means cmark will look for a function - * named "init_my_extension" if it encounters a dynamic library - * named "my-extension.so". - * - * See the 'cmark_plugin_init_func' typedef for the exact prototype - * this function should follow. - * - * For now the extensibility of cmark is not complete, as - * it only offers API to hook into the block parsing phase - * (). - * - * See 'cmark_plugin_register_syntax_extension' for more information. - */ - -/** The prototype plugins' init function should follow. - */ -typedef int (*cmark_plugin_init_func)(cmark_plugin *plugin); - -/** Register a syntax 'extension' with the 'plugin', it will be made - * available as an extension and, if attached to a cmark_parser - * with 'cmark_parser_attach_syntax_extension', it will contribute - * to the block parsing process. - * - * See the documentation for 'cmark_syntax_extension' for information - * on how to implement one. - * - * This function will typically be called from the init function - * of external modules. - * - * This takes ownership of 'extension', one should not call - * 'cmark_syntax_extension_free' on a registered extension. - */ -CMARK_GFM_EXPORT -int cmark_plugin_register_syntax_extension(cmark_plugin *plugin, - cmark_syntax_extension *extension); - -/** This will search for the syntax extension named 'name' among the - * registered syntax extensions. - * - * It can then be attached to a cmark_parser - * with the cmark_parser_attach_syntax_extension method. - */ -CMARK_GFM_EXPORT -cmark_syntax_extension *cmark_find_syntax_extension(const char *name); - -/** Should create and add a new open block to 'parent_container' if - * 'input' matches a syntax rule for that block type. It is allowed - * to modify the type of 'parent_container'. - * - * Should return the newly created block if there is one, or - * 'parent_container' if its type was modified, or NULL. - */ -typedef cmark_node * (*cmark_open_block_func) (cmark_syntax_extension *extension, - int indented, - cmark_parser *parser, - cmark_node *parent_container, - unsigned char *input, - int len); - -typedef cmark_node *(*cmark_match_inline_func)(cmark_syntax_extension *extension, - cmark_parser *parser, - cmark_node *parent, - unsigned char character, - cmark_inline_parser *inline_parser); - -typedef delimiter *(*cmark_inline_from_delim_func)(cmark_syntax_extension *extension, - cmark_parser *parser, - cmark_inline_parser *inline_parser, - delimiter *opener, - delimiter *closer); - -/** Should return 'true' if 'input' can be contained in 'container', - * 'false' otherwise. - */ -typedef int (*cmark_match_block_func) (cmark_syntax_extension *extension, - cmark_parser *parser, - unsigned char *input, - int len, - cmark_node *container); - -typedef const char *(*cmark_get_type_string_func) (cmark_syntax_extension *extension, - cmark_node *node); - -typedef int (*cmark_can_contain_func) (cmark_syntax_extension *extension, - cmark_node *node, - cmark_node_type child); - -typedef int (*cmark_contains_inlines_func) (cmark_syntax_extension *extension, - cmark_node *node); - -typedef void (*cmark_common_render_func) (cmark_syntax_extension *extension, - struct cmark_renderer *renderer, - cmark_node *node, - cmark_event_type ev_type, - int options); - -typedef int (*cmark_commonmark_escape_func) (cmark_syntax_extension *extension, - cmark_node *node, - int c); - -typedef const char* (*cmark_xml_attr_func) (cmark_syntax_extension *extension, - cmark_node *node); - -typedef void (*cmark_html_render_func) (cmark_syntax_extension *extension, - struct cmark_html_renderer *renderer, - cmark_node *node, - cmark_event_type ev_type, - int options); - -typedef int (*cmark_html_filter_func) (cmark_syntax_extension *extension, - const unsigned char *tag, - size_t tag_len); - -typedef cmark_node *(*cmark_postprocess_func) (cmark_syntax_extension *extension, - cmark_parser *parser, - cmark_node *root); - -typedef int (*cmark_ispunct_func) (char c); - -typedef void (*cmark_opaque_alloc_func) (cmark_syntax_extension *extension, - cmark_mem *mem, - cmark_node *node); - -typedef void (*cmark_opaque_free_func) (cmark_syntax_extension *extension, - cmark_mem *mem, - cmark_node *node); - -/** Free a cmark_syntax_extension. - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_free (cmark_mem *mem, cmark_syntax_extension *extension); - -/** Return a newly-constructed cmark_syntax_extension, named 'name'. - */ -CMARK_GFM_EXPORT -cmark_syntax_extension *cmark_syntax_extension_new (const char *name); - -CMARK_GFM_EXPORT -cmark_node_type cmark_syntax_extension_add_node(int is_inline); - -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_emphasis(cmark_syntax_extension *extension, int emphasis); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_open_block_func(cmark_syntax_extension *extension, - cmark_open_block_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_match_block_func(cmark_syntax_extension *extension, - cmark_match_block_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_match_inline_func(cmark_syntax_extension *extension, - cmark_match_inline_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_inline_from_delim_func(cmark_syntax_extension *extension, - cmark_inline_from_delim_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_special_inline_chars(cmark_syntax_extension *extension, - cmark_llist *special_chars); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_get_type_string_func(cmark_syntax_extension *extension, - cmark_get_type_string_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_can_contain_func(cmark_syntax_extension *extension, - cmark_can_contain_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_contains_inlines_func(cmark_syntax_extension *extension, - cmark_contains_inlines_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_commonmark_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_plaintext_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_latex_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_xml_attr_func(cmark_syntax_extension *extension, - cmark_xml_attr_func func); - - /** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_man_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_html_render_func(cmark_syntax_extension *extension, - cmark_html_render_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_html_filter_func(cmark_syntax_extension *extension, - cmark_html_filter_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_commonmark_escape_func(cmark_syntax_extension *extension, - cmark_commonmark_escape_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_private(cmark_syntax_extension *extension, - void *priv, - cmark_free_func free_func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void *cmark_syntax_extension_get_private(cmark_syntax_extension *extension); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_postprocess_func(cmark_syntax_extension *extension, - cmark_postprocess_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_opaque_alloc_func(cmark_syntax_extension *extension, - cmark_opaque_alloc_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_syntax_extension_set_opaque_free_func(cmark_syntax_extension *extension, - cmark_opaque_free_func func); - -/** See the documentation for 'cmark_syntax_extension' - */ -CMARK_GFM_EXPORT -void cmark_parser_set_backslash_ispunct_func(cmark_parser *parser, - cmark_ispunct_func func); - -/** Return the index of the line currently being parsed, starting with 1. - */ -CMARK_GFM_EXPORT -int cmark_parser_get_line_number(cmark_parser *parser); - -/** Return the offset in bytes in the line being processed. - * - * Example: - * - * ### foo - * - * Here, offset will first be 0, then 5 (the index of the 'f' character). - */ -CMARK_GFM_EXPORT -int cmark_parser_get_offset(cmark_parser *parser); - -/** - * Return the offset in 'columns' in the line being processed. - * - * This value may differ from the value returned by - * cmark_parser_get_offset() in that it accounts for tabs, - * and as such should not be used as an index in the current line's - * buffer. - * - * Example: - * - * cmark_parser_advance_offset() can be called to advance the - * offset by a number of columns, instead of a number of bytes. - * - * In that case, if offset falls "in the middle" of a tab - * character, 'column' and offset will differ. - * - * ``` - * foo \t bar - * ^ ^^ - * offset (0) 20 - * ``` - * - * If cmark_parser_advance_offset is called here with 'columns' - * set to 'true' and 'offset' set to 22, cmark_parser_get_offset() - * will return 20, whereas cmark_parser_get_column() will return - * 22. - * - * Additionally, as tabs expand to the next multiple of 4 column, - * cmark_parser_has_partially_consumed_tab() will now return - * 'true'. - */ -CMARK_GFM_EXPORT -int cmark_parser_get_column(cmark_parser *parser); - -/** Return the absolute index in bytes of the first nonspace - * character coming after the offset as returned by - * cmark_parser_get_offset() in the line currently being processed. - * - * Example: - * - * ``` - * foo bar baz \n - * ^ ^ ^ - * 0 offset (16) first_nonspace (28) - * ``` - */ -CMARK_GFM_EXPORT -int cmark_parser_get_first_nonspace(cmark_parser *parser); - -/** Return the absolute index of the first nonspace column coming after 'offset' - * in the line currently being processed, counting tabs as multiple - * columns as appropriate. - * - * See the documentation for cmark_parser_get_first_nonspace() and - * cmark_parser_get_column() for more information. - */ -CMARK_GFM_EXPORT -int cmark_parser_get_first_nonspace_column(cmark_parser *parser); - -/** Return the difference between the values returned by - * cmark_parser_get_first_nonspace_column() and - * cmark_parser_get_column(). - * - * This is not a byte offset, as it can count one tab as multiple - * characters. - */ -CMARK_GFM_EXPORT -int cmark_parser_get_indent(cmark_parser *parser); - -/** Return 'true' if the line currently being processed has been entirely - * consumed, 'false' otherwise. - * - * Example: - * - * ``` - * foo bar baz \n - * ^ - * offset - * ``` - * - * This function will return 'false' here. - * - * ``` - * foo bar baz \n - * ^ - * offset - * ``` - * This function will still return 'false'. - * - * ``` - * foo bar baz \n - * ^ - * offset - * ``` - * - * At this point, this function will now return 'true'. - */ -CMARK_GFM_EXPORT -int cmark_parser_is_blank(cmark_parser *parser); - -/** Return 'true' if the value returned by cmark_parser_get_offset() - * is 'inside' an expanded tab. - * - * See the documentation for cmark_parser_get_column() for more - * information. - */ -CMARK_GFM_EXPORT -int cmark_parser_has_partially_consumed_tab(cmark_parser *parser); - -/** Return the length in bytes of the previously processed line, excluding potential - * newline (\n) and carriage return (\r) trailing characters. - */ -CMARK_GFM_EXPORT -int cmark_parser_get_last_line_length(cmark_parser *parser); - -/** Add a child to 'parent' during the parsing process. - * - * If 'parent' isn't the kind of node that can accept this child, - * this function will back up till it hits a node that can, closing - * blocks as appropriate. - */ -CMARK_GFM_EXPORT -cmark_node*cmark_parser_add_child(cmark_parser *parser, - cmark_node *parent, - cmark_node_type block_type, - int start_column); - -/** Advance the 'offset' of the parser in the current line. - * - * See the documentation of cmark_parser_get_offset() and - * cmark_parser_get_column() for more information. - */ -CMARK_GFM_EXPORT -void cmark_parser_advance_offset(cmark_parser *parser, - const char *input, - int count, - int columns); - - -CMARK_GFM_EXPORT -void cmark_parser_feed_reentrant(cmark_parser *parser, const char *buffer, size_t len); - -/** Attach the syntax 'extension' to the 'parser', to provide extra syntax - * rules. - * See the documentation for cmark_syntax_extension for more information. - * - * Returns 'true' if the 'extension' was successfully attached, - * 'false' otherwise. - */ -CMARK_GFM_EXPORT -int cmark_parser_attach_syntax_extension(cmark_parser *parser, cmark_syntax_extension *extension); - -/** Change the type of 'node'. - * - * Return 0 if the type could be changed, 1 otherwise. - */ -CMARK_GFM_EXPORT int cmark_node_set_type(cmark_node *node, cmark_node_type type); - -/** Return the string content for all types of 'node'. - * The pointer stays valid as long as 'node' isn't freed. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_string_content(cmark_node *node); - -/** Set the string 'content' for all types of 'node'. - * Copies 'content'. - */ -CMARK_GFM_EXPORT int cmark_node_set_string_content(cmark_node *node, const char *content); - -/** Get the syntax extension responsible for the creation of 'node'. - * Return NULL if 'node' was created because it matched standard syntax rules. - */ -CMARK_GFM_EXPORT cmark_syntax_extension *cmark_node_get_syntax_extension(cmark_node *node); - -/** Set the syntax extension responsible for creating 'node'. - */ -CMARK_GFM_EXPORT int cmark_node_set_syntax_extension(cmark_node *node, - cmark_syntax_extension *extension); - -/** - * ## Inline syntax extension helpers - * - * The inline parsing process is described in detail at - * - */ - -/** Should return 'true' if the predicate matches 'c', 'false' otherwise - */ -typedef int (*cmark_inline_predicate)(int c); - -/** Advance the current inline parsing offset */ -CMARK_GFM_EXPORT -void cmark_inline_parser_advance_offset(cmark_inline_parser *parser); - -/** Get the current inline parsing offset */ -CMARK_GFM_EXPORT -int cmark_inline_parser_get_offset(cmark_inline_parser *parser); - -/** Set the offset in bytes in the chunk being processed by the given inline parser. - */ -CMARK_GFM_EXPORT -void cmark_inline_parser_set_offset(cmark_inline_parser *parser, int offset); - -/** Gets the cmark_chunk being operated on by the given inline parser. - * Use cmark_inline_parser_get_offset to get our current position in the chunk. - */ -CMARK_GFM_EXPORT -struct cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser); - -/** Returns 1 if the inline parser is currently in a bracket; pass 1 for 'image' - * if you want to know about an image-type bracket, 0 for link-type. */ -CMARK_GFM_EXPORT -int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image); - -/** Remove the last n characters from the last child of the given node. - * This only works where all n characters are in the single last child, and the last - * child is CMARK_NODE_TEXT. - */ -CMARK_GFM_EXPORT -void cmark_node_unput(cmark_node *node, int n); - - -/** Get the character located at the current inline parsing offset - */ -CMARK_GFM_EXPORT -unsigned char cmark_inline_parser_peek_char(cmark_inline_parser *parser); - -/** Get the character located 'pos' bytes in the current line. - */ -CMARK_GFM_EXPORT -unsigned char cmark_inline_parser_peek_at(cmark_inline_parser *parser, int pos); - -/** Whether the inline parser has reached the end of the current line - */ -CMARK_GFM_EXPORT -int cmark_inline_parser_is_eof(cmark_inline_parser *parser); - -/** Get the characters located after the current inline parsing offset - * while 'pred' matches. Free after usage. - */ -CMARK_GFM_EXPORT -char *cmark_inline_parser_take_while(cmark_inline_parser *parser, cmark_inline_predicate pred); - -/** Push a delimiter on the delimiter stack. - * See < for - * more information on the parameters - */ -CMARK_GFM_EXPORT -void cmark_inline_parser_push_delimiter(cmark_inline_parser *parser, - unsigned char c, - int can_open, - int can_close, - cmark_node *inl_text); - -/** Remove 'delim' from the delimiter stack - */ -CMARK_GFM_EXPORT -void cmark_inline_parser_remove_delimiter(cmark_inline_parser *parser, delimiter *delim); - -CMARK_GFM_EXPORT -delimiter *cmark_inline_parser_get_last_delimiter(cmark_inline_parser *parser); - -CMARK_GFM_EXPORT -int cmark_inline_parser_get_line(cmark_inline_parser *parser); - -CMARK_GFM_EXPORT -int cmark_inline_parser_get_column(cmark_inline_parser *parser); - -/** Convenience function to scan a given delimiter. - * - * 'left_flanking' and 'right_flanking' will be set to true if they - * respectively precede and follow a non-space, non-punctuation - * character. - * - * Additionally, 'punct_before' and 'punct_after' will respectively be set - * if the preceding or following character is a punctuation character. - * - * Note that 'left_flanking' and 'right_flanking' can both be 'true'. - * - * Returns the number of delimiters encountered, in the limit - * of 'max_delims', and advances the inline parsing offset. - */ -CMARK_GFM_EXPORT -int cmark_inline_parser_scan_delimiters(cmark_inline_parser *parser, - int max_delims, - unsigned char c, - int *left_flanking, - int *right_flanking, - int *punct_before, - int *punct_after); - -CMARK_GFM_EXPORT -void cmark_manage_extensions_special_characters(cmark_parser *parser, int add); - -CMARK_GFM_EXPORT -cmark_llist *cmark_parser_get_syntax_extensions(cmark_parser *parser); - -CMARK_GFM_EXPORT -void cmark_arena_push(void); - -CMARK_GFM_EXPORT -int cmark_arena_pop(void); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/cmark-gfm-extensions_export.h b/ext/commonmarker/cmark-gfm-extensions_export.h deleted file mode 100644 index 69c0bd78..00000000 --- a/ext/commonmarker/cmark-gfm-extensions_export.h +++ /dev/null @@ -1,42 +0,0 @@ - -#ifndef CMARK_GFM_EXTENSIONS_EXPORT_H -#define CMARK_GFM_EXTENSIONS_EXPORT_H - -#ifdef CMARK_GFM_EXTENSIONS_STATIC_DEFINE -# define CMARK_GFM_EXTENSIONS_EXPORT -# define CMARK_GFM_EXTENSIONS_NO_EXPORT -#else -# ifndef CMARK_GFM_EXTENSIONS_EXPORT -# ifdef libcmark_gfm_extensions_EXPORTS - /* We are building this library */ -# define CMARK_GFM_EXTENSIONS_EXPORT __attribute__((visibility("default"))) -# else - /* We are using this library */ -# define CMARK_GFM_EXTENSIONS_EXPORT __attribute__((visibility("default"))) -# endif -# endif - -# ifndef CMARK_GFM_EXTENSIONS_NO_EXPORT -# define CMARK_GFM_EXTENSIONS_NO_EXPORT __attribute__((visibility("hidden"))) -# endif -#endif - -#ifndef CMARK_GFM_EXTENSIONS_DEPRECATED -# define CMARK_GFM_EXTENSIONS_DEPRECATED __attribute__ ((__deprecated__)) -#endif - -#ifndef CMARK_GFM_EXTENSIONS_DEPRECATED_EXPORT -# define CMARK_GFM_EXTENSIONS_DEPRECATED_EXPORT CMARK_GFM_EXTENSIONS_EXPORT CMARK_GFM_EXTENSIONS_DEPRECATED -#endif - -#ifndef CMARK_GFM_EXTENSIONS_DEPRECATED_NO_EXPORT -# define CMARK_GFM_EXTENSIONS_DEPRECATED_NO_EXPORT CMARK_GFM_EXTENSIONS_NO_EXPORT CMARK_GFM_EXTENSIONS_DEPRECATED -#endif - -#if 0 /* DEFINE_NO_DEPRECATED */ -# ifndef CMARK_GFM_EXTENSIONS_NO_DEPRECATED -# define CMARK_GFM_EXTENSIONS_NO_DEPRECATED -# endif -#endif - -#endif /* CMARK_GFM_EXTENSIONS_EXPORT_H */ diff --git a/ext/commonmarker/cmark-gfm.h b/ext/commonmarker/cmark-gfm.h deleted file mode 100644 index 6fb28693..00000000 --- a/ext/commonmarker/cmark-gfm.h +++ /dev/null @@ -1,817 +0,0 @@ -#ifndef CMARK_GFM_H -#define CMARK_GFM_H - -#include -#include -#include "cmark-gfm_export.h" -#include "cmark-gfm_version.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** # NAME - * - * **cmark-gfm** - CommonMark parsing, manipulating, and rendering - */ - -/** # DESCRIPTION - * - * ## Simple Interface - */ - -/** Convert 'text' (assumed to be a UTF-8 encoded string with length - * 'len') from CommonMark Markdown to HTML, returning a null-terminated, - * UTF-8-encoded string. It is the caller's responsibility - * to free the returned buffer. - */ -CMARK_GFM_EXPORT -char *cmark_markdown_to_html(const char *text, size_t len, int options); - -/** ## Node Structure - */ - -#define CMARK_NODE_TYPE_PRESENT (0x8000) -#define CMARK_NODE_TYPE_BLOCK (CMARK_NODE_TYPE_PRESENT | 0x0000) -#define CMARK_NODE_TYPE_INLINE (CMARK_NODE_TYPE_PRESENT | 0x4000) -#define CMARK_NODE_TYPE_MASK (0xc000) -#define CMARK_NODE_VALUE_MASK (0x3fff) - -typedef enum { - /* Error status */ - CMARK_NODE_NONE = 0x0000, - - /* Block */ - CMARK_NODE_DOCUMENT = CMARK_NODE_TYPE_BLOCK | 0x0001, - CMARK_NODE_BLOCK_QUOTE = CMARK_NODE_TYPE_BLOCK | 0x0002, - CMARK_NODE_LIST = CMARK_NODE_TYPE_BLOCK | 0x0003, - CMARK_NODE_ITEM = CMARK_NODE_TYPE_BLOCK | 0x0004, - CMARK_NODE_CODE_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0005, - CMARK_NODE_HTML_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0006, - CMARK_NODE_CUSTOM_BLOCK = CMARK_NODE_TYPE_BLOCK | 0x0007, - CMARK_NODE_PARAGRAPH = CMARK_NODE_TYPE_BLOCK | 0x0008, - CMARK_NODE_HEADING = CMARK_NODE_TYPE_BLOCK | 0x0009, - CMARK_NODE_THEMATIC_BREAK = CMARK_NODE_TYPE_BLOCK | 0x000a, - CMARK_NODE_FOOTNOTE_DEFINITION = CMARK_NODE_TYPE_BLOCK | 0x000b, - - /* Inline */ - CMARK_NODE_TEXT = CMARK_NODE_TYPE_INLINE | 0x0001, - CMARK_NODE_SOFTBREAK = CMARK_NODE_TYPE_INLINE | 0x0002, - CMARK_NODE_LINEBREAK = CMARK_NODE_TYPE_INLINE | 0x0003, - CMARK_NODE_CODE = CMARK_NODE_TYPE_INLINE | 0x0004, - CMARK_NODE_HTML_INLINE = CMARK_NODE_TYPE_INLINE | 0x0005, - CMARK_NODE_CUSTOM_INLINE = CMARK_NODE_TYPE_INLINE | 0x0006, - CMARK_NODE_EMPH = CMARK_NODE_TYPE_INLINE | 0x0007, - CMARK_NODE_STRONG = CMARK_NODE_TYPE_INLINE | 0x0008, - CMARK_NODE_LINK = CMARK_NODE_TYPE_INLINE | 0x0009, - CMARK_NODE_IMAGE = CMARK_NODE_TYPE_INLINE | 0x000a, - CMARK_NODE_FOOTNOTE_REFERENCE = CMARK_NODE_TYPE_INLINE | 0x000b, -} cmark_node_type; - -extern cmark_node_type CMARK_NODE_LAST_BLOCK; -extern cmark_node_type CMARK_NODE_LAST_INLINE; - -/* For backwards compatibility: */ -#define CMARK_NODE_HEADER CMARK_NODE_HEADING -#define CMARK_NODE_HRULE CMARK_NODE_THEMATIC_BREAK -#define CMARK_NODE_HTML CMARK_NODE_HTML_BLOCK -#define CMARK_NODE_INLINE_HTML CMARK_NODE_HTML_INLINE - -typedef enum { - CMARK_NO_LIST, - CMARK_BULLET_LIST, - CMARK_ORDERED_LIST -} cmark_list_type; - -typedef enum { - CMARK_NO_DELIM, - CMARK_PERIOD_DELIM, - CMARK_PAREN_DELIM -} cmark_delim_type; - -typedef struct cmark_node cmark_node; -typedef struct cmark_parser cmark_parser; -typedef struct cmark_iter cmark_iter; -typedef struct cmark_syntax_extension cmark_syntax_extension; - -/** - * ## Custom memory allocator support - */ - -/** Defines the memory allocation functions to be used by CMark - * when parsing and allocating a document tree - */ -typedef struct cmark_mem { - void *(*calloc)(size_t, size_t); - void *(*realloc)(void *, size_t); - void (*free)(void *); -} cmark_mem; - -/** The default memory allocator; uses the system's calloc, - * realloc and free. - */ -CMARK_GFM_EXPORT -cmark_mem *cmark_get_default_mem_allocator(); - -/** An arena allocator; uses system calloc to allocate large - * slabs of memory. Memory in these slabs is not reused at all. - */ -CMARK_GFM_EXPORT -cmark_mem *cmark_get_arena_mem_allocator(); - -/** Resets the arena allocator, quickly returning all used memory - * to the operating system. - */ -CMARK_GFM_EXPORT -void cmark_arena_reset(void); - -/** Callback for freeing user data with a 'cmark_mem' context. - */ -typedef void (*cmark_free_func) (cmark_mem *mem, void *user_data); - - -/* - * ## Basic data structures - * - * To keep dependencies to the strict minimum, libcmark implements - * its own versions of "classic" data structures. - */ - -/** - * ### Linked list - */ - -/** A generic singly linked list. - */ -typedef struct _cmark_llist -{ - struct _cmark_llist *next; - void *data; -} cmark_llist; - -/** Append an element to the linked list, return the possibly modified - * head of the list. - */ -CMARK_GFM_EXPORT -cmark_llist * cmark_llist_append (cmark_mem * mem, - cmark_llist * head, - void * data); - -/** Free the list starting with 'head', calling 'free_func' with the - * data pointer of each of its elements - */ -CMARK_GFM_EXPORT -void cmark_llist_free_full (cmark_mem * mem, - cmark_llist * head, - cmark_free_func free_func); - -/** Free the list starting with 'head' - */ -CMARK_GFM_EXPORT -void cmark_llist_free (cmark_mem * mem, - cmark_llist * head); - -/** - * ## Creating and Destroying Nodes - */ - -/** Creates a new node of type 'type'. Note that the node may have - * other required properties, which it is the caller's responsibility - * to assign. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_new(cmark_node_type type); - -/** Same as `cmark_node_new`, 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. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_new_with_mem(cmark_node_type type, - cmark_mem *mem); - -CMARK_GFM_EXPORT cmark_node *cmark_node_new_with_ext(cmark_node_type type, - cmark_syntax_extension *extension); - -CMARK_GFM_EXPORT cmark_node *cmark_node_new_with_mem_and_ext(cmark_node_type type, - cmark_mem *mem, - cmark_syntax_extension *extension); - -/** Frees the memory allocated for a node and any children. - */ -CMARK_GFM_EXPORT void cmark_node_free(cmark_node *node); - -/** - * ## Tree Traversal - */ - -/** Returns the next node in the sequence after 'node', or NULL if - * there is none. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_next(cmark_node *node); - -/** Returns the previous node in the sequence after 'node', or NULL if - * there is none. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_previous(cmark_node *node); - -/** Returns the parent of 'node', or NULL if there is none. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_parent(cmark_node *node); - -/** Returns the first child of 'node', or NULL if 'node' has no children. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_first_child(cmark_node *node); - -/** Returns the last child of 'node', or NULL if 'node' has no children. - */ -CMARK_GFM_EXPORT cmark_node *cmark_node_last_child(cmark_node *node); - -/** - * ## Iterator - * - * 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 'cmark_event_type' of `CMARK_EVENT_EXIT`). The iterator will - * return `CMARK_EVENT_DONE` when it reaches the root node again. - * One natural application is an HTML renderer, where an `ENTER` event - * outputs an open tag and an `EXIT` 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. - * - * 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); - * } - * - * Iterators will never return `EXIT` events for leaf nodes, which are nodes - * of type: - * - * * CMARK_NODE_HTML_BLOCK - * * CMARK_NODE_THEMATIC_BREAK - * * CMARK_NODE_CODE_BLOCK - * * CMARK_NODE_TEXT - * * CMARK_NODE_SOFTBREAK - * * CMARK_NODE_LINEBREAK - * * CMARK_NODE_CODE - * * CMARK_NODE_HTML_INLINE - * - * Nodes must only be modified after an `EXIT` event, or an `ENTER` event for - * leaf nodes. - */ - -typedef enum { - CMARK_EVENT_NONE, - CMARK_EVENT_DONE, - CMARK_EVENT_ENTER, - CMARK_EVENT_EXIT -} cmark_event_type; - -/** Creates a new iterator starting at 'root'. The current node and event - * type are undefined until 'cmark_iter_next' is called for the first time. - * The memory allocated for the iterator should be released using - * 'cmark_iter_free' when it is no longer needed. - */ -CMARK_GFM_EXPORT -cmark_iter *cmark_iter_new(cmark_node *root); - -/** Frees the memory allocated for an iterator. - */ -CMARK_GFM_EXPORT -void cmark_iter_free(cmark_iter *iter); - -/** Advances to the next node and returns the event type (`CMARK_EVENT_ENTER`, - * `CMARK_EVENT_EXIT` or `CMARK_EVENT_DONE`). - */ -CMARK_GFM_EXPORT -cmark_event_type cmark_iter_next(cmark_iter *iter); - -/** Returns the current node. - */ -CMARK_GFM_EXPORT -cmark_node *cmark_iter_get_node(cmark_iter *iter); - -/** Returns the current event type. - */ -CMARK_GFM_EXPORT -cmark_event_type cmark_iter_get_event_type(cmark_iter *iter); - -/** Returns the root node. - */ -CMARK_GFM_EXPORT -cmark_node *cmark_iter_get_root(cmark_iter *iter); - -/** Resets the iterator so that the current node is 'current' and - * the event type is 'event_type'. The new current node must be a - * descendant of the root node or the root node itself. - */ -CMARK_GFM_EXPORT -void cmark_iter_reset(cmark_iter *iter, cmark_node *current, - cmark_event_type event_type); - -/** - * ## Accessors - */ - -/** Returns the user data of 'node'. - */ -CMARK_GFM_EXPORT void *cmark_node_get_user_data(cmark_node *node); - -/** Sets arbitrary user data for 'node'. Returns 1 on success, - * 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_user_data(cmark_node *node, void *user_data); - -/** Set free function for user data */ -CMARK_GFM_EXPORT -int cmark_node_set_user_data_free_func(cmark_node *node, - cmark_free_func free_func); - -/** Returns the type of 'node', or `CMARK_NODE_NONE` on error. - */ -CMARK_GFM_EXPORT cmark_node_type cmark_node_get_type(cmark_node *node); - -/** Like 'cmark_node_get_type', but returns a string representation - of the type, or `""`. - */ -CMARK_GFM_EXPORT -const char *cmark_node_get_type_string(cmark_node *node); - -/** Returns the string contents of 'node', or an empty - string if none is set. Returns NULL if called on a - node that does not have string content. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_literal(cmark_node *node); - -/** Sets the string contents of 'node'. Returns 1 on success, - * 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_literal(cmark_node *node, const char *content); - -/** Returns the heading level of 'node', or 0 if 'node' is not a heading. - */ -CMARK_GFM_EXPORT int cmark_node_get_heading_level(cmark_node *node); - -/* For backwards compatibility */ -#define cmark_node_get_header_level cmark_node_get_heading_level -#define cmark_node_set_header_level cmark_node_set_heading_level - -/** Sets the heading level of 'node', returning 1 on success and 0 on error. - */ -CMARK_GFM_EXPORT int cmark_node_set_heading_level(cmark_node *node, int level); - -/** Returns the list type of 'node', or `CMARK_NO_LIST` if 'node' - * is not a list. - */ -CMARK_GFM_EXPORT cmark_list_type cmark_node_get_list_type(cmark_node *node); - -/** Sets the list type of 'node', returning 1 on success and 0 on error. - */ -CMARK_GFM_EXPORT int cmark_node_set_list_type(cmark_node *node, - cmark_list_type type); - -/** Returns the list delimiter type of 'node', or `CMARK_NO_DELIM` if 'node' - * is not a list. - */ -CMARK_GFM_EXPORT cmark_delim_type cmark_node_get_list_delim(cmark_node *node); - -/** Sets the list delimiter type of 'node', returning 1 on success and 0 - * on error. - */ -CMARK_GFM_EXPORT int cmark_node_set_list_delim(cmark_node *node, - cmark_delim_type delim); - -/** Returns starting number of 'node', if it is an ordered list, otherwise 0. - */ -CMARK_GFM_EXPORT int cmark_node_get_list_start(cmark_node *node); - -/** Sets starting number of 'node', if it is an ordered list. Returns 1 - * on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_list_start(cmark_node *node, int start); - -/** Returns 1 if 'node' is a tight list, 0 otherwise. - */ -CMARK_GFM_EXPORT int cmark_node_get_list_tight(cmark_node *node); - -/** Sets the "tightness" of a list. Returns 1 on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_list_tight(cmark_node *node, int tight); - -/** Returns the info string from a fenced code block. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_fence_info(cmark_node *node); - -/** Sets the info string in a fenced code block, returning 1 on - * success and 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_fence_info(cmark_node *node, const char *info); - -/** Sets code blocks fencing details - */ -CMARK_GFM_EXPORT int cmark_node_set_fenced(cmark_node * node, int fenced, - int length, int offset, char character); - -/** Returns code blocks fencing details - */ -CMARK_GFM_EXPORT int cmark_node_get_fenced(cmark_node *node, int *length, int *offset, char *character); - -/** Returns the URL of a link or image 'node', or an empty string - if no URL is set. Returns NULL if called on a node that is - not a link or image. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_url(cmark_node *node); - -/** Sets the URL of a link or image 'node'. Returns 1 on success, - * 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_url(cmark_node *node, const char *url); - -/** Returns the title of a link or image 'node', or an empty - string if no title is set. Returns NULL if called on a node - that is not a link or image. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_title(cmark_node *node); - -/** Sets the title of a link or image 'node'. Returns 1 on success, - * 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_title(cmark_node *node, const char *title); - -/** Returns the literal "on enter" text for a custom 'node', or - an empty string if no on_enter is set. Returns NULL if called - on a non-custom node. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_on_enter(cmark_node *node); - -/** Sets the literal text to render "on enter" for a custom 'node'. - Any children of the node will be rendered after this text. - Returns 1 on success 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_on_enter(cmark_node *node, - const char *on_enter); - -/** Returns the literal "on exit" text for a custom 'node', or - an empty string if no on_exit is set. Returns NULL if - called on a non-custom node. - */ -CMARK_GFM_EXPORT const char *cmark_node_get_on_exit(cmark_node *node); - -/** Sets the literal text to render "on exit" for a custom 'node'. - Any children of the node will be rendered before this text. - Returns 1 on success 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_set_on_exit(cmark_node *node, const char *on_exit); - -/** Returns the line on which 'node' begins. - */ -CMARK_GFM_EXPORT int cmark_node_get_start_line(cmark_node *node); - -/** Returns the column at which 'node' begins. - */ -CMARK_GFM_EXPORT int cmark_node_get_start_column(cmark_node *node); - -/** Returns the line on which 'node' ends. - */ -CMARK_GFM_EXPORT int cmark_node_get_end_line(cmark_node *node); - -/** Returns the column at which 'node' ends. - */ -CMARK_GFM_EXPORT int cmark_node_get_end_column(cmark_node *node); - -/** - * ## Tree Manipulation - */ - -/** Unlinks a 'node', removing it from the tree, but not freeing its - * memory. (Use 'cmark_node_free' for that.) - */ -CMARK_GFM_EXPORT void cmark_node_unlink(cmark_node *node); - -/** Inserts 'sibling' before 'node'. Returns 1 on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_insert_before(cmark_node *node, - cmark_node *sibling); - -/** Inserts 'sibling' after 'node'. Returns 1 on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_insert_after(cmark_node *node, cmark_node *sibling); - -/** Replaces 'oldnode' with 'newnode' and unlinks 'oldnode' (but does - * not free its memory). - * Returns 1 on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode); - -/** Adds 'child' to the beginning of the children of 'node'. - * Returns 1 on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_prepend_child(cmark_node *node, cmark_node *child); - -/** Adds 'child' to the end of the children of 'node'. - * Returns 1 on success, 0 on failure. - */ -CMARK_GFM_EXPORT int cmark_node_append_child(cmark_node *node, cmark_node *child); - -/** Consolidates adjacent text nodes. - */ -CMARK_GFM_EXPORT void cmark_consolidate_text_nodes(cmark_node *root); - -/** Ensures a node and all its children own their own chunk memory. - */ -CMARK_GFM_EXPORT void cmark_node_own(cmark_node *root); - -/** - * ## Parsing - * - * Simple interface: - * - * cmark_node *document = cmark_parse_document("Hello *world*", 13, - * CMARK_OPT_DEFAULT); - * - * Streaming interface: - * - * 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); - */ - -/** Creates a new parser object. - */ -CMARK_GFM_EXPORT -cmark_parser *cmark_parser_new(int options); - -/** Creates a new parser object with the given memory allocator - */ -CMARK_GFM_EXPORT -cmark_parser *cmark_parser_new_with_mem(int options, cmark_mem *mem); - -/** Frees memory allocated for a parser object. - */ -CMARK_GFM_EXPORT -void cmark_parser_free(cmark_parser *parser); - -/** Feeds a string of length 'len' to 'parser'. - */ -CMARK_GFM_EXPORT -void cmark_parser_feed(cmark_parser *parser, const char *buffer, size_t len); - -/** Finish parsing and return a pointer to a tree of nodes. - */ -CMARK_GFM_EXPORT -cmark_node *cmark_parser_finish(cmark_parser *parser); - -/** Parse a CommonMark document in 'buffer' of length 'len'. - * Returns a pointer to a tree of nodes. The memory allocated for - * the node tree should be released using 'cmark_node_free' - * when it is no longer needed. - */ -CMARK_GFM_EXPORT -cmark_node *cmark_parse_document(const char *buffer, size_t len, int options); - -/** Parse a CommonMark document in file 'f', returning a pointer to - * a tree of nodes. The memory allocated for the node tree should be - * released using 'cmark_node_free' when it is no longer needed. - */ -CMARK_GFM_EXPORT -cmark_node *cmark_parse_file(FILE *f, int options); - -/** - * ## Rendering - */ - -/** Render a 'node' tree as XML. It is the caller's responsibility - * to free the returned buffer. - */ -CMARK_GFM_EXPORT -char *cmark_render_xml(cmark_node *root, int options); - -/** As for 'cmark_render_xml', but specifying the allocator to use for - * the resulting string. - */ -CMARK_GFM_EXPORT -char *cmark_render_xml_with_mem(cmark_node *root, int options, cmark_mem *mem); - -/** Render a 'node' 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. - */ -CMARK_GFM_EXPORT -char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions); - -/** As for 'cmark_render_html', but specifying the allocator to use for - * the resulting string. - */ -CMARK_GFM_EXPORT -char *cmark_render_html_with_mem(cmark_node *root, int options, cmark_llist *extensions, cmark_mem *mem); - -/** Render a 'node' tree as a groff man page, without the header. - * It is the caller's responsibility to free the returned buffer. - */ -CMARK_GFM_EXPORT -char *cmark_render_man(cmark_node *root, int options, int width); - -/** As for 'cmark_render_man', but specifying the allocator to use for - * the resulting string. - */ -CMARK_GFM_EXPORT -char *cmark_render_man_with_mem(cmark_node *root, int options, int width, cmark_mem *mem); - -/** Render a 'node' tree as a commonmark document. - * It is the caller's responsibility to free the returned buffer. - */ -CMARK_GFM_EXPORT -char *cmark_render_commonmark(cmark_node *root, int options, int width); - -/** As for 'cmark_render_commonmark', but specifying the allocator to use for - * the resulting string. - */ -CMARK_GFM_EXPORT -char *cmark_render_commonmark_with_mem(cmark_node *root, int options, int width, cmark_mem *mem); - -/** Render a 'node' tree as a plain text document. - * It is the caller's responsibility to free the returned buffer. - */ -CMARK_GFM_EXPORT -char *cmark_render_plaintext(cmark_node *root, int options, int width); - -/** As for 'cmark_render_plaintext', but specifying the allocator to use for - * the resulting string. - */ -CMARK_GFM_EXPORT -char *cmark_render_plaintext_with_mem(cmark_node *root, int options, int width, cmark_mem *mem); - -/** Render a 'node' tree as a LaTeX document. - * It is the caller's responsibility to free the returned buffer. - */ -CMARK_GFM_EXPORT -char *cmark_render_latex(cmark_node *root, int options, int width); - -/** As for 'cmark_render_latex', but specifying the allocator to use for - * the resulting string. - */ -CMARK_GFM_EXPORT -char *cmark_render_latex_with_mem(cmark_node *root, int options, int width, cmark_mem *mem); - -/** - * ## Options - */ - -/** Default options. - */ -#define CMARK_OPT_DEFAULT 0 - -/** - * ### Options affecting rendering - */ - -/** Include a `data-sourcepos` attribute on all block elements. - */ -#define CMARK_OPT_SOURCEPOS (1 << 1) - -/** Render `softbreak` elements as hard line breaks. - */ -#define CMARK_OPT_HARDBREAKS (1 << 2) - -/** `CMARK_OPT_SAFE` is defined here for API compatibility, - but it no longer has any effect. "Safe" mode is now the default: - set `CMARK_OPT_UNSAFE` to disable it. - */ -#define CMARK_OPT_SAFE (1 << 3) - -/** Render raw HTML and unsafe links (`javascript:`, `vbscript:`, - * `file:`, and `data:`, except for `image/png`, `image/gif`, - * `image/jpeg`, or `image/webp` mime types). By default, - * raw HTML is replaced by a placeholder HTML comment. Unsafe - * links are replaced by empty strings. - */ -#define CMARK_OPT_UNSAFE (1 << 17) - -/** Render `softbreak` elements as spaces. - */ -#define CMARK_OPT_NOBREAKS (1 << 4) - -/** - * ### Options affecting parsing - */ - -/** Legacy option (no effect). - */ -#define CMARK_OPT_NORMALIZE (1 << 8) - -/** Validate UTF-8 in the input before parsing, replacing illegal - * sequences with the replacement character U+FFFD. - */ -#define CMARK_OPT_VALIDATE_UTF8 (1 << 9) - -/** Convert straight quotes to curly, --- to em dashes, -- to en dashes. - */ -#define CMARK_OPT_SMART (1 << 10) - -/** Use GitHub-style
 tags for code blocks instead of 
.
- */
-#define CMARK_OPT_GITHUB_PRE_LANG (1 << 11)
-
-/** Be liberal in interpreting inline HTML tags.
- */
-#define CMARK_OPT_LIBERAL_HTML_TAG (1 << 12)
-
-/** Parse footnotes.
- */
-#define CMARK_OPT_FOOTNOTES (1 << 13)
-
-/** Only parse strikethroughs if surrounded by exactly 2 tildes.
- * Gives some compatibility with redcarpet.
- */
-#define CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE (1 << 14)
-
-/** Use style attributes to align table cells instead of align attributes.
- */
-#define CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES (1 << 15)
-
-/** Include the remainder of the info string in code blocks in
- * a separate attribute.
- */
-#define CMARK_OPT_FULL_INFO_STRING (1 << 16)
-
-/**
- * ## Version information
- */
-
-/** The library version as integer for runtime checks. Also available as
- * macro CMARK_VERSION for compile time checks.
- *
- * * Bits 16-23 contain the major version.
- * * Bits 8-15 contain the minor version.
- * * Bits 0-7 contain the patchlevel.
- *
- * In hexadecimal format, the number 0x010203 represents version 1.2.3.
- */
-CMARK_GFM_EXPORT
-int cmark_version(void);
-
-/** The library version string for runtime checks. Also available as
- * macro CMARK_VERSION_STRING for compile time checks.
- */
-CMARK_GFM_EXPORT
-const char *cmark_version_string(void);
-
-/** # AUTHORS
- *
- * John MacFarlane, Vicent Marti,  Kārlis Gaņģis, Nick Wellnhofer.
- */
-
-#ifndef CMARK_NO_SHORT_NAMES
-#define NODE_DOCUMENT CMARK_NODE_DOCUMENT
-#define NODE_BLOCK_QUOTE CMARK_NODE_BLOCK_QUOTE
-#define NODE_LIST CMARK_NODE_LIST
-#define NODE_ITEM CMARK_NODE_ITEM
-#define NODE_CODE_BLOCK CMARK_NODE_CODE_BLOCK
-#define NODE_HTML_BLOCK CMARK_NODE_HTML_BLOCK
-#define NODE_CUSTOM_BLOCK CMARK_NODE_CUSTOM_BLOCK
-#define NODE_PARAGRAPH CMARK_NODE_PARAGRAPH
-#define NODE_HEADING CMARK_NODE_HEADING
-#define NODE_HEADER CMARK_NODE_HEADER
-#define NODE_THEMATIC_BREAK CMARK_NODE_THEMATIC_BREAK
-#define NODE_HRULE CMARK_NODE_HRULE
-#define NODE_TEXT CMARK_NODE_TEXT
-#define NODE_SOFTBREAK CMARK_NODE_SOFTBREAK
-#define NODE_LINEBREAK CMARK_NODE_LINEBREAK
-#define NODE_CODE CMARK_NODE_CODE
-#define NODE_HTML_INLINE CMARK_NODE_HTML_INLINE
-#define NODE_CUSTOM_INLINE CMARK_NODE_CUSTOM_INLINE
-#define NODE_EMPH CMARK_NODE_EMPH
-#define NODE_STRONG CMARK_NODE_STRONG
-#define NODE_LINK CMARK_NODE_LINK
-#define NODE_IMAGE CMARK_NODE_IMAGE
-#define BULLET_LIST CMARK_BULLET_LIST
-#define ORDERED_LIST CMARK_ORDERED_LIST
-#define PERIOD_DELIM CMARK_PERIOD_DELIM
-#define PAREN_DELIM CMARK_PAREN_DELIM
-#endif
-
-typedef int32_t bufsize_t;
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ext/commonmarker/cmark-gfm_export.h b/ext/commonmarker/cmark-gfm_export.h
deleted file mode 100644
index 699d737f..00000000
--- a/ext/commonmarker/cmark-gfm_export.h
+++ /dev/null
@@ -1,42 +0,0 @@
-
-#ifndef CMARK_GFM_EXPORT_H
-#define CMARK_GFM_EXPORT_H
-
-#ifdef CMARK_GFM_STATIC_DEFINE
-#  define CMARK_GFM_EXPORT
-#  define CMARK_GFM_NO_EXPORT
-#else
-#  ifndef CMARK_GFM_EXPORT
-#    ifdef libcmark_gfm_EXPORTS
-        /* We are building this library */
-#      define CMARK_GFM_EXPORT __attribute__((visibility("default")))
-#    else
-        /* We are using this library */
-#      define CMARK_GFM_EXPORT __attribute__((visibility("default")))
-#    endif
-#  endif
-
-#  ifndef CMARK_GFM_NO_EXPORT
-#    define CMARK_GFM_NO_EXPORT __attribute__((visibility("hidden")))
-#  endif
-#endif
-
-#ifndef CMARK_GFM_DEPRECATED
-#  define CMARK_GFM_DEPRECATED __attribute__ ((__deprecated__))
-#endif
-
-#ifndef CMARK_GFM_DEPRECATED_EXPORT
-#  define CMARK_GFM_DEPRECATED_EXPORT CMARK_GFM_EXPORT CMARK_GFM_DEPRECATED
-#endif
-
-#ifndef CMARK_GFM_DEPRECATED_NO_EXPORT
-#  define CMARK_GFM_DEPRECATED_NO_EXPORT CMARK_GFM_NO_EXPORT CMARK_GFM_DEPRECATED
-#endif
-
-#if 0 /* DEFINE_NO_DEPRECATED */
-#  ifndef CMARK_GFM_NO_DEPRECATED
-#    define CMARK_GFM_NO_DEPRECATED
-#  endif
-#endif
-
-#endif /* CMARK_GFM_EXPORT_H */
diff --git a/ext/commonmarker/cmark-gfm_version.h b/ext/commonmarker/cmark-gfm_version.h
deleted file mode 100644
index ac403d4d..00000000
--- a/ext/commonmarker/cmark-gfm_version.h
+++ /dev/null
@@ -1,7 +0,0 @@
-#ifndef CMARK_GFM_VERSION_H
-#define CMARK_GFM_VERSION_H
-
-#define CMARK_GFM_VERSION ((0 << 24) | (29 << 16) | (0 << 8) | 4)
-#define CMARK_GFM_VERSION_STRING "0.29.0.gfm.4"
-
-#endif
diff --git a/ext/commonmarker/cmark.c b/ext/commonmarker/cmark.c
deleted file mode 100644
index b3fad4b0..00000000
--- a/ext/commonmarker/cmark.c
+++ /dev/null
@@ -1,55 +0,0 @@
-#include 
-#include 
-#include 
-#include "registry.h"
-#include "node.h"
-#include "houdini.h"
-#include "cmark-gfm.h"
-#include "buffer.h"
-
-cmark_node_type CMARK_NODE_LAST_BLOCK = CMARK_NODE_FOOTNOTE_DEFINITION;
-cmark_node_type CMARK_NODE_LAST_INLINE = CMARK_NODE_FOOTNOTE_REFERENCE;
-
-int cmark_version() { return CMARK_GFM_VERSION; }
-
-const char *cmark_version_string() { return CMARK_GFM_VERSION_STRING; }
-
-static void *xcalloc(size_t nmem, size_t size) {
-  void *ptr = calloc(nmem, size);
-  if (!ptr) {
-    fprintf(stderr, "[cmark] calloc returned null pointer, aborting\n");
-    abort();
-  }
-  return ptr;
-}
-
-static void *xrealloc(void *ptr, size_t size) {
-  void *new_ptr = realloc(ptr, size);
-  if (!new_ptr) {
-    fprintf(stderr, "[cmark] realloc returned null pointer, aborting\n");
-    abort();
-  }
-  return new_ptr;
-}
-
-static void xfree(void *ptr) {
-  free(ptr);
-}
-
-cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR = {xcalloc, xrealloc, xfree};
-
-cmark_mem *cmark_get_default_mem_allocator() {
-  return &CMARK_DEFAULT_MEM_ALLOCATOR;
-}
-
-char *cmark_markdown_to_html(const char *text, size_t len, int options) {
-  cmark_node *doc;
-  char *result;
-
-  doc = cmark_parse_document(text, len, options);
-
-  result = cmark_render_html(doc, options, NULL);
-  cmark_node_free(doc);
-
-  return result;
-}
diff --git a/ext/commonmarker/cmark_ctype.c b/ext/commonmarker/cmark_ctype.c
deleted file mode 100644
index c0c4d5b0..00000000
--- a/ext/commonmarker/cmark_ctype.c
+++ /dev/null
@@ -1,44 +0,0 @@
-#include 
-
-#include "cmark_ctype.h"
-
-/** 1 = space, 2 = punct, 3 = digit, 4 = alpha, 0 = other
- */
-static const uint8_t cmark_ctype_class[256] = {
-    /*      0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f */
-    /* 0 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 0,
-    /* 1 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* 2 */ 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
-    /* 3 */ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2,
-    /* 4 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-    /* 5 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 2,
-    /* 6 */ 2, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
-    /* 7 */ 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 2, 2, 2, 2, 0,
-    /* 8 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* 9 */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* a */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* b */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* c */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* d */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* e */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    /* f */ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
-
-/**
- * Returns 1 if c is a "whitespace" character as defined by the spec.
- */
-int cmark_isspace(char c) { return cmark_ctype_class[(uint8_t)c] == 1; }
-
-/**
- * Returns 1 if c is an ascii punctuation character.
- */
-int cmark_ispunct(char c) { return cmark_ctype_class[(uint8_t)c] == 2; }
-
-int cmark_isalnum(char c) {
-  uint8_t result;
-  result = cmark_ctype_class[(uint8_t)c];
-  return (result == 3 || result == 4);
-}
-
-int cmark_isdigit(char c) { return cmark_ctype_class[(uint8_t)c] == 3; }
-
-int cmark_isalpha(char c) { return cmark_ctype_class[(uint8_t)c] == 4; }
diff --git a/ext/commonmarker/cmark_ctype.h b/ext/commonmarker/cmark_ctype.h
deleted file mode 100644
index 67c1cb03..00000000
--- a/ext/commonmarker/cmark_ctype.h
+++ /dev/null
@@ -1,33 +0,0 @@
-#ifndef CMARK_CMARK_CTYPE_H
-#define CMARK_CMARK_CTYPE_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "cmark-gfm_export.h"
-
-/** Locale-independent versions of functions from ctype.h.
- * We want cmark to behave the same no matter what the system locale.
- */
-
-CMARK_GFM_EXPORT
-int cmark_isspace(char c);
-
-CMARK_GFM_EXPORT
-int cmark_ispunct(char c);
-
-CMARK_GFM_EXPORT
-int cmark_isalnum(char c);
-
-CMARK_GFM_EXPORT
-int cmark_isdigit(char c);
-
-CMARK_GFM_EXPORT
-int cmark_isalpha(char c);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ext/commonmarker/commonmark.c b/ext/commonmarker/commonmark.c
deleted file mode 100644
index 2e071944..00000000
--- a/ext/commonmarker/commonmark.c
+++ /dev/null
@@ -1,529 +0,0 @@
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include "config.h"
-#include "cmark-gfm.h"
-#include "node.h"
-#include "buffer.h"
-#include "utf8.h"
-#include "scanners.h"
-#include "render.h"
-#include "syntax_extension.h"
-
-#define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping)
-#define LIT(s) renderer->out(renderer, node, s, false, LITERAL)
-#define CR() renderer->cr(renderer)
-#define BLANKLINE() renderer->blankline(renderer)
-#define ENCODED_SIZE 20
-#define LISTMARKER_SIZE 20
-
-// Functions to convert cmark_nodes to commonmark strings.
-
-static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node, 
-                              cmark_escaping escape,
-                              int32_t c, unsigned char nextc) {
-  bool needs_escaping = false;
-  bool follows_digit =
-      renderer->buffer->size > 0 &&
-      cmark_isdigit(renderer->buffer->ptr[renderer->buffer->size - 1]);
-  char encoded[ENCODED_SIZE];
-
-  needs_escaping =
-      c < 0x80 && escape != LITERAL &&
-      ((escape == NORMAL &&
-        (c < 0x20 ||
-	 c == '*' || c == '_' || c == '[' || c == ']' || c == '#' || c == '<' ||
-         c == '>' || c == '\\' || c == '`' || c == '~' || c == '!' ||
-         (c == '&' && cmark_isalpha(nextc)) || (c == '!' && nextc == '[') ||
-         (renderer->begin_content && (c == '-' || c == '+' || c == '=') &&
-          // begin_content doesn't get set to false til we've passed digits
-          // at the beginning of line, so...
-          !follows_digit) ||
-         (renderer->begin_content && (c == '.' || c == ')') && follows_digit &&
-          (nextc == 0 || cmark_isspace(nextc))))) ||
-       (escape == URL &&
-        (c == '`' || c == '<' || c == '>' || cmark_isspace((char)c) || c == '\\' ||
-         c == ')' || c == '(')) ||
-       (escape == TITLE &&
-        (c == '`' || c == '<' || c == '>' || c == '"' || c == '\\')));
-
-  if (needs_escaping) {
-    if (escape == URL && cmark_isspace((char)c)) {
-      // use percent encoding for spaces
-      snprintf(encoded, ENCODED_SIZE, "%%%2X", c);
-      cmark_strbuf_puts(renderer->buffer, encoded);
-      renderer->column += 3;
-    } else if (cmark_ispunct((char)c)) {
-      cmark_render_ascii(renderer, "\\");
-      cmark_render_code_point(renderer, c);
-    } else { // render as entity
-      snprintf(encoded, ENCODED_SIZE, "&#%d;", c);
-      cmark_strbuf_puts(renderer->buffer, encoded);
-      renderer->column += (int)strlen(encoded);
-    }
-  } else {
-    cmark_render_code_point(renderer, c);
-  }
-}
-
-static int longest_backtick_sequence(const char *code) {
-  int longest = 0;
-  int current = 0;
-  size_t i = 0;
-  size_t code_len = strlen(code);
-  while (i <= code_len) {
-    if (code[i] == '`') {
-      current++;
-    } else {
-      if (current > longest) {
-        longest = current;
-      }
-      current = 0;
-    }
-    i++;
-  }
-  return longest;
-}
-
-static int shortest_unused_backtick_sequence(const char *code) {
-  // note: if the shortest sequence is >= 32, this returns 32
-  // so as not to overflow the bit array.
-  uint32_t used = 1;
-  int current = 0;
-  size_t i = 0;
-  size_t code_len = strlen(code);
-  while (i <= code_len) {
-    if (code[i] == '`') {
-      current++;
-    } else {
-      if (current > 0 && current < 32) {
-        used |= (1U << current);
-      }
-      current = 0;
-    }
-    i++;
-  }
-  // return number of first bit that is 0:
-  i = 0;
-  while (i < 32 && used & 1) {
-    used = used >> 1;
-    i++;
-  }
-  return (int)i;
-}
-
-static bool is_autolink(cmark_node *node) {
-  cmark_chunk *title;
-  cmark_chunk *url;
-  cmark_node *link_text;
-  char *realurl;
-  int realurllen;
-
-  if (node->type != CMARK_NODE_LINK) {
-    return false;
-  }
-
-  url = &node->as.link.url;
-  if (url->len == 0 || scan_scheme(url, 0) == 0) {
-    return false;
-  }
-
-  title = &node->as.link.title;
-  // if it has a title, we can't treat it as an autolink:
-  if (title->len > 0) {
-    return false;
-  }
-
-  link_text = node->first_child;
-  if (link_text == NULL) {
-    return false;
-  }
-  cmark_consolidate_text_nodes(link_text);
-  realurl = (char *)url->data;
-  realurllen = url->len;
-  if (strncmp(realurl, "mailto:", 7) == 0) {
-    realurl += 7;
-    realurllen -= 7;
-  }
-  return (realurllen == link_text->as.literal.len &&
-          strncmp(realurl, (char *)link_text->as.literal.data,
-                  link_text->as.literal.len) == 0);
-}
-
-// if node is a block node, returns node.
-// otherwise returns first block-level node that is an ancestor of node.
-// if there is no block-level ancestor, returns NULL.
-static cmark_node *get_containing_block(cmark_node *node) {
-  while (node) {
-    if (CMARK_NODE_BLOCK_P(node)) {
-      return node;
-    } else {
-      node = node->parent;
-    }
-  }
-  return NULL;
-}
-
-static int S_render_node(cmark_renderer *renderer, cmark_node *node,
-                         cmark_event_type ev_type, int options) {
-  cmark_node *tmp;
-  int list_number;
-  cmark_delim_type list_delim;
-  int numticks;
-  bool extra_spaces;
-  int i;
-  bool entering = (ev_type == CMARK_EVENT_ENTER);
-  const char *info, *code, *title;
-  char fencechar[2] = {'\0', '\0'};
-  size_t info_len, code_len;
-  char listmarker[LISTMARKER_SIZE];
-  char *emph_delim;
-  bool first_in_list_item;
-  bufsize_t marker_width;
-  bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) &&
-                    !(CMARK_OPT_HARDBREAKS & options);
-
-  // Don't adjust tight list status til we've started the list.
-  // Otherwise we loose the blank line between a paragraph and
-  // a following list.
-  if (!(node->type == CMARK_NODE_ITEM && node->prev == NULL && entering)) {
-    tmp = get_containing_block(node);
-    renderer->in_tight_list_item =
-        tmp && // tmp might be NULL if there is no containing block
-        ((tmp->type == CMARK_NODE_ITEM &&
-          cmark_node_get_list_tight(tmp->parent)) ||
-         (tmp && tmp->parent && tmp->parent->type == CMARK_NODE_ITEM &&
-          cmark_node_get_list_tight(tmp->parent->parent)));
-  }
-
-  if (node->extension && node->extension->commonmark_render_func) {
-    node->extension->commonmark_render_func(node->extension, renderer, node, ev_type, options);
-    return 1;
-  }
-
-  switch (node->type) {
-  case CMARK_NODE_DOCUMENT:
-    break;
-
-  case CMARK_NODE_BLOCK_QUOTE:
-    if (entering) {
-      LIT("> ");
-      renderer->begin_content = true;
-      cmark_strbuf_puts(renderer->prefix, "> ");
-    } else {
-      cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 2);
-      BLANKLINE();
-    }
-    break;
-
-  case CMARK_NODE_LIST:
-    if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK ||
-                                    node->next->type == CMARK_NODE_LIST)) {
-      // this ensures that a following indented code block or list will be
-      // inteprereted correctly.
-      CR();
-      LIT("");
-      BLANKLINE();
-    }
-    break;
-
-  case CMARK_NODE_ITEM:
-    if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
-      marker_width = 4;
-    } else {
-      list_number = cmark_node_get_list_start(node->parent);
-      list_delim = cmark_node_get_list_delim(node->parent);
-      tmp = node;
-      while (tmp->prev) {
-        tmp = tmp->prev;
-        list_number += 1;
-      }
-      // we ensure a width of at least 4 so
-      // we get nice transition from single digits
-      // to double
-      snprintf(listmarker, LISTMARKER_SIZE, "%d%s%s", list_number,
-               list_delim == CMARK_PAREN_DELIM ? ")" : ".",
-               list_number < 10 ? "  " : " ");
-      marker_width = (bufsize_t)strlen(listmarker);
-    }
-    if (entering) {
-      if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) {
-        LIT("  - ");
-        renderer->begin_content = true;
-      } else {
-        LIT(listmarker);
-        renderer->begin_content = true;
-      }
-      for (i = marker_width; i--;) {
-        cmark_strbuf_putc(renderer->prefix, ' ');
-      }
-    } else {
-      cmark_strbuf_truncate(renderer->prefix,
-                            renderer->prefix->size - marker_width);
-      CR();
-    }
-    break;
-
-  case CMARK_NODE_HEADING:
-    if (entering) {
-      for (i = cmark_node_get_heading_level(node); i > 0; i--) {
-        LIT("#");
-      }
-      LIT(" ");
-      renderer->begin_content = true;
-      renderer->no_linebreaks = true;
-    } else {
-      renderer->no_linebreaks = false;
-      BLANKLINE();
-    }
-    break;
-
-  case CMARK_NODE_CODE_BLOCK:
-    first_in_list_item = node->prev == NULL && node->parent &&
-                         node->parent->type == CMARK_NODE_ITEM;
-
-    if (!first_in_list_item) {
-      BLANKLINE();
-    }
-    info = cmark_node_get_fence_info(node);
-    info_len = strlen(info);
-    fencechar[0] = strchr(info, '`') == NULL ? '`' : '~';
-    code = cmark_node_get_literal(node);
-    code_len = strlen(code);
-    // use indented form if no info, and code doesn't
-    // begin or end with a blank line, and code isn't
-    // first thing in a list item
-    if (info_len == 0 && (code_len > 2 && !cmark_isspace(code[0]) &&
-                          !(cmark_isspace(code[code_len - 1]) &&
-                            cmark_isspace(code[code_len - 2]))) &&
-        !first_in_list_item) {
-      LIT("    ");
-      cmark_strbuf_puts(renderer->prefix, "    ");
-      OUT(cmark_node_get_literal(node), false, LITERAL);
-      cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4);
-    } else {
-      numticks = longest_backtick_sequence(code) + 1;
-      if (numticks < 3) {
-        numticks = 3;
-      }
-      for (i = 0; i < numticks; i++) {
-        LIT(fencechar);
-      }
-      LIT(" ");
-      OUT(info, false, LITERAL);
-      CR();
-      OUT(cmark_node_get_literal(node), false, LITERAL);
-      CR();
-      for (i = 0; i < numticks; i++) {
-        LIT(fencechar);
-      }
-    }
-    BLANKLINE();
-    break;
-
-  case CMARK_NODE_HTML_BLOCK:
-    BLANKLINE();
-    OUT(cmark_node_get_literal(node), false, LITERAL);
-    BLANKLINE();
-    break;
-
-  case CMARK_NODE_CUSTOM_BLOCK:
-    BLANKLINE();
-    OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node),
-        false, LITERAL);
-    BLANKLINE();
-    break;
-
-  case CMARK_NODE_THEMATIC_BREAK:
-    BLANKLINE();
-    LIT("-----");
-    BLANKLINE();
-    break;
-
-  case CMARK_NODE_PARAGRAPH:
-    if (!entering) {
-      BLANKLINE();
-    }
-    break;
-
-  case CMARK_NODE_TEXT:
-    OUT(cmark_node_get_literal(node), allow_wrap, NORMAL);
-    break;
-
-  case CMARK_NODE_LINEBREAK:
-    if (!(CMARK_OPT_HARDBREAKS & options)) {
-      LIT("  ");
-    }
-    CR();
-    break;
-
-  case CMARK_NODE_SOFTBREAK:
-    if (CMARK_OPT_HARDBREAKS & options) {
-      LIT("  ");
-      CR();
-    } else if (!renderer->no_linebreaks && renderer->width == 0 &&
-               !(CMARK_OPT_HARDBREAKS & options) &&
-               !(CMARK_OPT_NOBREAKS & options)) {
-      CR();
-    } else {
-      OUT(" ", allow_wrap, LITERAL);
-    }
-    break;
-
-  case CMARK_NODE_CODE:
-    code = cmark_node_get_literal(node);
-    code_len = strlen(code);
-    numticks = shortest_unused_backtick_sequence(code);
-    extra_spaces = code_len == 0 ||
-	    code[0] == '`' || code[code_len - 1] == '`' ||
-	    code[0] == ' ' || code[code_len - 1] == ' ';
-    for (i = 0; i < numticks; i++) {
-      LIT("`");
-    }
-    if (extra_spaces) {
-      LIT(" ");
-    }
-    OUT(cmark_node_get_literal(node), allow_wrap, LITERAL);
-    if (extra_spaces) {
-      LIT(" ");
-    }
-    for (i = 0; i < numticks; i++) {
-      LIT("`");
-    }
-    break;
-
-  case CMARK_NODE_HTML_INLINE:
-    OUT(cmark_node_get_literal(node), false, LITERAL);
-    break;
-
-  case CMARK_NODE_CUSTOM_INLINE:
-    OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node),
-        false, LITERAL);
-    break;
-
-  case CMARK_NODE_STRONG:
-    if (entering) {
-      LIT("**");
-    } else {
-      LIT("**");
-    }
-    break;
-
-  case CMARK_NODE_EMPH:
-    // If we have EMPH(EMPH(x)), we need to use *_x_*
-    // because **x** is STRONG(x):
-    if (node->parent && node->parent->type == CMARK_NODE_EMPH &&
-        node->next == NULL && node->prev == NULL) {
-      emph_delim = "_";
-    } else {
-      emph_delim = "*";
-    }
-    if (entering) {
-      LIT(emph_delim);
-    } else {
-      LIT(emph_delim);
-    }
-    break;
-
-  case CMARK_NODE_LINK:
-    if (is_autolink(node)) {
-      if (entering) {
-        LIT("<");
-        if (strncmp(cmark_node_get_url(node), "mailto:", 7) == 0) {
-          LIT((const char *)cmark_node_get_url(node) + 7);
-        } else {
-          LIT((const char *)cmark_node_get_url(node));
-        }
-        LIT(">");
-        // return signal to skip contents of node...
-        return 0;
-      }
-    } else {
-      if (entering) {
-        LIT("[");
-      } else {
-        LIT("](");
-        OUT(cmark_node_get_url(node), false, URL);
-        title = cmark_node_get_title(node);
-        if (strlen(title) > 0) {
-          LIT(" \"");
-          OUT(title, false, TITLE);
-          LIT("\"");
-        }
-        LIT(")");
-      }
-    }
-    break;
-
-  case CMARK_NODE_IMAGE:
-    if (entering) {
-      LIT("![");
-    } else {
-      LIT("](");
-      OUT(cmark_node_get_url(node), false, URL);
-      title = cmark_node_get_title(node);
-      if (strlen(title) > 0) {
-        OUT(" \"", allow_wrap, LITERAL);
-        OUT(title, false, TITLE);
-        LIT("\"");
-      }
-      LIT(")");
-    }
-    break;
-
-  case CMARK_NODE_FOOTNOTE_REFERENCE:
-    if (entering) {
-      LIT("[^");
-
-      char *footnote_label = renderer->mem->calloc(node->parent_footnote_def->as.literal.len + 1, sizeof(char));
-      memmove(footnote_label, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len);
-
-      OUT(footnote_label, false, LITERAL);
-      renderer->mem->free(footnote_label);
-
-      LIT("]");
-    }
-    break;
-
-  case CMARK_NODE_FOOTNOTE_DEFINITION:
-    if (entering) {
-      renderer->footnote_ix += 1;
-      LIT("[^");
-
-      char *footnote_label = renderer->mem->calloc(node->as.literal.len + 1, sizeof(char));
-      memmove(footnote_label, node->as.literal.data, node->as.literal.len);
-
-      OUT(footnote_label, false, LITERAL);
-      renderer->mem->free(footnote_label);
-
-      LIT("]:\n");
-
-      cmark_strbuf_puts(renderer->prefix, "    ");
-    } else {
-      cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4);
-    }
-    break;
-
-  default:
-    assert(false);
-    break;
-  }
-
-  return 1;
-}
-
-char *cmark_render_commonmark(cmark_node *root, int options, int width) {
-  return cmark_render_commonmark_with_mem(root, options, width, cmark_node_mem(root));
-}
-
-char *cmark_render_commonmark_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) {
-  if (options & CMARK_OPT_HARDBREAKS) {
-    // disable breaking on width, since it has
-    // a different meaning with OPT_HARDBREAKS
-    width = 0;
-  }
-  return cmark_render(mem, root, options, width, outc, S_render_node);
-}
diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c
index 1e930a94..6832d502 100644
--- a/ext/commonmarker/commonmarker.c
+++ b/ext/commonmarker/commonmarker.c
@@ -1,1307 +1,25 @@
 #include "commonmarker.h"
-#include "cmark-gfm.h"
-#include "houdini.h"
-#include "node.h"
-#include "registry.h"
-#include "parser.h"
-#include "syntax_extension.h"
-#include "cmark-gfm-core-extensions.h"
+#include "comrak.h"
 
-static VALUE rb_eNodeError;
-static VALUE rb_cNode;
+VALUE commonmarker_to_html(VALUE self, VALUE rb_commonmark_text, int options) {
+  Check_Type(rb_commonmark_text, T_STRING);
 
-static VALUE sym_document;
-static VALUE sym_blockquote;
-static VALUE sym_list;
-static VALUE sym_list_item;
-static VALUE sym_code_block;
-static VALUE sym_html;
-static VALUE sym_paragraph;
-static VALUE sym_header;
-static VALUE sym_hrule;
-static VALUE sym_text;
-static VALUE sym_softbreak;
-static VALUE sym_linebreak;
-static VALUE sym_code;
-static VALUE sym_inline_html;
-static VALUE sym_emph;
-static VALUE sym_strong;
-static VALUE sym_link;
-static VALUE sym_image;
-static VALUE sym_footnote_reference;
-static VALUE sym_footnote_definition;
+  char *commonmark_text = StringValueCStr(rb_commonmark_text);
 
-static VALUE sym_bullet_list;
-static VALUE sym_ordered_list;
+  comrak_options_t * default_options = comrak_options_new();
+  comrak_str_t html = comrak_commonmark_to_html(commonmark_text, default_options);
 
-static VALUE sym_left;
-static VALUE sym_right;
-static VALUE sym_center;
+  VALUE rb_html = rb_utf8_str_new(html.data, html.len);
 
-static VALUE encode_utf8_string(const char *c_string) {
-  VALUE string = rb_str_new2(c_string);
-  int enc = rb_enc_find_index("UTF-8");
-  rb_enc_associate_index(string, enc);
-  return string;
-}
-
-/* Encode a C string using the encoding from Ruby string +source+. */
-static VALUE encode_source_string(const char *c_string, VALUE source) {
-  VALUE string = rb_str_new2(c_string);
-  rb_enc_copy(string, source);
-  return string;
-}
-
-static void rb_mark_c_struct(void *data) {
-  cmark_node *node = data;
-  cmark_node *child;
-
-  /* Mark the parent to make sure that the tree won't be freed as
-     long as a child node is referenced. */
-  cmark_node *parent = cmark_node_parent(node);
-  if (parent) {
-    void *user_data = cmark_node_get_user_data(parent);
-    if (!user_data) {
-      /* This should never happen. Child can nodes can only
-         be returned from parents that already are
-         associated with a Ruby object. */
-      fprintf(stderr, "parent without user_data\n");
-      abort();
-    }
-    rb_gc_mark((VALUE)user_data);
-  }
-
-  /* Mark all children to make sure their cached Ruby objects won't
-     be freed. */
-  for (child = cmark_node_first_child(node); child != NULL;
-       child = cmark_node_next(child)) {
-    void *user_data = cmark_node_get_user_data(child);
-    if (user_data)
-      rb_gc_mark((VALUE)user_data);
-  }
-}
-
-static void rb_free_c_struct(void *data) {
-  /* It's important that the `free` function does not inspect the
-     node data, as it may be part of a tree that was already freed. */
-  cmark_node_free(data);
-}
-
-static VALUE rb_node_to_value(cmark_node *node) {
-  void *user_data;
-  RUBY_DATA_FUNC free_func;
-  VALUE val;
-
-  if (node == NULL)
-    return Qnil;
-
-  user_data = cmark_node_get_user_data(node);
-  if (user_data)
-    return (VALUE)user_data;
-
-  /* Only free tree roots. */
-  free_func = cmark_node_parent(node) ? NULL : rb_free_c_struct;
-  val = Data_Wrap_Struct(rb_cNode, rb_mark_c_struct, free_func, node);
-  cmark_node_set_user_data(node, (void *)val);
-
-  return val;
-}
-
-/* If the node structure is changed, the finalizers must be updated. */
-
-static void rb_parent_added(VALUE val) { RDATA(val)->dfree = NULL; }
-
-static void rb_parent_removed(VALUE val) {
-  RDATA(val)->dfree = rb_free_c_struct;
-}
-
-static cmark_parser *prepare_parser(VALUE rb_options, VALUE rb_extensions) {
-  int options;
-  VALUE rb_ext_name;
-  int i;
-
-  FIXNUM_P(rb_options);
-  options = FIX2INT(rb_options);
-
-  Check_Type(rb_extensions, T_ARRAY);
-
-  cmark_parser *parser = cmark_parser_new(options);
-
-  for (i = 0; i < RARRAY_LEN(rb_extensions); ++i) {
-    rb_ext_name = rb_ary_entry(rb_extensions, i);
-
-    if (!SYMBOL_P(rb_ext_name)) {
-      cmark_parser_free(parser);
-      rb_raise(rb_eTypeError, "extension names should be Symbols; got a %"PRIsVALUE"", rb_obj_class(rb_ext_name));
-    }
-
-    cmark_syntax_extension *syntax_extension =
-      cmark_find_syntax_extension(rb_id2name(SYM2ID(rb_ext_name)));
-
-    if (!syntax_extension) {
-      cmark_parser_free(parser);
-      rb_raise(rb_eArgError, "extension %s not found", rb_id2name(SYM2ID(rb_ext_name)));
-    }
-
-    cmark_parser_attach_syntax_extension(parser, syntax_extension);
-  }
-
-  return parser;
-}
-
-/*
- * Internal: Parses a Markdown string into an HTML string.
- *
- */
-static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options, VALUE rb_extensions) {
-  char *html;
-  cmark_parser *parser;
-  cmark_node *doc;
-
-  Check_Type(rb_text, T_STRING);
-
-  parser = prepare_parser(rb_options, rb_extensions);
-
-  cmark_parser_feed(parser, StringValuePtr(rb_text), RSTRING_LEN(rb_text));
-  doc = cmark_parser_finish(parser);
+  comrak_options_free(default_options);
+  comrak_str_free(html);
 
-  if (doc == NULL) {
-    cmark_parser_free(parser);
-    rb_raise(rb_eNodeError, "error parsing document");
-  }
-
-  html = cmark_render_html(doc, parser->options, parser->syntax_extensions);
-
-  cmark_parser_free(parser);
-  cmark_node_free(doc);
-
-  return rb_utf8_str_new_cstr(html);
-}
-
-/*
- * Internal: Parses a Markdown string into an HTML string.
- *
- */
-static VALUE rb_markdown_to_xml(VALUE self, VALUE rb_text, VALUE rb_options, VALUE rb_extensions) {
-  char *xml;
-  cmark_parser *parser;
-  cmark_node *doc;
-
-  Check_Type(rb_text, T_STRING);
-
-  parser = prepare_parser(rb_options, rb_extensions);
-
-  cmark_parser_feed(parser, StringValuePtr(rb_text), RSTRING_LEN(rb_text));
-  doc = cmark_parser_finish(parser);
-
-  if (doc == NULL) {
-    cmark_parser_free(parser);
-    rb_raise(rb_eNodeError, "error parsing document");
-  }
-
-  xml = cmark_render_xml(doc, parser->options);
-
-  cmark_parser_free(parser);
-  cmark_node_free(doc);
-
-  return rb_utf8_str_new_cstr(xml);
-}
-
-/*
- * Internal: Creates a node based on a node type.
- *
- * type -  A {Symbol} representing the node to be created. Must be one of the
- * following:
- * - `:document`
- * - `:blockquote`
- * - `:list`
- * - `:list_item`
- * - `:code_block`
- * - `:html`
- * - `:paragraph`
- * - `:header`
- * - `:hrule`
- * - `:text`
- * - `:softbreak`
- * - `:linebreak`
- * - `:code`
- * - `:inline_html`
- * - `:emph`
- * - `:strong`
- * - `:link`
- * - `:image`
- */
-static VALUE rb_node_new(VALUE self, VALUE type) {
-  cmark_node_type node_type = 0;
-  cmark_node *node;
-
-  Check_Type(type, T_SYMBOL);
-
-  if (type == sym_document)
-    node_type = CMARK_NODE_DOCUMENT;
-  else if (type == sym_blockquote)
-    node_type = CMARK_NODE_BLOCK_QUOTE;
-  else if (type == sym_list)
-    node_type = CMARK_NODE_LIST;
-  else if (type == sym_list_item)
-    node_type = CMARK_NODE_ITEM;
-  else if (type == sym_code_block)
-    node_type = CMARK_NODE_CODE_BLOCK;
-  else if (type == sym_html)
-    node_type = CMARK_NODE_HTML;
-  else if (type == sym_paragraph)
-    node_type = CMARK_NODE_PARAGRAPH;
-  else if (type == sym_header)
-    node_type = CMARK_NODE_HEADER;
-  else if (type == sym_hrule)
-    node_type = CMARK_NODE_HRULE;
-  else if (type == sym_text)
-    node_type = CMARK_NODE_TEXT;
-  else if (type == sym_softbreak)
-    node_type = CMARK_NODE_SOFTBREAK;
-  else if (type == sym_linebreak)
-    node_type = CMARK_NODE_LINEBREAK;
-  else if (type == sym_code)
-    node_type = CMARK_NODE_CODE;
-  else if (type == sym_inline_html)
-    node_type = CMARK_NODE_INLINE_HTML;
-  else if (type == sym_emph)
-    node_type = CMARK_NODE_EMPH;
-  else if (type == sym_strong)
-    node_type = CMARK_NODE_STRONG;
-  else if (type == sym_link)
-    node_type = CMARK_NODE_LINK;
-  else if (type == sym_image)
-    node_type = CMARK_NODE_IMAGE;
-  else if (type == sym_footnote_reference)
-    node_type = CMARK_NODE_FOOTNOTE_REFERENCE;
-  else if (type == sym_footnote_definition)
-    node_type = CMARK_NODE_FOOTNOTE_DEFINITION;
-  else
-    rb_raise(rb_eNodeError, "invalid node of type %d", node_type);
-
-  node = cmark_node_new(node_type);
-  if (node == NULL) {
-    rb_raise(rb_eNodeError, "could not create node of type %d", node_type);
-  }
-
-  return rb_node_to_value(node);
-}
-
-/*
- * Internal: Parses a Markdown string into a document.
- *
- */
-static VALUE rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len,
-                               VALUE rb_options, VALUE rb_extensions) {
-  char *text;
-  int len;
-  cmark_parser *parser;
-  cmark_node *doc;
-  Check_Type(rb_text, T_STRING);
-  Check_Type(rb_len, T_FIXNUM);
-  Check_Type(rb_options, T_FIXNUM);
-
-  parser = prepare_parser(rb_options, rb_extensions);
-
-  text = (char *)RSTRING_PTR(rb_text);
-  len = FIX2INT(rb_len);
-
-  cmark_parser_feed(parser, text, len);
-  doc = cmark_parser_finish(parser);
-  if (doc == NULL) {
-    rb_raise(rb_eNodeError, "error parsing document");
-  }
-  cmark_parser_free(parser);
-
-  return rb_node_to_value(doc);
-}
-
-/*
- * Public: Fetch the string contents of the node.
- *
- * Returns a {String}.
- */
-static VALUE rb_node_get_string_content(VALUE self) {
-  const char *text;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  text = cmark_node_get_literal(node);
-  if (text == NULL) {
-    rb_raise(rb_eNodeError, "could not get string content");
-  }
-
-  return encode_utf8_string(text);
-}
-
-/*
- * Public: Sets the string content of the node.
- *
- * string - A {String} containing new content.
- *
- * Raises NodeError if the string content can't be set.
- */
-static VALUE rb_node_set_string_content(VALUE self, VALUE s) {
-  char *text;
-  cmark_node *node;
-  Check_Type(s, T_STRING);
-
-  Data_Get_Struct(self, cmark_node, node);
-  text = StringValueCStr(s);
-
-  if (!cmark_node_set_literal(node, text)) {
-    rb_raise(rb_eNodeError, "could not set string content");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Fetches the list type of the node.
- *
- * Returns a {Symbol} representing the node's type.
- */
-static VALUE rb_node_get_type(VALUE self) {
-  int node_type;
-  cmark_node *node;
-  VALUE symbol;
-  const char *s;
-
-  Data_Get_Struct(self, cmark_node, node);
-
-  node_type = cmark_node_get_type(node);
-  symbol = Qnil;
-
-  switch (node_type) {
-  case CMARK_NODE_DOCUMENT:
-    symbol = sym_document;
-    break;
-  case CMARK_NODE_BLOCK_QUOTE:
-    symbol = sym_blockquote;
-    break;
-  case CMARK_NODE_LIST:
-    symbol = sym_list;
-    break;
-  case CMARK_NODE_ITEM:
-    symbol = sym_list_item;
-    break;
-  case CMARK_NODE_CODE_BLOCK:
-    symbol = sym_code_block;
-    break;
-  case CMARK_NODE_HTML:
-    symbol = sym_html;
-    break;
-  case CMARK_NODE_PARAGRAPH:
-    symbol = sym_paragraph;
-    break;
-  case CMARK_NODE_HEADER:
-    symbol = sym_header;
-    break;
-  case CMARK_NODE_HRULE:
-    symbol = sym_hrule;
-    break;
-  case CMARK_NODE_TEXT:
-    symbol = sym_text;
-    break;
-  case CMARK_NODE_SOFTBREAK:
-    symbol = sym_softbreak;
-    break;
-  case CMARK_NODE_LINEBREAK:
-    symbol = sym_linebreak;
-    break;
-  case CMARK_NODE_CODE:
-    symbol = sym_code;
-    break;
-  case CMARK_NODE_INLINE_HTML:
-    symbol = sym_inline_html;
-    break;
-  case CMARK_NODE_EMPH:
-    symbol = sym_emph;
-    break;
-  case CMARK_NODE_STRONG:
-    symbol = sym_strong;
-    break;
-  case CMARK_NODE_LINK:
-    symbol = sym_link;
-    break;
-  case CMARK_NODE_IMAGE:
-    symbol = sym_image;
-    break;
-  case CMARK_NODE_FOOTNOTE_REFERENCE:
-    symbol = sym_footnote_reference;
-    break;
-  case CMARK_NODE_FOOTNOTE_DEFINITION:
-    symbol = sym_footnote_definition;
-    break;
-  default:
-    if (node->extension) {
-      s = node->extension->get_type_string_func(node->extension, node);
-      return ID2SYM(rb_intern(s));
-    }
-    rb_raise(rb_eNodeError, "invalid node type %d", node_type);
-  }
-
-  return symbol;
-}
-
-/*
- * Public: Fetches the sourcepos of the node.
- *
- * Returns a {Hash} containing {Symbol} keys of the positions.
- */
-static VALUE rb_node_get_sourcepos(VALUE self) {
-  int start_line, start_column, end_line, end_column;
-  VALUE result;
-
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  start_line = cmark_node_get_start_line(node);
-  start_column = cmark_node_get_start_column(node);
-  end_line = cmark_node_get_end_line(node);
-  end_column = cmark_node_get_end_column(node);
-
-  result = rb_hash_new();
-  rb_hash_aset(result, CSTR2SYM("start_line"), INT2NUM(start_line));
-  rb_hash_aset(result, CSTR2SYM("start_column"), INT2NUM(start_column));
-  rb_hash_aset(result, CSTR2SYM("end_line"), INT2NUM(end_line));
-  rb_hash_aset(result, CSTR2SYM("end_column"), INT2NUM(end_column));
-
-  return result;
-}
-
-/*
- * Public: Returns the type of the current pointer as a string.
- *
- * Returns a {String}.
- */
-static VALUE rb_node_get_type_string(VALUE self) {
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  return rb_str_new2(cmark_node_get_type_string(node));
-}
-
-/*
- * Internal: Unlinks the node from the tree (fixing pointers in
- * parents and siblings appropriately).
- */
-static VALUE rb_node_unlink(VALUE self) {
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  cmark_node_unlink(node);
-
-  rb_parent_removed(self);
-
-  return Qnil;
-}
-
-/* Public: Fetches the first child of the node.
- *
- * Returns a {Node} if a child exists, `nil` otherise.
- */
-static VALUE rb_node_first_child(VALUE self) {
-  cmark_node *node, *child;
-  Data_Get_Struct(self, cmark_node, node);
-
-  child = cmark_node_first_child(node);
-
-  return rb_node_to_value(child);
-}
-
-/* Public: Fetches the next sibling of the node.
- *
- * Returns a {Node} if a sibling exists, `nil` otherwise.
- */
-static VALUE rb_node_next(VALUE self) {
-  cmark_node *node, *next;
-  Data_Get_Struct(self, cmark_node, node);
-
-  next = cmark_node_next(node);
-
-  return rb_node_to_value(next);
-}
-
-/*
- * Public: Inserts a node as a sibling before the current node.
- *
- * sibling - A sibling {Node} to insert.
- *
- * Returns `true` if successful.
- * Raises NodeError if the node can't be inserted.
- */
-static VALUE rb_node_insert_before(VALUE self, VALUE sibling) {
-  cmark_node *node1, *node2;
-  Data_Get_Struct(self, cmark_node, node1);
-
-  Data_Get_Struct(sibling, cmark_node, node2);
-
-  if (!cmark_node_insert_before(node1, node2)) {
-    rb_raise(rb_eNodeError, "could not insert before");
-  }
-
-  rb_parent_added(sibling);
-
-  return Qtrue;
-}
-
-/* Internal: Convert the node to an HTML string.
- *
- * Returns a {String}.
- */
-static VALUE rb_render_html(VALUE self, VALUE rb_options, VALUE rb_extensions) {
-  int options, extensions_len;
-  VALUE rb_ext_name;
-  int i;
-  cmark_node *node;
-  cmark_llist *extensions = NULL;
-  cmark_mem *mem = cmark_get_default_mem_allocator();
-  Check_Type(rb_options, T_FIXNUM);
-  Check_Type(rb_extensions, T_ARRAY);
-
-  options = FIX2INT(rb_options);
-  extensions_len = RARRAY_LEN(rb_extensions);
-
-  Data_Get_Struct(self, cmark_node, node);
-
-  for (i = 0; i < extensions_len; ++i) {
-    rb_ext_name = RARRAY_PTR(rb_extensions)[i];
-
-    if (!SYMBOL_P(rb_ext_name)) {
-      cmark_llist_free(mem, extensions);
-      rb_raise(rb_eTypeError, "extension names should be Symbols; got a %"PRIsVALUE"", rb_obj_class(rb_ext_name));
-    }
-
-    cmark_syntax_extension *syntax_extension =
-      cmark_find_syntax_extension(rb_id2name(SYM2ID(rb_ext_name)));
-
-    if (!syntax_extension) {
-      cmark_llist_free(mem, extensions);
-      rb_raise(rb_eArgError, "extension %s not found\n", rb_id2name(SYM2ID(rb_ext_name)));
-    }
-
-    extensions = cmark_llist_append(mem, extensions, syntax_extension);
-  }
-
-  char *html = cmark_render_html(node, options, extensions);
-  VALUE ruby_html = rb_str_new2(html);
-
-  cmark_llist_free(mem, extensions);
-  free(html);
-
-  return ruby_html;
-}
-
-/* Internal: Convert the node to an XML string.
- *
- * Returns a {String}.
- */
-static VALUE rb_render_xml(VALUE self, VALUE rb_options) {
-  int options;
-  cmark_node *node;
-  Check_Type(rb_options, T_FIXNUM);
-
-  options = FIX2INT(rb_options);
-
-  Data_Get_Struct(self, cmark_node, node);
-
-  char *xml = cmark_render_xml(node, options);
-  VALUE ruby_xml = rb_str_new2(xml);
-
-  free(xml);
-
-  return ruby_xml;
-}
-
-/* Internal: Convert the node to a CommonMark string.
- *
- * Returns a {String}.
- */
-static VALUE rb_render_commonmark(int argc, VALUE *argv, VALUE self) {
-  VALUE rb_options, rb_width;
-  rb_scan_args(argc, argv, "11", &rb_options, &rb_width);
-
-  int width = 120;
-  if (!NIL_P(rb_width)) {
-    Check_Type(rb_width, T_FIXNUM);
-    width = FIX2INT(rb_width);
-  }
-
-  int options;
-  cmark_node *node;
-  Check_Type(rb_options, T_FIXNUM);
-
-  options = FIX2INT(rb_options);
-  Data_Get_Struct(self, cmark_node, node);
-
-  char *cmark = cmark_render_commonmark(node, options, width);
-  VALUE ruby_cmark = rb_str_new2(cmark);
-  free(cmark);
-
-  return ruby_cmark;
-}
-
-/* Internal: Convert the node to a plain textstring.
- *
- * Returns a {String}.
- */
-static VALUE rb_render_plaintext(int argc, VALUE *argv, VALUE self) {
-  VALUE rb_options, rb_width;
-  rb_scan_args(argc, argv, "11", &rb_options, &rb_width);
-
-  int width = 120;
-  if (!NIL_P(rb_width)) {
-    Check_Type(rb_width, T_FIXNUM);
-    width = FIX2INT(rb_width);
-  }
-
-  int options;
-  cmark_node *node;
-  Check_Type(rb_options, T_FIXNUM);
-
-  options = FIX2INT(rb_options);
-  Data_Get_Struct(self, cmark_node, node);
-
-  char *text = cmark_render_plaintext(node, options, width);
-  VALUE ruby_text = rb_str_new2(text);
-  free(text);
-
-  return ruby_text;
-}
-
-/*
- * Public: Inserts a node as a sibling after the current node.
- *
- * sibling - A sibling {Node} to insert.
- *
- * Returns `true` if successful.
- * Raises NodeError if the node can't be inserted.
- */
-static VALUE rb_node_insert_after(VALUE self, VALUE sibling) {
-  cmark_node *node1, *node2;
-  Data_Get_Struct(self, cmark_node, node1);
-
-  Data_Get_Struct(sibling, cmark_node, node2);
-
-  if (!cmark_node_insert_after(node1, node2)) {
-    rb_raise(rb_eNodeError, "could not insert after");
-  }
-
-  rb_parent_added(sibling);
-
-  return Qtrue;
-}
-
-/*
- * Public: Inserts a node as the first child of the current node.
- *
- * child - A child {Node} to insert.
- *
- * Returns `true` if successful.
- * Raises NodeError if the node can't be inserted.
- */
-static VALUE rb_node_prepend_child(VALUE self, VALUE child) {
-  cmark_node *node1, *node2;
-  Data_Get_Struct(self, cmark_node, node1);
-
-  Data_Get_Struct(child, cmark_node, node2);
-
-  if (!cmark_node_prepend_child(node1, node2)) {
-    rb_raise(rb_eNodeError, "could not prepend child");
-  }
-
-  rb_parent_added(child);
-
-  return Qtrue;
-}
-
-/*
- * Public: Inserts a node as the last child of the current node.
- *
- * child - A child {Node} to insert.
- *
- * Returns `true` if successful.
- * Raises NodeError if the node can't be inserted.
- */
-static VALUE rb_node_append_child(VALUE self, VALUE child) {
-  cmark_node *node1, *node2;
-  Data_Get_Struct(self, cmark_node, node1);
-
-  Data_Get_Struct(child, cmark_node, node2);
-
-  if (!cmark_node_append_child(node1, node2)) {
-    rb_raise(rb_eNodeError, "could not append child");
-  }
-
-  rb_parent_added(child);
-
-  return Qtrue;
-}
-
-/* Public: Fetches the first child of the current node.
- *
- * Returns a {Node} if a child exists, `nil` otherise.
- */
-static VALUE rb_node_last_child(VALUE self) {
-  cmark_node *node, *child;
-  Data_Get_Struct(self, cmark_node, node);
-
-  child = cmark_node_last_child(node);
-
-  return rb_node_to_value(child);
-}
-
-/* Public: Fetches the parent of the current node.
- *
- * Returns a {Node} if a parent exists, `nil` otherise.
- */
-static VALUE rb_node_parent(VALUE self) {
-  cmark_node *node, *parent;
-  Data_Get_Struct(self, cmark_node, node);
-
-  parent = cmark_node_parent(node);
-
-  return rb_node_to_value(parent);
-}
-
-/* Public: Fetches the previous sibling of the current node.
- *
- * Returns a {Node} if a parent exists, `nil` otherise.
- */
-static VALUE rb_node_previous(VALUE self) {
-  cmark_node *node, *previous;
-  Data_Get_Struct(self, cmark_node, node);
-
-  previous = cmark_node_previous(node);
-
-  return rb_node_to_value(previous);
-}
-
-/*
- * Public: Gets the URL of the current node (must be a `:link` or `:image`).
- *
- * Returns a {String}.
- * Raises a NodeError if the URL can't be retrieved.
- */
-static VALUE rb_node_get_url(VALUE self) {
-  const char *text;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  text = cmark_node_get_url(node);
-  if (text == NULL) {
-    rb_raise(rb_eNodeError, "could not get url");
-  }
-
-  return rb_str_new2(text);
-}
-
-/*
- * Public: Sets the URL of the current node (must be a `:link` or `:image`).
- *
- * url - A {String} representing the new URL
- *
- * Raises a NodeError if the URL can't be set.
- */
-static VALUE rb_node_set_url(VALUE self, VALUE url) {
-  cmark_node *node;
-  char *text;
-  Check_Type(url, T_STRING);
-
-  Data_Get_Struct(self, cmark_node, node);
-  text = StringValueCStr(url);
-
-  if (!cmark_node_set_url(node, text)) {
-    rb_raise(rb_eNodeError, "could not set url");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Gets the title of the current node (must be a `:link` or `:image`).
- *
- * Returns a {String}.
- * Raises a NodeError if the title can't be retrieved.
- */
-static VALUE rb_node_get_title(VALUE self) {
-  const char *text;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  text = cmark_node_get_title(node);
-  if (text == NULL) {
-    rb_raise(rb_eNodeError, "could not get title");
-  }
-
-  return rb_str_new2(text);
-}
-
-/*
- * Public: Sets the title of the current node (must be a `:link` or `:image`).
- *
- * title - A {String} representing the new title
- *
- * Raises a NodeError if the title can't be set.
- */
-static VALUE rb_node_set_title(VALUE self, VALUE title) {
-  char *text;
-  cmark_node *node;
-  Check_Type(title, T_STRING);
-
-  Data_Get_Struct(self, cmark_node, node);
-  text = StringValueCStr(title);
-
-  if (!cmark_node_set_title(node, text)) {
-    rb_raise(rb_eNodeError, "could not set title");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Gets the header level of the current node (must be a `:header`).
- *
- * Returns a {Number} representing the header level.
- * Raises a NodeError if the header level can't be retrieved.
- */
-static VALUE rb_node_get_header_level(VALUE self) {
-  int header_level;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  header_level = cmark_node_get_header_level(node);
-
-  if (header_level == 0) {
-    rb_raise(rb_eNodeError, "could not get header_level");
-  }
-
-  return INT2NUM(header_level);
-}
-
-/*
- * Public: Sets the header level of the current node (must be a `:header`).
- *
- * level - A {Number} representing the new header level
- *
- * Raises a NodeError if the header level can't be set.
- */
-static VALUE rb_node_set_header_level(VALUE self, VALUE level) {
-  int l;
-  cmark_node *node;
-  Check_Type(level, T_FIXNUM);
-
-  Data_Get_Struct(self, cmark_node, node);
-  l = FIX2INT(level);
-
-  if (!cmark_node_set_header_level(node, l)) {
-    rb_raise(rb_eNodeError, "could not set header_level");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Gets the list type of the current node (must be a `:list`).
- *
- * Returns a {Symbol}.
- * Raises a NodeError if the title can't be retrieved.
- */
-static VALUE rb_node_get_list_type(VALUE self) {
-  int list_type;
-  cmark_node *node;
-  VALUE symbol;
-  Data_Get_Struct(self, cmark_node, node);
-
-  list_type = cmark_node_get_list_type(node);
-
-  if (list_type == CMARK_BULLET_LIST) {
-    symbol = sym_bullet_list;
-  } else if (list_type == CMARK_ORDERED_LIST) {
-    symbol = sym_ordered_list;
-  } else {
-    rb_raise(rb_eNodeError, "could not get list_type");
-  }
-
-  return symbol;
-}
-
-/*
- * Public: Sets the list type of the current node (must be a `:list`).
- *
- * level - A {Symbol} representing the new list type
- *
- * Raises a NodeError if the list type can't be set.
- */
-static VALUE rb_node_set_list_type(VALUE self, VALUE list_type) {
-  int type = 0;
-  cmark_node *node;
-  Check_Type(list_type, T_SYMBOL);
-
-  Data_Get_Struct(self, cmark_node, node);
-
-  if (list_type == sym_bullet_list) {
-    type = CMARK_BULLET_LIST;
-  } else if (list_type == sym_ordered_list) {
-    type = CMARK_ORDERED_LIST;
-  } else {
-    rb_raise(rb_eNodeError, "invalid list_type");
-  }
-
-  if (!cmark_node_set_list_type(node, type)) {
-    rb_raise(rb_eNodeError, "could not set list_type");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Gets the starting number the current node (must be an
- * `:ordered_list`).
- *
- * Returns a {Number} representing the starting number.
- * Raises a NodeError if the starting number can't be retrieved.
- */
-static VALUE rb_node_get_list_start(VALUE self) {
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  if (cmark_node_get_type(node) != CMARK_NODE_LIST ||
-      cmark_node_get_list_type(node) != CMARK_ORDERED_LIST) {
-    rb_raise(rb_eNodeError, "can't get list_start for non-ordered list %d",
-             cmark_node_get_list_type(node));
-  }
-
-  return INT2NUM(cmark_node_get_list_start(node));
-}
-
-/*
- * Public: Sets the starting number of the current node (must be an
- * `:ordered_list`).
- *
- * level - A {Number} representing the new starting number
- *
- * Raises a NodeError if the starting number can't be set.
- */
-static VALUE rb_node_set_list_start(VALUE self, VALUE start) {
-  int s;
-  cmark_node *node;
-  Check_Type(start, T_FIXNUM);
-
-  Data_Get_Struct(self, cmark_node, node);
-  s = FIX2INT(start);
-
-  if (!cmark_node_set_list_start(node, s)) {
-    rb_raise(rb_eNodeError, "could not set list_start");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Gets the tight status the current node (must be a `:list`).
- *
- * Returns a `true` if the list is tight, `false` otherwise.
- * Raises a NodeError if the starting number can't be retrieved.
- */
-static VALUE rb_node_get_list_tight(VALUE self) {
-  int flag;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  if (cmark_node_get_type(node) != CMARK_NODE_LIST) {
-    rb_raise(rb_eNodeError, "can't get list_tight for non-list");
-  }
-
-  flag = cmark_node_get_list_tight(node);
-
-  return flag ? Qtrue : Qfalse;
-}
-
-/*
- * Public: Sets the tight status of the current node (must be a `:list`).
- *
- * tight - A {Boolean} representing the new tightness
- *
- * Raises a NodeError if the tightness can't be set.
- */
-static VALUE rb_node_set_list_tight(VALUE self, VALUE tight) {
-  int t;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-  t = RTEST(tight);
-
-  if (!cmark_node_set_list_tight(node, t)) {
-    rb_raise(rb_eNodeError, "could not set list_tight");
-  }
-
-  return Qnil;
-}
-
-/*
- * Public: Gets the fence info of the current node (must be a `:code_block`).
- *
- * Returns a {String} representing the fence info.
- * Raises a NodeError if the fence info can't be retrieved.
- */
-static VALUE rb_node_get_fence_info(VALUE self) {
-  const char *fence_info;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  fence_info = cmark_node_get_fence_info(node);
-
-  if (fence_info == NULL) {
-    rb_raise(rb_eNodeError, "could not get fence_info");
-  }
-
-  return rb_str_new2(fence_info);
-}
-
-/*
- * Public: Sets the fence info of the current node (must be a `:code_block`).
- *
- * info - A {String} representing the new fence info
- *
- * Raises a NodeError if the fence info can't be set.
- */
-static VALUE rb_node_set_fence_info(VALUE self, VALUE info) {
-  char *text;
-  cmark_node *node;
-  Check_Type(info, T_STRING);
-
-  Data_Get_Struct(self, cmark_node, node);
-  text = StringValueCStr(info);
-
-  if (!cmark_node_set_fence_info(node, text)) {
-    rb_raise(rb_eNodeError, "could not set fence_info");
-  }
-
-  return Qnil;
-}
-
-static VALUE rb_node_get_tasklist_item_checked(VALUE self) {
-  int tasklist_state;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  tasklist_state = cmark_gfm_extensions_get_tasklist_item_checked(node);
-
-  if (tasklist_state == 1) {
-    return Qtrue;
-  } else {
-    return Qfalse;
-  }
-}
-
-/*
- * Public: Sets the checkbox state of the current node (must be a `:tasklist`).
- *
- * item_checked - A {Boolean} representing the new checkbox state
- *
- * Returns a {Boolean} representing the new checkbox state.
- * Raises a NodeError if the checkbox state can't be set.
- */
-static VALUE rb_node_set_tasklist_item_checked(VALUE self, VALUE item_checked) {
-  int tasklist_state;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-  tasklist_state = RTEST(item_checked);
-
-  if (!cmark_gfm_extensions_set_tasklist_item_checked(node, tasklist_state)) {
-    rb_raise(rb_eNodeError, "could not set tasklist_item_checked");
-  };
-
-  if (tasklist_state) {
-    return Qtrue;
-  } else {
-    return Qfalse;
-  }
-}
-
-// TODO: remove this, superseded by the above method
-static VALUE rb_node_get_tasklist_state(VALUE self) {
-  int tasklist_state;
-  cmark_node *node;
-  Data_Get_Struct(self, cmark_node, node);
-
-  tasklist_state = cmark_gfm_extensions_get_tasklist_item_checked(node);
-
-  if (tasklist_state == 1) {
-    return rb_str_new2("checked");
-  } else {
-    return rb_str_new2("unchecked");
-  }
-}
-
-static VALUE rb_node_get_table_alignments(VALUE self) {
-  uint16_t column_count, i;
-  uint8_t *alignments;
-  cmark_node *node;
-  VALUE ary;
-  Data_Get_Struct(self, cmark_node, node);
-
-  column_count = cmark_gfm_extensions_get_table_columns(node);
-  alignments = cmark_gfm_extensions_get_table_alignments(node);
-
-  if (!column_count || !alignments) {
-    rb_raise(rb_eNodeError, "could not get column_count or alignments");
-  }
-
-  ary = rb_ary_new();
-  for (i = 0; i < column_count; ++i) {
-    if (alignments[i] == 'l')
-      rb_ary_push(ary, sym_left);
-    else if (alignments[i] == 'c')
-      rb_ary_push(ary, sym_center);
-    else if (alignments[i] == 'r')
-      rb_ary_push(ary, sym_right);
-    else
-      rb_ary_push(ary, Qnil);
-  }
-  return ary;
-}
-
-/* Internal: Escapes href URLs safely. */
-static VALUE rb_html_escape_href(VALUE self, VALUE rb_text) {
-  char *result;
-  cmark_node *node;
-  Check_Type(rb_text, T_STRING);
-
-  Data_Get_Struct(self, cmark_node, node);
-
-  cmark_mem *mem = cmark_node_mem(node);
-  cmark_strbuf buf = CMARK_BUF_INIT(mem);
-
-  if (houdini_escape_href(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
-                          RSTRING_LEN(rb_text))) {
-    result = (char *)cmark_strbuf_detach(&buf);
-    return encode_source_string(result, rb_text);
-
-  }
-
-  return rb_text;
-}
-
-/* Internal: Escapes HTML content safely. */
-static VALUE rb_html_escape_html(VALUE self, VALUE rb_text) {
-  char *result;
-  cmark_node *node;
-  Check_Type(rb_text, T_STRING);
-
-  Data_Get_Struct(self, cmark_node, node);
-
-  cmark_mem *mem = cmark_node_mem(node);
-  cmark_strbuf buf = CMARK_BUF_INIT(mem);
-
-  if (houdini_escape_html0(&buf, (const uint8_t *)RSTRING_PTR(rb_text),
-                           RSTRING_LEN(rb_text), 0)) {
-    result = (char *)cmark_strbuf_detach(&buf);
-    return encode_source_string(result, rb_text);
-  }
-
-  return rb_text;
-}
-
-VALUE rb_extensions(VALUE self) {
-  cmark_llist *exts, *it;
-  cmark_syntax_extension *ext;
-  VALUE ary = rb_ary_new();
-
-  cmark_mem *mem = cmark_get_default_mem_allocator();
-  exts = cmark_list_syntax_extensions(mem);
-  for (it = exts; it; it = it->next) {
-    ext = it->data;
-    rb_ary_push(ary, rb_str_new2(ext->name));
-  }
-  cmark_llist_free(mem, exts);
-
-  return ary;
+  return rb_html;
 }
 
 __attribute__((visibility("default"))) void Init_commonmarker() {
   VALUE module;
-  sym_document = ID2SYM(rb_intern("document"));
-  sym_blockquote = ID2SYM(rb_intern("blockquote"));
-  sym_list = ID2SYM(rb_intern("list"));
-  sym_list_item = ID2SYM(rb_intern("list_item"));
-  sym_code_block = ID2SYM(rb_intern("code_block"));
-  sym_html = ID2SYM(rb_intern("html"));
-  sym_paragraph = ID2SYM(rb_intern("paragraph"));
-  sym_header = ID2SYM(rb_intern("header"));
-  sym_hrule = ID2SYM(rb_intern("hrule"));
-  sym_text = ID2SYM(rb_intern("text"));
-  sym_softbreak = ID2SYM(rb_intern("softbreak"));
-  sym_linebreak = ID2SYM(rb_intern("linebreak"));
-  sym_code = ID2SYM(rb_intern("code"));
-  sym_inline_html = ID2SYM(rb_intern("inline_html"));
-  sym_emph = ID2SYM(rb_intern("emph"));
-  sym_strong = ID2SYM(rb_intern("strong"));
-  sym_link = ID2SYM(rb_intern("link"));
-  sym_image = ID2SYM(rb_intern("image"));
-  sym_footnote_reference = ID2SYM(rb_intern("footnote_reference"));
-  sym_footnote_definition = ID2SYM(rb_intern("footnote_definition"));
-
-  sym_bullet_list = ID2SYM(rb_intern("bullet_list"));
-  sym_ordered_list = ID2SYM(rb_intern("ordered_list"));
-
-  sym_left = ID2SYM(rb_intern("left"));
-  sym_right = ID2SYM(rb_intern("right"));
-  sym_center = ID2SYM(rb_intern("center"));
-
-  module = rb_define_module("CommonMarker");
-  rb_define_singleton_method(module, "extensions", rb_extensions, 0);
-  rb_eNodeError = rb_define_class_under(module, "NodeError", rb_eStandardError);
-  rb_cNode = rb_define_class_under(module, "Node", rb_cObject);
-  rb_undef_alloc_func(rb_cNode);
-  rb_define_singleton_method(rb_cNode, "markdown_to_html", rb_markdown_to_html,
-                             3);
-  rb_define_singleton_method(rb_cNode, "markdown_to_xml", rb_markdown_to_xml,
-                             3);
-  rb_define_singleton_method(rb_cNode, "new", rb_node_new, 1);
-  rb_define_singleton_method(rb_cNode, "parse_document", rb_parse_document, 4);
-  rb_define_method(rb_cNode, "string_content", rb_node_get_string_content, 0);
-  rb_define_method(rb_cNode, "string_content=", rb_node_set_string_content, 1);
-  rb_define_method(rb_cNode, "type", rb_node_get_type, 0);
-  rb_define_method(rb_cNode, "type_string", rb_node_get_type_string, 0);
-  rb_define_method(rb_cNode, "sourcepos", rb_node_get_sourcepos, 0);
-  rb_define_method(rb_cNode, "delete", rb_node_unlink, 0);
-  rb_define_method(rb_cNode, "first_child", rb_node_first_child, 0);
-  rb_define_method(rb_cNode, "next", rb_node_next, 0);
-  rb_define_method(rb_cNode, "insert_before", rb_node_insert_before, 1);
-  rb_define_method(rb_cNode, "_render_html", rb_render_html, 2);
-  rb_define_method(rb_cNode, "_render_xml", rb_render_xml, 1);
-  rb_define_method(rb_cNode, "_render_commonmark", rb_render_commonmark, -1);
-  rb_define_method(rb_cNode, "_render_plaintext", rb_render_plaintext, -1);
-  rb_define_method(rb_cNode, "insert_after", rb_node_insert_after, 1);
-  rb_define_method(rb_cNode, "prepend_child", rb_node_prepend_child, 1);
-  rb_define_method(rb_cNode, "append_child", rb_node_append_child, 1);
-  rb_define_method(rb_cNode, "last_child", rb_node_last_child, 0);
-  rb_define_method(rb_cNode, "parent", rb_node_parent, 0);
-  rb_define_method(rb_cNode, "previous", rb_node_previous, 0);
-  rb_define_method(rb_cNode, "url", rb_node_get_url, 0);
-  rb_define_method(rb_cNode, "url=", rb_node_set_url, 1);
-  rb_define_method(rb_cNode, "title", rb_node_get_title, 0);
-  rb_define_method(rb_cNode, "title=", rb_node_set_title, 1);
-  rb_define_method(rb_cNode, "header_level", rb_node_get_header_level, 0);
-  rb_define_method(rb_cNode, "header_level=", rb_node_set_header_level, 1);
-  rb_define_method(rb_cNode, "list_type", rb_node_get_list_type, 0);
-  rb_define_method(rb_cNode, "list_type=", rb_node_set_list_type, 1);
-  rb_define_method(rb_cNode, "list_start", rb_node_get_list_start, 0);
-  rb_define_method(rb_cNode, "list_start=", rb_node_set_list_start, 1);
-  rb_define_method(rb_cNode, "list_tight", rb_node_get_list_tight, 0);
-  rb_define_method(rb_cNode, "list_tight=", rb_node_set_list_tight, 1);
-  rb_define_method(rb_cNode, "fence_info", rb_node_get_fence_info, 0);
-  rb_define_method(rb_cNode, "fence_info=", rb_node_set_fence_info, 1);
-  rb_define_method(rb_cNode, "table_alignments", rb_node_get_table_alignments, 0);
-  rb_define_method(rb_cNode, "tasklist_state", rb_node_get_tasklist_state, 0);
-  rb_define_method(rb_cNode, "tasklist_item_checked?", rb_node_get_tasklist_item_checked, 0);
-  rb_define_method(rb_cNode, "tasklist_item_checked=", rb_node_set_tasklist_item_checked, 1);
-
-  rb_define_method(rb_cNode, "html_escape_href", rb_html_escape_href, 1);
-  rb_define_method(rb_cNode, "html_escape_html", rb_html_escape_html, 1);
 
-  cmark_gfm_core_extensions_ensure_registered();
+  module = rb_define_module("Commonmarker");
+  rb_define_singleton_method(module, "commonmark_to_html", commonmarker_to_html, 2);
 }
diff --git a/ext/commonmarker/commonmarker.h b/ext/commonmarker/commonmarker.h
index da05dc4a..19e9e8db 100644
--- a/ext/commonmarker/commonmarker.h
+++ b/ext/commonmarker/commonmarker.h
@@ -5,12 +5,14 @@
 #define __MSXML_LIBRARY_DEFINED__
 #endif
 
-#include "cmark-gfm.h"
 #include "ruby.h"
 #include "ruby/encoding.h"
 
+#include "comrak.h"
+
 #define CSTR2SYM(s) (ID2SYM(rb_intern((s))))
 
 void Init_commonmarker();
+VALUE commonmarker_to_html(VALUE self, VALUE rb_commonmark_text, int options);
 
 #endif
diff --git a/ext/commonmarker/config.h b/ext/commonmarker/config.h
deleted file mode 100644
index d38c7c7a..00000000
--- a/ext/commonmarker/config.h
+++ /dev/null
@@ -1,76 +0,0 @@
-#ifndef CMARK_CONFIG_H
-#define CMARK_CONFIG_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#define HAVE_STDBOOL_H
-
-#ifdef HAVE_STDBOOL_H
-  #include 
-#elif !defined(__cplusplus)
-  typedef char bool;
-#endif
-
-#define HAVE___BUILTIN_EXPECT
-
-#define HAVE___ATTRIBUTE__
-
-#ifdef HAVE___ATTRIBUTE__
-  #define CMARK_ATTRIBUTE(list) __attribute__ (list)
-#else
-  #define CMARK_ATTRIBUTE(list)
-#endif
-
-#ifndef CMARK_INLINE
-  #if defined(_MSC_VER) && !defined(__cplusplus)
-    #define CMARK_INLINE __inline
-  #else
-    #define CMARK_INLINE inline
-  #endif
-#endif
-
-/* snprintf and vsnprintf fallbacks for MSVC before 2015,
-   due to Valentin Milea http://stackoverflow.com/questions/2915672/
-*/
-
-#if defined(_MSC_VER) && _MSC_VER < 1900
-
-#include 
-#include 
-
-#define snprintf c99_snprintf
-#define vsnprintf c99_vsnprintf
-
-CMARK_INLINE int c99_vsnprintf(char *outBuf, size_t size, const char *format, va_list ap)
-{
-    int count = -1;
-
-    if (size != 0)
-        count = _vsnprintf_s(outBuf, size, _TRUNCATE, format, ap);
-    if (count == -1)
-        count = _vscprintf(format, ap);
-
-    return count;
-}
-
-CMARK_INLINE int c99_snprintf(char *outBuf, size_t size, const char *format, ...)
-{
-    int count;
-    va_list ap;
-
-    va_start(ap, format);
-    count = c99_vsnprintf(outBuf, size, format, ap);
-    va_end(ap);
-
-    return count;
-}
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ext/commonmarker/core-extensions.c b/ext/commonmarker/core-extensions.c
deleted file mode 100644
index 846e2bc2..00000000
--- a/ext/commonmarker/core-extensions.c
+++ /dev/null
@@ -1,27 +0,0 @@
-#include "cmark-gfm-core-extensions.h"
-#include "autolink.h"
-#include "strikethrough.h"
-#include "table.h"
-#include "tagfilter.h"
-#include "tasklist.h"
-#include "registry.h"
-#include "plugin.h"
-
-static int core_extensions_registration(cmark_plugin *plugin) {
-  cmark_plugin_register_syntax_extension(plugin, create_table_extension());
-  cmark_plugin_register_syntax_extension(plugin,
-                                         create_strikethrough_extension());
-  cmark_plugin_register_syntax_extension(plugin, create_autolink_extension());
-  cmark_plugin_register_syntax_extension(plugin, create_tagfilter_extension());
-  cmark_plugin_register_syntax_extension(plugin, create_tasklist_extension());
-  return 1;
-}
-
-void cmark_gfm_core_extensions_ensure_registered(void) {
-  static int registered = 0;
-
-  if (!registered) {
-    cmark_register_plugin(core_extensions_registration);
-    registered = 1;
-  }
-}
diff --git a/ext/commonmarker/entities.inc b/ext/commonmarker/entities.inc
deleted file mode 100644
index a7c36e26..00000000
--- a/ext/commonmarker/entities.inc
+++ /dev/null
@@ -1,2138 +0,0 @@
-/* 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
-#define CMARK_NUM_ENTITIES 2125
-
-static const struct cmark_entity_node cmark_entities[] = {
-{(unsigned char*)"AElig", {195, 134, 0}},
-{(unsigned char*)"AMP", {38, 0}},
-{(unsigned char*)"Aacute", {195, 129, 0}},
-{(unsigned char*)"Abreve", {196, 130, 0}},
-{(unsigned char*)"Acirc", {195, 130, 0}},
-{(unsigned char*)"Acy", {208, 144, 0}},
-{(unsigned char*)"Afr", {240, 157, 148, 132, 0}},
-{(unsigned char*)"Agrave", {195, 128, 0}},
-{(unsigned char*)"Alpha", {206, 145, 0}},
-{(unsigned char*)"Amacr", {196, 128, 0}},
-{(unsigned char*)"And", {226, 169, 147, 0}},
-{(unsigned char*)"Aogon", {196, 132, 0}},
-{(unsigned char*)"Aopf", {240, 157, 148, 184, 0}},
-{(unsigned char*)"ApplyFunction", {226, 129, 161, 0}},
-{(unsigned char*)"Aring", {195, 133, 0}},
-{(unsigned char*)"Ascr", {240, 157, 146, 156, 0}},
-{(unsigned char*)"Assign", {226, 137, 148, 0}},
-{(unsigned char*)"Atilde", {195, 131, 0}},
-{(unsigned char*)"Auml", {195, 132, 0}},
-{(unsigned char*)"Backslash", {226, 136, 150, 0}},
-{(unsigned char*)"Barv", {226, 171, 167, 0}},
-{(unsigned char*)"Barwed", {226, 140, 134, 0}},
-{(unsigned char*)"Bcy", {208, 145, 0}},
-{(unsigned char*)"Because", {226, 136, 181, 0}},
-{(unsigned char*)"Bernoullis", {226, 132, 172, 0}},
-{(unsigned char*)"Beta", {206, 146, 0}},
-{(unsigned char*)"Bfr", {240, 157, 148, 133, 0}},
-{(unsigned char*)"Bopf", {240, 157, 148, 185, 0}},
-{(unsigned char*)"Breve", {203, 152, 0}},
-{(unsigned char*)"Bscr", {226, 132, 172, 0}},
-{(unsigned char*)"Bumpeq", {226, 137, 142, 0}},
-{(unsigned char*)"CHcy", {208, 167, 0}},
-{(unsigned char*)"COPY", {194, 169, 0}},
-{(unsigned char*)"Cacute", {196, 134, 0}},
-{(unsigned char*)"Cap", {226, 139, 146, 0}},
-{(unsigned char*)"CapitalDifferentialD", {226, 133, 133, 0}},
-{(unsigned char*)"Cayleys", {226, 132, 173, 0}},
-{(unsigned char*)"Ccaron", {196, 140, 0}},
-{(unsigned char*)"Ccedil", {195, 135, 0}},
-{(unsigned char*)"Ccirc", {196, 136, 0}},
-{(unsigned char*)"Cconint", {226, 136, 176, 0}},
-{(unsigned char*)"Cdot", {196, 138, 0}},
-{(unsigned char*)"Cedilla", {194, 184, 0}},
-{(unsigned char*)"CenterDot", {194, 183, 0}},
-{(unsigned char*)"Cfr", {226, 132, 173, 0}},
-{(unsigned char*)"Chi", {206, 167, 0}},
-{(unsigned char*)"CircleDot", {226, 138, 153, 0}},
-{(unsigned char*)"CircleMinus", {226, 138, 150, 0}},
-{(unsigned char*)"CirclePlus", {226, 138, 149, 0}},
-{(unsigned char*)"CircleTimes", {226, 138, 151, 0}},
-{(unsigned char*)"ClockwiseContourIntegral", {226, 136, 178, 0}},
-{(unsigned char*)"CloseCurlyDoubleQuote", {226, 128, 157, 0}},
-{(unsigned char*)"CloseCurlyQuote", {226, 128, 153, 0}},
-{(unsigned char*)"Colon", {226, 136, 183, 0}},
-{(unsigned char*)"Colone", {226, 169, 180, 0}},
-{(unsigned char*)"Congruent", {226, 137, 161, 0}},
-{(unsigned char*)"Conint", {226, 136, 175, 0}},
-{(unsigned char*)"ContourIntegral", {226, 136, 174, 0}},
-{(unsigned char*)"Copf", {226, 132, 130, 0}},
-{(unsigned char*)"Coproduct", {226, 136, 144, 0}},
-{(unsigned char*)"CounterClockwiseContourIntegral", {226, 136, 179, 0}},
-{(unsigned char*)"Cross", {226, 168, 175, 0}},
-{(unsigned char*)"Cscr", {240, 157, 146, 158, 0}},
-{(unsigned char*)"Cup", {226, 139, 147, 0}},
-{(unsigned char*)"CupCap", {226, 137, 141, 0}},
-{(unsigned char*)"DD", {226, 133, 133, 0}},
-{(unsigned char*)"DDotrahd", {226, 164, 145, 0}},
-{(unsigned char*)"DJcy", {208, 130, 0}},
-{(unsigned char*)"DScy", {208, 133, 0}},
-{(unsigned char*)"DZcy", {208, 143, 0}},
-{(unsigned char*)"Dagger", {226, 128, 161, 0}},
-{(unsigned char*)"Darr", {226, 134, 161, 0}},
-{(unsigned char*)"Dashv", {226, 171, 164, 0}},
-{(unsigned char*)"Dcaron", {196, 142, 0}},
-{(unsigned char*)"Dcy", {208, 148, 0}},
-{(unsigned char*)"Del", {226, 136, 135, 0}},
-{(unsigned char*)"Delta", {206, 148, 0}},
-{(unsigned char*)"Dfr", {240, 157, 148, 135, 0}},
-{(unsigned char*)"DiacriticalAcute", {194, 180, 0}},
-{(unsigned char*)"DiacriticalDot", {203, 153, 0}},
-{(unsigned char*)"DiacriticalDoubleAcute", {203, 157, 0}},
-{(unsigned char*)"DiacriticalGrave", {96, 0}},
-{(unsigned char*)"DiacriticalTilde", {203, 156, 0}},
-{(unsigned char*)"Diamond", {226, 139, 132, 0}},
-{(unsigned char*)"DifferentialD", {226, 133, 134, 0}},
-{(unsigned char*)"Dopf", {240, 157, 148, 187, 0}},
-{(unsigned char*)"Dot", {194, 168, 0}},
-{(unsigned char*)"DotDot", {226, 131, 156, 0}},
-{(unsigned char*)"DotEqual", {226, 137, 144, 0}},
-{(unsigned char*)"DoubleContourIntegral", {226, 136, 175, 0}},
-{(unsigned char*)"DoubleDot", {194, 168, 0}},
-{(unsigned char*)"DoubleDownArrow", {226, 135, 147, 0}},
-{(unsigned char*)"DoubleLeftArrow", {226, 135, 144, 0}},
-{(unsigned char*)"DoubleLeftRightArrow", {226, 135, 148, 0}},
-{(unsigned char*)"DoubleLeftTee", {226, 171, 164, 0}},
-{(unsigned char*)"DoubleLongLeftArrow", {226, 159, 184, 0}},
-{(unsigned char*)"DoubleLongLeftRightArrow", {226, 159, 186, 0}},
-{(unsigned char*)"DoubleLongRightArrow", {226, 159, 185, 0}},
-{(unsigned char*)"DoubleRightArrow", {226, 135, 146, 0}},
-{(unsigned char*)"DoubleRightTee", {226, 138, 168, 0}},
-{(unsigned char*)"DoubleUpArrow", {226, 135, 145, 0}},
-{(unsigned char*)"DoubleUpDownArrow", {226, 135, 149, 0}},
-{(unsigned char*)"DoubleVerticalBar", {226, 136, 165, 0}},
-{(unsigned char*)"DownArrow", {226, 134, 147, 0}},
-{(unsigned char*)"DownArrowBar", {226, 164, 147, 0}},
-{(unsigned char*)"DownArrowUpArrow", {226, 135, 181, 0}},
-{(unsigned char*)"DownBreve", {204, 145, 0}},
-{(unsigned char*)"DownLeftRightVector", {226, 165, 144, 0}},
-{(unsigned char*)"DownLeftTeeVector", {226, 165, 158, 0}},
-{(unsigned char*)"DownLeftVector", {226, 134, 189, 0}},
-{(unsigned char*)"DownLeftVectorBar", {226, 165, 150, 0}},
-{(unsigned char*)"DownRightTeeVector", {226, 165, 159, 0}},
-{(unsigned char*)"DownRightVector", {226, 135, 129, 0}},
-{(unsigned char*)"DownRightVectorBar", {226, 165, 151, 0}},
-{(unsigned char*)"DownTee", {226, 138, 164, 0}},
-{(unsigned char*)"DownTeeArrow", {226, 134, 167, 0}},
-{(unsigned char*)"Downarrow", {226, 135, 147, 0}},
-{(unsigned char*)"Dscr", {240, 157, 146, 159, 0}},
-{(unsigned char*)"Dstrok", {196, 144, 0}},
-{(unsigned char*)"ENG", {197, 138, 0}},
-{(unsigned char*)"ETH", {195, 144, 0}},
-{(unsigned char*)"Eacute", {195, 137, 0}},
-{(unsigned char*)"Ecaron", {196, 154, 0}},
-{(unsigned char*)"Ecirc", {195, 138, 0}},
-{(unsigned char*)"Ecy", {208, 173, 0}},
-{(unsigned char*)"Edot", {196, 150, 0}},
-{(unsigned char*)"Efr", {240, 157, 148, 136, 0}},
-{(unsigned char*)"Egrave", {195, 136, 0}},
-{(unsigned char*)"Element", {226, 136, 136, 0}},
-{(unsigned char*)"Emacr", {196, 146, 0}},
-{(unsigned char*)"EmptySmallSquare", {226, 151, 187, 0}},
-{(unsigned char*)"EmptyVerySmallSquare", {226, 150, 171, 0}},
-{(unsigned char*)"Eogon", {196, 152, 0}},
-{(unsigned char*)"Eopf", {240, 157, 148, 188, 0}},
-{(unsigned char*)"Epsilon", {206, 149, 0}},
-{(unsigned char*)"Equal", {226, 169, 181, 0}},
-{(unsigned char*)"EqualTilde", {226, 137, 130, 0}},
-{(unsigned char*)"Equilibrium", {226, 135, 140, 0}},
-{(unsigned char*)"Escr", {226, 132, 176, 0}},
-{(unsigned char*)"Esim", {226, 169, 179, 0}},
-{(unsigned char*)"Eta", {206, 151, 0}},
-{(unsigned char*)"Euml", {195, 139, 0}},
-{(unsigned char*)"Exists", {226, 136, 131, 0}},
-{(unsigned char*)"ExponentialE", {226, 133, 135, 0}},
-{(unsigned char*)"Fcy", {208, 164, 0}},
-{(unsigned char*)"Ffr", {240, 157, 148, 137, 0}},
-{(unsigned char*)"FilledSmallSquare", {226, 151, 188, 0}},
-{(unsigned char*)"FilledVerySmallSquare", {226, 150, 170, 0}},
-{(unsigned char*)"Fopf", {240, 157, 148, 189, 0}},
-{(unsigned char*)"ForAll", {226, 136, 128, 0}},
-{(unsigned char*)"Fouriertrf", {226, 132, 177, 0}},
-{(unsigned char*)"Fscr", {226, 132, 177, 0}},
-{(unsigned char*)"GJcy", {208, 131, 0}},
-{(unsigned char*)"GT", {62, 0}},
-{(unsigned char*)"Gamma", {206, 147, 0}},
-{(unsigned char*)"Gammad", {207, 156, 0}},
-{(unsigned char*)"Gbreve", {196, 158, 0}},
-{(unsigned char*)"Gcedil", {196, 162, 0}},
-{(unsigned char*)"Gcirc", {196, 156, 0}},
-{(unsigned char*)"Gcy", {208, 147, 0}},
-{(unsigned char*)"Gdot", {196, 160, 0}},
-{(unsigned char*)"Gfr", {240, 157, 148, 138, 0}},
-{(unsigned char*)"Gg", {226, 139, 153, 0}},
-{(unsigned char*)"Gopf", {240, 157, 148, 190, 0}},
-{(unsigned char*)"GreaterEqual", {226, 137, 165, 0}},
-{(unsigned char*)"GreaterEqualLess", {226, 139, 155, 0}},
-{(unsigned char*)"GreaterFullEqual", {226, 137, 167, 0}},
-{(unsigned char*)"GreaterGreater", {226, 170, 162, 0}},
-{(unsigned char*)"GreaterLess", {226, 137, 183, 0}},
-{(unsigned char*)"GreaterSlantEqual", {226, 169, 190, 0}},
-{(unsigned char*)"GreaterTilde", {226, 137, 179, 0}},
-{(unsigned char*)"Gscr", {240, 157, 146, 162, 0}},
-{(unsigned char*)"Gt", {226, 137, 171, 0}},
-{(unsigned char*)"HARDcy", {208, 170, 0}},
-{(unsigned char*)"Hacek", {203, 135, 0}},
-{(unsigned char*)"Hat", {94, 0}},
-{(unsigned char*)"Hcirc", {196, 164, 0}},
-{(unsigned char*)"Hfr", {226, 132, 140, 0}},
-{(unsigned char*)"HilbertSpace", {226, 132, 139, 0}},
-{(unsigned char*)"Hopf", {226, 132, 141, 0}},
-{(unsigned char*)"HorizontalLine", {226, 148, 128, 0}},
-{(unsigned char*)"Hscr", {226, 132, 139, 0}},
-{(unsigned char*)"Hstrok", {196, 166, 0}},
-{(unsigned char*)"HumpDownHump", {226, 137, 142, 0}},
-{(unsigned char*)"HumpEqual", {226, 137, 143, 0}},
-{(unsigned char*)"IEcy", {208, 149, 0}},
-{(unsigned char*)"IJlig", {196, 178, 0}},
-{(unsigned char*)"IOcy", {208, 129, 0}},
-{(unsigned char*)"Iacute", {195, 141, 0}},
-{(unsigned char*)"Icirc", {195, 142, 0}},
-{(unsigned char*)"Icy", {208, 152, 0}},
-{(unsigned char*)"Idot", {196, 176, 0}},
-{(unsigned char*)"Ifr", {226, 132, 145, 0}},
-{(unsigned char*)"Igrave", {195, 140, 0}},
-{(unsigned char*)"Im", {226, 132, 145, 0}},
-{(unsigned char*)"Imacr", {196, 170, 0}},
-{(unsigned char*)"ImaginaryI", {226, 133, 136, 0}},
-{(unsigned char*)"Implies", {226, 135, 146, 0}},
-{(unsigned char*)"Int", {226, 136, 172, 0}},
-{(unsigned char*)"Integral", {226, 136, 171, 0}},
-{(unsigned char*)"Intersection", {226, 139, 130, 0}},
-{(unsigned char*)"InvisibleComma", {226, 129, 163, 0}},
-{(unsigned char*)"InvisibleTimes", {226, 129, 162, 0}},
-{(unsigned char*)"Iogon", {196, 174, 0}},
-{(unsigned char*)"Iopf", {240, 157, 149, 128, 0}},
-{(unsigned char*)"Iota", {206, 153, 0}},
-{(unsigned char*)"Iscr", {226, 132, 144, 0}},
-{(unsigned char*)"Itilde", {196, 168, 0}},
-{(unsigned char*)"Iukcy", {208, 134, 0}},
-{(unsigned char*)"Iuml", {195, 143, 0}},
-{(unsigned char*)"Jcirc", {196, 180, 0}},
-{(unsigned char*)"Jcy", {208, 153, 0}},
-{(unsigned char*)"Jfr", {240, 157, 148, 141, 0}},
-{(unsigned char*)"Jopf", {240, 157, 149, 129, 0}},
-{(unsigned char*)"Jscr", {240, 157, 146, 165, 0}},
-{(unsigned char*)"Jsercy", {208, 136, 0}},
-{(unsigned char*)"Jukcy", {208, 132, 0}},
-{(unsigned char*)"KHcy", {208, 165, 0}},
-{(unsigned char*)"KJcy", {208, 140, 0}},
-{(unsigned char*)"Kappa", {206, 154, 0}},
-{(unsigned char*)"Kcedil", {196, 182, 0}},
-{(unsigned char*)"Kcy", {208, 154, 0}},
-{(unsigned char*)"Kfr", {240, 157, 148, 142, 0}},
-{(unsigned char*)"Kopf", {240, 157, 149, 130, 0}},
-{(unsigned char*)"Kscr", {240, 157, 146, 166, 0}},
-{(unsigned char*)"LJcy", {208, 137, 0}},
-{(unsigned char*)"LT", {60, 0}},
-{(unsigned char*)"Lacute", {196, 185, 0}},
-{(unsigned char*)"Lambda", {206, 155, 0}},
-{(unsigned char*)"Lang", {226, 159, 170, 0}},
-{(unsigned char*)"Laplacetrf", {226, 132, 146, 0}},
-{(unsigned char*)"Larr", {226, 134, 158, 0}},
-{(unsigned char*)"Lcaron", {196, 189, 0}},
-{(unsigned char*)"Lcedil", {196, 187, 0}},
-{(unsigned char*)"Lcy", {208, 155, 0}},
-{(unsigned char*)"LeftAngleBracket", {226, 159, 168, 0}},
-{(unsigned char*)"LeftArrow", {226, 134, 144, 0}},
-{(unsigned char*)"LeftArrowBar", {226, 135, 164, 0}},
-{(unsigned char*)"LeftArrowRightArrow", {226, 135, 134, 0}},
-{(unsigned char*)"LeftCeiling", {226, 140, 136, 0}},
-{(unsigned char*)"LeftDoubleBracket", {226, 159, 166, 0}},
-{(unsigned char*)"LeftDownTeeVector", {226, 165, 161, 0}},
-{(unsigned char*)"LeftDownVector", {226, 135, 131, 0}},
-{(unsigned char*)"LeftDownVectorBar", {226, 165, 153, 0}},
-{(unsigned char*)"LeftFloor", {226, 140, 138, 0}},
-{(unsigned char*)"LeftRightArrow", {226, 134, 148, 0}},
-{(unsigned char*)"LeftRightVector", {226, 165, 142, 0}},
-{(unsigned char*)"LeftTee", {226, 138, 163, 0}},
-{(unsigned char*)"LeftTeeArrow", {226, 134, 164, 0}},
-{(unsigned char*)"LeftTeeVector", {226, 165, 154, 0}},
-{(unsigned char*)"LeftTriangle", {226, 138, 178, 0}},
-{(unsigned char*)"LeftTriangleBar", {226, 167, 143, 0}},
-{(unsigned char*)"LeftTriangleEqual", {226, 138, 180, 0}},
-{(unsigned char*)"LeftUpDownVector", {226, 165, 145, 0}},
-{(unsigned char*)"LeftUpTeeVector", {226, 165, 160, 0}},
-{(unsigned char*)"LeftUpVector", {226, 134, 191, 0}},
-{(unsigned char*)"LeftUpVectorBar", {226, 165, 152, 0}},
-{(unsigned char*)"LeftVector", {226, 134, 188, 0}},
-{(unsigned char*)"LeftVectorBar", {226, 165, 146, 0}},
-{(unsigned char*)"Leftarrow", {226, 135, 144, 0}},
-{(unsigned char*)"Leftrightarrow", {226, 135, 148, 0}},
-{(unsigned char*)"LessEqualGreater", {226, 139, 154, 0}},
-{(unsigned char*)"LessFullEqual", {226, 137, 166, 0}},
-{(unsigned char*)"LessGreater", {226, 137, 182, 0}},
-{(unsigned char*)"LessLess", {226, 170, 161, 0}},
-{(unsigned char*)"LessSlantEqual", {226, 169, 189, 0}},
-{(unsigned char*)"LessTilde", {226, 137, 178, 0}},
-{(unsigned char*)"Lfr", {240, 157, 148, 143, 0}},
-{(unsigned char*)"Ll", {226, 139, 152, 0}},
-{(unsigned char*)"Lleftarrow", {226, 135, 154, 0}},
-{(unsigned char*)"Lmidot", {196, 191, 0}},
-{(unsigned char*)"LongLeftArrow", {226, 159, 181, 0}},
-{(unsigned char*)"LongLeftRightArrow", {226, 159, 183, 0}},
-{(unsigned char*)"LongRightArrow", {226, 159, 182, 0}},
-{(unsigned char*)"Longleftarrow", {226, 159, 184, 0}},
-{(unsigned char*)"Longleftrightarrow", {226, 159, 186, 0}},
-{(unsigned char*)"Longrightarrow", {226, 159, 185, 0}},
-{(unsigned char*)"Lopf", {240, 157, 149, 131, 0}},
-{(unsigned char*)"LowerLeftArrow", {226, 134, 153, 0}},
-{(unsigned char*)"LowerRightArrow", {226, 134, 152, 0}},
-{(unsigned char*)"Lscr", {226, 132, 146, 0}},
-{(unsigned char*)"Lsh", {226, 134, 176, 0}},
-{(unsigned char*)"Lstrok", {197, 129, 0}},
-{(unsigned char*)"Lt", {226, 137, 170, 0}},
-{(unsigned char*)"Map", {226, 164, 133, 0}},
-{(unsigned char*)"Mcy", {208, 156, 0}},
-{(unsigned char*)"MediumSpace", {226, 129, 159, 0}},
-{(unsigned char*)"Mellintrf", {226, 132, 179, 0}},
-{(unsigned char*)"Mfr", {240, 157, 148, 144, 0}},
-{(unsigned char*)"MinusPlus", {226, 136, 147, 0}},
-{(unsigned char*)"Mopf", {240, 157, 149, 132, 0}},
-{(unsigned char*)"Mscr", {226, 132, 179, 0}},
-{(unsigned char*)"Mu", {206, 156, 0}},
-{(unsigned char*)"NJcy", {208, 138, 0}},
-{(unsigned char*)"Nacute", {197, 131, 0}},
-{(unsigned char*)"Ncaron", {197, 135, 0}},
-{(unsigned char*)"Ncedil", {197, 133, 0}},
-{(unsigned char*)"Ncy", {208, 157, 0}},
-{(unsigned char*)"NegativeMediumSpace", {226, 128, 139, 0}},
-{(unsigned char*)"NegativeThickSpace", {226, 128, 139, 0}},
-{(unsigned char*)"NegativeThinSpace", {226, 128, 139, 0}},
-{(unsigned char*)"NegativeVeryThinSpace", {226, 128, 139, 0}},
-{(unsigned char*)"NestedGreaterGreater", {226, 137, 171, 0}},
-{(unsigned char*)"NestedLessLess", {226, 137, 170, 0}},
-{(unsigned char*)"NewLine", {10, 0}},
-{(unsigned char*)"Nfr", {240, 157, 148, 145, 0}},
-{(unsigned char*)"NoBreak", {226, 129, 160, 0}},
-{(unsigned char*)"NonBreakingSpace", {194, 160, 0}},
-{(unsigned char*)"Nopf", {226, 132, 149, 0}},
-{(unsigned char*)"Not", {226, 171, 172, 0}},
-{(unsigned char*)"NotCongruent", {226, 137, 162, 0}},
-{(unsigned char*)"NotCupCap", {226, 137, 173, 0}},
-{(unsigned char*)"NotDoubleVerticalBar", {226, 136, 166, 0}},
-{(unsigned char*)"NotElement", {226, 136, 137, 0}},
-{(unsigned char*)"NotEqual", {226, 137, 160, 0}},
-{(unsigned char*)"NotEqualTilde", {226, 137, 130, 204, 184, 0}},
-{(unsigned char*)"NotExists", {226, 136, 132, 0}},
-{(unsigned char*)"NotGreater", {226, 137, 175, 0}},
-{(unsigned char*)"NotGreaterEqual", {226, 137, 177, 0}},
-{(unsigned char*)"NotGreaterFullEqual", {226, 137, 167, 204, 184, 0}},
-{(unsigned char*)"NotGreaterGreater", {226, 137, 171, 204, 184, 0}},
-{(unsigned char*)"NotGreaterLess", {226, 137, 185, 0}},
-{(unsigned char*)"NotGreaterSlantEqual", {226, 169, 190, 204, 184, 0}},
-{(unsigned char*)"NotGreaterTilde", {226, 137, 181, 0}},
-{(unsigned char*)"NotHumpDownHump", {226, 137, 142, 204, 184, 0}},
-{(unsigned char*)"NotHumpEqual", {226, 137, 143, 204, 184, 0}},
-{(unsigned char*)"NotLeftTriangle", {226, 139, 170, 0}},
-{(unsigned char*)"NotLeftTriangleBar", {226, 167, 143, 204, 184, 0}},
-{(unsigned char*)"NotLeftTriangleEqual", {226, 139, 172, 0}},
-{(unsigned char*)"NotLess", {226, 137, 174, 0}},
-{(unsigned char*)"NotLessEqual", {226, 137, 176, 0}},
-{(unsigned char*)"NotLessGreater", {226, 137, 184, 0}},
-{(unsigned char*)"NotLessLess", {226, 137, 170, 204, 184, 0}},
-{(unsigned char*)"NotLessSlantEqual", {226, 169, 189, 204, 184, 0}},
-{(unsigned char*)"NotLessTilde", {226, 137, 180, 0}},
-{(unsigned char*)"NotNestedGreaterGreater", {226, 170, 162, 204, 184, 0}},
-{(unsigned char*)"NotNestedLessLess", {226, 170, 161, 204, 184, 0}},
-{(unsigned char*)"NotPrecedes", {226, 138, 128, 0}},
-{(unsigned char*)"NotPrecedesEqual", {226, 170, 175, 204, 184, 0}},
-{(unsigned char*)"NotPrecedesSlantEqual", {226, 139, 160, 0}},
-{(unsigned char*)"NotReverseElement", {226, 136, 140, 0}},
-{(unsigned char*)"NotRightTriangle", {226, 139, 171, 0}},
-{(unsigned char*)"NotRightTriangleBar", {226, 167, 144, 204, 184, 0}},
-{(unsigned char*)"NotRightTriangleEqual", {226, 139, 173, 0}},
-{(unsigned char*)"NotSquareSubset", {226, 138, 143, 204, 184, 0}},
-{(unsigned char*)"NotSquareSubsetEqual", {226, 139, 162, 0}},
-{(unsigned char*)"NotSquareSuperset", {226, 138, 144, 204, 184, 0}},
-{(unsigned char*)"NotSquareSupersetEqual", {226, 139, 163, 0}},
-{(unsigned char*)"NotSubset", {226, 138, 130, 226, 131, 146, 0}},
-{(unsigned char*)"NotSubsetEqual", {226, 138, 136, 0}},
-{(unsigned char*)"NotSucceeds", {226, 138, 129, 0}},
-{(unsigned char*)"NotSucceedsEqual", {226, 170, 176, 204, 184, 0}},
-{(unsigned char*)"NotSucceedsSlantEqual", {226, 139, 161, 0}},
-{(unsigned char*)"NotSucceedsTilde", {226, 137, 191, 204, 184, 0}},
-{(unsigned char*)"NotSuperset", {226, 138, 131, 226, 131, 146, 0}},
-{(unsigned char*)"NotSupersetEqual", {226, 138, 137, 0}},
-{(unsigned char*)"NotTilde", {226, 137, 129, 0}},
-{(unsigned char*)"NotTildeEqual", {226, 137, 132, 0}},
-{(unsigned char*)"NotTildeFullEqual", {226, 137, 135, 0}},
-{(unsigned char*)"NotTildeTilde", {226, 137, 137, 0}},
-{(unsigned char*)"NotVerticalBar", {226, 136, 164, 0}},
-{(unsigned char*)"Nscr", {240, 157, 146, 169, 0}},
-{(unsigned char*)"Ntilde", {195, 145, 0}},
-{(unsigned char*)"Nu", {206, 157, 0}},
-{(unsigned char*)"OElig", {197, 146, 0}},
-{(unsigned char*)"Oacute", {195, 147, 0}},
-{(unsigned char*)"Ocirc", {195, 148, 0}},
-{(unsigned char*)"Ocy", {208, 158, 0}},
-{(unsigned char*)"Odblac", {197, 144, 0}},
-{(unsigned char*)"Ofr", {240, 157, 148, 146, 0}},
-{(unsigned char*)"Ograve", {195, 146, 0}},
-{(unsigned char*)"Omacr", {197, 140, 0}},
-{(unsigned char*)"Omega", {206, 169, 0}},
-{(unsigned char*)"Omicron", {206, 159, 0}},
-{(unsigned char*)"Oopf", {240, 157, 149, 134, 0}},
-{(unsigned char*)"OpenCurlyDoubleQuote", {226, 128, 156, 0}},
-{(unsigned char*)"OpenCurlyQuote", {226, 128, 152, 0}},
-{(unsigned char*)"Or", {226, 169, 148, 0}},
-{(unsigned char*)"Oscr", {240, 157, 146, 170, 0}},
-{(unsigned char*)"Oslash", {195, 152, 0}},
-{(unsigned char*)"Otilde", {195, 149, 0}},
-{(unsigned char*)"Otimes", {226, 168, 183, 0}},
-{(unsigned char*)"Ouml", {195, 150, 0}},
-{(unsigned char*)"OverBar", {226, 128, 190, 0}},
-{(unsigned char*)"OverBrace", {226, 143, 158, 0}},
-{(unsigned char*)"OverBracket", {226, 142, 180, 0}},
-{(unsigned char*)"OverParenthesis", {226, 143, 156, 0}},
-{(unsigned char*)"PartialD", {226, 136, 130, 0}},
-{(unsigned char*)"Pcy", {208, 159, 0}},
-{(unsigned char*)"Pfr", {240, 157, 148, 147, 0}},
-{(unsigned char*)"Phi", {206, 166, 0}},
-{(unsigned char*)"Pi", {206, 160, 0}},
-{(unsigned char*)"PlusMinus", {194, 177, 0}},
-{(unsigned char*)"Poincareplane", {226, 132, 140, 0}},
-{(unsigned char*)"Popf", {226, 132, 153, 0}},
-{(unsigned char*)"Pr", {226, 170, 187, 0}},
-{(unsigned char*)"Precedes", {226, 137, 186, 0}},
-{(unsigned char*)"PrecedesEqual", {226, 170, 175, 0}},
-{(unsigned char*)"PrecedesSlantEqual", {226, 137, 188, 0}},
-{(unsigned char*)"PrecedesTilde", {226, 137, 190, 0}},
-{(unsigned char*)"Prime", {226, 128, 179, 0}},
-{(unsigned char*)"Product", {226, 136, 143, 0}},
-{(unsigned char*)"Proportion", {226, 136, 183, 0}},
-{(unsigned char*)"Proportional", {226, 136, 157, 0}},
-{(unsigned char*)"Pscr", {240, 157, 146, 171, 0}},
-{(unsigned char*)"Psi", {206, 168, 0}},
-{(unsigned char*)"QUOT", {34, 0}},
-{(unsigned char*)"Qfr", {240, 157, 148, 148, 0}},
-{(unsigned char*)"Qopf", {226, 132, 154, 0}},
-{(unsigned char*)"Qscr", {240, 157, 146, 172, 0}},
-{(unsigned char*)"RBarr", {226, 164, 144, 0}},
-{(unsigned char*)"REG", {194, 174, 0}},
-{(unsigned char*)"Racute", {197, 148, 0}},
-{(unsigned char*)"Rang", {226, 159, 171, 0}},
-{(unsigned char*)"Rarr", {226, 134, 160, 0}},
-{(unsigned char*)"Rarrtl", {226, 164, 150, 0}},
-{(unsigned char*)"Rcaron", {197, 152, 0}},
-{(unsigned char*)"Rcedil", {197, 150, 0}},
-{(unsigned char*)"Rcy", {208, 160, 0}},
-{(unsigned char*)"Re", {226, 132, 156, 0}},
-{(unsigned char*)"ReverseElement", {226, 136, 139, 0}},
-{(unsigned char*)"ReverseEquilibrium", {226, 135, 139, 0}},
-{(unsigned char*)"ReverseUpEquilibrium", {226, 165, 175, 0}},
-{(unsigned char*)"Rfr", {226, 132, 156, 0}},
-{(unsigned char*)"Rho", {206, 161, 0}},
-{(unsigned char*)"RightAngleBracket", {226, 159, 169, 0}},
-{(unsigned char*)"RightArrow", {226, 134, 146, 0}},
-{(unsigned char*)"RightArrowBar", {226, 135, 165, 0}},
-{(unsigned char*)"RightArrowLeftArrow", {226, 135, 132, 0}},
-{(unsigned char*)"RightCeiling", {226, 140, 137, 0}},
-{(unsigned char*)"RightDoubleBracket", {226, 159, 167, 0}},
-{(unsigned char*)"RightDownTeeVector", {226, 165, 157, 0}},
-{(unsigned char*)"RightDownVector", {226, 135, 130, 0}},
-{(unsigned char*)"RightDownVectorBar", {226, 165, 149, 0}},
-{(unsigned char*)"RightFloor", {226, 140, 139, 0}},
-{(unsigned char*)"RightTee", {226, 138, 162, 0}},
-{(unsigned char*)"RightTeeArrow", {226, 134, 166, 0}},
-{(unsigned char*)"RightTeeVector", {226, 165, 155, 0}},
-{(unsigned char*)"RightTriangle", {226, 138, 179, 0}},
-{(unsigned char*)"RightTriangleBar", {226, 167, 144, 0}},
-{(unsigned char*)"RightTriangleEqual", {226, 138, 181, 0}},
-{(unsigned char*)"RightUpDownVector", {226, 165, 143, 0}},
-{(unsigned char*)"RightUpTeeVector", {226, 165, 156, 0}},
-{(unsigned char*)"RightUpVector", {226, 134, 190, 0}},
-{(unsigned char*)"RightUpVectorBar", {226, 165, 148, 0}},
-{(unsigned char*)"RightVector", {226, 135, 128, 0}},
-{(unsigned char*)"RightVectorBar", {226, 165, 147, 0}},
-{(unsigned char*)"Rightarrow", {226, 135, 146, 0}},
-{(unsigned char*)"Ropf", {226, 132, 157, 0}},
-{(unsigned char*)"RoundImplies", {226, 165, 176, 0}},
-{(unsigned char*)"Rrightarrow", {226, 135, 155, 0}},
-{(unsigned char*)"Rscr", {226, 132, 155, 0}},
-{(unsigned char*)"Rsh", {226, 134, 177, 0}},
-{(unsigned char*)"RuleDelayed", {226, 167, 180, 0}},
-{(unsigned char*)"SHCHcy", {208, 169, 0}},
-{(unsigned char*)"SHcy", {208, 168, 0}},
-{(unsigned char*)"SOFTcy", {208, 172, 0}},
-{(unsigned char*)"Sacute", {197, 154, 0}},
-{(unsigned char*)"Sc", {226, 170, 188, 0}},
-{(unsigned char*)"Scaron", {197, 160, 0}},
-{(unsigned char*)"Scedil", {197, 158, 0}},
-{(unsigned char*)"Scirc", {197, 156, 0}},
-{(unsigned char*)"Scy", {208, 161, 0}},
-{(unsigned char*)"Sfr", {240, 157, 148, 150, 0}},
-{(unsigned char*)"ShortDownArrow", {226, 134, 147, 0}},
-{(unsigned char*)"ShortLeftArrow", {226, 134, 144, 0}},
-{(unsigned char*)"ShortRightArrow", {226, 134, 146, 0}},
-{(unsigned char*)"ShortUpArrow", {226, 134, 145, 0}},
-{(unsigned char*)"Sigma", {206, 163, 0}},
-{(unsigned char*)"SmallCircle", {226, 136, 152, 0}},
-{(unsigned char*)"Sopf", {240, 157, 149, 138, 0}},
-{(unsigned char*)"Sqrt", {226, 136, 154, 0}},
-{(unsigned char*)"Square", {226, 150, 161, 0}},
-{(unsigned char*)"SquareIntersection", {226, 138, 147, 0}},
-{(unsigned char*)"SquareSubset", {226, 138, 143, 0}},
-{(unsigned char*)"SquareSubsetEqual", {226, 138, 145, 0}},
-{(unsigned char*)"SquareSuperset", {226, 138, 144, 0}},
-{(unsigned char*)"SquareSupersetEqual", {226, 138, 146, 0}},
-{(unsigned char*)"SquareUnion", {226, 138, 148, 0}},
-{(unsigned char*)"Sscr", {240, 157, 146, 174, 0}},
-{(unsigned char*)"Star", {226, 139, 134, 0}},
-{(unsigned char*)"Sub", {226, 139, 144, 0}},
-{(unsigned char*)"Subset", {226, 139, 144, 0}},
-{(unsigned char*)"SubsetEqual", {226, 138, 134, 0}},
-{(unsigned char*)"Succeeds", {226, 137, 187, 0}},
-{(unsigned char*)"SucceedsEqual", {226, 170, 176, 0}},
-{(unsigned char*)"SucceedsSlantEqual", {226, 137, 189, 0}},
-{(unsigned char*)"SucceedsTilde", {226, 137, 191, 0}},
-{(unsigned char*)"SuchThat", {226, 136, 139, 0}},
-{(unsigned char*)"Sum", {226, 136, 145, 0}},
-{(unsigned char*)"Sup", {226, 139, 145, 0}},
-{(unsigned char*)"Superset", {226, 138, 131, 0}},
-{(unsigned char*)"SupersetEqual", {226, 138, 135, 0}},
-{(unsigned char*)"Supset", {226, 139, 145, 0}},
-{(unsigned char*)"THORN", {195, 158, 0}},
-{(unsigned char*)"TRADE", {226, 132, 162, 0}},
-{(unsigned char*)"TSHcy", {208, 139, 0}},
-{(unsigned char*)"TScy", {208, 166, 0}},
-{(unsigned char*)"Tab", {9, 0}},
-{(unsigned char*)"Tau", {206, 164, 0}},
-{(unsigned char*)"Tcaron", {197, 164, 0}},
-{(unsigned char*)"Tcedil", {197, 162, 0}},
-{(unsigned char*)"Tcy", {208, 162, 0}},
-{(unsigned char*)"Tfr", {240, 157, 148, 151, 0}},
-{(unsigned char*)"Therefore", {226, 136, 180, 0}},
-{(unsigned char*)"Theta", {206, 152, 0}},
-{(unsigned char*)"ThickSpace", {226, 129, 159, 226, 128, 138, 0}},
-{(unsigned char*)"ThinSpace", {226, 128, 137, 0}},
-{(unsigned char*)"Tilde", {226, 136, 188, 0}},
-{(unsigned char*)"TildeEqual", {226, 137, 131, 0}},
-{(unsigned char*)"TildeFullEqual", {226, 137, 133, 0}},
-{(unsigned char*)"TildeTilde", {226, 137, 136, 0}},
-{(unsigned char*)"Topf", {240, 157, 149, 139, 0}},
-{(unsigned char*)"TripleDot", {226, 131, 155, 0}},
-{(unsigned char*)"Tscr", {240, 157, 146, 175, 0}},
-{(unsigned char*)"Tstrok", {197, 166, 0}},
-{(unsigned char*)"Uacute", {195, 154, 0}},
-{(unsigned char*)"Uarr", {226, 134, 159, 0}},
-{(unsigned char*)"Uarrocir", {226, 165, 137, 0}},
-{(unsigned char*)"Ubrcy", {208, 142, 0}},
-{(unsigned char*)"Ubreve", {197, 172, 0}},
-{(unsigned char*)"Ucirc", {195, 155, 0}},
-{(unsigned char*)"Ucy", {208, 163, 0}},
-{(unsigned char*)"Udblac", {197, 176, 0}},
-{(unsigned char*)"Ufr", {240, 157, 148, 152, 0}},
-{(unsigned char*)"Ugrave", {195, 153, 0}},
-{(unsigned char*)"Umacr", {197, 170, 0}},
-{(unsigned char*)"UnderBar", {95, 0}},
-{(unsigned char*)"UnderBrace", {226, 143, 159, 0}},
-{(unsigned char*)"UnderBracket", {226, 142, 181, 0}},
-{(unsigned char*)"UnderParenthesis", {226, 143, 157, 0}},
-{(unsigned char*)"Union", {226, 139, 131, 0}},
-{(unsigned char*)"UnionPlus", {226, 138, 142, 0}},
-{(unsigned char*)"Uogon", {197, 178, 0}},
-{(unsigned char*)"Uopf", {240, 157, 149, 140, 0}},
-{(unsigned char*)"UpArrow", {226, 134, 145, 0}},
-{(unsigned char*)"UpArrowBar", {226, 164, 146, 0}},
-{(unsigned char*)"UpArrowDownArrow", {226, 135, 133, 0}},
-{(unsigned char*)"UpDownArrow", {226, 134, 149, 0}},
-{(unsigned char*)"UpEquilibrium", {226, 165, 174, 0}},
-{(unsigned char*)"UpTee", {226, 138, 165, 0}},
-{(unsigned char*)"UpTeeArrow", {226, 134, 165, 0}},
-{(unsigned char*)"Uparrow", {226, 135, 145, 0}},
-{(unsigned char*)"Updownarrow", {226, 135, 149, 0}},
-{(unsigned char*)"UpperLeftArrow", {226, 134, 150, 0}},
-{(unsigned char*)"UpperRightArrow", {226, 134, 151, 0}},
-{(unsigned char*)"Upsi", {207, 146, 0}},
-{(unsigned char*)"Upsilon", {206, 165, 0}},
-{(unsigned char*)"Uring", {197, 174, 0}},
-{(unsigned char*)"Uscr", {240, 157, 146, 176, 0}},
-{(unsigned char*)"Utilde", {197, 168, 0}},
-{(unsigned char*)"Uuml", {195, 156, 0}},
-{(unsigned char*)"VDash", {226, 138, 171, 0}},
-{(unsigned char*)"Vbar", {226, 171, 171, 0}},
-{(unsigned char*)"Vcy", {208, 146, 0}},
-{(unsigned char*)"Vdash", {226, 138, 169, 0}},
-{(unsigned char*)"Vdashl", {226, 171, 166, 0}},
-{(unsigned char*)"Vee", {226, 139, 129, 0}},
-{(unsigned char*)"Verbar", {226, 128, 150, 0}},
-{(unsigned char*)"Vert", {226, 128, 150, 0}},
-{(unsigned char*)"VerticalBar", {226, 136, 163, 0}},
-{(unsigned char*)"VerticalLine", {124, 0}},
-{(unsigned char*)"VerticalSeparator", {226, 157, 152, 0}},
-{(unsigned char*)"VerticalTilde", {226, 137, 128, 0}},
-{(unsigned char*)"VeryThinSpace", {226, 128, 138, 0}},
-{(unsigned char*)"Vfr", {240, 157, 148, 153, 0}},
-{(unsigned char*)"Vopf", {240, 157, 149, 141, 0}},
-{(unsigned char*)"Vscr", {240, 157, 146, 177, 0}},
-{(unsigned char*)"Vvdash", {226, 138, 170, 0}},
-{(unsigned char*)"Wcirc", {197, 180, 0}},
-{(unsigned char*)"Wedge", {226, 139, 128, 0}},
-{(unsigned char*)"Wfr", {240, 157, 148, 154, 0}},
-{(unsigned char*)"Wopf", {240, 157, 149, 142, 0}},
-{(unsigned char*)"Wscr", {240, 157, 146, 178, 0}},
-{(unsigned char*)"Xfr", {240, 157, 148, 155, 0}},
-{(unsigned char*)"Xi", {206, 158, 0}},
-{(unsigned char*)"Xopf", {240, 157, 149, 143, 0}},
-{(unsigned char*)"Xscr", {240, 157, 146, 179, 0}},
-{(unsigned char*)"YAcy", {208, 175, 0}},
-{(unsigned char*)"YIcy", {208, 135, 0}},
-{(unsigned char*)"YUcy", {208, 174, 0}},
-{(unsigned char*)"Yacute", {195, 157, 0}},
-{(unsigned char*)"Ycirc", {197, 182, 0}},
-{(unsigned char*)"Ycy", {208, 171, 0}},
-{(unsigned char*)"Yfr", {240, 157, 148, 156, 0}},
-{(unsigned char*)"Yopf", {240, 157, 149, 144, 0}},
-{(unsigned char*)"Yscr", {240, 157, 146, 180, 0}},
-{(unsigned char*)"Yuml", {197, 184, 0}},
-{(unsigned char*)"ZHcy", {208, 150, 0}},
-{(unsigned char*)"Zacute", {197, 185, 0}},
-{(unsigned char*)"Zcaron", {197, 189, 0}},
-{(unsigned char*)"Zcy", {208, 151, 0}},
-{(unsigned char*)"Zdot", {197, 187, 0}},
-{(unsigned char*)"ZeroWidthSpace", {226, 128, 139, 0}},
-{(unsigned char*)"Zeta", {206, 150, 0}},
-{(unsigned char*)"Zfr", {226, 132, 168, 0}},
-{(unsigned char*)"Zopf", {226, 132, 164, 0}},
-{(unsigned char*)"Zscr", {240, 157, 146, 181, 0}},
-{(unsigned char*)"aacute", {195, 161, 0}},
-{(unsigned char*)"abreve", {196, 131, 0}},
-{(unsigned char*)"ac", {226, 136, 190, 0}},
-{(unsigned char*)"acE", {226, 136, 190, 204, 179, 0}},
-{(unsigned char*)"acd", {226, 136, 191, 0}},
-{(unsigned char*)"acirc", {195, 162, 0}},
-{(unsigned char*)"acute", {194, 180, 0}},
-{(unsigned char*)"acy", {208, 176, 0}},
-{(unsigned char*)"aelig", {195, 166, 0}},
-{(unsigned char*)"af", {226, 129, 161, 0}},
-{(unsigned char*)"afr", {240, 157, 148, 158, 0}},
-{(unsigned char*)"agrave", {195, 160, 0}},
-{(unsigned char*)"alefsym", {226, 132, 181, 0}},
-{(unsigned char*)"aleph", {226, 132, 181, 0}},
-{(unsigned char*)"alpha", {206, 177, 0}},
-{(unsigned char*)"amacr", {196, 129, 0}},
-{(unsigned char*)"amalg", {226, 168, 191, 0}},
-{(unsigned char*)"amp", {38, 0}},
-{(unsigned char*)"and", {226, 136, 167, 0}},
-{(unsigned char*)"andand", {226, 169, 149, 0}},
-{(unsigned char*)"andd", {226, 169, 156, 0}},
-{(unsigned char*)"andslope", {226, 169, 152, 0}},
-{(unsigned char*)"andv", {226, 169, 154, 0}},
-{(unsigned char*)"ang", {226, 136, 160, 0}},
-{(unsigned char*)"ange", {226, 166, 164, 0}},
-{(unsigned char*)"angle", {226, 136, 160, 0}},
-{(unsigned char*)"angmsd", {226, 136, 161, 0}},
-{(unsigned char*)"angmsdaa", {226, 166, 168, 0}},
-{(unsigned char*)"angmsdab", {226, 166, 169, 0}},
-{(unsigned char*)"angmsdac", {226, 166, 170, 0}},
-{(unsigned char*)"angmsdad", {226, 166, 171, 0}},
-{(unsigned char*)"angmsdae", {226, 166, 172, 0}},
-{(unsigned char*)"angmsdaf", {226, 166, 173, 0}},
-{(unsigned char*)"angmsdag", {226, 166, 174, 0}},
-{(unsigned char*)"angmsdah", {226, 166, 175, 0}},
-{(unsigned char*)"angrt", {226, 136, 159, 0}},
-{(unsigned char*)"angrtvb", {226, 138, 190, 0}},
-{(unsigned char*)"angrtvbd", {226, 166, 157, 0}},
-{(unsigned char*)"angsph", {226, 136, 162, 0}},
-{(unsigned char*)"angst", {195, 133, 0}},
-{(unsigned char*)"angzarr", {226, 141, 188, 0}},
-{(unsigned char*)"aogon", {196, 133, 0}},
-{(unsigned char*)"aopf", {240, 157, 149, 146, 0}},
-{(unsigned char*)"ap", {226, 137, 136, 0}},
-{(unsigned char*)"apE", {226, 169, 176, 0}},
-{(unsigned char*)"apacir", {226, 169, 175, 0}},
-{(unsigned char*)"ape", {226, 137, 138, 0}},
-{(unsigned char*)"apid", {226, 137, 139, 0}},
-{(unsigned char*)"apos", {39, 0}},
-{(unsigned char*)"approx", {226, 137, 136, 0}},
-{(unsigned char*)"approxeq", {226, 137, 138, 0}},
-{(unsigned char*)"aring", {195, 165, 0}},
-{(unsigned char*)"ascr", {240, 157, 146, 182, 0}},
-{(unsigned char*)"ast", {42, 0}},
-{(unsigned char*)"asymp", {226, 137, 136, 0}},
-{(unsigned char*)"asympeq", {226, 137, 141, 0}},
-{(unsigned char*)"atilde", {195, 163, 0}},
-{(unsigned char*)"auml", {195, 164, 0}},
-{(unsigned char*)"awconint", {226, 136, 179, 0}},
-{(unsigned char*)"awint", {226, 168, 145, 0}},
-{(unsigned char*)"bNot", {226, 171, 173, 0}},
-{(unsigned char*)"backcong", {226, 137, 140, 0}},
-{(unsigned char*)"backepsilon", {207, 182, 0}},
-{(unsigned char*)"backprime", {226, 128, 181, 0}},
-{(unsigned char*)"backsim", {226, 136, 189, 0}},
-{(unsigned char*)"backsimeq", {226, 139, 141, 0}},
-{(unsigned char*)"barvee", {226, 138, 189, 0}},
-{(unsigned char*)"barwed", {226, 140, 133, 0}},
-{(unsigned char*)"barwedge", {226, 140, 133, 0}},
-{(unsigned char*)"bbrk", {226, 142, 181, 0}},
-{(unsigned char*)"bbrktbrk", {226, 142, 182, 0}},
-{(unsigned char*)"bcong", {226, 137, 140, 0}},
-{(unsigned char*)"bcy", {208, 177, 0}},
-{(unsigned char*)"bdquo", {226, 128, 158, 0}},
-{(unsigned char*)"becaus", {226, 136, 181, 0}},
-{(unsigned char*)"because", {226, 136, 181, 0}},
-{(unsigned char*)"bemptyv", {226, 166, 176, 0}},
-{(unsigned char*)"bepsi", {207, 182, 0}},
-{(unsigned char*)"bernou", {226, 132, 172, 0}},
-{(unsigned char*)"beta", {206, 178, 0}},
-{(unsigned char*)"beth", {226, 132, 182, 0}},
-{(unsigned char*)"between", {226, 137, 172, 0}},
-{(unsigned char*)"bfr", {240, 157, 148, 159, 0}},
-{(unsigned char*)"bigcap", {226, 139, 130, 0}},
-{(unsigned char*)"bigcirc", {226, 151, 175, 0}},
-{(unsigned char*)"bigcup", {226, 139, 131, 0}},
-{(unsigned char*)"bigodot", {226, 168, 128, 0}},
-{(unsigned char*)"bigoplus", {226, 168, 129, 0}},
-{(unsigned char*)"bigotimes", {226, 168, 130, 0}},
-{(unsigned char*)"bigsqcup", {226, 168, 134, 0}},
-{(unsigned char*)"bigstar", {226, 152, 133, 0}},
-{(unsigned char*)"bigtriangledown", {226, 150, 189, 0}},
-{(unsigned char*)"bigtriangleup", {226, 150, 179, 0}},
-{(unsigned char*)"biguplus", {226, 168, 132, 0}},
-{(unsigned char*)"bigvee", {226, 139, 129, 0}},
-{(unsigned char*)"bigwedge", {226, 139, 128, 0}},
-{(unsigned char*)"bkarow", {226, 164, 141, 0}},
-{(unsigned char*)"blacklozenge", {226, 167, 171, 0}},
-{(unsigned char*)"blacksquare", {226, 150, 170, 0}},
-{(unsigned char*)"blacktriangle", {226, 150, 180, 0}},
-{(unsigned char*)"blacktriangledown", {226, 150, 190, 0}},
-{(unsigned char*)"blacktriangleleft", {226, 151, 130, 0}},
-{(unsigned char*)"blacktriangleright", {226, 150, 184, 0}},
-{(unsigned char*)"blank", {226, 144, 163, 0}},
-{(unsigned char*)"blk12", {226, 150, 146, 0}},
-{(unsigned char*)"blk14", {226, 150, 145, 0}},
-{(unsigned char*)"blk34", {226, 150, 147, 0}},
-{(unsigned char*)"block", {226, 150, 136, 0}},
-{(unsigned char*)"bne", {61, 226, 131, 165, 0}},
-{(unsigned char*)"bnequiv", {226, 137, 161, 226, 131, 165, 0}},
-{(unsigned char*)"bnot", {226, 140, 144, 0}},
-{(unsigned char*)"bopf", {240, 157, 149, 147, 0}},
-{(unsigned char*)"bot", {226, 138, 165, 0}},
-{(unsigned char*)"bottom", {226, 138, 165, 0}},
-{(unsigned char*)"bowtie", {226, 139, 136, 0}},
-{(unsigned char*)"boxDL", {226, 149, 151, 0}},
-{(unsigned char*)"boxDR", {226, 149, 148, 0}},
-{(unsigned char*)"boxDl", {226, 149, 150, 0}},
-{(unsigned char*)"boxDr", {226, 149, 147, 0}},
-{(unsigned char*)"boxH", {226, 149, 144, 0}},
-{(unsigned char*)"boxHD", {226, 149, 166, 0}},
-{(unsigned char*)"boxHU", {226, 149, 169, 0}},
-{(unsigned char*)"boxHd", {226, 149, 164, 0}},
-{(unsigned char*)"boxHu", {226, 149, 167, 0}},
-{(unsigned char*)"boxUL", {226, 149, 157, 0}},
-{(unsigned char*)"boxUR", {226, 149, 154, 0}},
-{(unsigned char*)"boxUl", {226, 149, 156, 0}},
-{(unsigned char*)"boxUr", {226, 149, 153, 0}},
-{(unsigned char*)"boxV", {226, 149, 145, 0}},
-{(unsigned char*)"boxVH", {226, 149, 172, 0}},
-{(unsigned char*)"boxVL", {226, 149, 163, 0}},
-{(unsigned char*)"boxVR", {226, 149, 160, 0}},
-{(unsigned char*)"boxVh", {226, 149, 171, 0}},
-{(unsigned char*)"boxVl", {226, 149, 162, 0}},
-{(unsigned char*)"boxVr", {226, 149, 159, 0}},
-{(unsigned char*)"boxbox", {226, 167, 137, 0}},
-{(unsigned char*)"boxdL", {226, 149, 149, 0}},
-{(unsigned char*)"boxdR", {226, 149, 146, 0}},
-{(unsigned char*)"boxdl", {226, 148, 144, 0}},
-{(unsigned char*)"boxdr", {226, 148, 140, 0}},
-{(unsigned char*)"boxh", {226, 148, 128, 0}},
-{(unsigned char*)"boxhD", {226, 149, 165, 0}},
-{(unsigned char*)"boxhU", {226, 149, 168, 0}},
-{(unsigned char*)"boxhd", {226, 148, 172, 0}},
-{(unsigned char*)"boxhu", {226, 148, 180, 0}},
-{(unsigned char*)"boxminus", {226, 138, 159, 0}},
-{(unsigned char*)"boxplus", {226, 138, 158, 0}},
-{(unsigned char*)"boxtimes", {226, 138, 160, 0}},
-{(unsigned char*)"boxuL", {226, 149, 155, 0}},
-{(unsigned char*)"boxuR", {226, 149, 152, 0}},
-{(unsigned char*)"boxul", {226, 148, 152, 0}},
-{(unsigned char*)"boxur", {226, 148, 148, 0}},
-{(unsigned char*)"boxv", {226, 148, 130, 0}},
-{(unsigned char*)"boxvH", {226, 149, 170, 0}},
-{(unsigned char*)"boxvL", {226, 149, 161, 0}},
-{(unsigned char*)"boxvR", {226, 149, 158, 0}},
-{(unsigned char*)"boxvh", {226, 148, 188, 0}},
-{(unsigned char*)"boxvl", {226, 148, 164, 0}},
-{(unsigned char*)"boxvr", {226, 148, 156, 0}},
-{(unsigned char*)"bprime", {226, 128, 181, 0}},
-{(unsigned char*)"breve", {203, 152, 0}},
-{(unsigned char*)"brvbar", {194, 166, 0}},
-{(unsigned char*)"bscr", {240, 157, 146, 183, 0}},
-{(unsigned char*)"bsemi", {226, 129, 143, 0}},
-{(unsigned char*)"bsim", {226, 136, 189, 0}},
-{(unsigned char*)"bsime", {226, 139, 141, 0}},
-{(unsigned char*)"bsol", {92, 0}},
-{(unsigned char*)"bsolb", {226, 167, 133, 0}},
-{(unsigned char*)"bsolhsub", {226, 159, 136, 0}},
-{(unsigned char*)"bull", {226, 128, 162, 0}},
-{(unsigned char*)"bullet", {226, 128, 162, 0}},
-{(unsigned char*)"bump", {226, 137, 142, 0}},
-{(unsigned char*)"bumpE", {226, 170, 174, 0}},
-{(unsigned char*)"bumpe", {226, 137, 143, 0}},
-{(unsigned char*)"bumpeq", {226, 137, 143, 0}},
-{(unsigned char*)"cacute", {196, 135, 0}},
-{(unsigned char*)"cap", {226, 136, 169, 0}},
-{(unsigned char*)"capand", {226, 169, 132, 0}},
-{(unsigned char*)"capbrcup", {226, 169, 137, 0}},
-{(unsigned char*)"capcap", {226, 169, 139, 0}},
-{(unsigned char*)"capcup", {226, 169, 135, 0}},
-{(unsigned char*)"capdot", {226, 169, 128, 0}},
-{(unsigned char*)"caps", {226, 136, 169, 239, 184, 128, 0}},
-{(unsigned char*)"caret", {226, 129, 129, 0}},
-{(unsigned char*)"caron", {203, 135, 0}},
-{(unsigned char*)"ccaps", {226, 169, 141, 0}},
-{(unsigned char*)"ccaron", {196, 141, 0}},
-{(unsigned char*)"ccedil", {195, 167, 0}},
-{(unsigned char*)"ccirc", {196, 137, 0}},
-{(unsigned char*)"ccups", {226, 169, 140, 0}},
-{(unsigned char*)"ccupssm", {226, 169, 144, 0}},
-{(unsigned char*)"cdot", {196, 139, 0}},
-{(unsigned char*)"cedil", {194, 184, 0}},
-{(unsigned char*)"cemptyv", {226, 166, 178, 0}},
-{(unsigned char*)"cent", {194, 162, 0}},
-{(unsigned char*)"centerdot", {194, 183, 0}},
-{(unsigned char*)"cfr", {240, 157, 148, 160, 0}},
-{(unsigned char*)"chcy", {209, 135, 0}},
-{(unsigned char*)"check", {226, 156, 147, 0}},
-{(unsigned char*)"checkmark", {226, 156, 147, 0}},
-{(unsigned char*)"chi", {207, 135, 0}},
-{(unsigned char*)"cir", {226, 151, 139, 0}},
-{(unsigned char*)"cirE", {226, 167, 131, 0}},
-{(unsigned char*)"circ", {203, 134, 0}},
-{(unsigned char*)"circeq", {226, 137, 151, 0}},
-{(unsigned char*)"circlearrowleft", {226, 134, 186, 0}},
-{(unsigned char*)"circlearrowright", {226, 134, 187, 0}},
-{(unsigned char*)"circledR", {194, 174, 0}},
-{(unsigned char*)"circledS", {226, 147, 136, 0}},
-{(unsigned char*)"circledast", {226, 138, 155, 0}},
-{(unsigned char*)"circledcirc", {226, 138, 154, 0}},
-{(unsigned char*)"circleddash", {226, 138, 157, 0}},
-{(unsigned char*)"cire", {226, 137, 151, 0}},
-{(unsigned char*)"cirfnint", {226, 168, 144, 0}},
-{(unsigned char*)"cirmid", {226, 171, 175, 0}},
-{(unsigned char*)"cirscir", {226, 167, 130, 0}},
-{(unsigned char*)"clubs", {226, 153, 163, 0}},
-{(unsigned char*)"clubsuit", {226, 153, 163, 0}},
-{(unsigned char*)"colon", {58, 0}},
-{(unsigned char*)"colone", {226, 137, 148, 0}},
-{(unsigned char*)"coloneq", {226, 137, 148, 0}},
-{(unsigned char*)"comma", {44, 0}},
-{(unsigned char*)"commat", {64, 0}},
-{(unsigned char*)"comp", {226, 136, 129, 0}},
-{(unsigned char*)"compfn", {226, 136, 152, 0}},
-{(unsigned char*)"complement", {226, 136, 129, 0}},
-{(unsigned char*)"complexes", {226, 132, 130, 0}},
-{(unsigned char*)"cong", {226, 137, 133, 0}},
-{(unsigned char*)"congdot", {226, 169, 173, 0}},
-{(unsigned char*)"conint", {226, 136, 174, 0}},
-{(unsigned char*)"copf", {240, 157, 149, 148, 0}},
-{(unsigned char*)"coprod", {226, 136, 144, 0}},
-{(unsigned char*)"copy", {194, 169, 0}},
-{(unsigned char*)"copysr", {226, 132, 151, 0}},
-{(unsigned char*)"crarr", {226, 134, 181, 0}},
-{(unsigned char*)"cross", {226, 156, 151, 0}},
-{(unsigned char*)"cscr", {240, 157, 146, 184, 0}},
-{(unsigned char*)"csub", {226, 171, 143, 0}},
-{(unsigned char*)"csube", {226, 171, 145, 0}},
-{(unsigned char*)"csup", {226, 171, 144, 0}},
-{(unsigned char*)"csupe", {226, 171, 146, 0}},
-{(unsigned char*)"ctdot", {226, 139, 175, 0}},
-{(unsigned char*)"cudarrl", {226, 164, 184, 0}},
-{(unsigned char*)"cudarrr", {226, 164, 181, 0}},
-{(unsigned char*)"cuepr", {226, 139, 158, 0}},
-{(unsigned char*)"cuesc", {226, 139, 159, 0}},
-{(unsigned char*)"cularr", {226, 134, 182, 0}},
-{(unsigned char*)"cularrp", {226, 164, 189, 0}},
-{(unsigned char*)"cup", {226, 136, 170, 0}},
-{(unsigned char*)"cupbrcap", {226, 169, 136, 0}},
-{(unsigned char*)"cupcap", {226, 169, 134, 0}},
-{(unsigned char*)"cupcup", {226, 169, 138, 0}},
-{(unsigned char*)"cupdot", {226, 138, 141, 0}},
-{(unsigned char*)"cupor", {226, 169, 133, 0}},
-{(unsigned char*)"cups", {226, 136, 170, 239, 184, 128, 0}},
-{(unsigned char*)"curarr", {226, 134, 183, 0}},
-{(unsigned char*)"curarrm", {226, 164, 188, 0}},
-{(unsigned char*)"curlyeqprec", {226, 139, 158, 0}},
-{(unsigned char*)"curlyeqsucc", {226, 139, 159, 0}},
-{(unsigned char*)"curlyvee", {226, 139, 142, 0}},
-{(unsigned char*)"curlywedge", {226, 139, 143, 0}},
-{(unsigned char*)"curren", {194, 164, 0}},
-{(unsigned char*)"curvearrowleft", {226, 134, 182, 0}},
-{(unsigned char*)"curvearrowright", {226, 134, 183, 0}},
-{(unsigned char*)"cuvee", {226, 139, 142, 0}},
-{(unsigned char*)"cuwed", {226, 139, 143, 0}},
-{(unsigned char*)"cwconint", {226, 136, 178, 0}},
-{(unsigned char*)"cwint", {226, 136, 177, 0}},
-{(unsigned char*)"cylcty", {226, 140, 173, 0}},
-{(unsigned char*)"dArr", {226, 135, 147, 0}},
-{(unsigned char*)"dHar", {226, 165, 165, 0}},
-{(unsigned char*)"dagger", {226, 128, 160, 0}},
-{(unsigned char*)"daleth", {226, 132, 184, 0}},
-{(unsigned char*)"darr", {226, 134, 147, 0}},
-{(unsigned char*)"dash", {226, 128, 144, 0}},
-{(unsigned char*)"dashv", {226, 138, 163, 0}},
-{(unsigned char*)"dbkarow", {226, 164, 143, 0}},
-{(unsigned char*)"dblac", {203, 157, 0}},
-{(unsigned char*)"dcaron", {196, 143, 0}},
-{(unsigned char*)"dcy", {208, 180, 0}},
-{(unsigned char*)"dd", {226, 133, 134, 0}},
-{(unsigned char*)"ddagger", {226, 128, 161, 0}},
-{(unsigned char*)"ddarr", {226, 135, 138, 0}},
-{(unsigned char*)"ddotseq", {226, 169, 183, 0}},
-{(unsigned char*)"deg", {194, 176, 0}},
-{(unsigned char*)"delta", {206, 180, 0}},
-{(unsigned char*)"demptyv", {226, 166, 177, 0}},
-{(unsigned char*)"dfisht", {226, 165, 191, 0}},
-{(unsigned char*)"dfr", {240, 157, 148, 161, 0}},
-{(unsigned char*)"dharl", {226, 135, 131, 0}},
-{(unsigned char*)"dharr", {226, 135, 130, 0}},
-{(unsigned char*)"diam", {226, 139, 132, 0}},
-{(unsigned char*)"diamond", {226, 139, 132, 0}},
-{(unsigned char*)"diamondsuit", {226, 153, 166, 0}},
-{(unsigned char*)"diams", {226, 153, 166, 0}},
-{(unsigned char*)"die", {194, 168, 0}},
-{(unsigned char*)"digamma", {207, 157, 0}},
-{(unsigned char*)"disin", {226, 139, 178, 0}},
-{(unsigned char*)"div", {195, 183, 0}},
-{(unsigned char*)"divide", {195, 183, 0}},
-{(unsigned char*)"divideontimes", {226, 139, 135, 0}},
-{(unsigned char*)"divonx", {226, 139, 135, 0}},
-{(unsigned char*)"djcy", {209, 146, 0}},
-{(unsigned char*)"dlcorn", {226, 140, 158, 0}},
-{(unsigned char*)"dlcrop", {226, 140, 141, 0}},
-{(unsigned char*)"dollar", {36, 0}},
-{(unsigned char*)"dopf", {240, 157, 149, 149, 0}},
-{(unsigned char*)"dot", {203, 153, 0}},
-{(unsigned char*)"doteq", {226, 137, 144, 0}},
-{(unsigned char*)"doteqdot", {226, 137, 145, 0}},
-{(unsigned char*)"dotminus", {226, 136, 184, 0}},
-{(unsigned char*)"dotplus", {226, 136, 148, 0}},
-{(unsigned char*)"dotsquare", {226, 138, 161, 0}},
-{(unsigned char*)"doublebarwedge", {226, 140, 134, 0}},
-{(unsigned char*)"downarrow", {226, 134, 147, 0}},
-{(unsigned char*)"downdownarrows", {226, 135, 138, 0}},
-{(unsigned char*)"downharpoonleft", {226, 135, 131, 0}},
-{(unsigned char*)"downharpoonright", {226, 135, 130, 0}},
-{(unsigned char*)"drbkarow", {226, 164, 144, 0}},
-{(unsigned char*)"drcorn", {226, 140, 159, 0}},
-{(unsigned char*)"drcrop", {226, 140, 140, 0}},
-{(unsigned char*)"dscr", {240, 157, 146, 185, 0}},
-{(unsigned char*)"dscy", {209, 149, 0}},
-{(unsigned char*)"dsol", {226, 167, 182, 0}},
-{(unsigned char*)"dstrok", {196, 145, 0}},
-{(unsigned char*)"dtdot", {226, 139, 177, 0}},
-{(unsigned char*)"dtri", {226, 150, 191, 0}},
-{(unsigned char*)"dtrif", {226, 150, 190, 0}},
-{(unsigned char*)"duarr", {226, 135, 181, 0}},
-{(unsigned char*)"duhar", {226, 165, 175, 0}},
-{(unsigned char*)"dwangle", {226, 166, 166, 0}},
-{(unsigned char*)"dzcy", {209, 159, 0}},
-{(unsigned char*)"dzigrarr", {226, 159, 191, 0}},
-{(unsigned char*)"eDDot", {226, 169, 183, 0}},
-{(unsigned char*)"eDot", {226, 137, 145, 0}},
-{(unsigned char*)"eacute", {195, 169, 0}},
-{(unsigned char*)"easter", {226, 169, 174, 0}},
-{(unsigned char*)"ecaron", {196, 155, 0}},
-{(unsigned char*)"ecir", {226, 137, 150, 0}},
-{(unsigned char*)"ecirc", {195, 170, 0}},
-{(unsigned char*)"ecolon", {226, 137, 149, 0}},
-{(unsigned char*)"ecy", {209, 141, 0}},
-{(unsigned char*)"edot", {196, 151, 0}},
-{(unsigned char*)"ee", {226, 133, 135, 0}},
-{(unsigned char*)"efDot", {226, 137, 146, 0}},
-{(unsigned char*)"efr", {240, 157, 148, 162, 0}},
-{(unsigned char*)"eg", {226, 170, 154, 0}},
-{(unsigned char*)"egrave", {195, 168, 0}},
-{(unsigned char*)"egs", {226, 170, 150, 0}},
-{(unsigned char*)"egsdot", {226, 170, 152, 0}},
-{(unsigned char*)"el", {226, 170, 153, 0}},
-{(unsigned char*)"elinters", {226, 143, 167, 0}},
-{(unsigned char*)"ell", {226, 132, 147, 0}},
-{(unsigned char*)"els", {226, 170, 149, 0}},
-{(unsigned char*)"elsdot", {226, 170, 151, 0}},
-{(unsigned char*)"emacr", {196, 147, 0}},
-{(unsigned char*)"empty", {226, 136, 133, 0}},
-{(unsigned char*)"emptyset", {226, 136, 133, 0}},
-{(unsigned char*)"emptyv", {226, 136, 133, 0}},
-{(unsigned char*)"emsp", {226, 128, 131, 0}},
-{(unsigned char*)"emsp13", {226, 128, 132, 0}},
-{(unsigned char*)"emsp14", {226, 128, 133, 0}},
-{(unsigned char*)"eng", {197, 139, 0}},
-{(unsigned char*)"ensp", {226, 128, 130, 0}},
-{(unsigned char*)"eogon", {196, 153, 0}},
-{(unsigned char*)"eopf", {240, 157, 149, 150, 0}},
-{(unsigned char*)"epar", {226, 139, 149, 0}},
-{(unsigned char*)"eparsl", {226, 167, 163, 0}},
-{(unsigned char*)"eplus", {226, 169, 177, 0}},
-{(unsigned char*)"epsi", {206, 181, 0}},
-{(unsigned char*)"epsilon", {206, 181, 0}},
-{(unsigned char*)"epsiv", {207, 181, 0}},
-{(unsigned char*)"eqcirc", {226, 137, 150, 0}},
-{(unsigned char*)"eqcolon", {226, 137, 149, 0}},
-{(unsigned char*)"eqsim", {226, 137, 130, 0}},
-{(unsigned char*)"eqslantgtr", {226, 170, 150, 0}},
-{(unsigned char*)"eqslantless", {226, 170, 149, 0}},
-{(unsigned char*)"equals", {61, 0}},
-{(unsigned char*)"equest", {226, 137, 159, 0}},
-{(unsigned char*)"equiv", {226, 137, 161, 0}},
-{(unsigned char*)"equivDD", {226, 169, 184, 0}},
-{(unsigned char*)"eqvparsl", {226, 167, 165, 0}},
-{(unsigned char*)"erDot", {226, 137, 147, 0}},
-{(unsigned char*)"erarr", {226, 165, 177, 0}},
-{(unsigned char*)"escr", {226, 132, 175, 0}},
-{(unsigned char*)"esdot", {226, 137, 144, 0}},
-{(unsigned char*)"esim", {226, 137, 130, 0}},
-{(unsigned char*)"eta", {206, 183, 0}},
-{(unsigned char*)"eth", {195, 176, 0}},
-{(unsigned char*)"euml", {195, 171, 0}},
-{(unsigned char*)"euro", {226, 130, 172, 0}},
-{(unsigned char*)"excl", {33, 0}},
-{(unsigned char*)"exist", {226, 136, 131, 0}},
-{(unsigned char*)"expectation", {226, 132, 176, 0}},
-{(unsigned char*)"exponentiale", {226, 133, 135, 0}},
-{(unsigned char*)"fallingdotseq", {226, 137, 146, 0}},
-{(unsigned char*)"fcy", {209, 132, 0}},
-{(unsigned char*)"female", {226, 153, 128, 0}},
-{(unsigned char*)"ffilig", {239, 172, 131, 0}},
-{(unsigned char*)"fflig", {239, 172, 128, 0}},
-{(unsigned char*)"ffllig", {239, 172, 132, 0}},
-{(unsigned char*)"ffr", {240, 157, 148, 163, 0}},
-{(unsigned char*)"filig", {239, 172, 129, 0}},
-{(unsigned char*)"fjlig", {102, 106, 0}},
-{(unsigned char*)"flat", {226, 153, 173, 0}},
-{(unsigned char*)"fllig", {239, 172, 130, 0}},
-{(unsigned char*)"fltns", {226, 150, 177, 0}},
-{(unsigned char*)"fnof", {198, 146, 0}},
-{(unsigned char*)"fopf", {240, 157, 149, 151, 0}},
-{(unsigned char*)"forall", {226, 136, 128, 0}},
-{(unsigned char*)"fork", {226, 139, 148, 0}},
-{(unsigned char*)"forkv", {226, 171, 153, 0}},
-{(unsigned char*)"fpartint", {226, 168, 141, 0}},
-{(unsigned char*)"frac12", {194, 189, 0}},
-{(unsigned char*)"frac13", {226, 133, 147, 0}},
-{(unsigned char*)"frac14", {194, 188, 0}},
-{(unsigned char*)"frac15", {226, 133, 149, 0}},
-{(unsigned char*)"frac16", {226, 133, 153, 0}},
-{(unsigned char*)"frac18", {226, 133, 155, 0}},
-{(unsigned char*)"frac23", {226, 133, 148, 0}},
-{(unsigned char*)"frac25", {226, 133, 150, 0}},
-{(unsigned char*)"frac34", {194, 190, 0}},
-{(unsigned char*)"frac35", {226, 133, 151, 0}},
-{(unsigned char*)"frac38", {226, 133, 156, 0}},
-{(unsigned char*)"frac45", {226, 133, 152, 0}},
-{(unsigned char*)"frac56", {226, 133, 154, 0}},
-{(unsigned char*)"frac58", {226, 133, 157, 0}},
-{(unsigned char*)"frac78", {226, 133, 158, 0}},
-{(unsigned char*)"frasl", {226, 129, 132, 0}},
-{(unsigned char*)"frown", {226, 140, 162, 0}},
-{(unsigned char*)"fscr", {240, 157, 146, 187, 0}},
-{(unsigned char*)"gE", {226, 137, 167, 0}},
-{(unsigned char*)"gEl", {226, 170, 140, 0}},
-{(unsigned char*)"gacute", {199, 181, 0}},
-{(unsigned char*)"gamma", {206, 179, 0}},
-{(unsigned char*)"gammad", {207, 157, 0}},
-{(unsigned char*)"gap", {226, 170, 134, 0}},
-{(unsigned char*)"gbreve", {196, 159, 0}},
-{(unsigned char*)"gcirc", {196, 157, 0}},
-{(unsigned char*)"gcy", {208, 179, 0}},
-{(unsigned char*)"gdot", {196, 161, 0}},
-{(unsigned char*)"ge", {226, 137, 165, 0}},
-{(unsigned char*)"gel", {226, 139, 155, 0}},
-{(unsigned char*)"geq", {226, 137, 165, 0}},
-{(unsigned char*)"geqq", {226, 137, 167, 0}},
-{(unsigned char*)"geqslant", {226, 169, 190, 0}},
-{(unsigned char*)"ges", {226, 169, 190, 0}},
-{(unsigned char*)"gescc", {226, 170, 169, 0}},
-{(unsigned char*)"gesdot", {226, 170, 128, 0}},
-{(unsigned char*)"gesdoto", {226, 170, 130, 0}},
-{(unsigned char*)"gesdotol", {226, 170, 132, 0}},
-{(unsigned char*)"gesl", {226, 139, 155, 239, 184, 128, 0}},
-{(unsigned char*)"gesles", {226, 170, 148, 0}},
-{(unsigned char*)"gfr", {240, 157, 148, 164, 0}},
-{(unsigned char*)"gg", {226, 137, 171, 0}},
-{(unsigned char*)"ggg", {226, 139, 153, 0}},
-{(unsigned char*)"gimel", {226, 132, 183, 0}},
-{(unsigned char*)"gjcy", {209, 147, 0}},
-{(unsigned char*)"gl", {226, 137, 183, 0}},
-{(unsigned char*)"glE", {226, 170, 146, 0}},
-{(unsigned char*)"gla", {226, 170, 165, 0}},
-{(unsigned char*)"glj", {226, 170, 164, 0}},
-{(unsigned char*)"gnE", {226, 137, 169, 0}},
-{(unsigned char*)"gnap", {226, 170, 138, 0}},
-{(unsigned char*)"gnapprox", {226, 170, 138, 0}},
-{(unsigned char*)"gne", {226, 170, 136, 0}},
-{(unsigned char*)"gneq", {226, 170, 136, 0}},
-{(unsigned char*)"gneqq", {226, 137, 169, 0}},
-{(unsigned char*)"gnsim", {226, 139, 167, 0}},
-{(unsigned char*)"gopf", {240, 157, 149, 152, 0}},
-{(unsigned char*)"grave", {96, 0}},
-{(unsigned char*)"gscr", {226, 132, 138, 0}},
-{(unsigned char*)"gsim", {226, 137, 179, 0}},
-{(unsigned char*)"gsime", {226, 170, 142, 0}},
-{(unsigned char*)"gsiml", {226, 170, 144, 0}},
-{(unsigned char*)"gt", {62, 0}},
-{(unsigned char*)"gtcc", {226, 170, 167, 0}},
-{(unsigned char*)"gtcir", {226, 169, 186, 0}},
-{(unsigned char*)"gtdot", {226, 139, 151, 0}},
-{(unsigned char*)"gtlPar", {226, 166, 149, 0}},
-{(unsigned char*)"gtquest", {226, 169, 188, 0}},
-{(unsigned char*)"gtrapprox", {226, 170, 134, 0}},
-{(unsigned char*)"gtrarr", {226, 165, 184, 0}},
-{(unsigned char*)"gtrdot", {226, 139, 151, 0}},
-{(unsigned char*)"gtreqless", {226, 139, 155, 0}},
-{(unsigned char*)"gtreqqless", {226, 170, 140, 0}},
-{(unsigned char*)"gtrless", {226, 137, 183, 0}},
-{(unsigned char*)"gtrsim", {226, 137, 179, 0}},
-{(unsigned char*)"gvertneqq", {226, 137, 169, 239, 184, 128, 0}},
-{(unsigned char*)"gvnE", {226, 137, 169, 239, 184, 128, 0}},
-{(unsigned char*)"hArr", {226, 135, 148, 0}},
-{(unsigned char*)"hairsp", {226, 128, 138, 0}},
-{(unsigned char*)"half", {194, 189, 0}},
-{(unsigned char*)"hamilt", {226, 132, 139, 0}},
-{(unsigned char*)"hardcy", {209, 138, 0}},
-{(unsigned char*)"harr", {226, 134, 148, 0}},
-{(unsigned char*)"harrcir", {226, 165, 136, 0}},
-{(unsigned char*)"harrw", {226, 134, 173, 0}},
-{(unsigned char*)"hbar", {226, 132, 143, 0}},
-{(unsigned char*)"hcirc", {196, 165, 0}},
-{(unsigned char*)"hearts", {226, 153, 165, 0}},
-{(unsigned char*)"heartsuit", {226, 153, 165, 0}},
-{(unsigned char*)"hellip", {226, 128, 166, 0}},
-{(unsigned char*)"hercon", {226, 138, 185, 0}},
-{(unsigned char*)"hfr", {240, 157, 148, 165, 0}},
-{(unsigned char*)"hksearow", {226, 164, 165, 0}},
-{(unsigned char*)"hkswarow", {226, 164, 166, 0}},
-{(unsigned char*)"hoarr", {226, 135, 191, 0}},
-{(unsigned char*)"homtht", {226, 136, 187, 0}},
-{(unsigned char*)"hookleftarrow", {226, 134, 169, 0}},
-{(unsigned char*)"hookrightarrow", {226, 134, 170, 0}},
-{(unsigned char*)"hopf", {240, 157, 149, 153, 0}},
-{(unsigned char*)"horbar", {226, 128, 149, 0}},
-{(unsigned char*)"hscr", {240, 157, 146, 189, 0}},
-{(unsigned char*)"hslash", {226, 132, 143, 0}},
-{(unsigned char*)"hstrok", {196, 167, 0}},
-{(unsigned char*)"hybull", {226, 129, 131, 0}},
-{(unsigned char*)"hyphen", {226, 128, 144, 0}},
-{(unsigned char*)"iacute", {195, 173, 0}},
-{(unsigned char*)"ic", {226, 129, 163, 0}},
-{(unsigned char*)"icirc", {195, 174, 0}},
-{(unsigned char*)"icy", {208, 184, 0}},
-{(unsigned char*)"iecy", {208, 181, 0}},
-{(unsigned char*)"iexcl", {194, 161, 0}},
-{(unsigned char*)"iff", {226, 135, 148, 0}},
-{(unsigned char*)"ifr", {240, 157, 148, 166, 0}},
-{(unsigned char*)"igrave", {195, 172, 0}},
-{(unsigned char*)"ii", {226, 133, 136, 0}},
-{(unsigned char*)"iiiint", {226, 168, 140, 0}},
-{(unsigned char*)"iiint", {226, 136, 173, 0}},
-{(unsigned char*)"iinfin", {226, 167, 156, 0}},
-{(unsigned char*)"iiota", {226, 132, 169, 0}},
-{(unsigned char*)"ijlig", {196, 179, 0}},
-{(unsigned char*)"imacr", {196, 171, 0}},
-{(unsigned char*)"image", {226, 132, 145, 0}},
-{(unsigned char*)"imagline", {226, 132, 144, 0}},
-{(unsigned char*)"imagpart", {226, 132, 145, 0}},
-{(unsigned char*)"imath", {196, 177, 0}},
-{(unsigned char*)"imof", {226, 138, 183, 0}},
-{(unsigned char*)"imped", {198, 181, 0}},
-{(unsigned char*)"in", {226, 136, 136, 0}},
-{(unsigned char*)"incare", {226, 132, 133, 0}},
-{(unsigned char*)"infin", {226, 136, 158, 0}},
-{(unsigned char*)"infintie", {226, 167, 157, 0}},
-{(unsigned char*)"inodot", {196, 177, 0}},
-{(unsigned char*)"int", {226, 136, 171, 0}},
-{(unsigned char*)"intcal", {226, 138, 186, 0}},
-{(unsigned char*)"integers", {226, 132, 164, 0}},
-{(unsigned char*)"intercal", {226, 138, 186, 0}},
-{(unsigned char*)"intlarhk", {226, 168, 151, 0}},
-{(unsigned char*)"intprod", {226, 168, 188, 0}},
-{(unsigned char*)"iocy", {209, 145, 0}},
-{(unsigned char*)"iogon", {196, 175, 0}},
-{(unsigned char*)"iopf", {240, 157, 149, 154, 0}},
-{(unsigned char*)"iota", {206, 185, 0}},
-{(unsigned char*)"iprod", {226, 168, 188, 0}},
-{(unsigned char*)"iquest", {194, 191, 0}},
-{(unsigned char*)"iscr", {240, 157, 146, 190, 0}},
-{(unsigned char*)"isin", {226, 136, 136, 0}},
-{(unsigned char*)"isinE", {226, 139, 185, 0}},
-{(unsigned char*)"isindot", {226, 139, 181, 0}},
-{(unsigned char*)"isins", {226, 139, 180, 0}},
-{(unsigned char*)"isinsv", {226, 139, 179, 0}},
-{(unsigned char*)"isinv", {226, 136, 136, 0}},
-{(unsigned char*)"it", {226, 129, 162, 0}},
-{(unsigned char*)"itilde", {196, 169, 0}},
-{(unsigned char*)"iukcy", {209, 150, 0}},
-{(unsigned char*)"iuml", {195, 175, 0}},
-{(unsigned char*)"jcirc", {196, 181, 0}},
-{(unsigned char*)"jcy", {208, 185, 0}},
-{(unsigned char*)"jfr", {240, 157, 148, 167, 0}},
-{(unsigned char*)"jmath", {200, 183, 0}},
-{(unsigned char*)"jopf", {240, 157, 149, 155, 0}},
-{(unsigned char*)"jscr", {240, 157, 146, 191, 0}},
-{(unsigned char*)"jsercy", {209, 152, 0}},
-{(unsigned char*)"jukcy", {209, 148, 0}},
-{(unsigned char*)"kappa", {206, 186, 0}},
-{(unsigned char*)"kappav", {207, 176, 0}},
-{(unsigned char*)"kcedil", {196, 183, 0}},
-{(unsigned char*)"kcy", {208, 186, 0}},
-{(unsigned char*)"kfr", {240, 157, 148, 168, 0}},
-{(unsigned char*)"kgreen", {196, 184, 0}},
-{(unsigned char*)"khcy", {209, 133, 0}},
-{(unsigned char*)"kjcy", {209, 156, 0}},
-{(unsigned char*)"kopf", {240, 157, 149, 156, 0}},
-{(unsigned char*)"kscr", {240, 157, 147, 128, 0}},
-{(unsigned char*)"lAarr", {226, 135, 154, 0}},
-{(unsigned char*)"lArr", {226, 135, 144, 0}},
-{(unsigned char*)"lAtail", {226, 164, 155, 0}},
-{(unsigned char*)"lBarr", {226, 164, 142, 0}},
-{(unsigned char*)"lE", {226, 137, 166, 0}},
-{(unsigned char*)"lEg", {226, 170, 139, 0}},
-{(unsigned char*)"lHar", {226, 165, 162, 0}},
-{(unsigned char*)"lacute", {196, 186, 0}},
-{(unsigned char*)"laemptyv", {226, 166, 180, 0}},
-{(unsigned char*)"lagran", {226, 132, 146, 0}},
-{(unsigned char*)"lambda", {206, 187, 0}},
-{(unsigned char*)"lang", {226, 159, 168, 0}},
-{(unsigned char*)"langd", {226, 166, 145, 0}},
-{(unsigned char*)"langle", {226, 159, 168, 0}},
-{(unsigned char*)"lap", {226, 170, 133, 0}},
-{(unsigned char*)"laquo", {194, 171, 0}},
-{(unsigned char*)"larr", {226, 134, 144, 0}},
-{(unsigned char*)"larrb", {226, 135, 164, 0}},
-{(unsigned char*)"larrbfs", {226, 164, 159, 0}},
-{(unsigned char*)"larrfs", {226, 164, 157, 0}},
-{(unsigned char*)"larrhk", {226, 134, 169, 0}},
-{(unsigned char*)"larrlp", {226, 134, 171, 0}},
-{(unsigned char*)"larrpl", {226, 164, 185, 0}},
-{(unsigned char*)"larrsim", {226, 165, 179, 0}},
-{(unsigned char*)"larrtl", {226, 134, 162, 0}},
-{(unsigned char*)"lat", {226, 170, 171, 0}},
-{(unsigned char*)"latail", {226, 164, 153, 0}},
-{(unsigned char*)"late", {226, 170, 173, 0}},
-{(unsigned char*)"lates", {226, 170, 173, 239, 184, 128, 0}},
-{(unsigned char*)"lbarr", {226, 164, 140, 0}},
-{(unsigned char*)"lbbrk", {226, 157, 178, 0}},
-{(unsigned char*)"lbrace", {123, 0}},
-{(unsigned char*)"lbrack", {91, 0}},
-{(unsigned char*)"lbrke", {226, 166, 139, 0}},
-{(unsigned char*)"lbrksld", {226, 166, 143, 0}},
-{(unsigned char*)"lbrkslu", {226, 166, 141, 0}},
-{(unsigned char*)"lcaron", {196, 190, 0}},
-{(unsigned char*)"lcedil", {196, 188, 0}},
-{(unsigned char*)"lceil", {226, 140, 136, 0}},
-{(unsigned char*)"lcub", {123, 0}},
-{(unsigned char*)"lcy", {208, 187, 0}},
-{(unsigned char*)"ldca", {226, 164, 182, 0}},
-{(unsigned char*)"ldquo", {226, 128, 156, 0}},
-{(unsigned char*)"ldquor", {226, 128, 158, 0}},
-{(unsigned char*)"ldrdhar", {226, 165, 167, 0}},
-{(unsigned char*)"ldrushar", {226, 165, 139, 0}},
-{(unsigned char*)"ldsh", {226, 134, 178, 0}},
-{(unsigned char*)"le", {226, 137, 164, 0}},
-{(unsigned char*)"leftarrow", {226, 134, 144, 0}},
-{(unsigned char*)"leftarrowtail", {226, 134, 162, 0}},
-{(unsigned char*)"leftharpoondown", {226, 134, 189, 0}},
-{(unsigned char*)"leftharpoonup", {226, 134, 188, 0}},
-{(unsigned char*)"leftleftarrows", {226, 135, 135, 0}},
-{(unsigned char*)"leftrightarrow", {226, 134, 148, 0}},
-{(unsigned char*)"leftrightarrows", {226, 135, 134, 0}},
-{(unsigned char*)"leftrightharpoons", {226, 135, 139, 0}},
-{(unsigned char*)"leftrightsquigarrow", {226, 134, 173, 0}},
-{(unsigned char*)"leftthreetimes", {226, 139, 139, 0}},
-{(unsigned char*)"leg", {226, 139, 154, 0}},
-{(unsigned char*)"leq", {226, 137, 164, 0}},
-{(unsigned char*)"leqq", {226, 137, 166, 0}},
-{(unsigned char*)"leqslant", {226, 169, 189, 0}},
-{(unsigned char*)"les", {226, 169, 189, 0}},
-{(unsigned char*)"lescc", {226, 170, 168, 0}},
-{(unsigned char*)"lesdot", {226, 169, 191, 0}},
-{(unsigned char*)"lesdoto", {226, 170, 129, 0}},
-{(unsigned char*)"lesdotor", {226, 170, 131, 0}},
-{(unsigned char*)"lesg", {226, 139, 154, 239, 184, 128, 0}},
-{(unsigned char*)"lesges", {226, 170, 147, 0}},
-{(unsigned char*)"lessapprox", {226, 170, 133, 0}},
-{(unsigned char*)"lessdot", {226, 139, 150, 0}},
-{(unsigned char*)"lesseqgtr", {226, 139, 154, 0}},
-{(unsigned char*)"lesseqqgtr", {226, 170, 139, 0}},
-{(unsigned char*)"lessgtr", {226, 137, 182, 0}},
-{(unsigned char*)"lesssim", {226, 137, 178, 0}},
-{(unsigned char*)"lfisht", {226, 165, 188, 0}},
-{(unsigned char*)"lfloor", {226, 140, 138, 0}},
-{(unsigned char*)"lfr", {240, 157, 148, 169, 0}},
-{(unsigned char*)"lg", {226, 137, 182, 0}},
-{(unsigned char*)"lgE", {226, 170, 145, 0}},
-{(unsigned char*)"lhard", {226, 134, 189, 0}},
-{(unsigned char*)"lharu", {226, 134, 188, 0}},
-{(unsigned char*)"lharul", {226, 165, 170, 0}},
-{(unsigned char*)"lhblk", {226, 150, 132, 0}},
-{(unsigned char*)"ljcy", {209, 153, 0}},
-{(unsigned char*)"ll", {226, 137, 170, 0}},
-{(unsigned char*)"llarr", {226, 135, 135, 0}},
-{(unsigned char*)"llcorner", {226, 140, 158, 0}},
-{(unsigned char*)"llhard", {226, 165, 171, 0}},
-{(unsigned char*)"lltri", {226, 151, 186, 0}},
-{(unsigned char*)"lmidot", {197, 128, 0}},
-{(unsigned char*)"lmoust", {226, 142, 176, 0}},
-{(unsigned char*)"lmoustache", {226, 142, 176, 0}},
-{(unsigned char*)"lnE", {226, 137, 168, 0}},
-{(unsigned char*)"lnap", {226, 170, 137, 0}},
-{(unsigned char*)"lnapprox", {226, 170, 137, 0}},
-{(unsigned char*)"lne", {226, 170, 135, 0}},
-{(unsigned char*)"lneq", {226, 170, 135, 0}},
-{(unsigned char*)"lneqq", {226, 137, 168, 0}},
-{(unsigned char*)"lnsim", {226, 139, 166, 0}},
-{(unsigned char*)"loang", {226, 159, 172, 0}},
-{(unsigned char*)"loarr", {226, 135, 189, 0}},
-{(unsigned char*)"lobrk", {226, 159, 166, 0}},
-{(unsigned char*)"longleftarrow", {226, 159, 181, 0}},
-{(unsigned char*)"longleftrightarrow", {226, 159, 183, 0}},
-{(unsigned char*)"longmapsto", {226, 159, 188, 0}},
-{(unsigned char*)"longrightarrow", {226, 159, 182, 0}},
-{(unsigned char*)"looparrowleft", {226, 134, 171, 0}},
-{(unsigned char*)"looparrowright", {226, 134, 172, 0}},
-{(unsigned char*)"lopar", {226, 166, 133, 0}},
-{(unsigned char*)"lopf", {240, 157, 149, 157, 0}},
-{(unsigned char*)"loplus", {226, 168, 173, 0}},
-{(unsigned char*)"lotimes", {226, 168, 180, 0}},
-{(unsigned char*)"lowast", {226, 136, 151, 0}},
-{(unsigned char*)"lowbar", {95, 0}},
-{(unsigned char*)"loz", {226, 151, 138, 0}},
-{(unsigned char*)"lozenge", {226, 151, 138, 0}},
-{(unsigned char*)"lozf", {226, 167, 171, 0}},
-{(unsigned char*)"lpar", {40, 0}},
-{(unsigned char*)"lparlt", {226, 166, 147, 0}},
-{(unsigned char*)"lrarr", {226, 135, 134, 0}},
-{(unsigned char*)"lrcorner", {226, 140, 159, 0}},
-{(unsigned char*)"lrhar", {226, 135, 139, 0}},
-{(unsigned char*)"lrhard", {226, 165, 173, 0}},
-{(unsigned char*)"lrm", {226, 128, 142, 0}},
-{(unsigned char*)"lrtri", {226, 138, 191, 0}},
-{(unsigned char*)"lsaquo", {226, 128, 185, 0}},
-{(unsigned char*)"lscr", {240, 157, 147, 129, 0}},
-{(unsigned char*)"lsh", {226, 134, 176, 0}},
-{(unsigned char*)"lsim", {226, 137, 178, 0}},
-{(unsigned char*)"lsime", {226, 170, 141, 0}},
-{(unsigned char*)"lsimg", {226, 170, 143, 0}},
-{(unsigned char*)"lsqb", {91, 0}},
-{(unsigned char*)"lsquo", {226, 128, 152, 0}},
-{(unsigned char*)"lsquor", {226, 128, 154, 0}},
-{(unsigned char*)"lstrok", {197, 130, 0}},
-{(unsigned char*)"lt", {60, 0}},
-{(unsigned char*)"ltcc", {226, 170, 166, 0}},
-{(unsigned char*)"ltcir", {226, 169, 185, 0}},
-{(unsigned char*)"ltdot", {226, 139, 150, 0}},
-{(unsigned char*)"lthree", {226, 139, 139, 0}},
-{(unsigned char*)"ltimes", {226, 139, 137, 0}},
-{(unsigned char*)"ltlarr", {226, 165, 182, 0}},
-{(unsigned char*)"ltquest", {226, 169, 187, 0}},
-{(unsigned char*)"ltrPar", {226, 166, 150, 0}},
-{(unsigned char*)"ltri", {226, 151, 131, 0}},
-{(unsigned char*)"ltrie", {226, 138, 180, 0}},
-{(unsigned char*)"ltrif", {226, 151, 130, 0}},
-{(unsigned char*)"lurdshar", {226, 165, 138, 0}},
-{(unsigned char*)"luruhar", {226, 165, 166, 0}},
-{(unsigned char*)"lvertneqq", {226, 137, 168, 239, 184, 128, 0}},
-{(unsigned char*)"lvnE", {226, 137, 168, 239, 184, 128, 0}},
-{(unsigned char*)"mDDot", {226, 136, 186, 0}},
-{(unsigned char*)"macr", {194, 175, 0}},
-{(unsigned char*)"male", {226, 153, 130, 0}},
-{(unsigned char*)"malt", {226, 156, 160, 0}},
-{(unsigned char*)"maltese", {226, 156, 160, 0}},
-{(unsigned char*)"map", {226, 134, 166, 0}},
-{(unsigned char*)"mapsto", {226, 134, 166, 0}},
-{(unsigned char*)"mapstodown", {226, 134, 167, 0}},
-{(unsigned char*)"mapstoleft", {226, 134, 164, 0}},
-{(unsigned char*)"mapstoup", {226, 134, 165, 0}},
-{(unsigned char*)"marker", {226, 150, 174, 0}},
-{(unsigned char*)"mcomma", {226, 168, 169, 0}},
-{(unsigned char*)"mcy", {208, 188, 0}},
-{(unsigned char*)"mdash", {226, 128, 148, 0}},
-{(unsigned char*)"measuredangle", {226, 136, 161, 0}},
-{(unsigned char*)"mfr", {240, 157, 148, 170, 0}},
-{(unsigned char*)"mho", {226, 132, 167, 0}},
-{(unsigned char*)"micro", {194, 181, 0}},
-{(unsigned char*)"mid", {226, 136, 163, 0}},
-{(unsigned char*)"midast", {42, 0}},
-{(unsigned char*)"midcir", {226, 171, 176, 0}},
-{(unsigned char*)"middot", {194, 183, 0}},
-{(unsigned char*)"minus", {226, 136, 146, 0}},
-{(unsigned char*)"minusb", {226, 138, 159, 0}},
-{(unsigned char*)"minusd", {226, 136, 184, 0}},
-{(unsigned char*)"minusdu", {226, 168, 170, 0}},
-{(unsigned char*)"mlcp", {226, 171, 155, 0}},
-{(unsigned char*)"mldr", {226, 128, 166, 0}},
-{(unsigned char*)"mnplus", {226, 136, 147, 0}},
-{(unsigned char*)"models", {226, 138, 167, 0}},
-{(unsigned char*)"mopf", {240, 157, 149, 158, 0}},
-{(unsigned char*)"mp", {226, 136, 147, 0}},
-{(unsigned char*)"mscr", {240, 157, 147, 130, 0}},
-{(unsigned char*)"mstpos", {226, 136, 190, 0}},
-{(unsigned char*)"mu", {206, 188, 0}},
-{(unsigned char*)"multimap", {226, 138, 184, 0}},
-{(unsigned char*)"mumap", {226, 138, 184, 0}},
-{(unsigned char*)"nGg", {226, 139, 153, 204, 184, 0}},
-{(unsigned char*)"nGt", {226, 137, 171, 226, 131, 146, 0}},
-{(unsigned char*)"nGtv", {226, 137, 171, 204, 184, 0}},
-{(unsigned char*)"nLeftarrow", {226, 135, 141, 0}},
-{(unsigned char*)"nLeftrightarrow", {226, 135, 142, 0}},
-{(unsigned char*)"nLl", {226, 139, 152, 204, 184, 0}},
-{(unsigned char*)"nLt", {226, 137, 170, 226, 131, 146, 0}},
-{(unsigned char*)"nLtv", {226, 137, 170, 204, 184, 0}},
-{(unsigned char*)"nRightarrow", {226, 135, 143, 0}},
-{(unsigned char*)"nVDash", {226, 138, 175, 0}},
-{(unsigned char*)"nVdash", {226, 138, 174, 0}},
-{(unsigned char*)"nabla", {226, 136, 135, 0}},
-{(unsigned char*)"nacute", {197, 132, 0}},
-{(unsigned char*)"nang", {226, 136, 160, 226, 131, 146, 0}},
-{(unsigned char*)"nap", {226, 137, 137, 0}},
-{(unsigned char*)"napE", {226, 169, 176, 204, 184, 0}},
-{(unsigned char*)"napid", {226, 137, 139, 204, 184, 0}},
-{(unsigned char*)"napos", {197, 137, 0}},
-{(unsigned char*)"napprox", {226, 137, 137, 0}},
-{(unsigned char*)"natur", {226, 153, 174, 0}},
-{(unsigned char*)"natural", {226, 153, 174, 0}},
-{(unsigned char*)"naturals", {226, 132, 149, 0}},
-{(unsigned char*)"nbsp", {194, 160, 0}},
-{(unsigned char*)"nbump", {226, 137, 142, 204, 184, 0}},
-{(unsigned char*)"nbumpe", {226, 137, 143, 204, 184, 0}},
-{(unsigned char*)"ncap", {226, 169, 131, 0}},
-{(unsigned char*)"ncaron", {197, 136, 0}},
-{(unsigned char*)"ncedil", {197, 134, 0}},
-{(unsigned char*)"ncong", {226, 137, 135, 0}},
-{(unsigned char*)"ncongdot", {226, 169, 173, 204, 184, 0}},
-{(unsigned char*)"ncup", {226, 169, 130, 0}},
-{(unsigned char*)"ncy", {208, 189, 0}},
-{(unsigned char*)"ndash", {226, 128, 147, 0}},
-{(unsigned char*)"ne", {226, 137, 160, 0}},
-{(unsigned char*)"neArr", {226, 135, 151, 0}},
-{(unsigned char*)"nearhk", {226, 164, 164, 0}},
-{(unsigned char*)"nearr", {226, 134, 151, 0}},
-{(unsigned char*)"nearrow", {226, 134, 151, 0}},
-{(unsigned char*)"nedot", {226, 137, 144, 204, 184, 0}},
-{(unsigned char*)"nequiv", {226, 137, 162, 0}},
-{(unsigned char*)"nesear", {226, 164, 168, 0}},
-{(unsigned char*)"nesim", {226, 137, 130, 204, 184, 0}},
-{(unsigned char*)"nexist", {226, 136, 132, 0}},
-{(unsigned char*)"nexists", {226, 136, 132, 0}},
-{(unsigned char*)"nfr", {240, 157, 148, 171, 0}},
-{(unsigned char*)"ngE", {226, 137, 167, 204, 184, 0}},
-{(unsigned char*)"nge", {226, 137, 177, 0}},
-{(unsigned char*)"ngeq", {226, 137, 177, 0}},
-{(unsigned char*)"ngeqq", {226, 137, 167, 204, 184, 0}},
-{(unsigned char*)"ngeqslant", {226, 169, 190, 204, 184, 0}},
-{(unsigned char*)"nges", {226, 169, 190, 204, 184, 0}},
-{(unsigned char*)"ngsim", {226, 137, 181, 0}},
-{(unsigned char*)"ngt", {226, 137, 175, 0}},
-{(unsigned char*)"ngtr", {226, 137, 175, 0}},
-{(unsigned char*)"nhArr", {226, 135, 142, 0}},
-{(unsigned char*)"nharr", {226, 134, 174, 0}},
-{(unsigned char*)"nhpar", {226, 171, 178, 0}},
-{(unsigned char*)"ni", {226, 136, 139, 0}},
-{(unsigned char*)"nis", {226, 139, 188, 0}},
-{(unsigned char*)"nisd", {226, 139, 186, 0}},
-{(unsigned char*)"niv", {226, 136, 139, 0}},
-{(unsigned char*)"njcy", {209, 154, 0}},
-{(unsigned char*)"nlArr", {226, 135, 141, 0}},
-{(unsigned char*)"nlE", {226, 137, 166, 204, 184, 0}},
-{(unsigned char*)"nlarr", {226, 134, 154, 0}},
-{(unsigned char*)"nldr", {226, 128, 165, 0}},
-{(unsigned char*)"nle", {226, 137, 176, 0}},
-{(unsigned char*)"nleftarrow", {226, 134, 154, 0}},
-{(unsigned char*)"nleftrightarrow", {226, 134, 174, 0}},
-{(unsigned char*)"nleq", {226, 137, 176, 0}},
-{(unsigned char*)"nleqq", {226, 137, 166, 204, 184, 0}},
-{(unsigned char*)"nleqslant", {226, 169, 189, 204, 184, 0}},
-{(unsigned char*)"nles", {226, 169, 189, 204, 184, 0}},
-{(unsigned char*)"nless", {226, 137, 174, 0}},
-{(unsigned char*)"nlsim", {226, 137, 180, 0}},
-{(unsigned char*)"nlt", {226, 137, 174, 0}},
-{(unsigned char*)"nltri", {226, 139, 170, 0}},
-{(unsigned char*)"nltrie", {226, 139, 172, 0}},
-{(unsigned char*)"nmid", {226, 136, 164, 0}},
-{(unsigned char*)"nopf", {240, 157, 149, 159, 0}},
-{(unsigned char*)"not", {194, 172, 0}},
-{(unsigned char*)"notin", {226, 136, 137, 0}},
-{(unsigned char*)"notinE", {226, 139, 185, 204, 184, 0}},
-{(unsigned char*)"notindot", {226, 139, 181, 204, 184, 0}},
-{(unsigned char*)"notinva", {226, 136, 137, 0}},
-{(unsigned char*)"notinvb", {226, 139, 183, 0}},
-{(unsigned char*)"notinvc", {226, 139, 182, 0}},
-{(unsigned char*)"notni", {226, 136, 140, 0}},
-{(unsigned char*)"notniva", {226, 136, 140, 0}},
-{(unsigned char*)"notnivb", {226, 139, 190, 0}},
-{(unsigned char*)"notnivc", {226, 139, 189, 0}},
-{(unsigned char*)"npar", {226, 136, 166, 0}},
-{(unsigned char*)"nparallel", {226, 136, 166, 0}},
-{(unsigned char*)"nparsl", {226, 171, 189, 226, 131, 165, 0}},
-{(unsigned char*)"npart", {226, 136, 130, 204, 184, 0}},
-{(unsigned char*)"npolint", {226, 168, 148, 0}},
-{(unsigned char*)"npr", {226, 138, 128, 0}},
-{(unsigned char*)"nprcue", {226, 139, 160, 0}},
-{(unsigned char*)"npre", {226, 170, 175, 204, 184, 0}},
-{(unsigned char*)"nprec", {226, 138, 128, 0}},
-{(unsigned char*)"npreceq", {226, 170, 175, 204, 184, 0}},
-{(unsigned char*)"nrArr", {226, 135, 143, 0}},
-{(unsigned char*)"nrarr", {226, 134, 155, 0}},
-{(unsigned char*)"nrarrc", {226, 164, 179, 204, 184, 0}},
-{(unsigned char*)"nrarrw", {226, 134, 157, 204, 184, 0}},
-{(unsigned char*)"nrightarrow", {226, 134, 155, 0}},
-{(unsigned char*)"nrtri", {226, 139, 171, 0}},
-{(unsigned char*)"nrtrie", {226, 139, 173, 0}},
-{(unsigned char*)"nsc", {226, 138, 129, 0}},
-{(unsigned char*)"nsccue", {226, 139, 161, 0}},
-{(unsigned char*)"nsce", {226, 170, 176, 204, 184, 0}},
-{(unsigned char*)"nscr", {240, 157, 147, 131, 0}},
-{(unsigned char*)"nshortmid", {226, 136, 164, 0}},
-{(unsigned char*)"nshortparallel", {226, 136, 166, 0}},
-{(unsigned char*)"nsim", {226, 137, 129, 0}},
-{(unsigned char*)"nsime", {226, 137, 132, 0}},
-{(unsigned char*)"nsimeq", {226, 137, 132, 0}},
-{(unsigned char*)"nsmid", {226, 136, 164, 0}},
-{(unsigned char*)"nspar", {226, 136, 166, 0}},
-{(unsigned char*)"nsqsube", {226, 139, 162, 0}},
-{(unsigned char*)"nsqsupe", {226, 139, 163, 0}},
-{(unsigned char*)"nsub", {226, 138, 132, 0}},
-{(unsigned char*)"nsubE", {226, 171, 133, 204, 184, 0}},
-{(unsigned char*)"nsube", {226, 138, 136, 0}},
-{(unsigned char*)"nsubset", {226, 138, 130, 226, 131, 146, 0}},
-{(unsigned char*)"nsubseteq", {226, 138, 136, 0}},
-{(unsigned char*)"nsubseteqq", {226, 171, 133, 204, 184, 0}},
-{(unsigned char*)"nsucc", {226, 138, 129, 0}},
-{(unsigned char*)"nsucceq", {226, 170, 176, 204, 184, 0}},
-{(unsigned char*)"nsup", {226, 138, 133, 0}},
-{(unsigned char*)"nsupE", {226, 171, 134, 204, 184, 0}},
-{(unsigned char*)"nsupe", {226, 138, 137, 0}},
-{(unsigned char*)"nsupset", {226, 138, 131, 226, 131, 146, 0}},
-{(unsigned char*)"nsupseteq", {226, 138, 137, 0}},
-{(unsigned char*)"nsupseteqq", {226, 171, 134, 204, 184, 0}},
-{(unsigned char*)"ntgl", {226, 137, 185, 0}},
-{(unsigned char*)"ntilde", {195, 177, 0}},
-{(unsigned char*)"ntlg", {226, 137, 184, 0}},
-{(unsigned char*)"ntriangleleft", {226, 139, 170, 0}},
-{(unsigned char*)"ntrianglelefteq", {226, 139, 172, 0}},
-{(unsigned char*)"ntriangleright", {226, 139, 171, 0}},
-{(unsigned char*)"ntrianglerighteq", {226, 139, 173, 0}},
-{(unsigned char*)"nu", {206, 189, 0}},
-{(unsigned char*)"num", {35, 0}},
-{(unsigned char*)"numero", {226, 132, 150, 0}},
-{(unsigned char*)"numsp", {226, 128, 135, 0}},
-{(unsigned char*)"nvDash", {226, 138, 173, 0}},
-{(unsigned char*)"nvHarr", {226, 164, 132, 0}},
-{(unsigned char*)"nvap", {226, 137, 141, 226, 131, 146, 0}},
-{(unsigned char*)"nvdash", {226, 138, 172, 0}},
-{(unsigned char*)"nvge", {226, 137, 165, 226, 131, 146, 0}},
-{(unsigned char*)"nvgt", {62, 226, 131, 146, 0}},
-{(unsigned char*)"nvinfin", {226, 167, 158, 0}},
-{(unsigned char*)"nvlArr", {226, 164, 130, 0}},
-{(unsigned char*)"nvle", {226, 137, 164, 226, 131, 146, 0}},
-{(unsigned char*)"nvlt", {60, 226, 131, 146, 0}},
-{(unsigned char*)"nvltrie", {226, 138, 180, 226, 131, 146, 0}},
-{(unsigned char*)"nvrArr", {226, 164, 131, 0}},
-{(unsigned char*)"nvrtrie", {226, 138, 181, 226, 131, 146, 0}},
-{(unsigned char*)"nvsim", {226, 136, 188, 226, 131, 146, 0}},
-{(unsigned char*)"nwArr", {226, 135, 150, 0}},
-{(unsigned char*)"nwarhk", {226, 164, 163, 0}},
-{(unsigned char*)"nwarr", {226, 134, 150, 0}},
-{(unsigned char*)"nwarrow", {226, 134, 150, 0}},
-{(unsigned char*)"nwnear", {226, 164, 167, 0}},
-{(unsigned char*)"oS", {226, 147, 136, 0}},
-{(unsigned char*)"oacute", {195, 179, 0}},
-{(unsigned char*)"oast", {226, 138, 155, 0}},
-{(unsigned char*)"ocir", {226, 138, 154, 0}},
-{(unsigned char*)"ocirc", {195, 180, 0}},
-{(unsigned char*)"ocy", {208, 190, 0}},
-{(unsigned char*)"odash", {226, 138, 157, 0}},
-{(unsigned char*)"odblac", {197, 145, 0}},
-{(unsigned char*)"odiv", {226, 168, 184, 0}},
-{(unsigned char*)"odot", {226, 138, 153, 0}},
-{(unsigned char*)"odsold", {226, 166, 188, 0}},
-{(unsigned char*)"oelig", {197, 147, 0}},
-{(unsigned char*)"ofcir", {226, 166, 191, 0}},
-{(unsigned char*)"ofr", {240, 157, 148, 172, 0}},
-{(unsigned char*)"ogon", {203, 155, 0}},
-{(unsigned char*)"ograve", {195, 178, 0}},
-{(unsigned char*)"ogt", {226, 167, 129, 0}},
-{(unsigned char*)"ohbar", {226, 166, 181, 0}},
-{(unsigned char*)"ohm", {206, 169, 0}},
-{(unsigned char*)"oint", {226, 136, 174, 0}},
-{(unsigned char*)"olarr", {226, 134, 186, 0}},
-{(unsigned char*)"olcir", {226, 166, 190, 0}},
-{(unsigned char*)"olcross", {226, 166, 187, 0}},
-{(unsigned char*)"oline", {226, 128, 190, 0}},
-{(unsigned char*)"olt", {226, 167, 128, 0}},
-{(unsigned char*)"omacr", {197, 141, 0}},
-{(unsigned char*)"omega", {207, 137, 0}},
-{(unsigned char*)"omicron", {206, 191, 0}},
-{(unsigned char*)"omid", {226, 166, 182, 0}},
-{(unsigned char*)"ominus", {226, 138, 150, 0}},
-{(unsigned char*)"oopf", {240, 157, 149, 160, 0}},
-{(unsigned char*)"opar", {226, 166, 183, 0}},
-{(unsigned char*)"operp", {226, 166, 185, 0}},
-{(unsigned char*)"oplus", {226, 138, 149, 0}},
-{(unsigned char*)"or", {226, 136, 168, 0}},
-{(unsigned char*)"orarr", {226, 134, 187, 0}},
-{(unsigned char*)"ord", {226, 169, 157, 0}},
-{(unsigned char*)"order", {226, 132, 180, 0}},
-{(unsigned char*)"orderof", {226, 132, 180, 0}},
-{(unsigned char*)"ordf", {194, 170, 0}},
-{(unsigned char*)"ordm", {194, 186, 0}},
-{(unsigned char*)"origof", {226, 138, 182, 0}},
-{(unsigned char*)"oror", {226, 169, 150, 0}},
-{(unsigned char*)"orslope", {226, 169, 151, 0}},
-{(unsigned char*)"orv", {226, 169, 155, 0}},
-{(unsigned char*)"oscr", {226, 132, 180, 0}},
-{(unsigned char*)"oslash", {195, 184, 0}},
-{(unsigned char*)"osol", {226, 138, 152, 0}},
-{(unsigned char*)"otilde", {195, 181, 0}},
-{(unsigned char*)"otimes", {226, 138, 151, 0}},
-{(unsigned char*)"otimesas", {226, 168, 182, 0}},
-{(unsigned char*)"ouml", {195, 182, 0}},
-{(unsigned char*)"ovbar", {226, 140, 189, 0}},
-{(unsigned char*)"par", {226, 136, 165, 0}},
-{(unsigned char*)"para", {194, 182, 0}},
-{(unsigned char*)"parallel", {226, 136, 165, 0}},
-{(unsigned char*)"parsim", {226, 171, 179, 0}},
-{(unsigned char*)"parsl", {226, 171, 189, 0}},
-{(unsigned char*)"part", {226, 136, 130, 0}},
-{(unsigned char*)"pcy", {208, 191, 0}},
-{(unsigned char*)"percnt", {37, 0}},
-{(unsigned char*)"period", {46, 0}},
-{(unsigned char*)"permil", {226, 128, 176, 0}},
-{(unsigned char*)"perp", {226, 138, 165, 0}},
-{(unsigned char*)"pertenk", {226, 128, 177, 0}},
-{(unsigned char*)"pfr", {240, 157, 148, 173, 0}},
-{(unsigned char*)"phi", {207, 134, 0}},
-{(unsigned char*)"phiv", {207, 149, 0}},
-{(unsigned char*)"phmmat", {226, 132, 179, 0}},
-{(unsigned char*)"phone", {226, 152, 142, 0}},
-{(unsigned char*)"pi", {207, 128, 0}},
-{(unsigned char*)"pitchfork", {226, 139, 148, 0}},
-{(unsigned char*)"piv", {207, 150, 0}},
-{(unsigned char*)"planck", {226, 132, 143, 0}},
-{(unsigned char*)"planckh", {226, 132, 142, 0}},
-{(unsigned char*)"plankv", {226, 132, 143, 0}},
-{(unsigned char*)"plus", {43, 0}},
-{(unsigned char*)"plusacir", {226, 168, 163, 0}},
-{(unsigned char*)"plusb", {226, 138, 158, 0}},
-{(unsigned char*)"pluscir", {226, 168, 162, 0}},
-{(unsigned char*)"plusdo", {226, 136, 148, 0}},
-{(unsigned char*)"plusdu", {226, 168, 165, 0}},
-{(unsigned char*)"pluse", {226, 169, 178, 0}},
-{(unsigned char*)"plusmn", {194, 177, 0}},
-{(unsigned char*)"plussim", {226, 168, 166, 0}},
-{(unsigned char*)"plustwo", {226, 168, 167, 0}},
-{(unsigned char*)"pm", {194, 177, 0}},
-{(unsigned char*)"pointint", {226, 168, 149, 0}},
-{(unsigned char*)"popf", {240, 157, 149, 161, 0}},
-{(unsigned char*)"pound", {194, 163, 0}},
-{(unsigned char*)"pr", {226, 137, 186, 0}},
-{(unsigned char*)"prE", {226, 170, 179, 0}},
-{(unsigned char*)"prap", {226, 170, 183, 0}},
-{(unsigned char*)"prcue", {226, 137, 188, 0}},
-{(unsigned char*)"pre", {226, 170, 175, 0}},
-{(unsigned char*)"prec", {226, 137, 186, 0}},
-{(unsigned char*)"precapprox", {226, 170, 183, 0}},
-{(unsigned char*)"preccurlyeq", {226, 137, 188, 0}},
-{(unsigned char*)"preceq", {226, 170, 175, 0}},
-{(unsigned char*)"precnapprox", {226, 170, 185, 0}},
-{(unsigned char*)"precneqq", {226, 170, 181, 0}},
-{(unsigned char*)"precnsim", {226, 139, 168, 0}},
-{(unsigned char*)"precsim", {226, 137, 190, 0}},
-{(unsigned char*)"prime", {226, 128, 178, 0}},
-{(unsigned char*)"primes", {226, 132, 153, 0}},
-{(unsigned char*)"prnE", {226, 170, 181, 0}},
-{(unsigned char*)"prnap", {226, 170, 185, 0}},
-{(unsigned char*)"prnsim", {226, 139, 168, 0}},
-{(unsigned char*)"prod", {226, 136, 143, 0}},
-{(unsigned char*)"profalar", {226, 140, 174, 0}},
-{(unsigned char*)"profline", {226, 140, 146, 0}},
-{(unsigned char*)"profsurf", {226, 140, 147, 0}},
-{(unsigned char*)"prop", {226, 136, 157, 0}},
-{(unsigned char*)"propto", {226, 136, 157, 0}},
-{(unsigned char*)"prsim", {226, 137, 190, 0}},
-{(unsigned char*)"prurel", {226, 138, 176, 0}},
-{(unsigned char*)"pscr", {240, 157, 147, 133, 0}},
-{(unsigned char*)"psi", {207, 136, 0}},
-{(unsigned char*)"puncsp", {226, 128, 136, 0}},
-{(unsigned char*)"qfr", {240, 157, 148, 174, 0}},
-{(unsigned char*)"qint", {226, 168, 140, 0}},
-{(unsigned char*)"qopf", {240, 157, 149, 162, 0}},
-{(unsigned char*)"qprime", {226, 129, 151, 0}},
-{(unsigned char*)"qscr", {240, 157, 147, 134, 0}},
-{(unsigned char*)"quaternions", {226, 132, 141, 0}},
-{(unsigned char*)"quatint", {226, 168, 150, 0}},
-{(unsigned char*)"quest", {63, 0}},
-{(unsigned char*)"questeq", {226, 137, 159, 0}},
-{(unsigned char*)"quot", {34, 0}},
-{(unsigned char*)"rAarr", {226, 135, 155, 0}},
-{(unsigned char*)"rArr", {226, 135, 146, 0}},
-{(unsigned char*)"rAtail", {226, 164, 156, 0}},
-{(unsigned char*)"rBarr", {226, 164, 143, 0}},
-{(unsigned char*)"rHar", {226, 165, 164, 0}},
-{(unsigned char*)"race", {226, 136, 189, 204, 177, 0}},
-{(unsigned char*)"racute", {197, 149, 0}},
-{(unsigned char*)"radic", {226, 136, 154, 0}},
-{(unsigned char*)"raemptyv", {226, 166, 179, 0}},
-{(unsigned char*)"rang", {226, 159, 169, 0}},
-{(unsigned char*)"rangd", {226, 166, 146, 0}},
-{(unsigned char*)"range", {226, 166, 165, 0}},
-{(unsigned char*)"rangle", {226, 159, 169, 0}},
-{(unsigned char*)"raquo", {194, 187, 0}},
-{(unsigned char*)"rarr", {226, 134, 146, 0}},
-{(unsigned char*)"rarrap", {226, 165, 181, 0}},
-{(unsigned char*)"rarrb", {226, 135, 165, 0}},
-{(unsigned char*)"rarrbfs", {226, 164, 160, 0}},
-{(unsigned char*)"rarrc", {226, 164, 179, 0}},
-{(unsigned char*)"rarrfs", {226, 164, 158, 0}},
-{(unsigned char*)"rarrhk", {226, 134, 170, 0}},
-{(unsigned char*)"rarrlp", {226, 134, 172, 0}},
-{(unsigned char*)"rarrpl", {226, 165, 133, 0}},
-{(unsigned char*)"rarrsim", {226, 165, 180, 0}},
-{(unsigned char*)"rarrtl", {226, 134, 163, 0}},
-{(unsigned char*)"rarrw", {226, 134, 157, 0}},
-{(unsigned char*)"ratail", {226, 164, 154, 0}},
-{(unsigned char*)"ratio", {226, 136, 182, 0}},
-{(unsigned char*)"rationals", {226, 132, 154, 0}},
-{(unsigned char*)"rbarr", {226, 164, 141, 0}},
-{(unsigned char*)"rbbrk", {226, 157, 179, 0}},
-{(unsigned char*)"rbrace", {125, 0}},
-{(unsigned char*)"rbrack", {93, 0}},
-{(unsigned char*)"rbrke", {226, 166, 140, 0}},
-{(unsigned char*)"rbrksld", {226, 166, 142, 0}},
-{(unsigned char*)"rbrkslu", {226, 166, 144, 0}},
-{(unsigned char*)"rcaron", {197, 153, 0}},
-{(unsigned char*)"rcedil", {197, 151, 0}},
-{(unsigned char*)"rceil", {226, 140, 137, 0}},
-{(unsigned char*)"rcub", {125, 0}},
-{(unsigned char*)"rcy", {209, 128, 0}},
-{(unsigned char*)"rdca", {226, 164, 183, 0}},
-{(unsigned char*)"rdldhar", {226, 165, 169, 0}},
-{(unsigned char*)"rdquo", {226, 128, 157, 0}},
-{(unsigned char*)"rdquor", {226, 128, 157, 0}},
-{(unsigned char*)"rdsh", {226, 134, 179, 0}},
-{(unsigned char*)"real", {226, 132, 156, 0}},
-{(unsigned char*)"realine", {226, 132, 155, 0}},
-{(unsigned char*)"realpart", {226, 132, 156, 0}},
-{(unsigned char*)"reals", {226, 132, 157, 0}},
-{(unsigned char*)"rect", {226, 150, 173, 0}},
-{(unsigned char*)"reg", {194, 174, 0}},
-{(unsigned char*)"rfisht", {226, 165, 189, 0}},
-{(unsigned char*)"rfloor", {226, 140, 139, 0}},
-{(unsigned char*)"rfr", {240, 157, 148, 175, 0}},
-{(unsigned char*)"rhard", {226, 135, 129, 0}},
-{(unsigned char*)"rharu", {226, 135, 128, 0}},
-{(unsigned char*)"rharul", {226, 165, 172, 0}},
-{(unsigned char*)"rho", {207, 129, 0}},
-{(unsigned char*)"rhov", {207, 177, 0}},
-{(unsigned char*)"rightarrow", {226, 134, 146, 0}},
-{(unsigned char*)"rightarrowtail", {226, 134, 163, 0}},
-{(unsigned char*)"rightharpoondown", {226, 135, 129, 0}},
-{(unsigned char*)"rightharpoonup", {226, 135, 128, 0}},
-{(unsigned char*)"rightleftarrows", {226, 135, 132, 0}},
-{(unsigned char*)"rightleftharpoons", {226, 135, 140, 0}},
-{(unsigned char*)"rightrightarrows", {226, 135, 137, 0}},
-{(unsigned char*)"rightsquigarrow", {226, 134, 157, 0}},
-{(unsigned char*)"rightthreetimes", {226, 139, 140, 0}},
-{(unsigned char*)"ring", {203, 154, 0}},
-{(unsigned char*)"risingdotseq", {226, 137, 147, 0}},
-{(unsigned char*)"rlarr", {226, 135, 132, 0}},
-{(unsigned char*)"rlhar", {226, 135, 140, 0}},
-{(unsigned char*)"rlm", {226, 128, 143, 0}},
-{(unsigned char*)"rmoust", {226, 142, 177, 0}},
-{(unsigned char*)"rmoustache", {226, 142, 177, 0}},
-{(unsigned char*)"rnmid", {226, 171, 174, 0}},
-{(unsigned char*)"roang", {226, 159, 173, 0}},
-{(unsigned char*)"roarr", {226, 135, 190, 0}},
-{(unsigned char*)"robrk", {226, 159, 167, 0}},
-{(unsigned char*)"ropar", {226, 166, 134, 0}},
-{(unsigned char*)"ropf", {240, 157, 149, 163, 0}},
-{(unsigned char*)"roplus", {226, 168, 174, 0}},
-{(unsigned char*)"rotimes", {226, 168, 181, 0}},
-{(unsigned char*)"rpar", {41, 0}},
-{(unsigned char*)"rpargt", {226, 166, 148, 0}},
-{(unsigned char*)"rppolint", {226, 168, 146, 0}},
-{(unsigned char*)"rrarr", {226, 135, 137, 0}},
-{(unsigned char*)"rsaquo", {226, 128, 186, 0}},
-{(unsigned char*)"rscr", {240, 157, 147, 135, 0}},
-{(unsigned char*)"rsh", {226, 134, 177, 0}},
-{(unsigned char*)"rsqb", {93, 0}},
-{(unsigned char*)"rsquo", {226, 128, 153, 0}},
-{(unsigned char*)"rsquor", {226, 128, 153, 0}},
-{(unsigned char*)"rthree", {226, 139, 140, 0}},
-{(unsigned char*)"rtimes", {226, 139, 138, 0}},
-{(unsigned char*)"rtri", {226, 150, 185, 0}},
-{(unsigned char*)"rtrie", {226, 138, 181, 0}},
-{(unsigned char*)"rtrif", {226, 150, 184, 0}},
-{(unsigned char*)"rtriltri", {226, 167, 142, 0}},
-{(unsigned char*)"ruluhar", {226, 165, 168, 0}},
-{(unsigned char*)"rx", {226, 132, 158, 0}},
-{(unsigned char*)"sacute", {197, 155, 0}},
-{(unsigned char*)"sbquo", {226, 128, 154, 0}},
-{(unsigned char*)"sc", {226, 137, 187, 0}},
-{(unsigned char*)"scE", {226, 170, 180, 0}},
-{(unsigned char*)"scap", {226, 170, 184, 0}},
-{(unsigned char*)"scaron", {197, 161, 0}},
-{(unsigned char*)"sccue", {226, 137, 189, 0}},
-{(unsigned char*)"sce", {226, 170, 176, 0}},
-{(unsigned char*)"scedil", {197, 159, 0}},
-{(unsigned char*)"scirc", {197, 157, 0}},
-{(unsigned char*)"scnE", {226, 170, 182, 0}},
-{(unsigned char*)"scnap", {226, 170, 186, 0}},
-{(unsigned char*)"scnsim", {226, 139, 169, 0}},
-{(unsigned char*)"scpolint", {226, 168, 147, 0}},
-{(unsigned char*)"scsim", {226, 137, 191, 0}},
-{(unsigned char*)"scy", {209, 129, 0}},
-{(unsigned char*)"sdot", {226, 139, 133, 0}},
-{(unsigned char*)"sdotb", {226, 138, 161, 0}},
-{(unsigned char*)"sdote", {226, 169, 166, 0}},
-{(unsigned char*)"seArr", {226, 135, 152, 0}},
-{(unsigned char*)"searhk", {226, 164, 165, 0}},
-{(unsigned char*)"searr", {226, 134, 152, 0}},
-{(unsigned char*)"searrow", {226, 134, 152, 0}},
-{(unsigned char*)"sect", {194, 167, 0}},
-{(unsigned char*)"semi", {59, 0}},
-{(unsigned char*)"seswar", {226, 164, 169, 0}},
-{(unsigned char*)"setminus", {226, 136, 150, 0}},
-{(unsigned char*)"setmn", {226, 136, 150, 0}},
-{(unsigned char*)"sext", {226, 156, 182, 0}},
-{(unsigned char*)"sfr", {240, 157, 148, 176, 0}},
-{(unsigned char*)"sfrown", {226, 140, 162, 0}},
-{(unsigned char*)"sharp", {226, 153, 175, 0}},
-{(unsigned char*)"shchcy", {209, 137, 0}},
-{(unsigned char*)"shcy", {209, 136, 0}},
-{(unsigned char*)"shortmid", {226, 136, 163, 0}},
-{(unsigned char*)"shortparallel", {226, 136, 165, 0}},
-{(unsigned char*)"shy", {194, 173, 0}},
-{(unsigned char*)"sigma", {207, 131, 0}},
-{(unsigned char*)"sigmaf", {207, 130, 0}},
-{(unsigned char*)"sigmav", {207, 130, 0}},
-{(unsigned char*)"sim", {226, 136, 188, 0}},
-{(unsigned char*)"simdot", {226, 169, 170, 0}},
-{(unsigned char*)"sime", {226, 137, 131, 0}},
-{(unsigned char*)"simeq", {226, 137, 131, 0}},
-{(unsigned char*)"simg", {226, 170, 158, 0}},
-{(unsigned char*)"simgE", {226, 170, 160, 0}},
-{(unsigned char*)"siml", {226, 170, 157, 0}},
-{(unsigned char*)"simlE", {226, 170, 159, 0}},
-{(unsigned char*)"simne", {226, 137, 134, 0}},
-{(unsigned char*)"simplus", {226, 168, 164, 0}},
-{(unsigned char*)"simrarr", {226, 165, 178, 0}},
-{(unsigned char*)"slarr", {226, 134, 144, 0}},
-{(unsigned char*)"smallsetminus", {226, 136, 150, 0}},
-{(unsigned char*)"smashp", {226, 168, 179, 0}},
-{(unsigned char*)"smeparsl", {226, 167, 164, 0}},
-{(unsigned char*)"smid", {226, 136, 163, 0}},
-{(unsigned char*)"smile", {226, 140, 163, 0}},
-{(unsigned char*)"smt", {226, 170, 170, 0}},
-{(unsigned char*)"smte", {226, 170, 172, 0}},
-{(unsigned char*)"smtes", {226, 170, 172, 239, 184, 128, 0}},
-{(unsigned char*)"softcy", {209, 140, 0}},
-{(unsigned char*)"sol", {47, 0}},
-{(unsigned char*)"solb", {226, 167, 132, 0}},
-{(unsigned char*)"solbar", {226, 140, 191, 0}},
-{(unsigned char*)"sopf", {240, 157, 149, 164, 0}},
-{(unsigned char*)"spades", {226, 153, 160, 0}},
-{(unsigned char*)"spadesuit", {226, 153, 160, 0}},
-{(unsigned char*)"spar", {226, 136, 165, 0}},
-{(unsigned char*)"sqcap", {226, 138, 147, 0}},
-{(unsigned char*)"sqcaps", {226, 138, 147, 239, 184, 128, 0}},
-{(unsigned char*)"sqcup", {226, 138, 148, 0}},
-{(unsigned char*)"sqcups", {226, 138, 148, 239, 184, 128, 0}},
-{(unsigned char*)"sqsub", {226, 138, 143, 0}},
-{(unsigned char*)"sqsube", {226, 138, 145, 0}},
-{(unsigned char*)"sqsubset", {226, 138, 143, 0}},
-{(unsigned char*)"sqsubseteq", {226, 138, 145, 0}},
-{(unsigned char*)"sqsup", {226, 138, 144, 0}},
-{(unsigned char*)"sqsupe", {226, 138, 146, 0}},
-{(unsigned char*)"sqsupset", {226, 138, 144, 0}},
-{(unsigned char*)"sqsupseteq", {226, 138, 146, 0}},
-{(unsigned char*)"squ", {226, 150, 161, 0}},
-{(unsigned char*)"square", {226, 150, 161, 0}},
-{(unsigned char*)"squarf", {226, 150, 170, 0}},
-{(unsigned char*)"squf", {226, 150, 170, 0}},
-{(unsigned char*)"srarr", {226, 134, 146, 0}},
-{(unsigned char*)"sscr", {240, 157, 147, 136, 0}},
-{(unsigned char*)"ssetmn", {226, 136, 150, 0}},
-{(unsigned char*)"ssmile", {226, 140, 163, 0}},
-{(unsigned char*)"sstarf", {226, 139, 134, 0}},
-{(unsigned char*)"star", {226, 152, 134, 0}},
-{(unsigned char*)"starf", {226, 152, 133, 0}},
-{(unsigned char*)"straightepsilon", {207, 181, 0}},
-{(unsigned char*)"straightphi", {207, 149, 0}},
-{(unsigned char*)"strns", {194, 175, 0}},
-{(unsigned char*)"sub", {226, 138, 130, 0}},
-{(unsigned char*)"subE", {226, 171, 133, 0}},
-{(unsigned char*)"subdot", {226, 170, 189, 0}},
-{(unsigned char*)"sube", {226, 138, 134, 0}},
-{(unsigned char*)"subedot", {226, 171, 131, 0}},
-{(unsigned char*)"submult", {226, 171, 129, 0}},
-{(unsigned char*)"subnE", {226, 171, 139, 0}},
-{(unsigned char*)"subne", {226, 138, 138, 0}},
-{(unsigned char*)"subplus", {226, 170, 191, 0}},
-{(unsigned char*)"subrarr", {226, 165, 185, 0}},
-{(unsigned char*)"subset", {226, 138, 130, 0}},
-{(unsigned char*)"subseteq", {226, 138, 134, 0}},
-{(unsigned char*)"subseteqq", {226, 171, 133, 0}},
-{(unsigned char*)"subsetneq", {226, 138, 138, 0}},
-{(unsigned char*)"subsetneqq", {226, 171, 139, 0}},
-{(unsigned char*)"subsim", {226, 171, 135, 0}},
-{(unsigned char*)"subsub", {226, 171, 149, 0}},
-{(unsigned char*)"subsup", {226, 171, 147, 0}},
-{(unsigned char*)"succ", {226, 137, 187, 0}},
-{(unsigned char*)"succapprox", {226, 170, 184, 0}},
-{(unsigned char*)"succcurlyeq", {226, 137, 189, 0}},
-{(unsigned char*)"succeq", {226, 170, 176, 0}},
-{(unsigned char*)"succnapprox", {226, 170, 186, 0}},
-{(unsigned char*)"succneqq", {226, 170, 182, 0}},
-{(unsigned char*)"succnsim", {226, 139, 169, 0}},
-{(unsigned char*)"succsim", {226, 137, 191, 0}},
-{(unsigned char*)"sum", {226, 136, 145, 0}},
-{(unsigned char*)"sung", {226, 153, 170, 0}},
-{(unsigned char*)"sup", {226, 138, 131, 0}},
-{(unsigned char*)"sup1", {194, 185, 0}},
-{(unsigned char*)"sup2", {194, 178, 0}},
-{(unsigned char*)"sup3", {194, 179, 0}},
-{(unsigned char*)"supE", {226, 171, 134, 0}},
-{(unsigned char*)"supdot", {226, 170, 190, 0}},
-{(unsigned char*)"supdsub", {226, 171, 152, 0}},
-{(unsigned char*)"supe", {226, 138, 135, 0}},
-{(unsigned char*)"supedot", {226, 171, 132, 0}},
-{(unsigned char*)"suphsol", {226, 159, 137, 0}},
-{(unsigned char*)"suphsub", {226, 171, 151, 0}},
-{(unsigned char*)"suplarr", {226, 165, 187, 0}},
-{(unsigned char*)"supmult", {226, 171, 130, 0}},
-{(unsigned char*)"supnE", {226, 171, 140, 0}},
-{(unsigned char*)"supne", {226, 138, 139, 0}},
-{(unsigned char*)"supplus", {226, 171, 128, 0}},
-{(unsigned char*)"supset", {226, 138, 131, 0}},
-{(unsigned char*)"supseteq", {226, 138, 135, 0}},
-{(unsigned char*)"supseteqq", {226, 171, 134, 0}},
-{(unsigned char*)"supsetneq", {226, 138, 139, 0}},
-{(unsigned char*)"supsetneqq", {226, 171, 140, 0}},
-{(unsigned char*)"supsim", {226, 171, 136, 0}},
-{(unsigned char*)"supsub", {226, 171, 148, 0}},
-{(unsigned char*)"supsup", {226, 171, 150, 0}},
-{(unsigned char*)"swArr", {226, 135, 153, 0}},
-{(unsigned char*)"swarhk", {226, 164, 166, 0}},
-{(unsigned char*)"swarr", {226, 134, 153, 0}},
-{(unsigned char*)"swarrow", {226, 134, 153, 0}},
-{(unsigned char*)"swnwar", {226, 164, 170, 0}},
-{(unsigned char*)"szlig", {195, 159, 0}},
-{(unsigned char*)"target", {226, 140, 150, 0}},
-{(unsigned char*)"tau", {207, 132, 0}},
-{(unsigned char*)"tbrk", {226, 142, 180, 0}},
-{(unsigned char*)"tcaron", {197, 165, 0}},
-{(unsigned char*)"tcedil", {197, 163, 0}},
-{(unsigned char*)"tcy", {209, 130, 0}},
-{(unsigned char*)"tdot", {226, 131, 155, 0}},
-{(unsigned char*)"telrec", {226, 140, 149, 0}},
-{(unsigned char*)"tfr", {240, 157, 148, 177, 0}},
-{(unsigned char*)"there4", {226, 136, 180, 0}},
-{(unsigned char*)"therefore", {226, 136, 180, 0}},
-{(unsigned char*)"theta", {206, 184, 0}},
-{(unsigned char*)"thetasym", {207, 145, 0}},
-{(unsigned char*)"thetav", {207, 145, 0}},
-{(unsigned char*)"thickapprox", {226, 137, 136, 0}},
-{(unsigned char*)"thicksim", {226, 136, 188, 0}},
-{(unsigned char*)"thinsp", {226, 128, 137, 0}},
-{(unsigned char*)"thkap", {226, 137, 136, 0}},
-{(unsigned char*)"thksim", {226, 136, 188, 0}},
-{(unsigned char*)"thorn", {195, 190, 0}},
-{(unsigned char*)"tilde", {203, 156, 0}},
-{(unsigned char*)"times", {195, 151, 0}},
-{(unsigned char*)"timesb", {226, 138, 160, 0}},
-{(unsigned char*)"timesbar", {226, 168, 177, 0}},
-{(unsigned char*)"timesd", {226, 168, 176, 0}},
-{(unsigned char*)"tint", {226, 136, 173, 0}},
-{(unsigned char*)"toea", {226, 164, 168, 0}},
-{(unsigned char*)"top", {226, 138, 164, 0}},
-{(unsigned char*)"topbot", {226, 140, 182, 0}},
-{(unsigned char*)"topcir", {226, 171, 177, 0}},
-{(unsigned char*)"topf", {240, 157, 149, 165, 0}},
-{(unsigned char*)"topfork", {226, 171, 154, 0}},
-{(unsigned char*)"tosa", {226, 164, 169, 0}},
-{(unsigned char*)"tprime", {226, 128, 180, 0}},
-{(unsigned char*)"trade", {226, 132, 162, 0}},
-{(unsigned char*)"triangle", {226, 150, 181, 0}},
-{(unsigned char*)"triangledown", {226, 150, 191, 0}},
-{(unsigned char*)"triangleleft", {226, 151, 131, 0}},
-{(unsigned char*)"trianglelefteq", {226, 138, 180, 0}},
-{(unsigned char*)"triangleq", {226, 137, 156, 0}},
-{(unsigned char*)"triangleright", {226, 150, 185, 0}},
-{(unsigned char*)"trianglerighteq", {226, 138, 181, 0}},
-{(unsigned char*)"tridot", {226, 151, 172, 0}},
-{(unsigned char*)"trie", {226, 137, 156, 0}},
-{(unsigned char*)"triminus", {226, 168, 186, 0}},
-{(unsigned char*)"triplus", {226, 168, 185, 0}},
-{(unsigned char*)"trisb", {226, 167, 141, 0}},
-{(unsigned char*)"tritime", {226, 168, 187, 0}},
-{(unsigned char*)"trpezium", {226, 143, 162, 0}},
-{(unsigned char*)"tscr", {240, 157, 147, 137, 0}},
-{(unsigned char*)"tscy", {209, 134, 0}},
-{(unsigned char*)"tshcy", {209, 155, 0}},
-{(unsigned char*)"tstrok", {197, 167, 0}},
-{(unsigned char*)"twixt", {226, 137, 172, 0}},
-{(unsigned char*)"twoheadleftarrow", {226, 134, 158, 0}},
-{(unsigned char*)"twoheadrightarrow", {226, 134, 160, 0}},
-{(unsigned char*)"uArr", {226, 135, 145, 0}},
-{(unsigned char*)"uHar", {226, 165, 163, 0}},
-{(unsigned char*)"uacute", {195, 186, 0}},
-{(unsigned char*)"uarr", {226, 134, 145, 0}},
-{(unsigned char*)"ubrcy", {209, 158, 0}},
-{(unsigned char*)"ubreve", {197, 173, 0}},
-{(unsigned char*)"ucirc", {195, 187, 0}},
-{(unsigned char*)"ucy", {209, 131, 0}},
-{(unsigned char*)"udarr", {226, 135, 133, 0}},
-{(unsigned char*)"udblac", {197, 177, 0}},
-{(unsigned char*)"udhar", {226, 165, 174, 0}},
-{(unsigned char*)"ufisht", {226, 165, 190, 0}},
-{(unsigned char*)"ufr", {240, 157, 148, 178, 0}},
-{(unsigned char*)"ugrave", {195, 185, 0}},
-{(unsigned char*)"uharl", {226, 134, 191, 0}},
-{(unsigned char*)"uharr", {226, 134, 190, 0}},
-{(unsigned char*)"uhblk", {226, 150, 128, 0}},
-{(unsigned char*)"ulcorn", {226, 140, 156, 0}},
-{(unsigned char*)"ulcorner", {226, 140, 156, 0}},
-{(unsigned char*)"ulcrop", {226, 140, 143, 0}},
-{(unsigned char*)"ultri", {226, 151, 184, 0}},
-{(unsigned char*)"umacr", {197, 171, 0}},
-{(unsigned char*)"uml", {194, 168, 0}},
-{(unsigned char*)"uogon", {197, 179, 0}},
-{(unsigned char*)"uopf", {240, 157, 149, 166, 0}},
-{(unsigned char*)"uparrow", {226, 134, 145, 0}},
-{(unsigned char*)"updownarrow", {226, 134, 149, 0}},
-{(unsigned char*)"upharpoonleft", {226, 134, 191, 0}},
-{(unsigned char*)"upharpoonright", {226, 134, 190, 0}},
-{(unsigned char*)"uplus", {226, 138, 142, 0}},
-{(unsigned char*)"upsi", {207, 133, 0}},
-{(unsigned char*)"upsih", {207, 146, 0}},
-{(unsigned char*)"upsilon", {207, 133, 0}},
-{(unsigned char*)"upuparrows", {226, 135, 136, 0}},
-{(unsigned char*)"urcorn", {226, 140, 157, 0}},
-{(unsigned char*)"urcorner", {226, 140, 157, 0}},
-{(unsigned char*)"urcrop", {226, 140, 142, 0}},
-{(unsigned char*)"uring", {197, 175, 0}},
-{(unsigned char*)"urtri", {226, 151, 185, 0}},
-{(unsigned char*)"uscr", {240, 157, 147, 138, 0}},
-{(unsigned char*)"utdot", {226, 139, 176, 0}},
-{(unsigned char*)"utilde", {197, 169, 0}},
-{(unsigned char*)"utri", {226, 150, 181, 0}},
-{(unsigned char*)"utrif", {226, 150, 180, 0}},
-{(unsigned char*)"uuarr", {226, 135, 136, 0}},
-{(unsigned char*)"uuml", {195, 188, 0}},
-{(unsigned char*)"uwangle", {226, 166, 167, 0}},
-{(unsigned char*)"vArr", {226, 135, 149, 0}},
-{(unsigned char*)"vBar", {226, 171, 168, 0}},
-{(unsigned char*)"vBarv", {226, 171, 169, 0}},
-{(unsigned char*)"vDash", {226, 138, 168, 0}},
-{(unsigned char*)"vangrt", {226, 166, 156, 0}},
-{(unsigned char*)"varepsilon", {207, 181, 0}},
-{(unsigned char*)"varkappa", {207, 176, 0}},
-{(unsigned char*)"varnothing", {226, 136, 133, 0}},
-{(unsigned char*)"varphi", {207, 149, 0}},
-{(unsigned char*)"varpi", {207, 150, 0}},
-{(unsigned char*)"varpropto", {226, 136, 157, 0}},
-{(unsigned char*)"varr", {226, 134, 149, 0}},
-{(unsigned char*)"varrho", {207, 177, 0}},
-{(unsigned char*)"varsigma", {207, 130, 0}},
-{(unsigned char*)"varsubsetneq", {226, 138, 138, 239, 184, 128, 0}},
-{(unsigned char*)"varsubsetneqq", {226, 171, 139, 239, 184, 128, 0}},
-{(unsigned char*)"varsupsetneq", {226, 138, 139, 239, 184, 128, 0}},
-{(unsigned char*)"varsupsetneqq", {226, 171, 140, 239, 184, 128, 0}},
-{(unsigned char*)"vartheta", {207, 145, 0}},
-{(unsigned char*)"vartriangleleft", {226, 138, 178, 0}},
-{(unsigned char*)"vartriangleright", {226, 138, 179, 0}},
-{(unsigned char*)"vcy", {208, 178, 0}},
-{(unsigned char*)"vdash", {226, 138, 162, 0}},
-{(unsigned char*)"vee", {226, 136, 168, 0}},
-{(unsigned char*)"veebar", {226, 138, 187, 0}},
-{(unsigned char*)"veeeq", {226, 137, 154, 0}},
-{(unsigned char*)"vellip", {226, 139, 174, 0}},
-{(unsigned char*)"verbar", {124, 0}},
-{(unsigned char*)"vert", {124, 0}},
-{(unsigned char*)"vfr", {240, 157, 148, 179, 0}},
-{(unsigned char*)"vltri", {226, 138, 178, 0}},
-{(unsigned char*)"vnsub", {226, 138, 130, 226, 131, 146, 0}},
-{(unsigned char*)"vnsup", {226, 138, 131, 226, 131, 146, 0}},
-{(unsigned char*)"vopf", {240, 157, 149, 167, 0}},
-{(unsigned char*)"vprop", {226, 136, 157, 0}},
-{(unsigned char*)"vrtri", {226, 138, 179, 0}},
-{(unsigned char*)"vscr", {240, 157, 147, 139, 0}},
-{(unsigned char*)"vsubnE", {226, 171, 139, 239, 184, 128, 0}},
-{(unsigned char*)"vsubne", {226, 138, 138, 239, 184, 128, 0}},
-{(unsigned char*)"vsupnE", {226, 171, 140, 239, 184, 128, 0}},
-{(unsigned char*)"vsupne", {226, 138, 139, 239, 184, 128, 0}},
-{(unsigned char*)"vzigzag", {226, 166, 154, 0}},
-{(unsigned char*)"wcirc", {197, 181, 0}},
-{(unsigned char*)"wedbar", {226, 169, 159, 0}},
-{(unsigned char*)"wedge", {226, 136, 167, 0}},
-{(unsigned char*)"wedgeq", {226, 137, 153, 0}},
-{(unsigned char*)"weierp", {226, 132, 152, 0}},
-{(unsigned char*)"wfr", {240, 157, 148, 180, 0}},
-{(unsigned char*)"wopf", {240, 157, 149, 168, 0}},
-{(unsigned char*)"wp", {226, 132, 152, 0}},
-{(unsigned char*)"wr", {226, 137, 128, 0}},
-{(unsigned char*)"wreath", {226, 137, 128, 0}},
-{(unsigned char*)"wscr", {240, 157, 147, 140, 0}},
-{(unsigned char*)"xcap", {226, 139, 130, 0}},
-{(unsigned char*)"xcirc", {226, 151, 175, 0}},
-{(unsigned char*)"xcup", {226, 139, 131, 0}},
-{(unsigned char*)"xdtri", {226, 150, 189, 0}},
-{(unsigned char*)"xfr", {240, 157, 148, 181, 0}},
-{(unsigned char*)"xhArr", {226, 159, 186, 0}},
-{(unsigned char*)"xharr", {226, 159, 183, 0}},
-{(unsigned char*)"xi", {206, 190, 0}},
-{(unsigned char*)"xlArr", {226, 159, 184, 0}},
-{(unsigned char*)"xlarr", {226, 159, 181, 0}},
-{(unsigned char*)"xmap", {226, 159, 188, 0}},
-{(unsigned char*)"xnis", {226, 139, 187, 0}},
-{(unsigned char*)"xodot", {226, 168, 128, 0}},
-{(unsigned char*)"xopf", {240, 157, 149, 169, 0}},
-{(unsigned char*)"xoplus", {226, 168, 129, 0}},
-{(unsigned char*)"xotime", {226, 168, 130, 0}},
-{(unsigned char*)"xrArr", {226, 159, 185, 0}},
-{(unsigned char*)"xrarr", {226, 159, 182, 0}},
-{(unsigned char*)"xscr", {240, 157, 147, 141, 0}},
-{(unsigned char*)"xsqcup", {226, 168, 134, 0}},
-{(unsigned char*)"xuplus", {226, 168, 132, 0}},
-{(unsigned char*)"xutri", {226, 150, 179, 0}},
-{(unsigned char*)"xvee", {226, 139, 129, 0}},
-{(unsigned char*)"xwedge", {226, 139, 128, 0}},
-{(unsigned char*)"yacute", {195, 189, 0}},
-{(unsigned char*)"yacy", {209, 143, 0}},
-{(unsigned char*)"ycirc", {197, 183, 0}},
-{(unsigned char*)"ycy", {209, 139, 0}},
-{(unsigned char*)"yen", {194, 165, 0}},
-{(unsigned char*)"yfr", {240, 157, 148, 182, 0}},
-{(unsigned char*)"yicy", {209, 151, 0}},
-{(unsigned char*)"yopf", {240, 157, 149, 170, 0}},
-{(unsigned char*)"yscr", {240, 157, 147, 142, 0}},
-{(unsigned char*)"yucy", {209, 142, 0}},
-{(unsigned char*)"yuml", {195, 191, 0}},
-{(unsigned char*)"zacute", {197, 186, 0}},
-{(unsigned char*)"zcaron", {197, 190, 0}},
-{(unsigned char*)"zcy", {208, 183, 0}},
-{(unsigned char*)"zdot", {197, 188, 0}},
-{(unsigned char*)"zeetrf", {226, 132, 168, 0}},
-{(unsigned char*)"zeta", {206, 182, 0}},
-{(unsigned char*)"zfr", {240, 157, 148, 183, 0}},
-{(unsigned char*)"zhcy", {208, 182, 0}},
-{(unsigned char*)"zigrarr", {226, 135, 157, 0}},
-{(unsigned char*)"zopf", {240, 157, 149, 171, 0}},
-{(unsigned char*)"zscr", {240, 157, 147, 143, 0}},
-{(unsigned char*)"zwj", {226, 128, 141, 0}},
-{(unsigned char*)"zwnj", {226, 128, 140, 0}},
-};
diff --git a/ext/commonmarker/ext_scanners.c b/ext/commonmarker/ext_scanners.c
deleted file mode 100644
index 0d3ba288..00000000
--- a/ext/commonmarker/ext_scanners.c
+++ /dev/null
@@ -1,879 +0,0 @@
-/* Generated by re2c 1.3 */
-
-#include "ext_scanners.h"
-#include 
-
-bufsize_t _ext_scan_at(bufsize_t (*scanner)(const unsigned char *),
-                       unsigned char *ptr, int len, bufsize_t offset) {
-  bufsize_t res;
-
-  if (ptr == NULL || offset >= len) {
-    return 0;
-  } else {
-    unsigned char lim = ptr[len];
-
-    ptr[len] = '\0';
-    res = scanner(ptr + offset);
-    ptr[len] = lim;
-  }
-
-  return res;
-}
-
-bufsize_t _scan_table_start(const unsigned char *p) {
-  const unsigned char *marker = NULL;
-  const unsigned char *start = p;
-
-  {
-    unsigned char yych;
-    static const unsigned char yybm[] = {
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 64, 0,  64, 64, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  64, 0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 128, 0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0, 0, 0, 0, 0, 0, 0, 0, 0,
-        0, 0,   0, 0, 0, 0, 0, 0, 0, 0,  0,  0,  0,  0,
-    };
-    yych = *p;
-    if (yych <= ' ') {
-      if (yych <= '\n') {
-        if (yych == '\t')
-          goto yy4;
-      } else {
-        if (yych <= '\f')
-          goto yy4;
-        if (yych >= ' ')
-          goto yy4;
-      }
-    } else {
-      if (yych <= '9') {
-        if (yych == '-')
-          goto yy5;
-      } else {
-        if (yych <= ':')
-          goto yy6;
-        if (yych == '|')
-          goto yy4;
-      }
-    }
-    ++p;
-  yy3 : { return 0; }
-  yy4:
-    yych = *(marker = ++p);
-    if (yybm[0 + yych] & 64) {
-      goto yy7;
-    }
-    if (yych == '-')
-      goto yy10;
-    if (yych == ':')
-      goto yy12;
-    goto yy3;
-  yy5:
-    yych = *(marker = ++p);
-    if (yybm[0 + yych] & 128) {
-      goto yy10;
-    }
-    if (yych <= ' ') {
-      if (yych <= 0x08)
-        goto yy3;
-      if (yych <= '\r')
-        goto yy14;
-      if (yych <= 0x1F)
-        goto yy3;
-      goto yy14;
-    } else {
-      if (yych <= ':') {
-        if (yych <= '9')
-          goto yy3;
-        goto yy13;
-      } else {
-        if (yych == '|')
-          goto yy14;
-        goto yy3;
-      }
-    }
-  yy6:
-    yych = *(marker = ++p);
-    if (yybm[0 + yych] & 128) {
-      goto yy10;
-    }
-    goto yy3;
-  yy7:
-    yych = *++p;
-    if (yybm[0 + yych] & 64) {
-      goto yy7;
-    }
-    if (yych == '-')
-      goto yy10;
-    if (yych == ':')
-      goto yy12;
-  yy9:
-    p = marker;
-    goto yy3;
-  yy10:
-    yych = *++p;
-    if (yybm[0 + yych] & 128) {
-      goto yy10;
-    }
-    if (yych <= 0x1F) {
-      if (yych <= '\n') {
-        if (yych <= 0x08)
-          goto yy9;
-        if (yych <= '\t')
-          goto yy13;
-        goto yy15;
-      } else {
-        if (yych <= '\f')
-          goto yy13;
-        if (yych <= '\r')
-          goto yy17;
-        goto yy9;
-      }
-    } else {
-      if (yych <= ':') {
-        if (yych <= ' ')
-          goto yy13;
-        if (yych <= '9')
-          goto yy9;
-        goto yy13;
-      } else {
-        if (yych == '|')
-          goto yy18;
-        goto yy9;
-      }
-    }
-  yy12:
-    yych = *++p;
-    if (yybm[0 + yych] & 128) {
-      goto yy10;
-    }
-    goto yy9;
-  yy13:
-    yych = *++p;
-  yy14:
-    if (yych <= '\r') {
-      if (yych <= '\t') {
-        if (yych <= 0x08)
-          goto yy9;
-        goto yy13;
-      } else {
-        if (yych <= '\n')
-          goto yy15;
-        if (yych <= '\f')
-          goto yy13;
-        goto yy17;
-      }
-    } else {
-      if (yych <= ' ') {
-        if (yych <= 0x1F)
-          goto yy9;
-        goto yy13;
-      } else {
-        if (yych == '|')
-          goto yy18;
-        goto yy9;
-      }
-    }
-  yy15:
-    ++p;
-    { return (bufsize_t)(p - start); }
-  yy17:
-    yych = *++p;
-    if (yych == '\n')
-      goto yy15;
-    goto yy9;
-  yy18:
-    yych = *++p;
-    if (yybm[0 + yych] & 128) {
-      goto yy10;
-    }
-    if (yych <= '\r') {
-      if (yych <= '\t') {
-        if (yych <= 0x08)
-          goto yy9;
-        goto yy18;
-      } else {
-        if (yych <= '\n')
-          goto yy15;
-        if (yych <= '\f')
-          goto yy18;
-        goto yy17;
-      }
-    } else {
-      if (yych <= ' ') {
-        if (yych <= 0x1F)
-          goto yy9;
-        goto yy18;
-      } else {
-        if (yych == ':')
-          goto yy12;
-        goto yy9;
-      }
-    }
-  }
-}
-
-bufsize_t _scan_table_cell(const unsigned char *p) {
-  const unsigned char *marker = NULL;
-  const unsigned char *start = p;
-
-  {
-    unsigned char yych;
-    unsigned int yyaccept = 0;
-    static const unsigned char yybm[] = {
-        64, 64, 64,  64, 64, 64, 64, 64, 64, 64, 0,  64, 64, 0,  64, 64, 64, 64,
-        64, 64, 64,  64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-        64, 64, 64,  64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-        64, 64, 64,  64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-        64, 64, 64,  64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-        64, 64, 128, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
-        64, 64, 64,  64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 0,  64,
-        64, 64, 0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,
-        0,  0,  0,   0,
-    };
-    yych = *p;
-    if (yybm[0 + yych] & 64) {
-      goto yy22;
-    }
-    if (yych <= 0xEC) {
-      if (yych <= 0xC1) {
-        if (yych <= '\r')
-          goto yy25;
-        if (yych <= '\\')
-          goto yy27;
-        goto yy25;
-      } else {
-        if (yych <= 0xDF)
-          goto yy29;
-        if (yych <= 0xE0)
-          goto yy30;
-        goto yy31;
-      }
-    } else {
-      if (yych <= 0xF0) {
-        if (yych <= 0xED)
-          goto yy32;
-        if (yych <= 0xEF)
-          goto yy31;
-        goto yy33;
-      } else {
-        if (yych <= 0xF3)
-          goto yy34;
-        if (yych <= 0xF4)
-          goto yy35;
-        goto yy25;
-      }
-    }
-  yy22:
-    yyaccept = 0;
-    yych = *(marker = ++p);
-    if (yybm[0 + yych] & 64) {
-      goto yy22;
-    }
-    if (yych <= 0xEC) {
-      if (yych <= 0xC1) {
-        if (yych <= '\r')
-          goto yy24;
-        if (yych <= '\\')
-          goto yy27;
-      } else {
-        if (yych <= 0xDF)
-          goto yy36;
-        if (yych <= 0xE0)
-          goto yy38;
-        goto yy39;
-      }
-    } else {
-      if (yych <= 0xF0) {
-        if (yych <= 0xED)
-          goto yy40;
-        if (yych <= 0xEF)
-          goto yy39;
-        goto yy41;
-      } else {
-        if (yych <= 0xF3)
-          goto yy42;
-        if (yych <= 0xF4)
-          goto yy43;
-      }
-    }
-  yy24 : { return (bufsize_t)(p - start); }
-  yy25:
-    ++p;
-  yy26 : { return 0; }
-  yy27:
-    yyaccept = 0;
-    yych = *(marker = ++p);
-    if (yybm[0 + yych] & 128) {
-      goto yy27;
-    }
-    if (yych <= 0xDF) {
-      if (yych <= '\f') {
-        if (yych == '\n')
-          goto yy24;
-        goto yy22;
-      } else {
-        if (yych <= '\r')
-          goto yy24;
-        if (yych <= 0x7F)
-          goto yy22;
-        if (yych <= 0xC1)
-          goto yy24;
-        goto yy36;
-      }
-    } else {
-      if (yych <= 0xEF) {
-        if (yych <= 0xE0)
-          goto yy38;
-        if (yych == 0xED)
-          goto yy40;
-        goto yy39;
-      } else {
-        if (yych <= 0xF0)
-          goto yy41;
-        if (yych <= 0xF3)
-          goto yy42;
-        if (yych <= 0xF4)
-          goto yy43;
-        goto yy24;
-      }
-    }
-  yy29:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy26;
-    if (yych <= 0xBF)
-      goto yy22;
-    goto yy26;
-  yy30:
-    yyaccept = 1;
-    yych = *(marker = ++p);
-    if (yych <= 0x9F)
-      goto yy26;
-    if (yych <= 0xBF)
-      goto yy36;
-    goto yy26;
-  yy31:
-    yyaccept = 1;
-    yych = *(marker = ++p);
-    if (yych <= 0x7F)
-      goto yy26;
-    if (yych <= 0xBF)
-      goto yy36;
-    goto yy26;
-  yy32:
-    yyaccept = 1;
-    yych = *(marker = ++p);
-    if (yych <= 0x7F)
-      goto yy26;
-    if (yych <= 0x9F)
-      goto yy36;
-    goto yy26;
-  yy33:
-    yyaccept = 1;
-    yych = *(marker = ++p);
-    if (yych <= 0x8F)
-      goto yy26;
-    if (yych <= 0xBF)
-      goto yy39;
-    goto yy26;
-  yy34:
-    yyaccept = 1;
-    yych = *(marker = ++p);
-    if (yych <= 0x7F)
-      goto yy26;
-    if (yych <= 0xBF)
-      goto yy39;
-    goto yy26;
-  yy35:
-    yyaccept = 1;
-    yych = *(marker = ++p);
-    if (yych <= 0x7F)
-      goto yy26;
-    if (yych <= 0x8F)
-      goto yy39;
-    goto yy26;
-  yy36:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy37;
-    if (yych <= 0xBF)
-      goto yy22;
-  yy37:
-    p = marker;
-    if (yyaccept == 0) {
-      goto yy24;
-    } else {
-      goto yy26;
-    }
-  yy38:
-    yych = *++p;
-    if (yych <= 0x9F)
-      goto yy37;
-    if (yych <= 0xBF)
-      goto yy36;
-    goto yy37;
-  yy39:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy37;
-    if (yych <= 0xBF)
-      goto yy36;
-    goto yy37;
-  yy40:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy37;
-    if (yych <= 0x9F)
-      goto yy36;
-    goto yy37;
-  yy41:
-    yych = *++p;
-    if (yych <= 0x8F)
-      goto yy37;
-    if (yych <= 0xBF)
-      goto yy39;
-    goto yy37;
-  yy42:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy37;
-    if (yych <= 0xBF)
-      goto yy39;
-    goto yy37;
-  yy43:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy37;
-    if (yych <= 0x8F)
-      goto yy39;
-    goto yy37;
-  }
-}
-
-bufsize_t _scan_table_cell_end(const unsigned char *p) {
-  const unsigned char *start = p;
-
-  {
-    unsigned char yych;
-    static const unsigned char yybm[] = {
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 128, 128, 0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   128, 0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0,
-    };
-    yych = *p;
-    if (yych == '|')
-      goto yy48;
-    ++p;
-    { return 0; }
-  yy48:
-    yych = *++p;
-    if (yybm[0 + yych] & 128) {
-      goto yy48;
-    }
-    { return (bufsize_t)(p - start); }
-  }
-}
-
-bufsize_t _scan_table_row_end(const unsigned char *p) {
-  const unsigned char *marker = NULL;
-  const unsigned char *start = p;
-
-  {
-    unsigned char yych;
-    static const unsigned char yybm[] = {
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 128, 0, 128, 128, 0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   128, 0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0, 0, 0, 0, 0,
-        0, 0, 0, 0, 0, 0, 0, 0, 0, 0,   0, 0,   0,   0, 0, 0,
-    };
-    yych = *p;
-    if (yych <= '\f') {
-      if (yych <= 0x08)
-        goto yy53;
-      if (yych == '\n')
-        goto yy56;
-      goto yy55;
-    } else {
-      if (yych <= '\r')
-        goto yy58;
-      if (yych == ' ')
-        goto yy55;
-    }
-  yy53:
-    ++p;
-  yy54 : { return 0; }
-  yy55:
-    yych = *(marker = ++p);
-    if (yych <= 0x08)
-      goto yy54;
-    if (yych <= '\r')
-      goto yy60;
-    if (yych == ' ')
-      goto yy60;
-    goto yy54;
-  yy56:
-    ++p;
-    { return (bufsize_t)(p - start); }
-  yy58:
-    yych = *++p;
-    if (yych == '\n')
-      goto yy56;
-    goto yy54;
-  yy59:
-    yych = *++p;
-  yy60:
-    if (yybm[0 + yych] & 128) {
-      goto yy59;
-    }
-    if (yych <= 0x08)
-      goto yy61;
-    if (yych <= '\n')
-      goto yy56;
-    if (yych <= '\r')
-      goto yy62;
-  yy61:
-    p = marker;
-    goto yy54;
-  yy62:
-    yych = *++p;
-    if (yych == '\n')
-      goto yy56;
-    goto yy61;
-  }
-}
-
-bufsize_t _scan_tasklist(const unsigned char *p) {
-  const unsigned char *marker = NULL;
-  const unsigned char *start = p;
-
-  {
-    unsigned char yych;
-    static const unsigned char yybm[] = {
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   64,  0, 64, 64, 0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        64,  0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        128, 128, 128, 128, 128, 128, 128, 128, 128, 128, 0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-        0,   0,   0,   0,   0,   0,   0,   0,   0,   0,   0, 0,  0,  0, 0, 0,
-    };
-    yych = *p;
-    if (yych <= ' ') {
-      if (yych <= '\n') {
-        if (yych == '\t')
-          goto yy67;
-      } else {
-        if (yych <= '\f')
-          goto yy67;
-        if (yych >= ' ')
-          goto yy67;
-      }
-    } else {
-      if (yych <= ',') {
-        if (yych <= ')')
-          goto yy65;
-        if (yych <= '+')
-          goto yy68;
-      } else {
-        if (yych <= '-')
-          goto yy68;
-        if (yych <= '/')
-          goto yy65;
-        if (yych <= '9')
-          goto yy69;
-      }
-    }
-  yy65:
-    ++p;
-  yy66 : { return 0; }
-  yy67:
-    yych = *(marker = ++p);
-    if (yybm[0 + yych] & 64) {
-      goto yy70;
-    }
-    if (yych <= ',') {
-      if (yych <= ')')
-        goto yy66;
-      if (yych <= '+')
-        goto yy73;
-      goto yy66;
-    } else {
-      if (yych <= '-')
-        goto yy73;
-      if (yych <= '/')
-        goto yy66;
-      if (yych <= '9')
-        goto yy74;
-      goto yy66;
-    }
-  yy68:
-    yych = *(marker = ++p);
-    if (yych <= '\n') {
-      if (yych == '\t')
-        goto yy75;
-      goto yy66;
-    } else {
-      if (yych <= '\f')
-        goto yy75;
-      if (yych == ' ')
-        goto yy75;
-      goto yy66;
-    }
-  yy69:
-    yych = *(marker = ++p);
-    if (yych <= 0x1F) {
-      if (yych <= '\t') {
-        if (yych <= 0x08)
-          goto yy78;
-        goto yy73;
-      } else {
-        if (yych <= '\n')
-          goto yy66;
-        if (yych <= '\f')
-          goto yy73;
-        goto yy78;
-      }
-    } else {
-      if (yych <= 0x7F) {
-        if (yych <= ' ')
-          goto yy73;
-        goto yy78;
-      } else {
-        if (yych <= 0xC1)
-          goto yy66;
-        if (yych <= 0xF4)
-          goto yy78;
-        goto yy66;
-      }
-    }
-  yy70:
-    yych = *++p;
-    if (yybm[0 + yych] & 64) {
-      goto yy70;
-    }
-    if (yych <= ',') {
-      if (yych <= ')')
-        goto yy72;
-      if (yych <= '+')
-        goto yy73;
-    } else {
-      if (yych <= '-')
-        goto yy73;
-      if (yych <= '/')
-        goto yy72;
-      if (yych <= '9')
-        goto yy74;
-    }
-  yy72:
-    p = marker;
-    goto yy66;
-  yy73:
-    yych = *++p;
-    if (yych == '[')
-      goto yy72;
-    goto yy76;
-  yy74:
-    yych = *++p;
-    if (yych <= '\n') {
-      if (yych == '\t')
-        goto yy73;
-      goto yy78;
-    } else {
-      if (yych <= '\f')
-        goto yy73;
-      if (yych == ' ')
-        goto yy73;
-      goto yy78;
-    }
-  yy75:
-    yych = *++p;
-  yy76:
-    if (yych <= '\f') {
-      if (yych == '\t')
-        goto yy75;
-      if (yych <= '\n')
-        goto yy72;
-      goto yy75;
-    } else {
-      if (yych <= ' ') {
-        if (yych <= 0x1F)
-          goto yy72;
-        goto yy75;
-      } else {
-        if (yych == '[')
-          goto yy86;
-        goto yy72;
-      }
-    }
-  yy77:
-    yych = *++p;
-  yy78:
-    if (yybm[0 + yych] & 128) {
-      goto yy77;
-    }
-    if (yych <= 0xC1) {
-      if (yych <= '\f') {
-        if (yych <= 0x08)
-          goto yy73;
-        if (yych == '\n')
-          goto yy72;
-        goto yy75;
-      } else {
-        if (yych == ' ')
-          goto yy75;
-        if (yych <= 0x7F)
-          goto yy73;
-        goto yy72;
-      }
-    } else {
-      if (yych <= 0xED) {
-        if (yych <= 0xDF)
-          goto yy79;
-        if (yych <= 0xE0)
-          goto yy80;
-        if (yych <= 0xEC)
-          goto yy81;
-        goto yy82;
-      } else {
-        if (yych <= 0xF0) {
-          if (yych <= 0xEF)
-            goto yy81;
-          goto yy83;
-        } else {
-          if (yych <= 0xF3)
-            goto yy84;
-          if (yych <= 0xF4)
-            goto yy85;
-          goto yy72;
-        }
-      }
-    }
-  yy79:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy72;
-    if (yych <= 0xBF)
-      goto yy73;
-    goto yy72;
-  yy80:
-    yych = *++p;
-    if (yych <= 0x9F)
-      goto yy72;
-    if (yych <= 0xBF)
-      goto yy79;
-    goto yy72;
-  yy81:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy72;
-    if (yych <= 0xBF)
-      goto yy79;
-    goto yy72;
-  yy82:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy72;
-    if (yych <= 0x9F)
-      goto yy79;
-    goto yy72;
-  yy83:
-    yych = *++p;
-    if (yych <= 0x8F)
-      goto yy72;
-    if (yych <= 0xBF)
-      goto yy81;
-    goto yy72;
-  yy84:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy72;
-    if (yych <= 0xBF)
-      goto yy81;
-    goto yy72;
-  yy85:
-    yych = *++p;
-    if (yych <= 0x7F)
-      goto yy72;
-    if (yych <= 0x8F)
-      goto yy81;
-    goto yy72;
-  yy86:
-    yych = *++p;
-    if (yych <= 'W') {
-      if (yych != ' ')
-        goto yy72;
-    } else {
-      if (yych <= 'X')
-        goto yy87;
-      if (yych != 'x')
-        goto yy72;
-    }
-  yy87:
-    yych = *++p;
-    if (yych != ']')
-      goto yy72;
-    yych = *++p;
-    if (yych <= '\n') {
-      if (yych != '\t')
-        goto yy72;
-    } else {
-      if (yych <= '\f')
-        goto yy89;
-      if (yych != ' ')
-        goto yy72;
-    }
-  yy89:
-    yych = *++p;
-    if (yych <= '\n') {
-      if (yych == '\t')
-        goto yy89;
-    } else {
-      if (yych <= '\f')
-        goto yy89;
-      if (yych == ' ')
-        goto yy89;
-    }
-    { return (bufsize_t)(p - start); }
-  }
-}
diff --git a/ext/commonmarker/ext_scanners.h b/ext/commonmarker/ext_scanners.h
deleted file mode 100644
index 6dd4a725..00000000
--- a/ext/commonmarker/ext_scanners.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#include "chunk.h"
-#include "cmark-gfm.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-bufsize_t _ext_scan_at(bufsize_t (*scanner)(const unsigned char *),
-                       unsigned char *ptr, int len, bufsize_t offset);
-bufsize_t _scan_table_start(const unsigned char *p);
-bufsize_t _scan_table_cell(const unsigned char *p);
-bufsize_t _scan_table_cell_end(const unsigned char *p);
-bufsize_t _scan_table_row_end(const unsigned char *p);
-bufsize_t _scan_tasklist(const unsigned char *p);
-
-#define scan_table_start(c, l, n) _ext_scan_at(&_scan_table_start, c, l, n)
-#define scan_table_cell(c, l, n) _ext_scan_at(&_scan_table_cell, c, l, n)
-#define scan_table_cell_end(c, l, n) _ext_scan_at(&_scan_table_cell_end, c, l, n)
-#define scan_table_row_end(c, l, n) _ext_scan_at(&_scan_table_row_end, c, l, n)
-#define scan_tasklist(c, l, n) _ext_scan_at(&_scan_tasklist, c, l, n)
-
-#ifdef __cplusplus
-}
-#endif
diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb
index c64da73d..a7099d84 100644
--- a/ext/commonmarker/extconf.rb
+++ b/ext/commonmarker/extconf.rb
@@ -1,7 +1,71 @@
-# frozen_string_literal: true
+require "mkmf"
+require "mini_portile2"
 
-require 'mkmf'
+PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", ".."))
+EXT_DIR = File.join(PACKAGE_ROOT_DIR, "ext", "commonmarker")
+CROSS_BUILD_P = enable_config("cross-build")
+COMRAK_VERSION = "0.14.0"
 
-$CFLAGS << ' -std=c99'
+RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
+ENV["CC"] = RbConfig::CONFIG["CC"]
 
-create_makefile('commonmarker/commonmarker')
+def darwin?
+  RbConfig::CONFIG["target_os"].include?("darwin")
+end
+
+# what follows is pretty miuch an abuse of miniportile2, but it works for now
+# i just need something to download files and run a cargo build; one day this should
+# be replaced with actual prepacked binaries.
+TARBALL_URL = "https://github.com/kivikakk/comrak/archive/refs/tags/#{COMRAK_VERSION}.tar.gz"
+MiniPortile.new("comrak", COMRAK_VERSION).tap do |recipe|
+  recipe.target = File.join(PACKAGE_ROOT_DIR, "ports")
+  recipe.files = [{
+    url: TARBALL_URL,
+    sha256: "055fa44ef002a1a07853d3a4dd2a8c553a1dc58ff3809b4fa530ed35694d8571",
+  }]
+
+  # configure the environment that MiniPortile will use for subshells
+  if CROSS_BUILD_P
+    ENV.to_h.tap do |env|
+      # -fPIC is necessary for linking into a shared library
+      env["CFLAGS"] = [env["CFLAGS"], "-fPIC"].join(" ")
+
+      recipe.configure_options += env.map { |key, value| "#{key}=#{value.strip}" }
+    end
+  end
+
+  unless File.exist?(File.join(recipe.target, recipe.host, recipe.name, recipe.version))
+    recipe.download unless recipe.downloaded?
+    recipe.extract
+
+    host = if darwin?
+      recipe.host =~ /arm64-apple-darwin(\d+)\.\d+\.0/
+      "arm64-darwin#{$1}"
+    else
+      recipe.host
+    end
+
+    # Why is this so long?
+    tarball_extract_path = File.join(PACKAGE_ROOT_DIR, "tmp", host, "commonmarker", RUBY_VERSION, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}")
+    Dir.chdir(tarball_extract_path) do
+      puts `cargo build --manifest-path=./c-api/Cargo.toml --release`
+    end
+    lib_header_path = File.join(tarball_extract_path, "c-api", "include")
+    lib_build_path = File.join(tarball_extract_path, "c-api", "target", "release")
+
+    HEADER_DIRS = [lib_header_path]
+    LIB_DIRS = [lib_build_path]
+
+    dir_config('commonmarker', HEADER_DIRS, LIB_DIRS)
+  end
+
+  recipe.activate
+
+  $LIBS << ' -lcomrak_ffi'
+end
+
+unless find_header("comrak.h")
+  abort("\nERROR: *** could not find comrak.h ***\n\n")
+end
+
+create_makefile("commonmarker/commonmarker")
diff --git a/ext/commonmarker/footnotes.c b/ext/commonmarker/footnotes.c
deleted file mode 100644
index c2b745f7..00000000
--- a/ext/commonmarker/footnotes.c
+++ /dev/null
@@ -1,63 +0,0 @@
-#include "cmark-gfm.h"
-#include "parser.h"
-#include "footnotes.h"
-#include "inlines.h"
-#include "chunk.h"
-
-static void footnote_free(cmark_map *map, cmark_map_entry *_ref) {
-  cmark_footnote *ref = (cmark_footnote *)_ref;
-  cmark_mem *mem = map->mem;
-  if (ref != NULL) {
-    mem->free(ref->entry.label);
-    if (ref->node)
-      cmark_node_free(ref->node);
-    mem->free(ref);
-  }
-}
-
-void cmark_footnote_create(cmark_map *map, cmark_node *node) {
-  cmark_footnote *ref;
-  unsigned char *reflabel = normalize_map_label(map->mem, &node->as.literal);
-
-  /* empty footnote name, or composed from only whitespace */
-  if (reflabel == NULL)
-    return;
-
-  assert(map->sorted == NULL);
-
-  ref = (cmark_footnote *)map->mem->calloc(1, sizeof(*ref));
-  ref->entry.label = reflabel;
-  ref->node = node;
-  ref->entry.age = map->size;
-  ref->entry.next = map->refs;
-
-  map->refs = (cmark_map_entry *)ref;
-  map->size++;
-}
-
-cmark_map *cmark_footnote_map_new(cmark_mem *mem) {
-  return cmark_map_new(mem, footnote_free);
-}
-
-// Before calling `cmark_map_free` on a map with `cmark_footnotes`, first
-// unlink all of the footnote nodes before freeing their memory.
-//
-// Sometimes, two (unused) footnote nodes can end up referencing each other,
-// which as they get freed up by calling `cmark_map_free` -> `footnote_free` ->
-// etc, can lead to a use-after-free error.
-//
-// Better to `unlink` every footnote node first, setting their next, prev, and
-// parent pointers to NULL, and only then walk thru & free them up.
-void cmark_unlink_footnotes_map(cmark_map *map) {
-  cmark_map_entry *ref;
-  cmark_map_entry *next;
-
-  ref = map->refs;
-  while(ref) {
-    next = ref->next;
-    if (((cmark_footnote *)ref)->node) {
-      cmark_node_unlink(((cmark_footnote *)ref)->node);
-    }
-    ref = next;
-  }
-}
diff --git a/ext/commonmarker/footnotes.h b/ext/commonmarker/footnotes.h
deleted file mode 100644
index 64e2901e..00000000
--- a/ext/commonmarker/footnotes.h
+++ /dev/null
@@ -1,27 +0,0 @@
-#ifndef CMARK_FOOTNOTES_H
-#define CMARK_FOOTNOTES_H
-
-#include "map.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct cmark_footnote {
-  cmark_map_entry entry;
-  cmark_node *node;
-  unsigned int ix;
-};
-
-typedef struct cmark_footnote cmark_footnote;
-
-void cmark_footnote_create(cmark_map *map, cmark_node *node);
-cmark_map *cmark_footnote_map_new(cmark_mem *mem);
-
-void cmark_unlink_footnotes_map(cmark_map *map);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ext/commonmarker/houdini.h b/ext/commonmarker/houdini.h
deleted file mode 100644
index 7625b045..00000000
--- a/ext/commonmarker/houdini.h
+++ /dev/null
@@ -1,57 +0,0 @@
-#ifndef CMARK_HOUDINI_H
-#define CMARK_HOUDINI_H
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include 
-#include "config.h"
-#include "buffer.h"
-
-#ifdef HAVE___BUILTIN_EXPECT
-#define likely(x) __builtin_expect((x), 1)
-#define unlikely(x) __builtin_expect((x), 0)
-#else
-#define likely(x) (x)
-#define unlikely(x) (x)
-#endif
-
-#ifdef HOUDINI_USE_LOCALE
-#define _isxdigit(c) isxdigit(c)
-#define _isdigit(c) isdigit(c)
-#else
-/*
- * Helper _isdigit methods -- do not trust the current locale
- * */
-#define _isxdigit(c) (strchr("0123456789ABCDEFabcdef", (c)) != NULL)
-#define _isdigit(c) ((c) >= '0' && (c) <= '9')
-#endif
-
-#define HOUDINI_ESCAPED_SIZE(x) (((x)*12) / 10)
-#define HOUDINI_UNESCAPED_SIZE(x) (x)
-
-CMARK_GFM_EXPORT
-bufsize_t houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src,
-                                      bufsize_t size);
-CMARK_GFM_EXPORT
-int houdini_escape_html(cmark_strbuf *ob, const uint8_t *src,
-                               bufsize_t size);
-CMARK_GFM_EXPORT
-int houdini_escape_html0(cmark_strbuf *ob, const uint8_t *src,
-                                bufsize_t size, int secure);
-CMARK_GFM_EXPORT
-int houdini_unescape_html(cmark_strbuf *ob, const uint8_t *src,
-                                 bufsize_t size);
-CMARK_GFM_EXPORT
-void houdini_unescape_html_f(cmark_strbuf *ob, const uint8_t *src,
-                                    bufsize_t size);
-CMARK_GFM_EXPORT
-int houdini_escape_href(cmark_strbuf *ob, const uint8_t *src,
-                               bufsize_t size);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/ext/commonmarker/houdini_href_e.c b/ext/commonmarker/houdini_href_e.c
deleted file mode 100644
index 16938919..00000000
--- a/ext/commonmarker/houdini_href_e.c
+++ /dev/null
@@ -1,100 +0,0 @@
-#include 
-#include 
-#include 
-
-#include "houdini.h"
-
-/*
- * The following characters will not be escaped:
- *
- *		-_.+!*'(),%#@?=;:/,+&$~ alphanum
- *
- * Note that this character set is the addition of:
- *
- *	- The characters which are safe to be in an URL
- *	- The characters which are *not* safe to be in
- *	an URL because they are RESERVED characters.
- *
- * We assume (lazily) that any RESERVED char that
- * appears inside an URL is actually meant to
- * have its native function (i.e. as an URL
- * component/separator) and hence needs no escaping.
- *
- * There are two exceptions: the chacters & (amp)
- * and ' (single quote) do not appear in the table.
- * They are meant to appear in the URL as components,
- * yet they require special HTML-entity escaping
- * to generate valid HTML markup.
- *
- * All other characters will be escaped to %XX.
- *
- */
-static const char HREF_SAFE[] = {
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1,
-    0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
-    1, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-int houdini_escape_href(cmark_strbuf *ob, const uint8_t *src, bufsize_t size) {
-  static const uint8_t hex_chars[] = "0123456789ABCDEF";
-  bufsize_t i = 0, org;
-  uint8_t hex_str[3];
-
-  hex_str[0] = '%';
-
-  while (i < size) {
-    org = i;
-    while (i < size && HREF_SAFE[src[i]] != 0)
-      i++;
-
-    if (likely(i > org))
-      cmark_strbuf_put(ob, src + org, i - org);
-
-    /* escaping */
-    if (i >= size)
-      break;
-
-    switch (src[i]) {
-    /* amp appears all the time in URLs, but needs
-     * HTML-entity escaping to be inside an href */
-    case '&':
-      cmark_strbuf_puts(ob, "&");
-      break;
-
-    /* the single quote is a valid URL character
-     * according to the standard; it needs HTML
-     * entity escaping too */
-    case '\'':
-      cmark_strbuf_puts(ob, "'");
-      break;
-
-/* the space can be escaped to %20 or a plus
- * sign. we're going with the generic escape
- * for now. the plus thing is more commonly seen
- * when building GET strings */
-#if 0
-		case ' ':
-			cmark_strbuf_putc(ob, '+');
-			break;
-#endif
-
-    /* every other character goes with a %XX escaping */
-    default:
-      hex_str[1] = hex_chars[(src[i] >> 4) & 0xF];
-      hex_str[2] = hex_chars[src[i] & 0xF];
-      cmark_strbuf_put(ob, hex_str, 3);
-    }
-
-    i++;
-  }
-
-  return 1;
-}
diff --git a/ext/commonmarker/houdini_html_e.c b/ext/commonmarker/houdini_html_e.c
deleted file mode 100644
index da0b15c5..00000000
--- a/ext/commonmarker/houdini_html_e.c
+++ /dev/null
@@ -1,66 +0,0 @@
-#include 
-#include 
-#include 
-
-#include "houdini.h"
-
-/**
- * According to the OWASP rules:
- *
- * & --> &
- * < --> <
- * > --> >
- * " --> "
- * ' --> '     ' is not recommended
- * / --> /     forward slash is included as it helps end an HTML entity
- *
- */
-static const char HTML_ESCAPE_TABLE[] = {
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 0, 4,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-    0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-};
-
-static const char *HTML_ESCAPES[] = {"",      """, "&", "'",
-                                     "/", "<",   ">"};
-
-int houdini_escape_html0(cmark_strbuf *ob, const uint8_t *src, bufsize_t size,
-                         int secure) {
-  bufsize_t i = 0, org, esc = 0;
-
-  while (i < size) {
-    org = i;
-    while (i < size && (esc = HTML_ESCAPE_TABLE[src[i]]) == 0)
-      i++;
-
-    if (i > org)
-      cmark_strbuf_put(ob, src + org, i - org);
-
-    /* escaping */
-    if (unlikely(i >= size))
-      break;
-
-    /* The forward slash and single quote are only escaped in secure mode */
-    if ((src[i] == '/' || src[i] == '\'') && !secure) {
-      cmark_strbuf_putc(ob, src[i]);
-    } else {
-      cmark_strbuf_puts(ob, HTML_ESCAPES[esc]);
-    }
-
-    i++;
-  }
-
-  return 1;
-}
-
-int houdini_escape_html(cmark_strbuf *ob, const uint8_t *src, bufsize_t size) {
-  return houdini_escape_html0(ob, src, size, 1);
-}
diff --git a/ext/commonmarker/houdini_html_u.c b/ext/commonmarker/houdini_html_u.c
deleted file mode 100644
index 30d08aa4..00000000
--- a/ext/commonmarker/houdini_html_u.c
+++ /dev/null
@@ -1,149 +0,0 @@
-#include 
-#include 
-#include 
-
-#include "buffer.h"
-#include "houdini.h"
-#include "utf8.h"
-#include "entities.inc"
-
-/* Binary tree lookup code for entities added by JGM */
-
-static const unsigned char *S_lookup(int i, int low, int hi,
-                                     const unsigned char *s, int len) {
-  int j;
-  int cmp =
-      strncmp((const char *)s, (const char *)cmark_entities[i].entity, len);
-  if (cmp == 0 && cmark_entities[i].entity[len] == 0) {
-    return (const unsigned char *)cmark_entities[i].bytes;
-  } else if (cmp <= 0 && i > low) {
-    j = i - ((i - low) / 2);
-    if (j == i)
-      j -= 1;
-    return S_lookup(j, low, i - 1, s, len);
-  } else if (cmp > 0 && i < hi) {
-    j = i + ((hi - i) / 2);
-    if (j == i)
-      j += 1;
-    return S_lookup(j, i + 1, hi, s, len);
-  } else {
-    return NULL;
-  }
-}
-
-static const unsigned char *S_lookup_entity(const unsigned char *s, int len) {
-  return S_lookup(CMARK_NUM_ENTITIES / 2, 0, CMARK_NUM_ENTITIES - 1, s, len);
-}
-
-bufsize_t houdini_unescape_ent(cmark_strbuf *ob, const uint8_t *src,
-                               bufsize_t size) {
-  bufsize_t i = 0;
-
-  if (size >= 3 && src[0] == '#') {
-    int codepoint = 0;
-    int num_digits = 0;
-
-    if (_isdigit(src[1])) {
-      for (i = 1; i < size && _isdigit(src[i]); ++i) {
-        codepoint = (codepoint * 10) + (src[i] - '0');
-
-        if (codepoint >= 0x110000) {
-          // Keep counting digits but
-          // avoid integer overflow.
-          codepoint = 0x110000;
-        }
-      }
-
-      num_digits = i - 1;
-    }
-
-    else if (src[1] == 'x' || src[1] == 'X') {
-      for (i = 2; i < size && _isxdigit(src[i]); ++i) {
-        codepoint = (codepoint * 16) + ((src[i] | 32) % 39 - 9);
-
-        if (codepoint >= 0x110000) {
-          // Keep counting digits but
-          // avoid integer overflow.
-          codepoint = 0x110000;
-        }
-      }
-
-      num_digits = i - 2;
-    }
-
-    if (num_digits >= 1 && num_digits <= 8 && i < size && src[i] == ';') {
-      if (codepoint == 0 || (codepoint >= 0xD800 && codepoint < 0xE000) ||
-          codepoint >= 0x110000) {
-        codepoint = 0xFFFD;
-      }
-      cmark_utf8proc_encode_char(codepoint, ob);
-      return i + 1;
-    }
-  }
-
-  else {
-    if (size > CMARK_ENTITY_MAX_LENGTH)
-      size = CMARK_ENTITY_MAX_LENGTH;
-
-    for (i = CMARK_ENTITY_MIN_LENGTH; i < size; ++i) {
-      if (src[i] == ' ')
-        break;
-
-      if (src[i] == ';') {
-        const unsigned char *entity = S_lookup_entity(src, i);
-
-        if (entity != NULL) {
-          cmark_strbuf_puts(ob, (const char *)entity);
-          return i + 1;
-        }
-
-        break;
-      }
-    }
-  }
-
-  return 0;
-}
-
-int houdini_unescape_html(cmark_strbuf *ob, const uint8_t *src,
-                          bufsize_t size) {
-  bufsize_t i = 0, org, ent;
-
-  while (i < size) {
-    org = i;
-    while (i < size && src[i] != '&')
-      i++;
-
-    if (likely(i > org)) {
-      if (unlikely(org == 0)) {
-        if (i >= size)
-          return 0;
-
-        cmark_strbuf_grow(ob, HOUDINI_UNESCAPED_SIZE(size));
-      }
-
-      cmark_strbuf_put(ob, src + org, i - org);
-    }
-
-    /* escaping */
-    if (i >= size)
-      break;
-
-    i++;
-
-    ent = houdini_unescape_ent(ob, src + i, size - i);
-    i += ent;
-
-    /* not really an entity */
-    if (ent == 0)
-      cmark_strbuf_putc(ob, '&');
-  }
-
-  return 1;
-}
-
-void houdini_unescape_html_f(cmark_strbuf *ob, const uint8_t *src,
-                             bufsize_t size) {
-  if (!houdini_unescape_html(ob, src, size))
-    cmark_strbuf_put(ob, src, size);
-}
diff --git a/ext/commonmarker/html.c b/ext/commonmarker/html.c
deleted file mode 100644
index 12d3c3e9..00000000
--- a/ext/commonmarker/html.c
+++ /dev/null
@@ -1,486 +0,0 @@
-#include 
-#include 
-#include 
-#include 
-#include "cmark_ctype.h"
-#include "config.h"
-#include "cmark-gfm.h"
-#include "houdini.h"
-#include "scanners.h"
-#include "syntax_extension.h"
-#include "html.h"
-#include "render.h"
-
-// Functions to convert cmark_nodes to HTML strings.
-
-static void escape_html(cmark_strbuf *dest, const unsigned char *source,
-                        bufsize_t length) {
-  houdini_escape_html0(dest, source, length, 0);
-}
-
-static void filter_html_block(cmark_html_renderer *renderer, uint8_t *data, size_t len) {
-  cmark_strbuf *html = renderer->html;
-  cmark_llist *it;
-  cmark_syntax_extension *ext;
-  bool filtered;
-  uint8_t *match;
-
-  while (len) {
-    match = (uint8_t *) memchr(data, '<', len);
-    if (!match)
-      break;
-
-    if (match != data) {
-      cmark_strbuf_put(html, data, (bufsize_t)(match - data));
-      len -= (match - data);
-      data = match;
-    }
-
-    filtered = false;
-    for (it = renderer->filter_extensions; it; it = it->next) {
-      ext = ((cmark_syntax_extension *) it->data);
-      if (!ext->html_filter_func(ext, data, len)) {
-        filtered = true;
-        break;
-      }
-    }
-
-    if (!filtered) {
-      cmark_strbuf_putc(html, '<');
-    } else {
-      cmark_strbuf_puts(html, "<");
-    }
-
-    ++data;
-    --len;
-  }
-
-  if (len)
-    cmark_strbuf_put(html, data, (bufsize_t)len);
-}
-
-static bool S_put_footnote_backref(cmark_html_renderer *renderer, cmark_strbuf *html, cmark_node *node) {
-  if (renderer->written_footnote_ix >= renderer->footnote_ix)
-    return false;
-  renderer->written_footnote_ix = renderer->footnote_ix;
-
-  cmark_strbuf_puts(html, "as.literal.data, node->as.literal.len);
-  cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩");
-
-  if (node->footnote.def_count > 1)
-  {
-    for(int i = 2; i <= node->footnote.def_count; i++) {
-      char n[32];
-      snprintf(n, sizeof(n), "%d", i);
-
-      cmark_strbuf_puts(html, " as.literal.data, node->as.literal.len);
-      cmark_strbuf_puts(html, "-");
-      cmark_strbuf_puts(html, n);
-      cmark_strbuf_puts(html, "\" class=\"footnote-backref\" data-footnote-backref aria-label=\"Back to content\">↩");
-      cmark_strbuf_puts(html, n);
-      cmark_strbuf_puts(html, "");
-    }
-  }
-
-  return true;
-}
-
-static int S_render_node(cmark_html_renderer *renderer, cmark_node *node,
-                         cmark_event_type ev_type, int options) {
-  cmark_node *parent;
-  cmark_node *grandparent;
-  cmark_strbuf *html = renderer->html;
-  cmark_llist *it;
-  cmark_syntax_extension *ext;
-  char start_heading[] = "plain == node) { // back at original node
-    renderer->plain = NULL;
-  }
-
-  if (renderer->plain != NULL) {
-    switch (node->type) {
-    case CMARK_NODE_TEXT:
-    case CMARK_NODE_CODE:
-    case CMARK_NODE_HTML_INLINE:
-      escape_html(html, node->as.literal.data, node->as.literal.len);
-      break;
-
-    case CMARK_NODE_LINEBREAK:
-    case CMARK_NODE_SOFTBREAK:
-      cmark_strbuf_putc(html, ' ');
-      break;
-
-    default:
-      break;
-    }
-    return 1;
-  }
-
-  if (node->extension && node->extension->html_render_func) {
-    node->extension->html_render_func(node->extension, renderer, node, ev_type, options);
-    return 1;
-  }
-
-  switch (node->type) {
-  case CMARK_NODE_DOCUMENT:
-    break;
-
-  case CMARK_NODE_BLOCK_QUOTE:
-    if (entering) {
-      cmark_html_render_cr(html);
-      cmark_strbuf_puts(html, "\n");
-    } else {
-      cmark_html_render_cr(html);
-      cmark_strbuf_puts(html, "\n");
-    }
-    break;
-
-  case CMARK_NODE_LIST: {
-    cmark_list_type list_type = node->as.list.list_type;
-    int start = node->as.list.start;
-
-    if (entering) {
-      cmark_html_render_cr(html);
-      if (list_type == CMARK_BULLET_LIST) {
-        cmark_strbuf_puts(html, "\n");
-      } else if (start == 1) {
-        cmark_strbuf_puts(html, "\n");
-      } else {
-        snprintf(buffer, BUFFER_SIZE, "
    \n"); - } - } else { - cmark_strbuf_puts(html, - list_type == CMARK_BULLET_LIST ? "\n" : "
\n"); - } - break; - } - - case CMARK_NODE_ITEM: - if (entering) { - cmark_html_render_cr(html); - cmark_strbuf_puts(html, "'); - } else { - cmark_strbuf_puts(html, "\n"); - } - break; - - case CMARK_NODE_HEADING: - if (entering) { - cmark_html_render_cr(html); - start_heading[2] = (char)('0' + node->as.heading.level); - cmark_strbuf_puts(html, start_heading); - cmark_html_render_sourcepos(node, html, options); - cmark_strbuf_putc(html, '>'); - } else { - end_heading[3] = (char)('0' + node->as.heading.level); - cmark_strbuf_puts(html, end_heading); - cmark_strbuf_puts(html, ">\n"); - } - break; - - case CMARK_NODE_CODE_BLOCK: - cmark_html_render_cr(html); - - if (node->as.code.info.len == 0) { - cmark_strbuf_puts(html, ""); - } else { - bufsize_t first_tag = 0; - while (first_tag < node->as.code.info.len && - !cmark_isspace(node->as.code.info.data[first_tag])) { - first_tag += 1; - } - - if (options & CMARK_OPT_GITHUB_PRE_LANG) { - cmark_strbuf_puts(html, "as.code.info.data, first_tag); - if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) { - cmark_strbuf_puts(html, "\" data-meta=\""); - escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1); - } - cmark_strbuf_puts(html, "\">"); - } else { - cmark_strbuf_puts(html, "as.code.info.data, first_tag); - if (first_tag < node->as.code.info.len && (options & CMARK_OPT_FULL_INFO_STRING)) { - cmark_strbuf_puts(html, "\" data-meta=\""); - escape_html(html, node->as.code.info.data + first_tag + 1, node->as.code.info.len - first_tag - 1); - } - cmark_strbuf_puts(html, "\">"); - } - } - - escape_html(html, node->as.code.literal.data, node->as.code.literal.len); - cmark_strbuf_puts(html, "
\n"); - break; - - case CMARK_NODE_HTML_BLOCK: - cmark_html_render_cr(html); - if (!(options & CMARK_OPT_UNSAFE)) { - cmark_strbuf_puts(html, ""); - } else if (renderer->filter_extensions) { - filter_html_block(renderer, node->as.literal.data, node->as.literal.len); - } else { - cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len); - } - cmark_html_render_cr(html); - break; - - case CMARK_NODE_CUSTOM_BLOCK: - cmark_html_render_cr(html); - if (entering) { - cmark_strbuf_put(html, node->as.custom.on_enter.data, - node->as.custom.on_enter.len); - } else { - cmark_strbuf_put(html, node->as.custom.on_exit.data, - node->as.custom.on_exit.len); - } - cmark_html_render_cr(html); - break; - - case CMARK_NODE_THEMATIC_BREAK: - cmark_html_render_cr(html); - cmark_strbuf_puts(html, "\n"); - break; - - case CMARK_NODE_PARAGRAPH: - parent = cmark_node_parent(node); - grandparent = cmark_node_parent(parent); - if (grandparent != NULL && grandparent->type == CMARK_NODE_LIST) { - tight = grandparent->as.list.tight; - } else { - tight = false; - } - if (!tight) { - if (entering) { - cmark_html_render_cr(html); - cmark_strbuf_puts(html, "'); - } else { - if (parent->type == CMARK_NODE_FOOTNOTE_DEFINITION && node->next == NULL) { - cmark_strbuf_putc(html, ' '); - S_put_footnote_backref(renderer, html, parent); - } - cmark_strbuf_puts(html, "

\n"); - } - } - break; - - case CMARK_NODE_TEXT: - escape_html(html, node->as.literal.data, node->as.literal.len); - break; - - case CMARK_NODE_LINEBREAK: - cmark_strbuf_puts(html, "
\n"); - break; - - case CMARK_NODE_SOFTBREAK: - if (options & CMARK_OPT_HARDBREAKS) { - cmark_strbuf_puts(html, "
\n"); - } else if (options & CMARK_OPT_NOBREAKS) { - cmark_strbuf_putc(html, ' '); - } else { - cmark_strbuf_putc(html, '\n'); - } - break; - - case CMARK_NODE_CODE: - cmark_strbuf_puts(html, ""); - escape_html(html, node->as.literal.data, node->as.literal.len); - cmark_strbuf_puts(html, ""); - break; - - case CMARK_NODE_HTML_INLINE: - if (!(options & CMARK_OPT_UNSAFE)) { - cmark_strbuf_puts(html, ""); - } else { - filtered = false; - for (it = renderer->filter_extensions; it; it = it->next) { - ext = (cmark_syntax_extension *) it->data; - if (!ext->html_filter_func(ext, node->as.literal.data, node->as.literal.len)) { - filtered = true; - break; - } - } - if (!filtered) { - cmark_strbuf_put(html, node->as.literal.data, node->as.literal.len); - } else { - cmark_strbuf_puts(html, "<"); - cmark_strbuf_put(html, node->as.literal.data + 1, node->as.literal.len - 1); - } - } - break; - - case CMARK_NODE_CUSTOM_INLINE: - if (entering) { - cmark_strbuf_put(html, node->as.custom.on_enter.data, - node->as.custom.on_enter.len); - } else { - cmark_strbuf_put(html, node->as.custom.on_exit.data, - node->as.custom.on_exit.len); - } - break; - - case CMARK_NODE_STRONG: - if (entering) { - cmark_strbuf_puts(html, ""); - } else { - cmark_strbuf_puts(html, ""); - } - break; - - case CMARK_NODE_EMPH: - if (entering) { - cmark_strbuf_puts(html, ""); - } else { - cmark_strbuf_puts(html, ""); - } - break; - - case CMARK_NODE_LINK: - if (entering) { - cmark_strbuf_puts(html, "as.link.url, 0))) { - houdini_escape_href(html, node->as.link.url.data, - node->as.link.url.len); - } - if (node->as.link.title.len) { - cmark_strbuf_puts(html, "\" title=\""); - escape_html(html, node->as.link.title.data, node->as.link.title.len); - } - cmark_strbuf_puts(html, "\">"); - } else { - cmark_strbuf_puts(html, ""); - } - break; - - case CMARK_NODE_IMAGE: - if (entering) { - cmark_strbuf_puts(html, "as.link.url, 0))) { - houdini_escape_href(html, node->as.link.url.data, - node->as.link.url.len); - } - cmark_strbuf_puts(html, "\" alt=\""); - renderer->plain = node; - } else { - if (node->as.link.title.len) { - cmark_strbuf_puts(html, "\" title=\""); - escape_html(html, node->as.link.title.data, node->as.link.title.len); - } - - cmark_strbuf_puts(html, "\" />"); - } - break; - - case CMARK_NODE_FOOTNOTE_DEFINITION: - if (entering) { - if (renderer->footnote_ix == 0) { - cmark_strbuf_puts(html, "
\n
    \n"); - } - ++renderer->footnote_ix; - - cmark_strbuf_puts(html, "
  1. as.literal.data, node->as.literal.len); - cmark_strbuf_puts(html, "\">\n"); - } else { - if (S_put_footnote_backref(renderer, html, node)) { - cmark_strbuf_putc(html, '\n'); - } - cmark_strbuf_puts(html, "
  2. \n"); - } - break; - - case CMARK_NODE_FOOTNOTE_REFERENCE: - if (entering) { - cmark_strbuf_puts(html, "parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len); - cmark_strbuf_puts(html, "\" id=\"fnref-"); - houdini_escape_href(html, node->parent_footnote_def->as.literal.data, node->parent_footnote_def->as.literal.len); - - if (node->footnote.ref_ix > 1) { - char n[32]; - snprintf(n, sizeof(n), "%d", node->footnote.ref_ix); - cmark_strbuf_puts(html, "-"); - cmark_strbuf_puts(html, n); - } - - cmark_strbuf_puts(html, "\" data-footnote-ref>"); - houdini_escape_href(html, node->as.literal.data, node->as.literal.len); - cmark_strbuf_puts(html, ""); - } - break; - - default: - assert(false); - break; - } - - return 1; -} - -char *cmark_render_html(cmark_node *root, int options, cmark_llist *extensions) { - return cmark_render_html_with_mem(root, options, extensions, cmark_node_mem(root)); -} - -char *cmark_render_html_with_mem(cmark_node *root, int options, cmark_llist *extensions, cmark_mem *mem) { - char *result; - cmark_strbuf html = CMARK_BUF_INIT(mem); - cmark_event_type ev_type; - cmark_node *cur; - cmark_html_renderer renderer = {&html, NULL, NULL, 0, 0, NULL}; - cmark_iter *iter = cmark_iter_new(root); - - for (; extensions; extensions = extensions->next) - if (((cmark_syntax_extension *) extensions->data)->html_filter_func) - renderer.filter_extensions = cmark_llist_append( - mem, - renderer.filter_extensions, - (cmark_syntax_extension *) extensions->data); - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - S_render_node(&renderer, cur, ev_type, options); - } - - if (renderer.footnote_ix) { - cmark_strbuf_puts(&html, "
\n
\n"); - } - - result = (char *)cmark_strbuf_detach(&html); - - cmark_llist_free(mem, renderer.filter_extensions); - - cmark_iter_free(iter); - return result; -} diff --git a/ext/commonmarker/html.h b/ext/commonmarker/html.h deleted file mode 100644 index aeba7bcd..00000000 --- a/ext/commonmarker/html.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef CMARK_HTML_H -#define CMARK_HTML_H - -#include "buffer.h" -#include "node.h" - -CMARK_INLINE -static void cmark_html_render_cr(cmark_strbuf *html) { - if (html->size && html->ptr[html->size - 1] != '\n') - cmark_strbuf_putc(html, '\n'); -} - -#define BUFFER_SIZE 100 - -CMARK_INLINE -static void cmark_html_render_sourcepos(cmark_node *node, cmark_strbuf *html, int options) { - char buffer[BUFFER_SIZE]; - if (CMARK_OPT_SOURCEPOS & options) { - snprintf(buffer, BUFFER_SIZE, " data-sourcepos=\"%d:%d-%d:%d\"", - cmark_node_get_start_line(node), cmark_node_get_start_column(node), - cmark_node_get_end_line(node), cmark_node_get_end_column(node)); - cmark_strbuf_puts(html, buffer); - } -} - - -#endif diff --git a/ext/commonmarker/inlines.c b/ext/commonmarker/inlines.c deleted file mode 100644 index 4a118a63..00000000 --- a/ext/commonmarker/inlines.c +++ /dev/null @@ -1,1691 +0,0 @@ -#include -#include -#include - -#include "cmark_ctype.h" -#include "config.h" -#include "node.h" -#include "parser.h" -#include "references.h" -#include "cmark-gfm.h" -#include "houdini.h" -#include "utf8.h" -#include "scanners.h" -#include "inlines.h" -#include "syntax_extension.h" - -static const char *EMDASH = "\xE2\x80\x94"; -static const char *ENDASH = "\xE2\x80\x93"; -static const char *ELLIPSES = "\xE2\x80\xA6"; -static const char *LEFTDOUBLEQUOTE = "\xE2\x80\x9C"; -static const char *RIGHTDOUBLEQUOTE = "\xE2\x80\x9D"; -static const char *LEFTSINGLEQUOTE = "\xE2\x80\x98"; -static const char *RIGHTSINGLEQUOTE = "\xE2\x80\x99"; - -// Macros for creating various kinds of simple. -#define make_str(subj, sc, ec, s) make_literal(subj, CMARK_NODE_TEXT, sc, ec, s) -#define make_code(subj, sc, ec, s) make_literal(subj, CMARK_NODE_CODE, sc, ec, s) -#define make_raw_html(subj, sc, ec, s) make_literal(subj, CMARK_NODE_HTML_INLINE, sc, ec, s) -#define make_linebreak(mem) make_simple(mem, CMARK_NODE_LINEBREAK) -#define make_softbreak(mem) make_simple(mem, CMARK_NODE_SOFTBREAK) -#define make_emph(mem) make_simple(mem, CMARK_NODE_EMPH) -#define make_strong(mem) make_simple(mem, CMARK_NODE_STRONG) - -#define MAXBACKTICKS 80 - -typedef struct bracket { - struct bracket *previous; - struct delimiter *previous_delimiter; - cmark_node *inl_text; - bufsize_t position; - bool image; - bool active; - bool bracket_after; -} bracket; - -typedef struct subject{ - cmark_mem *mem; - cmark_chunk input; - int line; - bufsize_t pos; - int block_offset; - int column_offset; - cmark_map *refmap; - delimiter *last_delim; - bracket *last_bracket; - bufsize_t backticks[MAXBACKTICKS + 1]; - bool scanned_for_backticks; -} subject; - -// Extensions may populate this. -static int8_t SKIP_CHARS[256]; - -static CMARK_INLINE bool S_is_line_end_char(char c) { - return (c == '\n' || c == '\r'); -} - -static delimiter *S_insert_emph(subject *subj, delimiter *opener, - delimiter *closer); - -static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent, int options); - -static void subject_from_buf(cmark_mem *mem, int line_number, int block_offset, subject *e, - cmark_chunk *buffer, cmark_map *refmap); -static bufsize_t subject_find_special_char(subject *subj, int options); - -// Create an inline with a literal string value. -static CMARK_INLINE cmark_node *make_literal(subject *subj, cmark_node_type t, - int start_column, int end_column, - cmark_chunk s) { - cmark_node *e = (cmark_node *)subj->mem->calloc(1, sizeof(*e)); - cmark_strbuf_init(subj->mem, &e->content, 0); - e->type = (uint16_t)t; - e->as.literal = s; - e->start_line = e->end_line = subj->line; - // columns are 1 based. - e->start_column = start_column + 1 + subj->column_offset + subj->block_offset; - e->end_column = end_column + 1 + subj->column_offset + subj->block_offset; - return e; -} - -// Create an inline with no value. -static CMARK_INLINE cmark_node *make_simple(cmark_mem *mem, cmark_node_type t) { - cmark_node *e = (cmark_node *)mem->calloc(1, sizeof(*e)); - cmark_strbuf_init(mem, &e->content, 0); - e->type = (uint16_t)t; - return e; -} - -// Like make_str, but parses entities. -static cmark_node *make_str_with_entities(subject *subj, - int start_column, int end_column, - cmark_chunk *content) { - cmark_strbuf unescaped = CMARK_BUF_INIT(subj->mem); - - if (houdini_unescape_html(&unescaped, content->data, content->len)) { - return make_str(subj, start_column, end_column, cmark_chunk_buf_detach(&unescaped)); - } else { - return make_str(subj, start_column, end_column, *content); - } -} - -// Duplicate a chunk by creating a copy of the buffer not by reusing the -// buffer like cmark_chunk_dup does. -static cmark_chunk chunk_clone(cmark_mem *mem, cmark_chunk *src) { - cmark_chunk c; - bufsize_t len = src->len; - - c.len = len; - c.data = (unsigned char *)mem->calloc(len + 1, 1); - c.alloc = 1; - if (len) - memcpy(c.data, src->data, len); - c.data[len] = '\0'; - - return c; -} - -static cmark_chunk cmark_clean_autolink(cmark_mem *mem, cmark_chunk *url, - int is_email) { - cmark_strbuf buf = CMARK_BUF_INIT(mem); - - cmark_chunk_trim(url); - - if (url->len == 0) { - cmark_chunk result = CMARK_CHUNK_EMPTY; - return result; - } - - if (is_email) - cmark_strbuf_puts(&buf, "mailto:"); - - houdini_unescape_html_f(&buf, url->data, url->len); - return cmark_chunk_buf_detach(&buf); -} - -static CMARK_INLINE cmark_node *make_autolink(subject *subj, - int start_column, int end_column, - cmark_chunk url, int is_email) { - cmark_node *link = make_simple(subj->mem, CMARK_NODE_LINK); - link->as.link.url = cmark_clean_autolink(subj->mem, &url, is_email); - link->as.link.title = cmark_chunk_literal(""); - link->start_line = link->end_line = subj->line; - link->start_column = start_column + 1; - link->end_column = end_column + 1; - cmark_node_append_child(link, make_str_with_entities(subj, start_column + 1, end_column - 1, &url)); - return link; -} - -static void subject_from_buf(cmark_mem *mem, int line_number, int block_offset, subject *e, - cmark_chunk *chunk, cmark_map *refmap) { - int i; - e->mem = mem; - e->input = *chunk; - e->line = line_number; - e->pos = 0; - e->block_offset = block_offset; - e->column_offset = 0; - e->refmap = refmap; - e->last_delim = NULL; - e->last_bracket = NULL; - for (i = 0; i <= MAXBACKTICKS; i++) { - e->backticks[i] = 0; - } - e->scanned_for_backticks = false; -} - -static CMARK_INLINE int isbacktick(int c) { return (c == '`'); } - -static CMARK_INLINE unsigned char peek_char_n(subject *subj, bufsize_t n) { - // NULL bytes should have been stripped out by now. If they're - // present, it's a programming error: - assert(!(subj->pos + n < subj->input.len && subj->input.data[subj->pos + n] == 0)); - return (subj->pos + n < subj->input.len) ? subj->input.data[subj->pos + n] : 0; -} - -static CMARK_INLINE unsigned char peek_char(subject *subj) { - return peek_char_n(subj, 0); -} - -static CMARK_INLINE unsigned char peek_at(subject *subj, bufsize_t pos) { - return subj->input.data[pos]; -} - -// Return true if there are more characters in the subject. -static CMARK_INLINE int is_eof(subject *subj) { - return (subj->pos >= subj->input.len); -} - -// Advance the subject. Doesn't check for eof. -#define advance(subj) (subj)->pos += 1 - -static CMARK_INLINE bool skip_spaces(subject *subj) { - bool skipped = false; - while (peek_char(subj) == ' ' || peek_char(subj) == '\t') { - advance(subj); - skipped = true; - } - return skipped; -} - -static CMARK_INLINE bool skip_line_end(subject *subj) { - bool seen_line_end_char = false; - if (peek_char(subj) == '\r') { - advance(subj); - seen_line_end_char = true; - } - if (peek_char(subj) == '\n') { - advance(subj); - seen_line_end_char = true; - } - return seen_line_end_char || is_eof(subj); -} - -// Take characters while a predicate holds, and return a string. -static CMARK_INLINE cmark_chunk take_while(subject *subj, int (*f)(int)) { - unsigned char c; - bufsize_t startpos = subj->pos; - bufsize_t len = 0; - - while ((c = peek_char(subj)) && (*f)(c)) { - advance(subj); - len++; - } - - return cmark_chunk_dup(&subj->input, startpos, len); -} - -// Return the number of newlines in a given span of text in a subject. If -// the number is greater than zero, also return the number of characters -// between the last newline and the end of the span in `since_newline`. -static int count_newlines(subject *subj, bufsize_t from, bufsize_t len, int *since_newline) { - int nls = 0; - int since_nl = 0; - - while (len--) { - if (subj->input.data[from++] == '\n') { - ++nls; - since_nl = 0; - } else { - ++since_nl; - } - } - - if (!nls) - return 0; - - *since_newline = since_nl; - return nls; -} - -// Adjust `node`'s `end_line`, `end_column`, and `subj`'s `line` and -// `column_offset` according to the number of newlines in a just-matched span -// of text in `subj`. -static void adjust_subj_node_newlines(subject *subj, cmark_node *node, int matchlen, int extra, int options) { - if (!(options & CMARK_OPT_SOURCEPOS)) { - return; - } - - int since_newline; - int newlines = count_newlines(subj, subj->pos - matchlen - extra, matchlen, &since_newline); - if (newlines) { - subj->line += newlines; - node->end_line += newlines; - node->end_column = since_newline; - subj->column_offset = -subj->pos + since_newline + extra; - } -} - -// Try to process a backtick code span that began with a -// span of ticks of length openticklength length (already -// parsed). Return 0 if you don't find matching closing -// backticks, otherwise return the position in the subject -// after the closing backticks. -static bufsize_t scan_to_closing_backticks(subject *subj, - bufsize_t openticklength) { - - bool found = false; - if (openticklength > MAXBACKTICKS) { - // we limit backtick string length because of the array subj->backticks: - return 0; - } - if (subj->scanned_for_backticks && - subj->backticks[openticklength] <= subj->pos) { - // return if we already know there's no closer - return 0; - } - while (!found) { - // read non backticks - unsigned char c; - while ((c = peek_char(subj)) && c != '`') { - advance(subj); - } - if (is_eof(subj)) { - break; - } - bufsize_t numticks = 0; - while (peek_char(subj) == '`') { - advance(subj); - numticks++; - } - // store position of ender - if (numticks <= MAXBACKTICKS) { - subj->backticks[numticks] = subj->pos - numticks; - } - if (numticks == openticklength) { - return (subj->pos); - } - } - // got through whole input without finding closer - subj->scanned_for_backticks = true; - return 0; -} - -// Destructively modify string, converting newlines to -// spaces, then removing a single leading + trailing space, -// unless the code span consists entirely of space characters. -static void S_normalize_code(cmark_strbuf *s) { - bufsize_t r, w; - bool contains_nonspace = false; - - for (r = 0, w = 0; r < s->size; ++r) { - switch (s->ptr[r]) { - case '\r': - if (s->ptr[r + 1] != '\n') { - s->ptr[w++] = ' '; - } - break; - case '\n': - s->ptr[w++] = ' '; - break; - default: - s->ptr[w++] = s->ptr[r]; - } - if (s->ptr[r] != ' ') { - contains_nonspace = true; - } - } - - // begins and ends with space? - if (contains_nonspace && - s->ptr[0] == ' ' && s->ptr[w - 1] == ' ') { - cmark_strbuf_drop(s, 1); - cmark_strbuf_truncate(s, w - 2); - } else { - cmark_strbuf_truncate(s, w); - } - -} - - -// Parse backtick code section or raw backticks, return an inline. -// Assumes that the subject has a backtick at the current position. -static cmark_node *handle_backticks(subject *subj, int options) { - cmark_chunk openticks = take_while(subj, isbacktick); - bufsize_t startpos = subj->pos; - bufsize_t endpos = scan_to_closing_backticks(subj, openticks.len); - - if (endpos == 0) { // not found - subj->pos = startpos; // rewind - return make_str(subj, subj->pos, subj->pos, openticks); - } else { - cmark_strbuf buf = CMARK_BUF_INIT(subj->mem); - - cmark_strbuf_set(&buf, subj->input.data + startpos, - endpos - startpos - openticks.len); - S_normalize_code(&buf); - - cmark_node *node = make_code(subj, startpos, endpos - openticks.len - 1, cmark_chunk_buf_detach(&buf)); - adjust_subj_node_newlines(subj, node, endpos - startpos, openticks.len, options); - return node; - } -} - - -// Scan ***, **, or * and return number scanned, or 0. -// Advances position. -static int scan_delims(subject *subj, unsigned char c, bool *can_open, - bool *can_close) { - int numdelims = 0; - bufsize_t before_char_pos, after_char_pos; - int32_t after_char = 0; - int32_t before_char = 0; - int len; - bool left_flanking, right_flanking; - - if (subj->pos == 0) { - before_char = 10; - } else { - before_char_pos = subj->pos - 1; - // walk back to the beginning of the UTF_8 sequence: - while ((peek_at(subj, before_char_pos) >> 6 == 2 || SKIP_CHARS[peek_at(subj, before_char_pos)]) && before_char_pos > 0) { - before_char_pos -= 1; - } - len = cmark_utf8proc_iterate(subj->input.data + before_char_pos, - subj->pos - before_char_pos, &before_char); - if (len == -1 || (before_char < 256 && SKIP_CHARS[(unsigned char) before_char])) { - before_char = 10; - } - } - - if (c == '\'' || c == '"') { - numdelims++; - advance(subj); // limit to 1 delim for quotes - } else { - while (peek_char(subj) == c) { - numdelims++; - advance(subj); - } - } - - if (subj->pos == subj->input.len) { - after_char = 10; - } else { - after_char_pos = subj->pos; - while (SKIP_CHARS[peek_at(subj, after_char_pos)] && after_char_pos < subj->input.len) { - after_char_pos += 1; - } - len = cmark_utf8proc_iterate(subj->input.data + after_char_pos, - subj->input.len - after_char_pos, &after_char); - if (len == -1 || (after_char < 256 && SKIP_CHARS[(unsigned char) after_char])) { - after_char = 10; - } - } - - left_flanking = numdelims > 0 && !cmark_utf8proc_is_space(after_char) && - (!cmark_utf8proc_is_punctuation(after_char) || - cmark_utf8proc_is_space(before_char) || - cmark_utf8proc_is_punctuation(before_char)); - right_flanking = numdelims > 0 && !cmark_utf8proc_is_space(before_char) && - (!cmark_utf8proc_is_punctuation(before_char) || - cmark_utf8proc_is_space(after_char) || - cmark_utf8proc_is_punctuation(after_char)); - if (c == '_') { - *can_open = left_flanking && - (!right_flanking || cmark_utf8proc_is_punctuation(before_char)); - *can_close = right_flanking && - (!left_flanking || cmark_utf8proc_is_punctuation(after_char)); - } else if (c == '\'' || c == '"') { - *can_open = left_flanking && !right_flanking && - before_char != ']' && before_char != ')'; - *can_close = right_flanking; - } else { - *can_open = left_flanking; - *can_close = right_flanking; - } - return numdelims; -} - -/* -static void print_delimiters(subject *subj) -{ - delimiter *delim; - delim = subj->last_delim; - while (delim != NULL) { - printf("Item at stack pos %p: %d %d %d next(%p) prev(%p)\n", - (void*)delim, delim->delim_char, - delim->can_open, delim->can_close, - (void*)delim->next, (void*)delim->previous); - delim = delim->previous; - } -} -*/ - -static void remove_delimiter(subject *subj, delimiter *delim) { - if (delim == NULL) - return; - if (delim->next == NULL) { - // end of list: - assert(delim == subj->last_delim); - subj->last_delim = delim->previous; - } else { - delim->next->previous = delim->previous; - } - if (delim->previous != NULL) { - delim->previous->next = delim->next; - } - subj->mem->free(delim); -} - -static void pop_bracket(subject *subj) { - bracket *b; - if (subj->last_bracket == NULL) - return; - b = subj->last_bracket; - subj->last_bracket = subj->last_bracket->previous; - subj->mem->free(b); -} - -static void push_delimiter(subject *subj, unsigned char c, bool can_open, - bool can_close, cmark_node *inl_text) { - delimiter *delim = (delimiter *)subj->mem->calloc(1, sizeof(delimiter)); - delim->delim_char = c; - delim->can_open = can_open; - delim->can_close = can_close; - delim->inl_text = inl_text; - delim->length = inl_text->as.literal.len; - delim->previous = subj->last_delim; - delim->next = NULL; - if (delim->previous != NULL) { - delim->previous->next = delim; - } - subj->last_delim = delim; -} - -static void push_bracket(subject *subj, bool image, cmark_node *inl_text) { - bracket *b = (bracket *)subj->mem->calloc(1, sizeof(bracket)); - if (subj->last_bracket != NULL) { - subj->last_bracket->bracket_after = true; - } - b->image = image; - b->active = true; - b->inl_text = inl_text; - b->previous = subj->last_bracket; - b->previous_delimiter = subj->last_delim; - b->position = subj->pos; - b->bracket_after = false; - subj->last_bracket = b; -} - -// Assumes the subject has a c at the current position. -static cmark_node *handle_delim(subject *subj, unsigned char c, bool smart) { - bufsize_t numdelims; - cmark_node *inl_text; - bool can_open, can_close; - cmark_chunk contents; - - numdelims = scan_delims(subj, c, &can_open, &can_close); - - if (c == '\'' && smart) { - contents = cmark_chunk_literal(RIGHTSINGLEQUOTE); - } else if (c == '"' && smart) { - contents = - cmark_chunk_literal(can_close ? RIGHTDOUBLEQUOTE : LEFTDOUBLEQUOTE); - } else { - contents = cmark_chunk_dup(&subj->input, subj->pos - numdelims, numdelims); - } - - inl_text = make_str(subj, subj->pos - numdelims, subj->pos - 1, contents); - - if ((can_open || can_close) && (!(c == '\'' || c == '"') || smart)) { - push_delimiter(subj, c, can_open, can_close, inl_text); - } - - return inl_text; -} - -// Assumes we have a hyphen at the current position. -static cmark_node *handle_hyphen(subject *subj, bool smart) { - int startpos = subj->pos; - - advance(subj); - - if (!smart || peek_char(subj) != '-') { - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("-")); - } - - while (smart && peek_char(subj) == '-') { - advance(subj); - } - - int numhyphens = subj->pos - startpos; - int en_count = 0; - int em_count = 0; - int i; - cmark_strbuf buf = CMARK_BUF_INIT(subj->mem); - - if (numhyphens % 3 == 0) { // if divisible by 3, use all em dashes - em_count = numhyphens / 3; - } else if (numhyphens % 2 == 0) { // if divisible by 2, use all en dashes - en_count = numhyphens / 2; - } else if (numhyphens % 3 == 2) { // use one en dash at end - en_count = 1; - em_count = (numhyphens - 2) / 3; - } else { // use two en dashes at the end - en_count = 2; - em_count = (numhyphens - 4) / 3; - } - - for (i = em_count; i > 0; i--) { - cmark_strbuf_puts(&buf, EMDASH); - } - - for (i = en_count; i > 0; i--) { - cmark_strbuf_puts(&buf, ENDASH); - } - - return make_str(subj, startpos, subj->pos - 1, cmark_chunk_buf_detach(&buf)); -} - -// Assumes we have a period at the current position. -static cmark_node *handle_period(subject *subj, bool smart) { - advance(subj); - if (smart && peek_char(subj) == '.') { - advance(subj); - if (peek_char(subj) == '.') { - advance(subj); - return make_str(subj, subj->pos - 3, subj->pos - 1, cmark_chunk_literal(ELLIPSES)); - } else { - return make_str(subj, subj->pos - 2, subj->pos - 1, cmark_chunk_literal("..")); - } - } else { - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal(".")); - } -} - -static cmark_syntax_extension *get_extension_for_special_char(cmark_parser *parser, unsigned char c) { - cmark_llist *tmp_ext; - - for (tmp_ext = parser->inline_syntax_extensions; tmp_ext; tmp_ext=tmp_ext->next) { - cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp_ext->data; - cmark_llist *tmp_char; - for (tmp_char = ext->special_inline_chars; tmp_char; tmp_char=tmp_char->next) { - unsigned char tmp_c = (unsigned char)(size_t)tmp_char->data; - - if (tmp_c == c) { - return ext; - } - } - } - - return NULL; -} - -static void process_emphasis(cmark_parser *parser, subject *subj, delimiter *stack_bottom) { - delimiter *closer = subj->last_delim; - delimiter *opener; - delimiter *old_closer; - bool opener_found; - delimiter *openers_bottom[3][128]; - int i; - - // initialize openers_bottom: - memset(&openers_bottom, 0, sizeof(openers_bottom)); - for (i=0; i < 3; i++) { - openers_bottom[i]['*'] = stack_bottom; - openers_bottom[i]['_'] = stack_bottom; - openers_bottom[i]['\''] = stack_bottom; - openers_bottom[i]['"'] = stack_bottom; - } - - // move back to first relevant delim. - while (closer != NULL && closer->previous != stack_bottom) { - closer = closer->previous; - } - - // now move forward, looking for closers, and handling each - while (closer != NULL) { - cmark_syntax_extension *extension = get_extension_for_special_char(parser, closer->delim_char); - if (closer->can_close) { - // Now look backwards for first matching opener: - opener = closer->previous; - opener_found = false; - while (opener != NULL && opener != stack_bottom && - opener != openers_bottom[closer->length % 3][closer->delim_char]) { - if (opener->can_open && opener->delim_char == closer->delim_char) { - // interior closer of size 2 can't match opener of size 1 - // or of size 1 can't match 2 - if (!(closer->can_open || opener->can_close) || - closer->length % 3 == 0 || - (opener->length + closer->length) % 3 != 0) { - opener_found = true; - break; - } - } - opener = opener->previous; - } - old_closer = closer; - - if (extension) { - if (opener_found) - closer = extension->insert_inline_from_delim(extension, parser, subj, opener, closer); - else - closer = closer->next; - } else if (closer->delim_char == '*' || closer->delim_char == '_') { - if (opener_found) { - closer = S_insert_emph(subj, opener, closer); - } else { - closer = closer->next; - } - } else if (closer->delim_char == '\'') { - cmark_chunk_free(subj->mem, &closer->inl_text->as.literal); - closer->inl_text->as.literal = cmark_chunk_literal(RIGHTSINGLEQUOTE); - if (opener_found) { - cmark_chunk_free(subj->mem, &opener->inl_text->as.literal); - opener->inl_text->as.literal = cmark_chunk_literal(LEFTSINGLEQUOTE); - } - closer = closer->next; - } else if (closer->delim_char == '"') { - cmark_chunk_free(subj->mem, &closer->inl_text->as.literal); - closer->inl_text->as.literal = cmark_chunk_literal(RIGHTDOUBLEQUOTE); - if (opener_found) { - cmark_chunk_free(subj->mem, &opener->inl_text->as.literal); - opener->inl_text->as.literal = cmark_chunk_literal(LEFTDOUBLEQUOTE); - } - closer = closer->next; - } - if (!opener_found) { - // set lower bound for future searches for openers - openers_bottom[old_closer->length % 3][old_closer->delim_char] = - old_closer->previous; - if (!old_closer->can_open) { - // we can remove a closer that can't be an - // opener, once we've seen there's no - // matching opener: - remove_delimiter(subj, old_closer); - } - } - } else { - closer = closer->next; - } - } - // free all delimiters in list until stack_bottom: - while (subj->last_delim != NULL && subj->last_delim != stack_bottom) { - remove_delimiter(subj, subj->last_delim); - } -} - -static delimiter *S_insert_emph(subject *subj, delimiter *opener, - delimiter *closer) { - delimiter *delim, *tmp_delim; - bufsize_t use_delims; - cmark_node *opener_inl = opener->inl_text; - cmark_node *closer_inl = closer->inl_text; - bufsize_t opener_num_chars = opener_inl->as.literal.len; - bufsize_t closer_num_chars = closer_inl->as.literal.len; - cmark_node *tmp, *tmpnext, *emph; - - // calculate the actual number of characters used from this closer - use_delims = (closer_num_chars >= 2 && opener_num_chars >= 2) ? 2 : 1; - - // remove used characters from associated inlines. - opener_num_chars -= use_delims; - closer_num_chars -= use_delims; - opener_inl->as.literal.len = opener_num_chars; - closer_inl->as.literal.len = closer_num_chars; - - // free delimiters between opener and closer - delim = closer->previous; - while (delim != NULL && delim != opener) { - tmp_delim = delim->previous; - remove_delimiter(subj, delim); - delim = tmp_delim; - } - - // create new emph or strong, and splice it in to our inlines - // between the opener and closer - emph = use_delims == 1 ? make_emph(subj->mem) : make_strong(subj->mem); - - tmp = opener_inl->next; - while (tmp && tmp != closer_inl) { - tmpnext = tmp->next; - cmark_node_append_child(emph, tmp); - tmp = tmpnext; - } - cmark_node_insert_after(opener_inl, emph); - - emph->start_line = opener_inl->start_line; - emph->end_line = closer_inl->end_line; - emph->start_column = opener_inl->start_column; - emph->end_column = closer_inl->end_column; - - // if opener has 0 characters, remove it and its associated inline - if (opener_num_chars == 0) { - cmark_node_free(opener_inl); - remove_delimiter(subj, opener); - } - - // if closer has 0 characters, remove it and its associated inline - if (closer_num_chars == 0) { - // remove empty closer inline - cmark_node_free(closer_inl); - // remove closer from list - tmp_delim = closer->next; - remove_delimiter(subj, closer); - closer = tmp_delim; - } - - return closer; -} - -// Parse backslash-escape or just a backslash, returning an inline. -static cmark_node *handle_backslash(cmark_parser *parser, subject *subj) { - advance(subj); - unsigned char nextchar = peek_char(subj); - if ((parser->backslash_ispunct ? parser->backslash_ispunct : cmark_ispunct)(nextchar)) { - // only ascii symbols and newline can be escaped - advance(subj); - return make_str(subj, subj->pos - 2, subj->pos - 1, cmark_chunk_dup(&subj->input, subj->pos - 1, 1)); - } else if (!is_eof(subj) && skip_line_end(subj)) { - return make_linebreak(subj->mem); - } else { - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("\\")); - } -} - -// Parse an entity or a regular "&" string. -// Assumes the subject has an '&' character at the current position. -static cmark_node *handle_entity(subject *subj) { - cmark_strbuf ent = CMARK_BUF_INIT(subj->mem); - bufsize_t len; - - advance(subj); - - len = houdini_unescape_ent(&ent, subj->input.data + subj->pos, - subj->input.len - subj->pos); - - if (len == 0) - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("&")); - - subj->pos += len; - return make_str(subj, subj->pos - 1 - len, subj->pos - 1, cmark_chunk_buf_detach(&ent)); -} - -// Clean a URL: remove surrounding whitespace, and remove \ that escape -// punctuation. -cmark_chunk cmark_clean_url(cmark_mem *mem, cmark_chunk *url) { - cmark_strbuf buf = CMARK_BUF_INIT(mem); - - cmark_chunk_trim(url); - - if (url->len == 0) { - cmark_chunk result = CMARK_CHUNK_EMPTY; - return result; - } - - houdini_unescape_html_f(&buf, url->data, url->len); - - cmark_strbuf_unescape(&buf); - return cmark_chunk_buf_detach(&buf); -} - -cmark_chunk cmark_clean_title(cmark_mem *mem, cmark_chunk *title) { - cmark_strbuf buf = CMARK_BUF_INIT(mem); - unsigned char first, last; - - if (title->len == 0) { - cmark_chunk result = CMARK_CHUNK_EMPTY; - return result; - } - - first = title->data[0]; - last = title->data[title->len - 1]; - - // remove surrounding quotes if any: - if ((first == '\'' && last == '\'') || (first == '(' && last == ')') || - (first == '"' && last == '"')) { - houdini_unescape_html_f(&buf, title->data + 1, title->len - 2); - } else { - houdini_unescape_html_f(&buf, title->data, title->len); - } - - cmark_strbuf_unescape(&buf); - return cmark_chunk_buf_detach(&buf); -} - -// Parse an autolink or HTML tag. -// Assumes the subject has a '<' character at the current position. -static cmark_node *handle_pointy_brace(subject *subj, int options) { - bufsize_t matchlen = 0; - cmark_chunk contents; - - advance(subj); // advance past first < - - // first try to match a URL autolink - matchlen = scan_autolink_uri(&subj->input, subj->pos); - if (matchlen > 0) { - contents = cmark_chunk_dup(&subj->input, subj->pos, matchlen - 1); - subj->pos += matchlen; - - return make_autolink(subj, subj->pos - 1 - matchlen, subj->pos - 1, contents, 0); - } - - // next try to match an email autolink - matchlen = scan_autolink_email(&subj->input, subj->pos); - if (matchlen > 0) { - contents = cmark_chunk_dup(&subj->input, subj->pos, matchlen - 1); - subj->pos += matchlen; - - return make_autolink(subj, subj->pos - 1 - matchlen, subj->pos - 1, contents, 1); - } - - // finally, try to match an html tag - matchlen = scan_html_tag(&subj->input, subj->pos); - if (matchlen > 0) { - contents = cmark_chunk_dup(&subj->input, subj->pos - 1, matchlen + 1); - subj->pos += matchlen; - cmark_node *node = make_raw_html(subj, subj->pos - matchlen - 1, subj->pos - 1, contents); - adjust_subj_node_newlines(subj, node, matchlen, 1, options); - return node; - } - - if (options & CMARK_OPT_LIBERAL_HTML_TAG) { - matchlen = scan_liberal_html_tag(&subj->input, subj->pos); - if (matchlen > 0) { - contents = cmark_chunk_dup(&subj->input, subj->pos - 1, matchlen + 1); - subj->pos += matchlen; - cmark_node *node = make_raw_html(subj, subj->pos - matchlen - 1, subj->pos - 1, contents); - adjust_subj_node_newlines(subj, node, matchlen, 1, options); - return node; - } - } - - // if nothing matches, just return the opening <: - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("<")); -} - -// Parse a link label. Returns 1 if successful. -// Note: unescaped brackets are not allowed in labels. -// The label begins with `[` and ends with the first `]` character -// encountered. Backticks in labels do not start code spans. -static int link_label(subject *subj, cmark_chunk *raw_label) { - bufsize_t startpos = subj->pos; - int length = 0; - unsigned char c; - - // advance past [ - if (peek_char(subj) == '[') { - advance(subj); - } else { - return 0; - } - - while ((c = peek_char(subj)) && c != '[' && c != ']') { - if (c == '\\') { - advance(subj); - length++; - if (cmark_ispunct(peek_char(subj))) { - advance(subj); - length++; - } - } else { - advance(subj); - length++; - } - if (length > MAX_LINK_LABEL_LENGTH) { - goto noMatch; - } - } - - if (c == ']') { // match found - *raw_label = - cmark_chunk_dup(&subj->input, startpos + 1, subj->pos - (startpos + 1)); - cmark_chunk_trim(raw_label); - advance(subj); // advance past ] - return 1; - } - -noMatch: - subj->pos = startpos; // rewind - return 0; -} - -static bufsize_t manual_scan_link_url_2(cmark_chunk *input, bufsize_t offset, - cmark_chunk *output) { - bufsize_t i = offset; - size_t nb_p = 0; - - while (i < input->len) { - if (input->data[i] == '\\' && - i + 1 < input-> len && - cmark_ispunct(input->data[i+1])) - i += 2; - else if (input->data[i] == '(') { - ++nb_p; - ++i; - if (nb_p > 32) - return -1; - } else if (input->data[i] == ')') { - if (nb_p == 0) - break; - --nb_p; - ++i; - } else if (cmark_isspace(input->data[i])) { - if (i == offset) { - return -1; - } - break; - } else { - ++i; - } - } - - if (i >= input->len) - return -1; - - { - cmark_chunk result = {input->data + offset, i - offset, 0}; - *output = result; - } - return i - offset; -} - -static bufsize_t manual_scan_link_url(cmark_chunk *input, bufsize_t offset, - cmark_chunk *output) { - bufsize_t i = offset; - - if (i < input->len && input->data[i] == '<') { - ++i; - while (i < input->len) { - if (input->data[i] == '>') { - ++i; - break; - } else if (input->data[i] == '\\') - i += 2; - else if (input->data[i] == '\n' || input->data[i] == '<') - return -1; - else - ++i; - } - } else { - return manual_scan_link_url_2(input, offset, output); - } - - if (i >= input->len) - return -1; - - { - cmark_chunk result = {input->data + offset + 1, i - 2 - offset, 0}; - *output = result; - } - return i - offset; -} - -// Return a link, an image, or a literal close bracket. -static cmark_node *handle_close_bracket(cmark_parser *parser, subject *subj) { - bufsize_t initial_pos, after_link_text_pos; - bufsize_t endurl, starttitle, endtitle, endall; - bufsize_t sps, n; - cmark_reference *ref = NULL; - cmark_chunk url_chunk, title_chunk; - cmark_chunk url, title; - bracket *opener; - cmark_node *inl; - cmark_chunk raw_label; - int found_label; - cmark_node *tmp, *tmpnext; - bool is_image; - - advance(subj); // advance past ] - initial_pos = subj->pos; - - // get last [ or ![ - opener = subj->last_bracket; - - if (opener == NULL) { - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("]")); - } - - if (!opener->active) { - // take delimiter off stack - pop_bracket(subj); - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("]")); - } - - // If we got here, we matched a potential link/image text. - // Now we check to see if it's a link/image. - is_image = opener->image; - - after_link_text_pos = subj->pos; - - // First, look for an inline link. - if (peek_char(subj) == '(' && - ((sps = scan_spacechars(&subj->input, subj->pos + 1)) > -1) && - ((n = manual_scan_link_url(&subj->input, subj->pos + 1 + sps, - &url_chunk)) > -1)) { - - // try to parse an explicit link: - endurl = subj->pos + 1 + sps + n; - starttitle = endurl + scan_spacechars(&subj->input, endurl); - - // ensure there are spaces btw url and title - endtitle = (starttitle == endurl) - ? starttitle - : starttitle + scan_link_title(&subj->input, starttitle); - - endall = endtitle + scan_spacechars(&subj->input, endtitle); - - if (peek_at(subj, endall) == ')') { - subj->pos = endall + 1; - - title_chunk = - cmark_chunk_dup(&subj->input, starttitle, endtitle - starttitle); - url = cmark_clean_url(subj->mem, &url_chunk); - title = cmark_clean_title(subj->mem, &title_chunk); - cmark_chunk_free(subj->mem, &url_chunk); - cmark_chunk_free(subj->mem, &title_chunk); - goto match; - - } else { - // it could still be a shortcut reference link - subj->pos = after_link_text_pos; - } - } - - // Next, look for a following [link label] that matches in refmap. - // skip spaces - raw_label = cmark_chunk_literal(""); - found_label = link_label(subj, &raw_label); - if (!found_label) { - // If we have a shortcut reference link, back up - // to before the spacse we skipped. - subj->pos = initial_pos; - } - - if ((!found_label || raw_label.len == 0) && !opener->bracket_after) { - cmark_chunk_free(subj->mem, &raw_label); - raw_label = cmark_chunk_dup(&subj->input, opener->position, - initial_pos - opener->position - 1); - found_label = true; - } - - if (found_label) { - ref = (cmark_reference *)cmark_map_lookup(subj->refmap, &raw_label); - cmark_chunk_free(subj->mem, &raw_label); - } - - if (ref != NULL) { // found - url = chunk_clone(subj->mem, &ref->url); - title = chunk_clone(subj->mem, &ref->title); - goto match; - } else { - goto noMatch; - } - -noMatch: - // If we fall through to here, it means we didn't match a link. - // What if we're a footnote link? - if (parser->options & CMARK_OPT_FOOTNOTES && - opener->inl_text->next && - opener->inl_text->next->type == CMARK_NODE_TEXT) { - - cmark_chunk *literal = &opener->inl_text->next->as.literal; - - // look back to the opening '[', and skip ahead to the next character - // if we're looking at a '[^' sequence, and there is other text or nodes - // after the ^, let's call it a footnote reference. - if ((literal->len > 0 && literal->data[0] == '^') && (literal->len > 1 || opener->inl_text->next->next)) { - - // Before we got this far, the `handle_close_bracket` function may have - // advanced the current state beyond our footnote's actual closing - // bracket, ie if it went looking for a `link_label`. - // Let's just rewind the subject's position: - subj->pos = initial_pos; - - cmark_node *fnref = make_simple(subj->mem, CMARK_NODE_FOOTNOTE_REFERENCE); - - // the start and end of the footnote ref is the opening and closing brace - // i.e. the subject's current position, and the opener's start_column - int fnref_end_column = subj->pos + subj->column_offset + subj->block_offset; - int fnref_start_column = opener->inl_text->start_column; - - // any given node delineates a substring of the line being processed, - // with the remainder of the line being pointed to thru its 'literal' - // struct member. - // here, we copy the literal's pointer, moving it past the '^' character - // for a length equal to the size of footnote reference text. - // i.e. end_col minus start_col, minus the [ and the ^ characters - // - // this copies the footnote reference string, even if between the - // `opener` and the subject's current position there are other nodes - // - // (first, check for underflows) - if ((fnref_start_column + 2) <= fnref_end_column) { - fnref->as.literal = cmark_chunk_dup(literal, 1, (fnref_end_column - fnref_start_column) - 2); - } else { - fnref->as.literal = cmark_chunk_dup(literal, 1, 0); - } - - fnref->start_line = fnref->end_line = subj->line; - fnref->start_column = fnref_start_column; - fnref->end_column = fnref_end_column; - - // we then replace the opener with this new fnref node, the net effect - // being replacing the opening '[' text node with a `^footnote-ref]` node. - cmark_node_insert_before(opener->inl_text, fnref); - - process_emphasis(parser, subj, opener->previous_delimiter); - // sometimes, the footnote reference text gets parsed into multiple nodes - // i.e. '[^example]' parsed into '[', '^exam', 'ple]'. - // this happens for ex with the autolink extension. when the autolinker - // finds the 'w' character, it will split the text into multiple nodes - // in hopes of being able to match a 'www.' substring. - // - // because this function is called one character at a time via the - // `parse_inlines` function, and the current subj->pos is pointing at the - // closing ] brace, and because we copy all the text between the [ ] - // braces, we should be able to safely ignore and delete any nodes after - // the opener->inl_text->next. - // - // therefore, here we walk thru the list and free them all up - cmark_node *next_node; - cmark_node *current_node = opener->inl_text->next; - while(current_node) { - next_node = current_node->next; - cmark_node_free(current_node); - current_node = next_node; - } - - cmark_node_free(opener->inl_text); - - pop_bracket(subj); - return NULL; - } - } - - pop_bracket(subj); // remove this opener from delimiter list - subj->pos = initial_pos; - return make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("]")); - -match: - inl = make_simple(subj->mem, is_image ? CMARK_NODE_IMAGE : CMARK_NODE_LINK); - inl->as.link.url = url; - inl->as.link.title = title; - inl->start_line = inl->end_line = subj->line; - inl->start_column = opener->inl_text->start_column; - inl->end_column = subj->pos + subj->column_offset + subj->block_offset; - cmark_node_insert_before(opener->inl_text, inl); - // Add link text: - tmp = opener->inl_text->next; - while (tmp) { - tmpnext = tmp->next; - cmark_node_append_child(inl, tmp); - tmp = tmpnext; - } - - // Free the bracket [: - cmark_node_free(opener->inl_text); - - process_emphasis(parser, subj, opener->previous_delimiter); - pop_bracket(subj); - - // Now, if we have a link, we also want to deactivate earlier link - // delimiters. (This code can be removed if we decide to allow links - // inside links.) - if (!is_image) { - opener = subj->last_bracket; - while (opener != NULL) { - if (!opener->image) { - if (!opener->active) { - break; - } else { - opener->active = false; - } - } - opener = opener->previous; - } - } - - return NULL; -} - -// Parse a hard or soft linebreak, returning an inline. -// Assumes the subject has a cr or newline at the current position. -static cmark_node *handle_newline(subject *subj) { - bufsize_t nlpos = subj->pos; - // skip over cr, crlf, or lf: - if (peek_at(subj, subj->pos) == '\r') { - advance(subj); - } - if (peek_at(subj, subj->pos) == '\n') { - advance(subj); - } - ++subj->line; - subj->column_offset = -subj->pos; - // skip spaces at beginning of line - skip_spaces(subj); - if (nlpos > 1 && peek_at(subj, nlpos - 1) == ' ' && - peek_at(subj, nlpos - 2) == ' ') { - return make_linebreak(subj->mem); - } else { - return make_softbreak(subj->mem); - } -} - -// "\r\n\\`&_*[]pos + 1; - - while (n < subj->input.len) { - if (SPECIAL_CHARS[subj->input.data[n]]) - return n; - if (options & CMARK_OPT_SMART && SMART_PUNCT_CHARS[subj->input.data[n]]) - return n; - n++; - } - - return subj->input.len; -} - -void cmark_inlines_add_special_character(unsigned char c, bool emphasis) { - SPECIAL_CHARS[c] = 1; - if (emphasis) - SKIP_CHARS[c] = 1; -} - -void cmark_inlines_remove_special_character(unsigned char c, bool emphasis) { - SPECIAL_CHARS[c] = 0; - if (emphasis) - SKIP_CHARS[c] = 0; -} - -static cmark_node *try_extensions(cmark_parser *parser, - cmark_node *parent, - unsigned char c, - subject *subj) { - cmark_node *res = NULL; - cmark_llist *tmp; - - for (tmp = parser->inline_syntax_extensions; tmp; tmp = tmp->next) { - cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp->data; - res = ext->match_inline(ext, parser, parent, c, subj); - - if (res) - break; - } - - return res; -} - -// Parse an inline, advancing subject, and add it as a child of parent. -// Return 0 if no inline can be parsed, 1 otherwise. -static int parse_inline(cmark_parser *parser, subject *subj, cmark_node *parent, int options) { - cmark_node *new_inl = NULL; - cmark_chunk contents; - unsigned char c; - bufsize_t startpos, endpos; - c = peek_char(subj); - if (c == 0) { - return 0; - } - switch (c) { - case '\r': - case '\n': - new_inl = handle_newline(subj); - break; - case '`': - new_inl = handle_backticks(subj, options); - break; - case '\\': - new_inl = handle_backslash(parser, subj); - break; - case '&': - new_inl = handle_entity(subj); - break; - case '<': - new_inl = handle_pointy_brace(subj, options); - break; - case '*': - case '_': - case '\'': - case '"': - new_inl = handle_delim(subj, c, (options & CMARK_OPT_SMART) != 0); - break; - case '-': - new_inl = handle_hyphen(subj, (options & CMARK_OPT_SMART) != 0); - break; - case '.': - new_inl = handle_period(subj, (options & CMARK_OPT_SMART) != 0); - break; - case '[': - advance(subj); - new_inl = make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("[")); - push_bracket(subj, false, new_inl); - break; - case ']': - new_inl = handle_close_bracket(parser, subj); - break; - case '!': - advance(subj); - if (peek_char(subj) == '[' && peek_char_n(subj, 1) != '^') { - advance(subj); - new_inl = make_str(subj, subj->pos - 2, subj->pos - 1, cmark_chunk_literal("![")); - push_bracket(subj, true, new_inl); - } else { - new_inl = make_str(subj, subj->pos - 1, subj->pos - 1, cmark_chunk_literal("!")); - } - break; - default: - new_inl = try_extensions(parser, parent, c, subj); - if (new_inl != NULL) - break; - - endpos = subject_find_special_char(subj, options); - contents = cmark_chunk_dup(&subj->input, subj->pos, endpos - subj->pos); - startpos = subj->pos; - subj->pos = endpos; - - // if we're at a newline, strip trailing spaces. - if (S_is_line_end_char(peek_char(subj))) { - cmark_chunk_rtrim(&contents); - } - - new_inl = make_str(subj, startpos, endpos - 1, contents); - } - if (new_inl != NULL) { - cmark_node_append_child(parent, new_inl); - } - - return 1; -} - -// Parse inlines from parent's string_content, adding as children of parent. -void cmark_parse_inlines(cmark_parser *parser, - cmark_node *parent, - cmark_map *refmap, - int options) { - subject subj; - cmark_chunk content = {parent->content.ptr, parent->content.size, 0}; - subject_from_buf(parser->mem, parent->start_line, parent->start_column - 1 + parent->internal_offset, &subj, &content, refmap); - cmark_chunk_rtrim(&subj.input); - - while (!is_eof(&subj) && parse_inline(parser, &subj, parent, options)) - ; - - process_emphasis(parser, &subj, NULL); - // free bracket and delim stack - while (subj.last_delim) { - remove_delimiter(&subj, subj.last_delim); - } - while (subj.last_bracket) { - pop_bracket(&subj); - } -} - -// Parse zero or more space characters, including at most one newline. -static void spnl(subject *subj) { - skip_spaces(subj); - if (skip_line_end(subj)) { - skip_spaces(subj); - } -} - -// Parse reference. Assumes string begins with '[' character. -// Modify refmap if a reference is encountered. -// Return 0 if no reference found, otherwise position of subject -// after reference is parsed. -bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input, - cmark_map *refmap) { - subject subj; - - cmark_chunk lab; - cmark_chunk url; - cmark_chunk title; - - bufsize_t matchlen = 0; - bufsize_t beforetitle; - - subject_from_buf(mem, -1, 0, &subj, input, NULL); - - // parse label: - if (!link_label(&subj, &lab) || lab.len == 0) - return 0; - - // colon: - if (peek_char(&subj) == ':') { - advance(&subj); - } else { - return 0; - } - - // parse link url: - spnl(&subj); - if ((matchlen = manual_scan_link_url(&subj.input, subj.pos, &url)) > -1) { - subj.pos += matchlen; - } else { - return 0; - } - - // parse optional link_title - beforetitle = subj.pos; - spnl(&subj); - matchlen = subj.pos == beforetitle ? 0 : scan_link_title(&subj.input, subj.pos); - if (matchlen) { - title = cmark_chunk_dup(&subj.input, subj.pos, matchlen); - subj.pos += matchlen; - } else { - subj.pos = beforetitle; - title = cmark_chunk_literal(""); - } - - // parse final spaces and newline: - skip_spaces(&subj); - if (!skip_line_end(&subj)) { - if (matchlen) { // try rewinding before title - subj.pos = beforetitle; - skip_spaces(&subj); - if (!skip_line_end(&subj)) { - return 0; - } - } else { - return 0; - } - } - // insert reference into refmap - cmark_reference_create(refmap, &lab, &url, &title); - return subj.pos; -} - -unsigned char cmark_inline_parser_peek_char(cmark_inline_parser *parser) { - return peek_char(parser); -} - -unsigned char cmark_inline_parser_peek_at(cmark_inline_parser *parser, bufsize_t pos) { - return peek_at(parser, pos); -} - -int cmark_inline_parser_is_eof(cmark_inline_parser *parser) { - return is_eof(parser); -} - -static char * -my_strndup (const char *s, size_t n) -{ - char *result; - size_t len = strlen (s); - - if (n < len) - len = n; - - result = (char *) malloc (len + 1); - if (!result) - return 0; - - result[len] = '\0'; - return (char *) memcpy (result, s, len); -} - -char *cmark_inline_parser_take_while(cmark_inline_parser *parser, cmark_inline_predicate pred) { - unsigned char c; - bufsize_t startpos = parser->pos; - bufsize_t len = 0; - - while ((c = peek_char(parser)) && (*pred)(c)) { - advance(parser); - len++; - } - - return my_strndup((const char *) parser->input.data + startpos, len); -} - -void cmark_inline_parser_push_delimiter(cmark_inline_parser *parser, - unsigned char c, - int can_open, - int can_close, - cmark_node *inl_text) { - push_delimiter(parser, c, can_open != 0, can_close != 0, inl_text); -} - -void cmark_inline_parser_remove_delimiter(cmark_inline_parser *parser, delimiter *delim) { - remove_delimiter(parser, delim); -} - -int cmark_inline_parser_scan_delimiters(cmark_inline_parser *parser, - int max_delims, - unsigned char c, - int *left_flanking, - int *right_flanking, - int *punct_before, - int *punct_after) { - int numdelims = 0; - bufsize_t before_char_pos; - int32_t after_char = 0; - int32_t before_char = 0; - int len; - bool space_before, space_after; - - if (parser->pos == 0) { - before_char = 10; - } else { - before_char_pos = parser->pos - 1; - // walk back to the beginning of the UTF_8 sequence: - while (peek_at(parser, before_char_pos) >> 6 == 2 && before_char_pos > 0) { - before_char_pos -= 1; - } - len = cmark_utf8proc_iterate(parser->input.data + before_char_pos, - parser->pos - before_char_pos, &before_char); - if (len == -1) { - before_char = 10; - } - } - - while (peek_char(parser) == c && numdelims < max_delims) { - numdelims++; - advance(parser); - } - - len = cmark_utf8proc_iterate(parser->input.data + parser->pos, - parser->input.len - parser->pos, &after_char); - if (len == -1) { - after_char = 10; - } - - *punct_before = cmark_utf8proc_is_punctuation(before_char); - *punct_after = cmark_utf8proc_is_punctuation(after_char); - space_before = cmark_utf8proc_is_space(before_char) != 0; - space_after = cmark_utf8proc_is_space(after_char) != 0; - - *left_flanking = numdelims > 0 && !cmark_utf8proc_is_space(after_char) && - !(*punct_after && !space_before && !*punct_before); - *right_flanking = numdelims > 0 && !cmark_utf8proc_is_space(before_char) && - !(*punct_before && !space_after && !*punct_after); - - return numdelims; -} - -void cmark_inline_parser_advance_offset(cmark_inline_parser *parser) { - advance(parser); -} - -int cmark_inline_parser_get_offset(cmark_inline_parser *parser) { - return parser->pos; -} - -void cmark_inline_parser_set_offset(cmark_inline_parser *parser, int offset) { - parser->pos = offset; -} - -int cmark_inline_parser_get_column(cmark_inline_parser *parser) { - return parser->pos + 1 + parser->column_offset + parser->block_offset; -} - -cmark_chunk *cmark_inline_parser_get_chunk(cmark_inline_parser *parser) { - return &parser->input; -} - -int cmark_inline_parser_in_bracket(cmark_inline_parser *parser, int image) { - for (bracket *b = parser->last_bracket; b; b = b->previous) - if (b->active && b->image == (image != 0)) - return 1; - return 0; -} - -void cmark_node_unput(cmark_node *node, int n) { - node = node->last_child; - while (n > 0 && node && node->type == CMARK_NODE_TEXT) { - if (node->as.literal.len < n) { - n -= node->as.literal.len; - node->as.literal.len = 0; - } else { - node->as.literal.len -= n; - n = 0; - } - node = node->prev; - } -} - -delimiter *cmark_inline_parser_get_last_delimiter(cmark_inline_parser *parser) { - return parser->last_delim; -} - -int cmark_inline_parser_get_line(cmark_inline_parser *parser) { - return parser->line; -} diff --git a/ext/commonmarker/inlines.h b/ext/commonmarker/inlines.h deleted file mode 100644 index 7dd91bf5..00000000 --- a/ext/commonmarker/inlines.h +++ /dev/null @@ -1,29 +0,0 @@ -#ifndef CMARK_INLINES_H -#define CMARK_INLINES_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "references.h" - -cmark_chunk cmark_clean_url(cmark_mem *mem, cmark_chunk *url); -cmark_chunk cmark_clean_title(cmark_mem *mem, cmark_chunk *title); - -CMARK_GFM_EXPORT -void cmark_parse_inlines(cmark_parser *parser, - cmark_node *parent, - cmark_map *refmap, - int options); - -bufsize_t cmark_parse_reference_inline(cmark_mem *mem, cmark_chunk *input, - cmark_map *refmap); - -void cmark_inlines_add_special_character(unsigned char c, bool emphasis); -void cmark_inlines_remove_special_character(unsigned char c, bool emphasis); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/iterator.c b/ext/commonmarker/iterator.c deleted file mode 100644 index 13fdb761..00000000 --- a/ext/commonmarker/iterator.c +++ /dev/null @@ -1,159 +0,0 @@ -#include -#include - -#include "config.h" -#include "node.h" -#include "cmark-gfm.h" -#include "iterator.h" - -cmark_iter *cmark_iter_new(cmark_node *root) { - if (root == NULL) { - return NULL; - } - cmark_mem *mem = root->content.mem; - cmark_iter *iter = (cmark_iter *)mem->calloc(1, sizeof(cmark_iter)); - iter->mem = mem; - iter->root = root; - iter->cur.ev_type = CMARK_EVENT_NONE; - iter->cur.node = NULL; - iter->next.ev_type = CMARK_EVENT_ENTER; - iter->next.node = root; - return iter; -} - -void cmark_iter_free(cmark_iter *iter) { iter->mem->free(iter); } - -static bool S_is_leaf(cmark_node *node) { - switch (node->type) { - case CMARK_NODE_HTML_BLOCK: - case CMARK_NODE_THEMATIC_BREAK: - case CMARK_NODE_CODE_BLOCK: - case CMARK_NODE_TEXT: - case CMARK_NODE_SOFTBREAK: - case CMARK_NODE_LINEBREAK: - case CMARK_NODE_CODE: - case CMARK_NODE_HTML_INLINE: - return 1; - } - return 0; -} - -cmark_event_type cmark_iter_next(cmark_iter *iter) { - cmark_event_type ev_type = iter->next.ev_type; - cmark_node *node = iter->next.node; - - iter->cur.ev_type = ev_type; - iter->cur.node = node; - - if (ev_type == CMARK_EVENT_DONE) { - return ev_type; - } - - /* roll forward to next item, setting both fields */ - if (ev_type == CMARK_EVENT_ENTER && !S_is_leaf(node)) { - if (node->first_child == NULL) { - /* stay on this node but exit */ - iter->next.ev_type = CMARK_EVENT_EXIT; - } else { - iter->next.ev_type = CMARK_EVENT_ENTER; - iter->next.node = node->first_child; - } - } else if (node == iter->root) { - /* don't move past root */ - iter->next.ev_type = CMARK_EVENT_DONE; - iter->next.node = NULL; - } else if (node->next) { - iter->next.ev_type = CMARK_EVENT_ENTER; - iter->next.node = node->next; - } else if (node->parent) { - iter->next.ev_type = CMARK_EVENT_EXIT; - iter->next.node = node->parent; - } else { - assert(false); - iter->next.ev_type = CMARK_EVENT_DONE; - iter->next.node = NULL; - } - - return ev_type; -} - -void cmark_iter_reset(cmark_iter *iter, cmark_node *current, - cmark_event_type event_type) { - iter->next.ev_type = event_type; - iter->next.node = current; - cmark_iter_next(iter); -} - -cmark_node *cmark_iter_get_node(cmark_iter *iter) { return iter->cur.node; } - -cmark_event_type cmark_iter_get_event_type(cmark_iter *iter) { - return iter->cur.ev_type; -} - -cmark_node *cmark_iter_get_root(cmark_iter *iter) { return iter->root; } - -void cmark_consolidate_text_nodes(cmark_node *root) { - if (root == NULL) { - return; - } - cmark_iter *iter = cmark_iter_new(root); - cmark_strbuf buf = CMARK_BUF_INIT(iter->mem); - cmark_event_type ev_type; - cmark_node *cur, *tmp, *next; - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - if (ev_type == CMARK_EVENT_ENTER && cur->type == CMARK_NODE_TEXT && - cur->next && cur->next->type == CMARK_NODE_TEXT) { - cmark_strbuf_clear(&buf); - cmark_strbuf_put(&buf, cur->as.literal.data, cur->as.literal.len); - tmp = cur->next; - while (tmp && tmp->type == CMARK_NODE_TEXT) { - cmark_iter_next(iter); // advance pointer - cmark_strbuf_put(&buf, tmp->as.literal.data, tmp->as.literal.len); - cur->end_column = tmp->end_column; - next = tmp->next; - cmark_node_free(tmp); - tmp = next; - } - cmark_chunk_free(iter->mem, &cur->as.literal); - cur->as.literal = cmark_chunk_buf_detach(&buf); - } - } - - cmark_strbuf_free(&buf); - cmark_iter_free(iter); -} - -void cmark_node_own(cmark_node *root) { - if (root == NULL) { - return; - } - cmark_iter *iter = cmark_iter_new(root); - cmark_event_type ev_type; - cmark_node *cur; - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - if (ev_type == CMARK_EVENT_ENTER) { - switch (cur->type) { - case CMARK_NODE_TEXT: - case CMARK_NODE_HTML_INLINE: - case CMARK_NODE_CODE: - case CMARK_NODE_HTML_BLOCK: - cmark_chunk_to_cstr(iter->mem, &cur->as.literal); - break; - case CMARK_NODE_LINK: - cmark_chunk_to_cstr(iter->mem, &cur->as.link.url); - cmark_chunk_to_cstr(iter->mem, &cur->as.link.title); - break; - case CMARK_NODE_CUSTOM_INLINE: - cmark_chunk_to_cstr(iter->mem, &cur->as.custom.on_enter); - cmark_chunk_to_cstr(iter->mem, &cur->as.custom.on_exit); - break; - } - } - } - - cmark_iter_free(iter); -} diff --git a/ext/commonmarker/iterator.h b/ext/commonmarker/iterator.h deleted file mode 100644 index 47e10e57..00000000 --- a/ext/commonmarker/iterator.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CMARK_ITERATOR_H -#define CMARK_ITERATOR_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmark-gfm.h" - -typedef struct { - cmark_event_type ev_type; - cmark_node *node; -} cmark_iter_state; - -struct cmark_iter { - cmark_mem *mem; - cmark_node *root; - cmark_iter_state cur; - cmark_iter_state next; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/latex.c b/ext/commonmarker/latex.c deleted file mode 100644 index 8be15b0d..00000000 --- a/ext/commonmarker/latex.c +++ /dev/null @@ -1,466 +0,0 @@ -#include -#include -#include -#include - -#include "config.h" -#include "cmark-gfm.h" -#include "node.h" -#include "buffer.h" -#include "utf8.h" -#include "scanners.h" -#include "render.h" -#include "syntax_extension.h" - -#define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping) -#define LIT(s) renderer->out(renderer, node, s, false, LITERAL) -#define CR() renderer->cr(renderer) -#define BLANKLINE() renderer->blankline(renderer) -#define LIST_NUMBER_STRING_SIZE 20 - -static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node, - cmark_escaping escape, - int32_t c, unsigned char nextc) { - if (escape == LITERAL) { - cmark_render_code_point(renderer, c); - return; - } - - switch (c) { - case 123: // '{' - case 125: // '}' - case 35: // '#' - case 37: // '%' - case 38: // '&' - cmark_render_ascii(renderer, "\\"); - cmark_render_code_point(renderer, c); - break; - case 36: // '$' - case 95: // '_' - if (escape == NORMAL) { - cmark_render_ascii(renderer, "\\"); - } - cmark_render_code_point(renderer, c); - break; - case 45: // '-' - if (nextc == 45) { // prevent ligature - cmark_render_ascii(renderer, "-{}"); - } else { - cmark_render_ascii(renderer, "-"); - } - break; - case 126: // '~' - if (escape == NORMAL) { - cmark_render_ascii(renderer, "\\textasciitilde{}"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 94: // '^' - cmark_render_ascii(renderer, "\\^{}"); - break; - case 92: // '\\' - if (escape == URL) { - // / acts as path sep even on windows: - cmark_render_ascii(renderer, "/"); - } else { - cmark_render_ascii(renderer, "\\textbackslash{}"); - } - break; - case 124: // '|' - cmark_render_ascii(renderer, "\\textbar{}"); - break; - case 60: // '<' - cmark_render_ascii(renderer, "\\textless{}"); - break; - case 62: // '>' - cmark_render_ascii(renderer, "\\textgreater{}"); - break; - case 91: // '[' - case 93: // ']' - cmark_render_ascii(renderer, "{"); - cmark_render_code_point(renderer, c); - cmark_render_ascii(renderer, "}"); - break; - case 34: // '"' - cmark_render_ascii(renderer, "\\textquotedbl{}"); - // requires \usepackage[T1]{fontenc} - break; - case 39: // '\'' - cmark_render_ascii(renderer, "\\textquotesingle{}"); - // requires \usepackage{textcomp} - break; - case 160: // nbsp - cmark_render_ascii(renderer, "~"); - break; - case 8230: // hellip - cmark_render_ascii(renderer, "\\ldots{}"); - break; - case 8216: // lsquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "`"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8217: // rsquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "\'"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8220: // ldquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "``"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8221: // rdquo - if (escape == NORMAL) { - cmark_render_ascii(renderer, "''"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8212: // emdash - if (escape == NORMAL) { - cmark_render_ascii(renderer, "---"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 8211: // endash - if (escape == NORMAL) { - cmark_render_ascii(renderer, "--"); - } else { - cmark_render_code_point(renderer, c); - } - break; - default: - cmark_render_code_point(renderer, c); - } -} - -typedef enum { - NO_LINK, - URL_AUTOLINK, - EMAIL_AUTOLINK, - NORMAL_LINK, - INTERNAL_LINK -} link_type; - -static link_type get_link_type(cmark_node *node) { - size_t title_len, url_len; - cmark_node *link_text; - char *realurl; - int realurllen; - bool isemail = false; - - if (node->type != CMARK_NODE_LINK) { - return NO_LINK; - } - - const char *url = cmark_node_get_url(node); - cmark_chunk url_chunk = cmark_chunk_literal(url); - - if (url && *url == '#') { - return INTERNAL_LINK; - } - - url_len = strlen(url); - if (url_len == 0 || scan_scheme(&url_chunk, 0) == 0) { - return NO_LINK; - } - - const char *title = cmark_node_get_title(node); - title_len = strlen(title); - // if it has a title, we can't treat it as an autolink: - if (title_len == 0) { - - link_text = node->first_child; - cmark_consolidate_text_nodes(link_text); - - if (!link_text) - return NO_LINK; - - realurl = (char *)url; - realurllen = (int)url_len; - if (strncmp(realurl, "mailto:", 7) == 0) { - realurl += 7; - realurllen -= 7; - isemail = true; - } - if (realurllen == link_text->as.literal.len && - strncmp(realurl, (char *)link_text->as.literal.data, - link_text->as.literal.len) == 0) { - if (isemail) { - return EMAIL_AUTOLINK; - } else { - return URL_AUTOLINK; - } - } - } - - return NORMAL_LINK; -} - -static int S_get_enumlevel(cmark_node *node) { - int enumlevel = 0; - cmark_node *tmp = node; - while (tmp) { - if (tmp->type == CMARK_NODE_LIST && - cmark_node_get_list_type(node) == CMARK_ORDERED_LIST) { - enumlevel++; - } - tmp = tmp->parent; - } - return enumlevel; -} - -static int S_render_node(cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - int list_number; - int enumlevel; - char list_number_string[LIST_NUMBER_STRING_SIZE]; - bool entering = (ev_type == CMARK_EVENT_ENTER); - cmark_list_type list_type; - bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options); - - if (node->extension && node->extension->latex_render_func) { - node->extension->latex_render_func(node->extension, renderer, node, ev_type, options); - return 1; - } - - switch (node->type) { - case CMARK_NODE_DOCUMENT: - break; - - case CMARK_NODE_BLOCK_QUOTE: - if (entering) { - LIT("\\begin{quote}"); - CR(); - } else { - LIT("\\end{quote}"); - BLANKLINE(); - } - break; - - case CMARK_NODE_LIST: - list_type = cmark_node_get_list_type(node); - if (entering) { - LIT("\\begin{"); - LIT(list_type == CMARK_ORDERED_LIST ? "enumerate" : "itemize"); - LIT("}"); - CR(); - list_number = cmark_node_get_list_start(node); - if (list_number > 1) { - enumlevel = S_get_enumlevel(node); - // latex normally supports only five levels - if (enumlevel >= 1 && enumlevel <= 5) { - snprintf(list_number_string, LIST_NUMBER_STRING_SIZE, "%d", - list_number); - LIT("\\setcounter{enum"); - switch (enumlevel) { - case 1: LIT("i"); break; - case 2: LIT("ii"); break; - case 3: LIT("iii"); break; - case 4: LIT("iv"); break; - case 5: LIT("v"); break; - default: LIT("i"); break; - } - LIT("}{"); - OUT(list_number_string, false, NORMAL); - LIT("}"); - } - CR(); - } - } else { - LIT("\\end{"); - LIT(list_type == CMARK_ORDERED_LIST ? "enumerate" : "itemize"); - LIT("}"); - BLANKLINE(); - } - break; - - case CMARK_NODE_ITEM: - if (entering) { - LIT("\\item "); - } else { - CR(); - } - break; - - case CMARK_NODE_HEADING: - if (entering) { - switch (cmark_node_get_heading_level(node)) { - case 1: - LIT("\\section"); - break; - case 2: - LIT("\\subsection"); - break; - case 3: - LIT("\\subsubsection"); - break; - case 4: - LIT("\\paragraph"); - break; - case 5: - LIT("\\subparagraph"); - break; - } - LIT("{"); - } else { - LIT("}"); - BLANKLINE(); - } - break; - - case CMARK_NODE_CODE_BLOCK: - CR(); - LIT("\\begin{verbatim}"); - CR(); - OUT(cmark_node_get_literal(node), false, LITERAL); - CR(); - LIT("\\end{verbatim}"); - BLANKLINE(); - break; - - case CMARK_NODE_HTML_BLOCK: - break; - - case CMARK_NODE_CUSTOM_BLOCK: - CR(); - OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node), - false, LITERAL); - CR(); - break; - - case CMARK_NODE_THEMATIC_BREAK: - BLANKLINE(); - LIT("\\begin{center}\\rule{0.5\\linewidth}{\\linethickness}\\end{center}"); - BLANKLINE(); - break; - - case CMARK_NODE_PARAGRAPH: - if (!entering) { - BLANKLINE(); - } - break; - - case CMARK_NODE_TEXT: - OUT(cmark_node_get_literal(node), allow_wrap, NORMAL); - break; - - case CMARK_NODE_LINEBREAK: - LIT("\\\\"); - CR(); - break; - - case CMARK_NODE_SOFTBREAK: - if (options & CMARK_OPT_HARDBREAKS) { - LIT("\\\\"); - CR(); - } else if (renderer->width == 0 && !(CMARK_OPT_NOBREAKS & options)) { - CR(); - } else { - OUT(" ", allow_wrap, NORMAL); - } - break; - - case CMARK_NODE_CODE: - LIT("\\texttt{"); - OUT(cmark_node_get_literal(node), false, NORMAL); - LIT("}"); - break; - - case CMARK_NODE_HTML_INLINE: - break; - - case CMARK_NODE_CUSTOM_INLINE: - OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node), - false, LITERAL); - break; - - case CMARK_NODE_STRONG: - if (entering) { - LIT("\\textbf{"); - } else { - LIT("}"); - } - break; - - case CMARK_NODE_EMPH: - if (entering) { - LIT("\\emph{"); - } else { - LIT("}"); - } - break; - - case CMARK_NODE_LINK: - if (entering) { - const char *url = cmark_node_get_url(node); - // requires \usepackage{hyperref} - switch (get_link_type(node)) { - case URL_AUTOLINK: - LIT("\\url{"); - OUT(url, false, URL); - LIT("}"); - return 0; // Don't process further nodes to avoid double-rendering artefacts - case EMAIL_AUTOLINK: - LIT("\\href{"); - OUT(url, false, URL); - LIT("}\\nolinkurl{"); - break; - case NORMAL_LINK: - LIT("\\href{"); - OUT(url, false, URL); - LIT("}{"); - break; - case INTERNAL_LINK: - LIT("\\protect\\hyperlink{"); - OUT(url + 1, false, URL); - LIT("}{"); - break; - case NO_LINK: - LIT("{"); // error? - } - } else { - LIT("}"); - } - - break; - - case CMARK_NODE_IMAGE: - if (entering) { - LIT("\\protect\\includegraphics{"); - // requires \include{graphicx} - OUT(cmark_node_get_url(node), false, URL); - LIT("}"); - return 0; - } - break; - - case CMARK_NODE_FOOTNOTE_DEFINITION: - case CMARK_NODE_FOOTNOTE_REFERENCE: - // TODO - break; - - default: - assert(false); - break; - } - - return 1; -} - -char *cmark_render_latex(cmark_node *root, int options, int width) { - return cmark_render_latex_with_mem(root, options, width, cmark_node_mem(root)); -} - -char *cmark_render_latex_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) { - return cmark_render(mem, root, options, width, outc, S_render_node); -} diff --git a/ext/commonmarker/linked_list.c b/ext/commonmarker/linked_list.c deleted file mode 100644 index 8c26dc55..00000000 --- a/ext/commonmarker/linked_list.c +++ /dev/null @@ -1,37 +0,0 @@ -#include - -#include "cmark-gfm.h" - -cmark_llist *cmark_llist_append(cmark_mem *mem, cmark_llist *head, void *data) { - cmark_llist *tmp; - cmark_llist *new_node = (cmark_llist *) mem->calloc(1, sizeof(cmark_llist)); - - new_node->data = data; - new_node->next = NULL; - - if (!head) - return new_node; - - for (tmp = head; tmp->next; tmp=tmp->next); - - tmp->next = new_node; - - return head; -} - -void cmark_llist_free_full(cmark_mem *mem, cmark_llist *head, cmark_free_func free_func) { - cmark_llist *tmp, *prev; - - for (tmp = head; tmp;) { - if (free_func) - free_func(mem, tmp->data); - - prev = tmp; - tmp = tmp->next; - mem->free(prev); - } -} - -void cmark_llist_free(cmark_mem *mem, cmark_llist *head) { - cmark_llist_free_full(mem, head, NULL); -} diff --git a/ext/commonmarker/man.c b/ext/commonmarker/man.c deleted file mode 100644 index 441a96e4..00000000 --- a/ext/commonmarker/man.c +++ /dev/null @@ -1,278 +0,0 @@ -#include -#include -#include -#include - -#include "config.h" -#include "cmark-gfm.h" -#include "node.h" -#include "buffer.h" -#include "utf8.h" -#include "render.h" -#include "syntax_extension.h" - -#define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping) -#define LIT(s) renderer->out(renderer, node, s, false, LITERAL) -#define CR() renderer->cr(renderer) -#define BLANKLINE() renderer->blankline(renderer) -#define LIST_NUMBER_SIZE 20 - -// Functions to convert cmark_nodes to groff man strings. -static void S_outc(cmark_renderer *renderer, cmark_node *node, - cmark_escaping escape, int32_t c, - unsigned char nextc) { - (void)(nextc); - - if (escape == LITERAL) { - cmark_render_code_point(renderer, c); - return; - } - - switch (c) { - case 46: - if (renderer->begin_line) { - cmark_render_ascii(renderer, "\\&."); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 39: - if (renderer->begin_line) { - cmark_render_ascii(renderer, "\\&'"); - } else { - cmark_render_code_point(renderer, c); - } - break; - case 45: - cmark_render_ascii(renderer, "\\-"); - break; - case 92: - cmark_render_ascii(renderer, "\\e"); - break; - case 8216: // left single quote - cmark_render_ascii(renderer, "\\[oq]"); - break; - case 8217: // right single quote - cmark_render_ascii(renderer, "\\[cq]"); - break; - case 8220: // left double quote - cmark_render_ascii(renderer, "\\[lq]"); - break; - case 8221: // right double quote - cmark_render_ascii(renderer, "\\[rq]"); - break; - case 8212: // em dash - cmark_render_ascii(renderer, "\\[em]"); - break; - case 8211: // en dash - cmark_render_ascii(renderer, "\\[en]"); - break; - default: - cmark_render_code_point(renderer, c); - } -} - -static int S_render_node(cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - cmark_node *tmp; - int list_number; - bool entering = (ev_type == CMARK_EVENT_ENTER); - bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options); - - if (node->extension && node->extension->man_render_func) { - node->extension->man_render_func(node->extension, renderer, node, ev_type, options); - return 1; - } - - switch (node->type) { - case CMARK_NODE_DOCUMENT: - if (entering) { - /* Define a strikethrough macro */ - /* Commenting out because this makes tests fail - LIT(".de ST"); - CR(); - LIT(".nr ww \\w'\\\\$1'"); - CR(); - LIT("\\Z@\\v'-.25m'\\l'\\\\n[ww]u'@\\\\$1"); - CR(); - LIT(".."); - CR(); - */ - } - break; - - case CMARK_NODE_BLOCK_QUOTE: - if (entering) { - CR(); - LIT(".RS"); - CR(); - } else { - CR(); - LIT(".RE"); - CR(); - } - break; - - case CMARK_NODE_LIST: - break; - - case CMARK_NODE_ITEM: - if (entering) { - CR(); - LIT(".IP "); - if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) { - LIT("\\[bu] 2"); - } else { - list_number = cmark_node_get_list_start(node->parent); - tmp = node; - while (tmp->prev) { - tmp = tmp->prev; - list_number += 1; - } - char list_number_s[LIST_NUMBER_SIZE]; - snprintf(list_number_s, LIST_NUMBER_SIZE, "\"%d.\" 4", list_number); - LIT(list_number_s); - } - CR(); - } else { - CR(); - } - break; - - case CMARK_NODE_HEADING: - if (entering) { - CR(); - LIT(cmark_node_get_heading_level(node) == 1 ? ".SH" : ".SS"); - CR(); - } else { - CR(); - } - break; - - case CMARK_NODE_CODE_BLOCK: - CR(); - LIT(".IP\n.nf\n\\f[C]\n"); - OUT(cmark_node_get_literal(node), false, NORMAL); - CR(); - LIT("\\f[]\n.fi"); - CR(); - break; - - case CMARK_NODE_HTML_BLOCK: - break; - - case CMARK_NODE_CUSTOM_BLOCK: - CR(); - OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node), - false, LITERAL); - CR(); - break; - - case CMARK_NODE_THEMATIC_BREAK: - CR(); - LIT(".PP\n * * * * *"); - CR(); - break; - - case CMARK_NODE_PARAGRAPH: - if (entering) { - // no blank line if first paragraph in list: - if (node->parent && node->parent->type == CMARK_NODE_ITEM && - node->prev == NULL) { - // no blank line or .PP - } else { - CR(); - LIT(".PP"); - CR(); - } - } else { - CR(); - } - break; - - case CMARK_NODE_TEXT: - OUT(cmark_node_get_literal(node), allow_wrap, NORMAL); - break; - - case CMARK_NODE_LINEBREAK: - LIT(".PD 0\n.P\n.PD"); - CR(); - break; - - case CMARK_NODE_SOFTBREAK: - if (options & CMARK_OPT_HARDBREAKS) { - LIT(".PD 0\n.P\n.PD"); - CR(); - } else if (renderer->width == 0 && !(CMARK_OPT_NOBREAKS & options)) { - CR(); - } else { - OUT(" ", allow_wrap, LITERAL); - } - break; - - case CMARK_NODE_CODE: - LIT("\\f[C]"); - OUT(cmark_node_get_literal(node), allow_wrap, NORMAL); - LIT("\\f[]"); - break; - - case CMARK_NODE_HTML_INLINE: - break; - - case CMARK_NODE_CUSTOM_INLINE: - OUT(entering ? cmark_node_get_on_enter(node) : cmark_node_get_on_exit(node), - false, LITERAL); - break; - - case CMARK_NODE_STRONG: - if (entering) { - LIT("\\f[B]"); - } else { - LIT("\\f[]"); - } - break; - - case CMARK_NODE_EMPH: - if (entering) { - LIT("\\f[I]"); - } else { - LIT("\\f[]"); - } - break; - - case CMARK_NODE_LINK: - if (!entering) { - LIT(" ("); - OUT(cmark_node_get_url(node), allow_wrap, URL); - LIT(")"); - } - break; - - case CMARK_NODE_IMAGE: - if (entering) { - LIT("[IMAGE: "); - } else { - LIT("]"); - } - break; - - case CMARK_NODE_FOOTNOTE_DEFINITION: - case CMARK_NODE_FOOTNOTE_REFERENCE: - // TODO - break; - - default: - assert(false); - break; - } - - return 1; -} - -char *cmark_render_man(cmark_node *root, int options, int width) { - return cmark_render_man_with_mem(root, options, width, cmark_node_mem(root)); -} - -char *cmark_render_man_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) { - return cmark_render(mem, root, options, width, S_outc, S_render_node); -} diff --git a/ext/commonmarker/map.c b/ext/commonmarker/map.c deleted file mode 100644 index 9a418dfd..00000000 --- a/ext/commonmarker/map.c +++ /dev/null @@ -1,122 +0,0 @@ -#include "map.h" -#include "utf8.h" -#include "parser.h" - -// normalize map label: collapse internal whitespace to single space, -// remove leading/trailing whitespace, case fold -// Return NULL if the label is actually empty (i.e. composed solely from -// whitespace) -unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref) { - cmark_strbuf normalized = CMARK_BUF_INIT(mem); - unsigned char *result; - - if (ref == NULL) - return NULL; - - if (ref->len == 0) - return NULL; - - cmark_utf8proc_case_fold(&normalized, ref->data, ref->len); - cmark_strbuf_trim(&normalized); - cmark_strbuf_normalize_whitespace(&normalized); - - result = cmark_strbuf_detach(&normalized); - assert(result); - - if (result[0] == '\0') { - mem->free(result); - return NULL; - } - - return result; -} - -static int -labelcmp(const unsigned char *a, const unsigned char *b) { - return strcmp((const char *)a, (const char *)b); -} - -static int -refcmp(const void *p1, const void *p2) { - cmark_map_entry *r1 = *(cmark_map_entry **)p1; - cmark_map_entry *r2 = *(cmark_map_entry **)p2; - int res = labelcmp(r1->label, r2->label); - return res ? res : ((int)r1->age - (int)r2->age); -} - -static int -refsearch(const void *label, const void *p2) { - cmark_map_entry *ref = *(cmark_map_entry **)p2; - return labelcmp((const unsigned char *)label, ref->label); -} - -static void sort_map(cmark_map *map) { - unsigned int i = 0, last = 0, size = map->size; - cmark_map_entry *r = map->refs, **sorted = NULL; - - sorted = (cmark_map_entry **)map->mem->calloc(size, sizeof(cmark_map_entry *)); - while (r) { - sorted[i++] = r; - r = r->next; - } - - qsort(sorted, size, sizeof(cmark_map_entry *), refcmp); - - for (i = 1; i < size; i++) { - if (labelcmp(sorted[i]->label, sorted[last]->label) != 0) - sorted[++last] = sorted[i]; - } - - map->sorted = sorted; - map->size = last + 1; -} - -cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label) { - cmark_map_entry **ref = NULL; - unsigned char *norm; - - if (label->len < 1 || label->len > MAX_LINK_LABEL_LENGTH) - return NULL; - - if (map == NULL || !map->size) - return NULL; - - norm = normalize_map_label(map->mem, label); - if (norm == NULL) - return NULL; - - if (!map->sorted) - sort_map(map); - - ref = (cmark_map_entry **)bsearch(norm, map->sorted, map->size, sizeof(cmark_map_entry *), refsearch); - map->mem->free(norm); - - if (!ref) - return NULL; - - return ref[0]; -} - -void cmark_map_free(cmark_map *map) { - cmark_map_entry *ref; - - if (map == NULL) - return; - - ref = map->refs; - while (ref) { - cmark_map_entry *next = ref->next; - map->free(map, ref); - ref = next; - } - - map->mem->free(map->sorted); - map->mem->free(map); -} - -cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free) { - cmark_map *map = (cmark_map *)mem->calloc(1, sizeof(cmark_map)); - map->mem = mem; - map->free = free; - return map; -} diff --git a/ext/commonmarker/map.h b/ext/commonmarker/map.h deleted file mode 100644 index aa4c06e5..00000000 --- a/ext/commonmarker/map.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef CMARK_MAP_H -#define CMARK_MAP_H - -#include "chunk.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct cmark_map_entry { - struct cmark_map_entry *next; - unsigned char *label; - unsigned int age; -}; - -typedef struct cmark_map_entry cmark_map_entry; - -struct cmark_map; - -typedef void (*cmark_map_free_f)(struct cmark_map *, cmark_map_entry *); - -struct cmark_map { - cmark_mem *mem; - cmark_map_entry *refs; - cmark_map_entry **sorted; - unsigned int size; - cmark_map_free_f free; -}; - -typedef struct cmark_map cmark_map; - -unsigned char *normalize_map_label(cmark_mem *mem, cmark_chunk *ref); -cmark_map *cmark_map_new(cmark_mem *mem, cmark_map_free_f free); -void cmark_map_free(cmark_map *map); -cmark_map_entry *cmark_map_lookup(cmark_map *map, cmark_chunk *label); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/node.c b/ext/commonmarker/node.c deleted file mode 100644 index 0118d651..00000000 --- a/ext/commonmarker/node.c +++ /dev/null @@ -1,979 +0,0 @@ -#include -#include - -#include "config.h" -#include "node.h" -#include "syntax_extension.h" - -static void S_node_unlink(cmark_node *node); - -#define NODE_MEM(node) cmark_node_mem(node) - -bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type) { - if (child_type == CMARK_NODE_DOCUMENT) { - return false; - } - - if (node->extension && node->extension->can_contain_func) { - return node->extension->can_contain_func(node->extension, node, child_type) != 0; - } - - switch (node->type) { - case CMARK_NODE_DOCUMENT: - case CMARK_NODE_BLOCK_QUOTE: - case CMARK_NODE_FOOTNOTE_DEFINITION: - case CMARK_NODE_ITEM: - return CMARK_NODE_TYPE_BLOCK_P(child_type) && child_type != CMARK_NODE_ITEM; - - case CMARK_NODE_LIST: - return child_type == CMARK_NODE_ITEM; - - case CMARK_NODE_CUSTOM_BLOCK: - return true; - - case CMARK_NODE_PARAGRAPH: - case CMARK_NODE_HEADING: - case CMARK_NODE_EMPH: - case CMARK_NODE_STRONG: - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - case CMARK_NODE_CUSTOM_INLINE: - return CMARK_NODE_TYPE_INLINE_P(child_type); - - default: - break; - } - - return false; -} - -static bool S_can_contain(cmark_node *node, cmark_node *child) { - cmark_node *cur; - - if (node == NULL || child == NULL) { - return false; - } - if (NODE_MEM(node) != NODE_MEM(child)) { - return 0; - } - - // Verify that child is not an ancestor of node or equal to node. - cur = node; - do { - if (cur == child) { - return false; - } - cur = cur->parent; - } while (cur != NULL); - - return cmark_node_can_contain_type(node, (cmark_node_type) child->type); -} - -cmark_node *cmark_node_new_with_mem_and_ext(cmark_node_type type, cmark_mem *mem, cmark_syntax_extension *extension) { - cmark_node *node = (cmark_node *)mem->calloc(1, sizeof(*node)); - cmark_strbuf_init(mem, &node->content, 0); - node->type = (uint16_t)type; - node->extension = extension; - - switch (node->type) { - case CMARK_NODE_HEADING: - node->as.heading.level = 1; - break; - - case CMARK_NODE_LIST: { - cmark_list *list = &node->as.list; - list->list_type = CMARK_BULLET_LIST; - list->start = 0; - list->tight = false; - break; - } - - default: - break; - } - - if (node->extension && node->extension->opaque_alloc_func) { - node->extension->opaque_alloc_func(node->extension, mem, node); - } - - return node; -} - -cmark_node *cmark_node_new_with_ext(cmark_node_type type, cmark_syntax_extension *extension) { - extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR; - return cmark_node_new_with_mem_and_ext(type, &CMARK_DEFAULT_MEM_ALLOCATOR, extension); -} - -cmark_node *cmark_node_new_with_mem(cmark_node_type type, cmark_mem *mem) -{ - return cmark_node_new_with_mem_and_ext(type, mem, NULL); -} - -cmark_node *cmark_node_new(cmark_node_type type) { - return cmark_node_new_with_ext(type, NULL); -} - -static void free_node_as(cmark_node *node) { - switch (node->type) { - case CMARK_NODE_CODE_BLOCK: - cmark_chunk_free(NODE_MEM(node), &node->as.code.info); - cmark_chunk_free(NODE_MEM(node), &node->as.code.literal); - break; - case CMARK_NODE_TEXT: - case CMARK_NODE_HTML_INLINE: - case CMARK_NODE_CODE: - case CMARK_NODE_HTML_BLOCK: - case CMARK_NODE_FOOTNOTE_REFERENCE: - case CMARK_NODE_FOOTNOTE_DEFINITION: - cmark_chunk_free(NODE_MEM(node), &node->as.literal); - break; - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - cmark_chunk_free(NODE_MEM(node), &node->as.link.url); - cmark_chunk_free(NODE_MEM(node), &node->as.link.title); - break; - case CMARK_NODE_CUSTOM_BLOCK: - case CMARK_NODE_CUSTOM_INLINE: - cmark_chunk_free(NODE_MEM(node), &node->as.custom.on_enter); - cmark_chunk_free(NODE_MEM(node), &node->as.custom.on_exit); - break; - default: - break; - } -} - -// Free a cmark_node list and any children. -static void S_free_nodes(cmark_node *e) { - cmark_node *next; - while (e != NULL) { - cmark_strbuf_free(&e->content); - - if (e->user_data && e->user_data_free_func) - e->user_data_free_func(NODE_MEM(e), e->user_data); - - if (e->as.opaque && e->extension && e->extension->opaque_free_func) - e->extension->opaque_free_func(e->extension, NODE_MEM(e), e); - - free_node_as(e); - - if (e->last_child) { - // Splice children into list - e->last_child->next = e->next; - e->next = e->first_child; - } - next = e->next; - NODE_MEM(e)->free(e); - e = next; - } -} - -void cmark_node_free(cmark_node *node) { - S_node_unlink(node); - node->next = NULL; - S_free_nodes(node); -} - -cmark_node_type cmark_node_get_type(cmark_node *node) { - if (node == NULL) { - return CMARK_NODE_NONE; - } else { - return (cmark_node_type)node->type; - } -} - -int cmark_node_set_type(cmark_node * node, cmark_node_type type) { - cmark_node_type initial_type; - - if (type == node->type) - return 1; - - initial_type = (cmark_node_type) node->type; - node->type = (uint16_t)type; - - if (!S_can_contain(node->parent, node)) { - node->type = (uint16_t)initial_type; - return 0; - } - - /* We rollback the type to free the union members appropriately */ - node->type = (uint16_t)initial_type; - free_node_as(node); - - node->type = (uint16_t)type; - - return 1; -} - -const char *cmark_node_get_type_string(cmark_node *node) { - if (node == NULL) { - return "NONE"; - } - - if (node->extension && node->extension->get_type_string_func) { - return node->extension->get_type_string_func(node->extension, node); - } - - switch (node->type) { - case CMARK_NODE_NONE: - return "none"; - case CMARK_NODE_DOCUMENT: - return "document"; - case CMARK_NODE_BLOCK_QUOTE: - return "block_quote"; - case CMARK_NODE_LIST: - return "list"; - case CMARK_NODE_ITEM: - return "item"; - case CMARK_NODE_CODE_BLOCK: - return "code_block"; - case CMARK_NODE_HTML_BLOCK: - return "html_block"; - case CMARK_NODE_CUSTOM_BLOCK: - return "custom_block"; - case CMARK_NODE_PARAGRAPH: - return "paragraph"; - case CMARK_NODE_HEADING: - return "heading"; - case CMARK_NODE_THEMATIC_BREAK: - return "thematic_break"; - case CMARK_NODE_TEXT: - return "text"; - case CMARK_NODE_SOFTBREAK: - return "softbreak"; - case CMARK_NODE_LINEBREAK: - return "linebreak"; - case CMARK_NODE_CODE: - return "code"; - case CMARK_NODE_HTML_INLINE: - return "html_inline"; - case CMARK_NODE_CUSTOM_INLINE: - return "custom_inline"; - case CMARK_NODE_EMPH: - return "emph"; - case CMARK_NODE_STRONG: - return "strong"; - case CMARK_NODE_LINK: - return "link"; - case CMARK_NODE_IMAGE: - return "image"; - } - - return ""; -} - -cmark_node *cmark_node_next(cmark_node *node) { - if (node == NULL) { - return NULL; - } else { - return node->next; - } -} - -cmark_node *cmark_node_previous(cmark_node *node) { - if (node == NULL) { - return NULL; - } else { - return node->prev; - } -} - -cmark_node *cmark_node_parent(cmark_node *node) { - if (node == NULL) { - return NULL; - } else { - return node->parent; - } -} - -cmark_node *cmark_node_first_child(cmark_node *node) { - if (node == NULL) { - return NULL; - } else { - return node->first_child; - } -} - -cmark_node *cmark_node_last_child(cmark_node *node) { - if (node == NULL) { - return NULL; - } else { - return node->last_child; - } -} - -void *cmark_node_get_user_data(cmark_node *node) { - if (node == NULL) { - return NULL; - } else { - return node->user_data; - } -} - -int cmark_node_set_user_data(cmark_node *node, void *user_data) { - if (node == NULL) { - return 0; - } - node->user_data = user_data; - return 1; -} - -int cmark_node_set_user_data_free_func(cmark_node *node, - cmark_free_func free_func) { - if (node == NULL) { - return 0; - } - node->user_data_free_func = free_func; - return 1; -} - -const char *cmark_node_get_literal(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - switch (node->type) { - case CMARK_NODE_HTML_BLOCK: - case CMARK_NODE_TEXT: - case CMARK_NODE_HTML_INLINE: - case CMARK_NODE_CODE: - case CMARK_NODE_FOOTNOTE_REFERENCE: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.literal); - - case CMARK_NODE_CODE_BLOCK: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.code.literal); - - default: - break; - } - - return NULL; -} - -int cmark_node_set_literal(cmark_node *node, const char *content) { - if (node == NULL) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_HTML_BLOCK: - case CMARK_NODE_TEXT: - case CMARK_NODE_HTML_INLINE: - case CMARK_NODE_CODE: - case CMARK_NODE_FOOTNOTE_REFERENCE: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.literal, content); - return 1; - - case CMARK_NODE_CODE_BLOCK: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.code.literal, content); - return 1; - - default: - break; - } - - return 0; -} - -const char *cmark_node_get_string_content(cmark_node *node) { - return (char *) node->content.ptr; -} - -int cmark_node_set_string_content(cmark_node *node, const char *content) { - cmark_strbuf_sets(&node->content, content); - return true; -} - -int cmark_node_get_heading_level(cmark_node *node) { - if (node == NULL) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_HEADING: - return node->as.heading.level; - - default: - break; - } - - return 0; -} - -int cmark_node_set_heading_level(cmark_node *node, int level) { - if (node == NULL || level < 1 || level > 6) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_HEADING: - node->as.heading.level = level; - return 1; - - default: - break; - } - - return 0; -} - -cmark_list_type cmark_node_get_list_type(cmark_node *node) { - if (node == NULL) { - return CMARK_NO_LIST; - } - - if (node->type == CMARK_NODE_LIST) { - return node->as.list.list_type; - } else { - return CMARK_NO_LIST; - } -} - -int cmark_node_set_list_type(cmark_node *node, cmark_list_type type) { - if (!(type == CMARK_BULLET_LIST || type == CMARK_ORDERED_LIST)) { - return 0; - } - - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_LIST) { - node->as.list.list_type = type; - return 1; - } else { - return 0; - } -} - -cmark_delim_type cmark_node_get_list_delim(cmark_node *node) { - if (node == NULL) { - return CMARK_NO_DELIM; - } - - if (node->type == CMARK_NODE_LIST) { - return node->as.list.delimiter; - } else { - return CMARK_NO_DELIM; - } -} - -int cmark_node_set_list_delim(cmark_node *node, cmark_delim_type delim) { - if (!(delim == CMARK_PERIOD_DELIM || delim == CMARK_PAREN_DELIM)) { - return 0; - } - - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_LIST) { - node->as.list.delimiter = delim; - return 1; - } else { - return 0; - } -} - -int cmark_node_get_list_start(cmark_node *node) { - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_LIST) { - return node->as.list.start; - } else { - return 0; - } -} - -int cmark_node_set_list_start(cmark_node *node, int start) { - if (node == NULL || start < 0) { - return 0; - } - - if (node->type == CMARK_NODE_LIST) { - node->as.list.start = start; - return 1; - } else { - return 0; - } -} - -int cmark_node_get_list_tight(cmark_node *node) { - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_LIST) { - return node->as.list.tight; - } else { - return 0; - } -} - -int cmark_node_set_list_tight(cmark_node *node, int tight) { - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_LIST) { - node->as.list.tight = tight == 1; - return 1; - } else { - return 0; - } -} - -const char *cmark_node_get_fence_info(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - if (node->type == CMARK_NODE_CODE_BLOCK) { - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.code.info); - } else { - return NULL; - } -} - -int cmark_node_set_fence_info(cmark_node *node, const char *info) { - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_CODE_BLOCK) { - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.code.info, info); - return 1; - } else { - return 0; - } -} - -int cmark_node_get_fenced(cmark_node *node, int *length, int *offset, char *character) { - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_CODE_BLOCK) { - *length = node->as.code.fence_length; - *offset = node->as.code.fence_offset; - *character = node->as.code.fence_char; - return node->as.code.fenced; - } else { - return 0; - } -} - -int cmark_node_set_fenced(cmark_node * node, int fenced, - int length, int offset, char character) { - if (node == NULL) { - return 0; - } - - if (node->type == CMARK_NODE_CODE_BLOCK) { - node->as.code.fenced = (int8_t)fenced; - node->as.code.fence_length = (uint8_t)length; - node->as.code.fence_offset = (uint8_t)offset; - node->as.code.fence_char = character; - return 1; - } else { - return 0; - } -} - -const char *cmark_node_get_url(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - switch (node->type) { - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.link.url); - default: - break; - } - - return NULL; -} - -int cmark_node_set_url(cmark_node *node, const char *url) { - if (node == NULL) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.link.url, url); - return 1; - default: - break; - } - - return 0; -} - -const char *cmark_node_get_title(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - switch (node->type) { - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.link.title); - default: - break; - } - - return NULL; -} - -int cmark_node_set_title(cmark_node *node, const char *title) { - if (node == NULL) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.link.title, title); - return 1; - default: - break; - } - - return 0; -} - -const char *cmark_node_get_on_enter(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - switch (node->type) { - case CMARK_NODE_CUSTOM_INLINE: - case CMARK_NODE_CUSTOM_BLOCK: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.custom.on_enter); - default: - break; - } - - return NULL; -} - -int cmark_node_set_on_enter(cmark_node *node, const char *on_enter) { - if (node == NULL) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_CUSTOM_INLINE: - case CMARK_NODE_CUSTOM_BLOCK: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.custom.on_enter, on_enter); - return 1; - default: - break; - } - - return 0; -} - -const char *cmark_node_get_on_exit(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - switch (node->type) { - case CMARK_NODE_CUSTOM_INLINE: - case CMARK_NODE_CUSTOM_BLOCK: - return cmark_chunk_to_cstr(NODE_MEM(node), &node->as.custom.on_exit); - default: - break; - } - - return NULL; -} - -int cmark_node_set_on_exit(cmark_node *node, const char *on_exit) { - if (node == NULL) { - return 0; - } - - switch (node->type) { - case CMARK_NODE_CUSTOM_INLINE: - case CMARK_NODE_CUSTOM_BLOCK: - cmark_chunk_set_cstr(NODE_MEM(node), &node->as.custom.on_exit, on_exit); - return 1; - default: - break; - } - - return 0; -} - -cmark_syntax_extension *cmark_node_get_syntax_extension(cmark_node *node) { - if (node == NULL) { - return NULL; - } - - return node->extension; -} - -int cmark_node_set_syntax_extension(cmark_node *node, cmark_syntax_extension *extension) { - if (node == NULL) { - return 0; - } - - node->extension = extension; - return 1; -} - -int cmark_node_get_start_line(cmark_node *node) { - if (node == NULL) { - return 0; - } - return node->start_line; -} - -int cmark_node_get_start_column(cmark_node *node) { - if (node == NULL) { - return 0; - } - return node->start_column; -} - -int cmark_node_get_end_line(cmark_node *node) { - if (node == NULL) { - return 0; - } - return node->end_line; -} - -int cmark_node_get_end_column(cmark_node *node) { - if (node == NULL) { - return 0; - } - return node->end_column; -} - -// Unlink a node without adjusting its next, prev, and parent pointers. -static void S_node_unlink(cmark_node *node) { - if (node == NULL) { - return; - } - - if (node->prev) { - node->prev->next = node->next; - } - if (node->next) { - node->next->prev = node->prev; - } - - // Adjust first_child and last_child of parent. - cmark_node *parent = node->parent; - if (parent) { - if (parent->first_child == node) { - parent->first_child = node->next; - } - if (parent->last_child == node) { - parent->last_child = node->prev; - } - } -} - -void cmark_node_unlink(cmark_node *node) { - S_node_unlink(node); - - node->next = NULL; - node->prev = NULL; - node->parent = NULL; -} - -int cmark_node_insert_before(cmark_node *node, cmark_node *sibling) { - if (node == NULL || sibling == NULL) { - return 0; - } - - if (!node->parent || !S_can_contain(node->parent, sibling)) { - return 0; - } - - S_node_unlink(sibling); - - cmark_node *old_prev = node->prev; - - // Insert 'sibling' between 'old_prev' and 'node'. - if (old_prev) { - old_prev->next = sibling; - } - sibling->prev = old_prev; - sibling->next = node; - node->prev = sibling; - - // Set new parent. - cmark_node *parent = node->parent; - sibling->parent = parent; - - // Adjust first_child of parent if inserted as first child. - if (parent && !old_prev) { - parent->first_child = sibling; - } - - return 1; -} - -int cmark_node_insert_after(cmark_node *node, cmark_node *sibling) { - if (node == NULL || sibling == NULL) { - return 0; - } - - if (!node->parent || !S_can_contain(node->parent, sibling)) { - return 0; - } - - S_node_unlink(sibling); - - cmark_node *old_next = node->next; - - // Insert 'sibling' between 'node' and 'old_next'. - if (old_next) { - old_next->prev = sibling; - } - sibling->next = old_next; - sibling->prev = node; - node->next = sibling; - - // Set new parent. - cmark_node *parent = node->parent; - sibling->parent = parent; - - // Adjust last_child of parent if inserted as last child. - if (parent && !old_next) { - parent->last_child = sibling; - } - - return 1; -} - -int cmark_node_replace(cmark_node *oldnode, cmark_node *newnode) { - if (!cmark_node_insert_before(oldnode, newnode)) { - return 0; - } - cmark_node_unlink(oldnode); - return 1; -} - -int cmark_node_prepend_child(cmark_node *node, cmark_node *child) { - if (!S_can_contain(node, child)) { - return 0; - } - - S_node_unlink(child); - - cmark_node *old_first_child = node->first_child; - - child->next = old_first_child; - child->prev = NULL; - child->parent = node; - node->first_child = child; - - if (old_first_child) { - old_first_child->prev = child; - } else { - // Also set last_child if node previously had no children. - node->last_child = child; - } - - return 1; -} - -int cmark_node_append_child(cmark_node *node, cmark_node *child) { - if (!S_can_contain(node, child)) { - return 0; - } - - S_node_unlink(child); - - cmark_node *old_last_child = node->last_child; - - child->next = NULL; - child->prev = old_last_child; - child->parent = node; - node->last_child = child; - - if (old_last_child) { - old_last_child->next = child; - } else { - // Also set first_child if node previously had no children. - node->first_child = child; - } - - return 1; -} - -static void S_print_error(FILE *out, cmark_node *node, const char *elem) { - if (out == NULL) { - return; - } - fprintf(out, "Invalid '%s' in node type %s at %d:%d\n", elem, - cmark_node_get_type_string(node), node->start_line, - node->start_column); -} - -int cmark_node_check(cmark_node *node, FILE *out) { - cmark_node *cur; - int errors = 0; - - if (!node) { - return 0; - } - - cur = node; - for (;;) { - if (cur->first_child) { - if (cur->first_child->prev != NULL) { - S_print_error(out, cur->first_child, "prev"); - cur->first_child->prev = NULL; - ++errors; - } - if (cur->first_child->parent != cur) { - S_print_error(out, cur->first_child, "parent"); - cur->first_child->parent = cur; - ++errors; - } - cur = cur->first_child; - continue; - } - - next_sibling: - if (cur == node) { - break; - } - if (cur->next) { - if (cur->next->prev != cur) { - S_print_error(out, cur->next, "prev"); - cur->next->prev = cur; - ++errors; - } - if (cur->next->parent != cur->parent) { - S_print_error(out, cur->next, "parent"); - cur->next->parent = cur->parent; - ++errors; - } - cur = cur->next; - continue; - } - - if (cur->parent->last_child != cur) { - S_print_error(out, cur->parent, "last_child"); - cur->parent->last_child = cur; - ++errors; - } - cur = cur->parent; - goto next_sibling; - } - - return errors; -} diff --git a/ext/commonmarker/node.h b/ext/commonmarker/node.h deleted file mode 100644 index b094c16e..00000000 --- a/ext/commonmarker/node.h +++ /dev/null @@ -1,125 +0,0 @@ -#ifndef CMARK_NODE_H -#define CMARK_NODE_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include - -#include "cmark-gfm.h" -#include "cmark-gfm-extension_api.h" -#include "buffer.h" -#include "chunk.h" - -typedef struct { - cmark_list_type list_type; - int marker_offset; - int padding; - int start; - cmark_delim_type delimiter; - unsigned char bullet_char; - bool tight; - bool checked; // For task list extension -} cmark_list; - -typedef struct { - cmark_chunk info; - cmark_chunk literal; - uint8_t fence_length; - uint8_t fence_offset; - unsigned char fence_char; - int8_t fenced; -} cmark_code; - -typedef struct { - int level; - bool setext; -} cmark_heading; - -typedef struct { - cmark_chunk url; - cmark_chunk title; -} cmark_link; - -typedef struct { - cmark_chunk on_enter; - cmark_chunk on_exit; -} cmark_custom; - -enum cmark_node__internal_flags { - CMARK_NODE__OPEN = (1 << 0), - CMARK_NODE__LAST_LINE_BLANK = (1 << 1), - CMARK_NODE__LAST_LINE_CHECKED = (1 << 2), -}; - -struct cmark_node { - cmark_strbuf content; - - struct cmark_node *next; - struct cmark_node *prev; - struct cmark_node *parent; - struct cmark_node *first_child; - struct cmark_node *last_child; - - void *user_data; - cmark_free_func user_data_free_func; - - int start_line; - int start_column; - int end_line; - int end_column; - int internal_offset; - uint16_t type; - uint16_t flags; - - cmark_syntax_extension *extension; - - union { - int ref_ix; - int def_count; - } footnote; - - cmark_node *parent_footnote_def; - - union { - cmark_chunk literal; - cmark_list list; - cmark_code code; - cmark_heading heading; - cmark_link link; - cmark_custom custom; - int html_block_type; - void *opaque; - } as; -}; - -static CMARK_INLINE cmark_mem *cmark_node_mem(cmark_node *node) { - return node->content.mem; -} -CMARK_GFM_EXPORT int cmark_node_check(cmark_node *node, FILE *out); - -static CMARK_INLINE bool CMARK_NODE_TYPE_BLOCK_P(cmark_node_type node_type) { - return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_BLOCK; -} - -static CMARK_INLINE bool CMARK_NODE_BLOCK_P(cmark_node *node) { - return node != NULL && CMARK_NODE_TYPE_BLOCK_P((cmark_node_type) node->type); -} - -static CMARK_INLINE bool CMARK_NODE_TYPE_INLINE_P(cmark_node_type node_type) { - return (node_type & CMARK_NODE_TYPE_MASK) == CMARK_NODE_TYPE_INLINE; -} - -static CMARK_INLINE bool CMARK_NODE_INLINE_P(cmark_node *node) { - return node != NULL && CMARK_NODE_TYPE_INLINE_P((cmark_node_type) node->type); -} - -CMARK_GFM_EXPORT bool cmark_node_can_contain_type(cmark_node *node, cmark_node_type child_type); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/parser.h b/ext/commonmarker/parser.h deleted file mode 100644 index 245580b8..00000000 --- a/ext/commonmarker/parser.h +++ /dev/null @@ -1,58 +0,0 @@ -#ifndef CMARK_PARSER_H -#define CMARK_PARSER_H - -#include -#include "references.h" -#include "node.h" -#include "buffer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define MAX_LINK_LABEL_LENGTH 1000 - -struct cmark_parser { - struct cmark_mem *mem; - /* A hashtable of urls in the current document for cross-references */ - struct cmark_map *refmap; - /* The root node of the parser, always a CMARK_NODE_DOCUMENT */ - struct cmark_node *root; - /* The last open block after a line is fully processed */ - struct cmark_node *current; - /* See the documentation for cmark_parser_get_line_number() in cmark.h */ - int line_number; - /* See the documentation for cmark_parser_get_offset() in cmark.h */ - bufsize_t offset; - /* See the documentation for cmark_parser_get_column() in cmark.h */ - bufsize_t column; - /* See the documentation for cmark_parser_get_first_nonspace() in cmark.h */ - bufsize_t first_nonspace; - /* See the documentation for cmark_parser_get_first_nonspace_column() in cmark.h */ - bufsize_t first_nonspace_column; - bufsize_t thematic_break_kill_pos; - /* See the documentation for cmark_parser_get_indent() in cmark.h */ - int indent; - /* See the documentation for cmark_parser_is_blank() in cmark.h */ - bool blank; - /* See the documentation for cmark_parser_has_partially_consumed_tab() in cmark.h */ - bool partially_consumed_tab; - /* Contains the currently processed line */ - cmark_strbuf curline; - /* See the documentation for cmark_parser_get_last_line_length() in cmark.h */ - bufsize_t last_line_length; - /* FIXME: not sure about the difference with curline */ - cmark_strbuf linebuf; - /* Options set by the user, see the Options section in cmark.h */ - int options; - bool last_buffer_ended_with_cr; - cmark_llist *syntax_extensions; - cmark_llist *inline_syntax_extensions; - cmark_ispunct_func backslash_ispunct; -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/plaintext.c b/ext/commonmarker/plaintext.c deleted file mode 100644 index b25e4a39..00000000 --- a/ext/commonmarker/plaintext.c +++ /dev/null @@ -1,235 +0,0 @@ -#include "node.h" -#include "syntax_extension.h" -#include "render.h" - -#define OUT(s, wrap, escaping) renderer->out(renderer, node, s, wrap, escaping) -#define LIT(s) renderer->out(renderer, node, s, false, LITERAL) -#define CR() renderer->cr(renderer) -#define BLANKLINE() renderer->blankline(renderer) -#define LISTMARKER_SIZE 20 - -// Functions to convert cmark_nodes to plain text strings. - -static CMARK_INLINE void outc(cmark_renderer *renderer, cmark_node *node, - cmark_escaping escape, - int32_t c, unsigned char nextc) { - cmark_render_code_point(renderer, c); -} - -// if node is a block node, returns node. -// otherwise returns first block-level node that is an ancestor of node. -// if there is no block-level ancestor, returns NULL. -static cmark_node *get_containing_block(cmark_node *node) { - while (node) { - if (CMARK_NODE_BLOCK_P(node)) { - return node; - } else { - node = node->parent; - } - } - return NULL; -} - -static int S_render_node(cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - cmark_node *tmp; - int list_number; - cmark_delim_type list_delim; - int i; - bool entering = (ev_type == CMARK_EVENT_ENTER); - char listmarker[LISTMARKER_SIZE]; - bool first_in_list_item; - bufsize_t marker_width; - bool allow_wrap = renderer->width > 0 && !(CMARK_OPT_NOBREAKS & options) && - !(CMARK_OPT_HARDBREAKS & options); - - // Don't adjust tight list status til we've started the list. - // Otherwise we loose the blank line between a paragraph and - // a following list. - if (!(node->type == CMARK_NODE_ITEM && node->prev == NULL && entering)) { - tmp = get_containing_block(node); - renderer->in_tight_list_item = - tmp && // tmp might be NULL if there is no containing block - ((tmp->type == CMARK_NODE_ITEM && - cmark_node_get_list_tight(tmp->parent)) || - (tmp && tmp->parent && tmp->parent->type == CMARK_NODE_ITEM && - cmark_node_get_list_tight(tmp->parent->parent))); - } - - if (node->extension && node->extension->plaintext_render_func) { - node->extension->plaintext_render_func(node->extension, renderer, node, ev_type, options); - return 1; - } - - switch (node->type) { - case CMARK_NODE_DOCUMENT: - break; - - case CMARK_NODE_BLOCK_QUOTE: - break; - - case CMARK_NODE_LIST: - if (!entering && node->next && (node->next->type == CMARK_NODE_CODE_BLOCK || - node->next->type == CMARK_NODE_LIST)) { - CR(); - } - break; - - case CMARK_NODE_ITEM: - if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) { - marker_width = 4; - } else { - list_number = cmark_node_get_list_start(node->parent); - list_delim = cmark_node_get_list_delim(node->parent); - tmp = node; - while (tmp->prev) { - tmp = tmp->prev; - list_number += 1; - } - // we ensure a width of at least 4 so - // we get nice transition from single digits - // to double - snprintf(listmarker, LISTMARKER_SIZE, "%d%s%s", list_number, - list_delim == CMARK_PAREN_DELIM ? ")" : ".", - list_number < 10 ? " " : " "); - marker_width = (bufsize_t)strlen(listmarker); - } - if (entering) { - if (cmark_node_get_list_type(node->parent) == CMARK_BULLET_LIST) { - LIT(" - "); - renderer->begin_content = true; - } else { - LIT(listmarker); - renderer->begin_content = true; - } - for (i = marker_width; i--;) { - cmark_strbuf_putc(renderer->prefix, ' '); - } - } else { - cmark_strbuf_truncate(renderer->prefix, - renderer->prefix->size - marker_width); - CR(); - } - break; - - case CMARK_NODE_HEADING: - if (entering) { - renderer->begin_content = true; - renderer->no_linebreaks = true; - } else { - renderer->no_linebreaks = false; - BLANKLINE(); - } - break; - - case CMARK_NODE_CODE_BLOCK: - first_in_list_item = node->prev == NULL && node->parent && - node->parent->type == CMARK_NODE_ITEM; - - if (!first_in_list_item) { - BLANKLINE(); - } - OUT(cmark_node_get_literal(node), false, LITERAL); - BLANKLINE(); - break; - - case CMARK_NODE_HTML_BLOCK: - break; - - case CMARK_NODE_CUSTOM_BLOCK: - break; - - case CMARK_NODE_THEMATIC_BREAK: - BLANKLINE(); - break; - - case CMARK_NODE_PARAGRAPH: - if (!entering) { - BLANKLINE(); - } - break; - - case CMARK_NODE_TEXT: - OUT(cmark_node_get_literal(node), allow_wrap, NORMAL); - break; - - case CMARK_NODE_LINEBREAK: - CR(); - break; - - case CMARK_NODE_SOFTBREAK: - if (CMARK_OPT_HARDBREAKS & options) { - CR(); - } else if (!renderer->no_linebreaks && renderer->width == 0 && - !(CMARK_OPT_HARDBREAKS & options) && - !(CMARK_OPT_NOBREAKS & options)) { - CR(); - } else { - OUT(" ", allow_wrap, LITERAL); - } - break; - - case CMARK_NODE_CODE: - OUT(cmark_node_get_literal(node), allow_wrap, LITERAL); - break; - - case CMARK_NODE_HTML_INLINE: - break; - - case CMARK_NODE_CUSTOM_INLINE: - break; - - case CMARK_NODE_STRONG: - break; - - case CMARK_NODE_EMPH: - break; - - case CMARK_NODE_LINK: - break; - - case CMARK_NODE_IMAGE: - break; - - case CMARK_NODE_FOOTNOTE_REFERENCE: - if (entering) { - LIT("[^"); - OUT(cmark_chunk_to_cstr(renderer->mem, &node->as.literal), false, LITERAL); - LIT("]"); - } - break; - - case CMARK_NODE_FOOTNOTE_DEFINITION: - if (entering) { - renderer->footnote_ix += 1; - LIT("[^"); - char n[32]; - snprintf(n, sizeof(n), "%d", renderer->footnote_ix); - OUT(n, false, LITERAL); - LIT("]: "); - - cmark_strbuf_puts(renderer->prefix, " "); - } else { - cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 4); - } - break; - default: - assert(false); - break; - } - - return 1; -} - -char *cmark_render_plaintext(cmark_node *root, int options, int width) { - return cmark_render_plaintext_with_mem(root, options, width, cmark_node_mem(root)); -} - -char *cmark_render_plaintext_with_mem(cmark_node *root, int options, int width, cmark_mem *mem) { - if (options & CMARK_OPT_HARDBREAKS) { - // disable breaking on width, since it has - // a different meaning with OPT_HARDBREAKS - width = 0; - } - return cmark_render(mem, root, options, width, outc, S_render_node); -} diff --git a/ext/commonmarker/plugin.c b/ext/commonmarker/plugin.c deleted file mode 100644 index 3992fe19..00000000 --- a/ext/commonmarker/plugin.c +++ /dev/null @@ -1,36 +0,0 @@ -#include - -#include "plugin.h" - -extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR; - -int cmark_plugin_register_syntax_extension(cmark_plugin * plugin, - cmark_syntax_extension * extension) { - plugin->syntax_extensions = cmark_llist_append(&CMARK_DEFAULT_MEM_ALLOCATOR, plugin->syntax_extensions, extension); - return 1; -} - -cmark_plugin * -cmark_plugin_new(void) { - cmark_plugin *res = (cmark_plugin *) CMARK_DEFAULT_MEM_ALLOCATOR.calloc(1, sizeof(cmark_plugin)); - - res->syntax_extensions = NULL; - - return res; -} - -void -cmark_plugin_free(cmark_plugin *plugin) { - cmark_llist_free_full(&CMARK_DEFAULT_MEM_ALLOCATOR, - plugin->syntax_extensions, - (cmark_free_func) cmark_syntax_extension_free); - CMARK_DEFAULT_MEM_ALLOCATOR.free(plugin); -} - -cmark_llist * -cmark_plugin_steal_syntax_extensions(cmark_plugin *plugin) { - cmark_llist *res = plugin->syntax_extensions; - - plugin->syntax_extensions = NULL; - return res; -} diff --git a/ext/commonmarker/plugin.h b/ext/commonmarker/plugin.h deleted file mode 100644 index 7bcbd19a..00000000 --- a/ext/commonmarker/plugin.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CMARK_PLUGIN_H -#define CMARK_PLUGIN_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmark-gfm.h" -#include "cmark-gfm-extension_api.h" - -/** - * cmark_plugin: - * - * A plugin structure, which should be filled by plugin's - * init functions. - */ -struct cmark_plugin { - cmark_llist *syntax_extensions; -}; - -cmark_llist * -cmark_plugin_steal_syntax_extensions(cmark_plugin *plugin); - -cmark_plugin * -cmark_plugin_new(void); - -void -cmark_plugin_free(cmark_plugin *plugin); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/references.c b/ext/commonmarker/references.c deleted file mode 100644 index 7e7f34b3..00000000 --- a/ext/commonmarker/references.c +++ /dev/null @@ -1,42 +0,0 @@ -#include "cmark-gfm.h" -#include "parser.h" -#include "references.h" -#include "inlines.h" -#include "chunk.h" - -static void reference_free(cmark_map *map, cmark_map_entry *_ref) { - cmark_reference *ref = (cmark_reference *)_ref; - cmark_mem *mem = map->mem; - if (ref != NULL) { - mem->free(ref->entry.label); - cmark_chunk_free(mem, &ref->url); - cmark_chunk_free(mem, &ref->title); - mem->free(ref); - } -} - -void cmark_reference_create(cmark_map *map, cmark_chunk *label, - cmark_chunk *url, cmark_chunk *title) { - cmark_reference *ref; - unsigned char *reflabel = normalize_map_label(map->mem, label); - - /* empty reference name, or composed from only whitespace */ - if (reflabel == NULL) - return; - - assert(map->sorted == NULL); - - ref = (cmark_reference *)map->mem->calloc(1, sizeof(*ref)); - ref->entry.label = reflabel; - ref->url = cmark_clean_url(map->mem, url); - ref->title = cmark_clean_title(map->mem, title); - ref->entry.age = map->size; - ref->entry.next = map->refs; - - map->refs = (cmark_map_entry *)ref; - map->size++; -} - -cmark_map *cmark_reference_map_new(cmark_mem *mem) { - return cmark_map_new(mem, reference_free); -} diff --git a/ext/commonmarker/references.h b/ext/commonmarker/references.h deleted file mode 100644 index def944dc..00000000 --- a/ext/commonmarker/references.h +++ /dev/null @@ -1,26 +0,0 @@ -#ifndef CMARK_REFERENCES_H -#define CMARK_REFERENCES_H - -#include "map.h" - -#ifdef __cplusplus -extern "C" { -#endif - -struct cmark_reference { - cmark_map_entry entry; - cmark_chunk url; - cmark_chunk title; -}; - -typedef struct cmark_reference cmark_reference; - -void cmark_reference_create(cmark_map *map, cmark_chunk *label, - cmark_chunk *url, cmark_chunk *title); -cmark_map *cmark_reference_map_new(cmark_mem *mem); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/registry.c b/ext/commonmarker/registry.c deleted file mode 100644 index f4f2040d..00000000 --- a/ext/commonmarker/registry.c +++ /dev/null @@ -1,63 +0,0 @@ -#include -#include -#include - -#include "config.h" -#include "cmark-gfm.h" -#include "syntax_extension.h" -#include "registry.h" -#include "plugin.h" - -extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR; - -static cmark_llist *syntax_extensions = NULL; - -void cmark_register_plugin(cmark_plugin_init_func reg_fn) { - cmark_plugin *plugin = cmark_plugin_new(); - - if (!reg_fn(plugin)) { - cmark_plugin_free(plugin); - return; - } - - cmark_llist *syntax_extensions_list = cmark_plugin_steal_syntax_extensions(plugin), - *it; - - for (it = syntax_extensions_list; it; it = it->next) { - syntax_extensions = cmark_llist_append(&CMARK_DEFAULT_MEM_ALLOCATOR, syntax_extensions, it->data); - } - - cmark_llist_free(&CMARK_DEFAULT_MEM_ALLOCATOR, syntax_extensions_list); - cmark_plugin_free(plugin); -} - -void cmark_release_plugins(void) { - if (syntax_extensions) { - cmark_llist_free_full( - &CMARK_DEFAULT_MEM_ALLOCATOR, - syntax_extensions, - (cmark_free_func) cmark_syntax_extension_free); - syntax_extensions = NULL; - } -} - -cmark_llist *cmark_list_syntax_extensions(cmark_mem *mem) { - cmark_llist *it; - cmark_llist *res = NULL; - - for (it = syntax_extensions; it; it = it->next) { - res = cmark_llist_append(mem, res, it->data); - } - return res; -} - -cmark_syntax_extension *cmark_find_syntax_extension(const char *name) { - cmark_llist *tmp; - - for (tmp = syntax_extensions; tmp; tmp = tmp->next) { - cmark_syntax_extension *ext = (cmark_syntax_extension *) tmp->data; - if (!strcmp(ext->name, name)) - return ext; - } - return NULL; -} diff --git a/ext/commonmarker/registry.h b/ext/commonmarker/registry.h deleted file mode 100644 index fece2b63..00000000 --- a/ext/commonmarker/registry.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef CMARK_REGISTRY_H -#define CMARK_REGISTRY_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "cmark-gfm.h" -#include "plugin.h" - -CMARK_GFM_EXPORT -void cmark_register_plugin(cmark_plugin_init_func reg_fn); - -CMARK_GFM_EXPORT -void cmark_release_plugins(void); - -CMARK_GFM_EXPORT -cmark_llist *cmark_list_syntax_extensions(cmark_mem *mem); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/render.c b/ext/commonmarker/render.c deleted file mode 100644 index 02e9e838..00000000 --- a/ext/commonmarker/render.c +++ /dev/null @@ -1,205 +0,0 @@ -#include -#include "buffer.h" -#include "chunk.h" -#include "cmark-gfm.h" -#include "utf8.h" -#include "render.h" -#include "node.h" -#include "syntax_extension.h" - -static CMARK_INLINE void S_cr(cmark_renderer *renderer) { - if (renderer->need_cr < 1) { - renderer->need_cr = 1; - } -} - -static CMARK_INLINE void S_blankline(cmark_renderer *renderer) { - if (renderer->need_cr < 2) { - renderer->need_cr = 2; - } -} - -static void S_out(cmark_renderer *renderer, cmark_node *node, - const char *source, bool wrap, - cmark_escaping escape) { - int length = (int)strlen(source); - unsigned char nextc; - int32_t c; - int i = 0; - int last_nonspace; - int len; - cmark_chunk remainder = cmark_chunk_literal(""); - int k = renderer->buffer->size - 1; - - cmark_syntax_extension *ext = NULL; - cmark_node *n = node; - while (n && !ext) { - ext = n->extension; - if (!ext) - n = n->parent; - } - if (ext && !ext->commonmark_escape_func) - ext = NULL; - - wrap = wrap && !renderer->no_linebreaks; - - if (renderer->in_tight_list_item && renderer->need_cr > 1) { - renderer->need_cr = 1; - } - while (renderer->need_cr) { - if (k < 0 || renderer->buffer->ptr[k] == '\n') { - k -= 1; - } else { - cmark_strbuf_putc(renderer->buffer, '\n'); - if (renderer->need_cr > 1) { - cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr, - renderer->prefix->size); - } - } - renderer->column = 0; - renderer->last_breakable = 0; - renderer->begin_line = true; - renderer->begin_content = true; - renderer->need_cr -= 1; - } - - while (i < length) { - if (renderer->begin_line) { - cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr, - renderer->prefix->size); - // note: this assumes prefix is ascii: - renderer->column = renderer->prefix->size; - } - - len = cmark_utf8proc_iterate((const uint8_t *)source + i, length - i, &c); - if (len == -1) { // error condition - return; // return without rendering rest of string - } - - if (ext && ext->commonmark_escape_func(ext, node, c)) - cmark_strbuf_putc(renderer->buffer, '\\'); - - nextc = source[i + len]; - if (c == 32 && wrap) { - if (!renderer->begin_line) { - last_nonspace = renderer->buffer->size; - cmark_strbuf_putc(renderer->buffer, ' '); - renderer->column += 1; - renderer->begin_line = false; - renderer->begin_content = false; - // skip following spaces - while (source[i + 1] == ' ') { - i++; - } - // We don't allow breaks that make a digit the first character - // because this causes problems with commonmark output. - if (!cmark_isdigit(source[i + 1])) { - renderer->last_breakable = last_nonspace; - } - } - - } else if (escape == LITERAL) { - if (c == 10) { - cmark_strbuf_putc(renderer->buffer, '\n'); - renderer->column = 0; - renderer->begin_line = true; - renderer->begin_content = true; - renderer->last_breakable = 0; - } else { - cmark_render_code_point(renderer, c); - renderer->begin_line = false; - // we don't set 'begin_content' to false til we've - // finished parsing a digit. Reason: in commonmark - // we need to escape a potential list marker after - // a digit: - renderer->begin_content = - renderer->begin_content && cmark_isdigit((char)c) == 1; - } - } else { - (renderer->outc)(renderer, node, escape, c, nextc); - renderer->begin_line = false; - renderer->begin_content = - renderer->begin_content && cmark_isdigit((char)c) == 1; - } - - // If adding the character went beyond width, look for an - // earlier place where the line could be broken: - if (renderer->width > 0 && renderer->column > renderer->width && - !renderer->begin_line && renderer->last_breakable > 0) { - - // copy from last_breakable to remainder - cmark_chunk_set_cstr(renderer->mem, &remainder, - (char *)renderer->buffer->ptr + - renderer->last_breakable + 1); - // truncate at last_breakable - cmark_strbuf_truncate(renderer->buffer, renderer->last_breakable); - // add newline, prefix, and remainder - cmark_strbuf_putc(renderer->buffer, '\n'); - cmark_strbuf_put(renderer->buffer, renderer->prefix->ptr, - renderer->prefix->size); - cmark_strbuf_put(renderer->buffer, remainder.data, remainder.len); - renderer->column = renderer->prefix->size + remainder.len; - cmark_chunk_free(renderer->mem, &remainder); - renderer->last_breakable = 0; - renderer->begin_line = false; - renderer->begin_content = false; - } - - i += len; - } -} - -// Assumes no newlines, assumes ascii content: -void cmark_render_ascii(cmark_renderer *renderer, const char *s) { - int origsize = renderer->buffer->size; - cmark_strbuf_puts(renderer->buffer, s); - renderer->column += renderer->buffer->size - origsize; -} - -void cmark_render_code_point(cmark_renderer *renderer, uint32_t c) { - cmark_utf8proc_encode_char(c, renderer->buffer); - renderer->column += 1; -} - -char *cmark_render(cmark_mem *mem, cmark_node *root, int options, int width, - void (*outc)(cmark_renderer *, cmark_node *, - cmark_escaping, int32_t, - unsigned char), - int (*render_node)(cmark_renderer *renderer, - cmark_node *node, - cmark_event_type ev_type, int options)) { - cmark_strbuf pref = CMARK_BUF_INIT(mem); - cmark_strbuf buf = CMARK_BUF_INIT(mem); - cmark_node *cur; - cmark_event_type ev_type; - char *result; - cmark_iter *iter = cmark_iter_new(root); - - cmark_renderer renderer = {mem, &buf, &pref, 0, width, - 0, 0, true, true, false, - false, outc, S_cr, S_blankline, S_out, - 0}; - - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - if (!render_node(&renderer, cur, ev_type, options)) { - // a false value causes us to skip processing - // the node's contents. this is used for - // autolinks. - cmark_iter_reset(iter, cur, CMARK_EVENT_EXIT); - } - } - - // ensure final newline - if (renderer.buffer->size == 0 || renderer.buffer->ptr[renderer.buffer->size - 1] != '\n') { - cmark_strbuf_putc(renderer.buffer, '\n'); - } - - result = (char *)cmark_strbuf_detach(renderer.buffer); - - cmark_iter_free(iter); - cmark_strbuf_free(renderer.prefix); - cmark_strbuf_free(renderer.buffer); - - return result; -} diff --git a/ext/commonmarker/render.h b/ext/commonmarker/render.h deleted file mode 100644 index 4a68d1e0..00000000 --- a/ext/commonmarker/render.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef CMARK_RENDER_H -#define CMARK_RENDER_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include -#include "buffer.h" -#include "chunk.h" - -typedef enum { LITERAL, NORMAL, TITLE, URL } cmark_escaping; - -struct cmark_renderer { - cmark_mem *mem; - cmark_strbuf *buffer; - cmark_strbuf *prefix; - int column; - int width; - int need_cr; - bufsize_t last_breakable; - bool begin_line; - bool begin_content; - bool no_linebreaks; - bool in_tight_list_item; - void (*outc)(struct cmark_renderer *, cmark_node *, cmark_escaping, int32_t, unsigned char); - void (*cr)(struct cmark_renderer *); - void (*blankline)(struct cmark_renderer *); - void (*out)(struct cmark_renderer *, cmark_node *, const char *, bool, cmark_escaping); - unsigned int footnote_ix; -}; - -typedef struct cmark_renderer cmark_renderer; - -struct cmark_html_renderer { - cmark_strbuf *html; - cmark_node *plain; - cmark_llist *filter_extensions; - unsigned int footnote_ix; - unsigned int written_footnote_ix; - void *opaque; -}; - -typedef struct cmark_html_renderer cmark_html_renderer; - -void cmark_render_ascii(cmark_renderer *renderer, const char *s); - -void cmark_render_code_point(cmark_renderer *renderer, uint32_t c); - -char *cmark_render(cmark_mem *mem, cmark_node *root, int options, int width, - void (*outc)(cmark_renderer *, cmark_node *, - cmark_escaping, int32_t, - unsigned char), - int (*render_node)(cmark_renderer *renderer, - cmark_node *node, - cmark_event_type ev_type, int options)); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/scanners.c b/ext/commonmarker/scanners.c deleted file mode 100644 index 285b7a31..00000000 --- a/ext/commonmarker/scanners.c +++ /dev/null @@ -1,10508 +0,0 @@ -/* Generated by re2c 1.3 */ -#include -#include "chunk.h" -#include "scanners.h" - -bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c, bufsize_t offset) -{ - bufsize_t res; - unsigned char *ptr = (unsigned char *)c->data; - - if (ptr == NULL || offset > c->len) { - return 0; - } else { - unsigned char lim = ptr[c->len]; - - ptr[c->len] = '\0'; - res = scanner(ptr + offset); - ptr[c->len] = lim; - } - - return res; -} - - - -// Try to match a scheme including colon. -bufsize_t _scan_scheme(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - yych = *p; - if (yych <= '@') goto yy2; - if (yych <= 'Z') goto yy4; - if (yych <= '`') goto yy2; - if (yych <= 'z') goto yy4; -yy2: - ++p; -yy3: - { return 0; } -yy4: - yych = *(marker = ++p); - if (yych <= '/') { - if (yych <= '+') { - if (yych <= '*') goto yy3; - } else { - if (yych <= ',') goto yy3; - if (yych >= '/') goto yy3; - } - } else { - if (yych <= 'Z') { - if (yych <= '9') goto yy5; - if (yych <= '@') goto yy3; - } else { - if (yych <= '`') goto yy3; - if (yych >= '{') goto yy3; - } - } -yy5: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych == '+') goto yy7; - } else { - if (yych != '/') goto yy7; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych >= 'A') goto yy7; - } else { - if (yych <= '`') goto yy6; - if (yych <= 'z') goto yy7; - } - } -yy6: - p = marker; - goto yy3; -yy7: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych == '+') goto yy10; - goto yy6; - } else { - if (yych == '/') goto yy6; - goto yy10; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - goto yy10; - } else { - if (yych <= '`') goto yy6; - if (yych <= 'z') goto yy10; - goto yy6; - } - } -yy8: - ++p; - { return (bufsize_t)(p - start); } -yy10: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy6; - } else { - if (yych == '/') goto yy6; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy8; - if (yych <= '@') goto yy6; - } else { - if (yych <= '`') goto yy6; - if (yych >= '{') goto yy6; - } - } - yych = *++p; - if (yych == ':') goto yy8; - goto yy6; -} - -} - -// Try to match URI autolink after first <, returning number of chars matched. -bufsize_t _scan_autolink_uri(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 0, 128, 0, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= '@') goto yy41; - if (yych <= 'Z') goto yy43; - if (yych <= '`') goto yy41; - if (yych <= 'z') goto yy43; -yy41: - ++p; -yy42: - { return 0; } -yy43: - yych = *(marker = ++p); - if (yych <= '/') { - if (yych <= '+') { - if (yych <= '*') goto yy42; - } else { - if (yych <= ',') goto yy42; - if (yych >= '/') goto yy42; - } - } else { - if (yych <= 'Z') { - if (yych <= '9') goto yy44; - if (yych <= '@') goto yy42; - } else { - if (yych <= '`') goto yy42; - if (yych >= '{') goto yy42; - } - } -yy44: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych == '+') goto yy46; - } else { - if (yych != '/') goto yy46; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych >= 'A') goto yy46; - } else { - if (yych <= '`') goto yy45; - if (yych <= 'z') goto yy46; - } - } -yy45: - p = marker; - goto yy42; -yy46: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych == '+') goto yy49; - goto yy45; - } else { - if (yych == '/') goto yy45; - goto yy49; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - goto yy49; - } else { - if (yych <= '`') goto yy45; - if (yych <= 'z') goto yy49; - goto yy45; - } - } -yy47: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy47; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '<') goto yy45; - if (yych <= '>') goto yy50; - goto yy45; - } else { - if (yych <= 0xDF) goto yy52; - if (yych <= 0xE0) goto yy53; - goto yy54; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy55; - if (yych <= 0xEF) goto yy54; - goto yy56; - } else { - if (yych <= 0xF3) goto yy57; - if (yych <= 0xF4) goto yy58; - goto yy45; - } - } -yy49: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych == '+') goto yy59; - goto yy45; - } else { - if (yych == '/') goto yy45; - goto yy59; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - goto yy59; - } else { - if (yych <= '`') goto yy45; - if (yych <= 'z') goto yy59; - goto yy45; - } - } -yy50: - ++p; - { return (bufsize_t)(p - start); } -yy52: - yych = *++p; - if (yych <= 0x7F) goto yy45; - if (yych <= 0xBF) goto yy47; - goto yy45; -yy53: - yych = *++p; - if (yych <= 0x9F) goto yy45; - if (yych <= 0xBF) goto yy52; - goto yy45; -yy54: - yych = *++p; - if (yych <= 0x7F) goto yy45; - if (yych <= 0xBF) goto yy52; - goto yy45; -yy55: - yych = *++p; - if (yych <= 0x7F) goto yy45; - if (yych <= 0x9F) goto yy52; - goto yy45; -yy56: - yych = *++p; - if (yych <= 0x8F) goto yy45; - if (yych <= 0xBF) goto yy54; - goto yy45; -yy57: - yych = *++p; - if (yych <= 0x7F) goto yy45; - if (yych <= 0xBF) goto yy54; - goto yy45; -yy58: - yych = *++p; - if (yych <= 0x7F) goto yy45; - if (yych <= 0x8F) goto yy54; - goto yy45; -yy59: - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych <= '9') { - if (yych <= ',') { - if (yych != '+') goto yy45; - } else { - if (yych == '/') goto yy45; - } - } else { - if (yych <= 'Z') { - if (yych <= ':') goto yy47; - if (yych <= '@') goto yy45; - } else { - if (yych <= '`') goto yy45; - if (yych >= '{') goto yy45; - } - } - yych = *++p; - if (yych == ':') goto yy47; - goto yy45; -} - -} - -// Try to match email autolink after first <, returning num of chars matched. -bufsize_t _scan_autolink_email(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 0, 128, 128, 128, 128, 128, - 0, 0, 128, 128, 0, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 0, 0, 0, 128, 0, 128, - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 0, 0, 0, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= '9') { - if (yych <= '\'') { - if (yych == '!') goto yy91; - if (yych >= '#') goto yy91; - } else { - if (yych <= ')') goto yy89; - if (yych != ',') goto yy91; - } - } else { - if (yych <= '?') { - if (yych == '=') goto yy91; - if (yych >= '?') goto yy91; - } else { - if (yych <= 'Z') { - if (yych >= 'A') goto yy91; - } else { - if (yych <= ']') goto yy89; - if (yych <= '~') goto yy91; - } - } - } -yy89: - ++p; -yy90: - { return 0; } -yy91: - yych = *(marker = ++p); - if (yych <= ',') { - if (yych <= '"') { - if (yych == '!') goto yy93; - goto yy90; - } else { - if (yych <= '\'') goto yy93; - if (yych <= ')') goto yy90; - if (yych <= '+') goto yy93; - goto yy90; - } - } else { - if (yych <= '>') { - if (yych <= '9') goto yy93; - if (yych == '=') goto yy93; - goto yy90; - } else { - if (yych <= 'Z') goto yy93; - if (yych <= ']') goto yy90; - if (yych <= '~') goto yy93; - goto yy90; - } - } -yy92: - yych = *++p; -yy93: - if (yybm[0+yych] & 128) { - goto yy92; - } - if (yych <= '>') goto yy94; - if (yych <= '@') goto yy95; -yy94: - p = marker; - goto yy90; -yy95: - yych = *++p; - if (yych <= '@') { - if (yych <= '/') goto yy94; - if (yych >= ':') goto yy94; - } else { - if (yych <= 'Z') goto yy96; - if (yych <= '`') goto yy94; - if (yych >= '{') goto yy94; - } -yy96: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy98; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy98; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy98; - goto yy94; - } - } - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy101; - if (yych <= '/') goto yy94; - goto yy102; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy102; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy102; - goto yy94; - } - } -yy98: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych <= '-') goto yy101; - goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy102; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy102; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy102; - goto yy94; - } - } -yy99: - ++p; - { return (bufsize_t)(p - start); } -yy101: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy103; - if (yych <= '/') goto yy94; - goto yy104; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy104; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy104; - goto yy94; - } - } -yy102: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy104; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy104; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy104; - goto yy94; - } - } -yy103: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy105; - if (yych <= '/') goto yy94; - goto yy106; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy106; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy106; - goto yy94; - } - } -yy104: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy106; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy106; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy106; - goto yy94; - } - } -yy105: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy107; - if (yych <= '/') goto yy94; - goto yy108; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy108; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy108; - goto yy94; - } - } -yy106: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy108; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy108; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy108; - goto yy94; - } - } -yy107: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy109; - if (yych <= '/') goto yy94; - goto yy110; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy110; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy110; - goto yy94; - } - } -yy108: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy110; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy110; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy110; - goto yy94; - } - } -yy109: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy111; - if (yych <= '/') goto yy94; - goto yy112; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy112; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy112; - goto yy94; - } - } -yy110: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy112; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy112; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy112; - goto yy94; - } - } -yy111: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy113; - if (yych <= '/') goto yy94; - goto yy114; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy114; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy114; - goto yy94; - } - } -yy112: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy114; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy114; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy114; - goto yy94; - } - } -yy113: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy115; - if (yych <= '/') goto yy94; - goto yy116; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy116; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy116; - goto yy94; - } - } -yy114: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy116; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy116; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy116; - goto yy94; - } - } -yy115: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy117; - if (yych <= '/') goto yy94; - goto yy118; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy118; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy118; - goto yy94; - } - } -yy116: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy118; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy118; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy118; - goto yy94; - } - } -yy117: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy119; - if (yych <= '/') goto yy94; - goto yy120; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy120; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy120; - goto yy94; - } - } -yy118: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy120; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy120; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy120; - goto yy94; - } - } -yy119: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy121; - if (yych <= '/') goto yy94; - goto yy122; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy122; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy122; - goto yy94; - } - } -yy120: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy122; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy122; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy122; - goto yy94; - } - } -yy121: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy123; - if (yych <= '/') goto yy94; - goto yy124; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy124; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy124; - goto yy94; - } - } -yy122: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy124; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy124; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy124; - goto yy94; - } - } -yy123: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy125; - if (yych <= '/') goto yy94; - goto yy126; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy126; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy126; - goto yy94; - } - } -yy124: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy126; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy126; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy126; - goto yy94; - } - } -yy125: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy127; - if (yych <= '/') goto yy94; - goto yy128; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy128; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy128; - goto yy94; - } - } -yy126: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy128; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy128; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy128; - goto yy94; - } - } -yy127: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy129; - if (yych <= '/') goto yy94; - goto yy130; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy130; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy130; - goto yy94; - } - } -yy128: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy130; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy130; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy130; - goto yy94; - } - } -yy129: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy131; - if (yych <= '/') goto yy94; - goto yy132; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy132; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy132; - goto yy94; - } - } -yy130: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy132; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy132; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy132; - goto yy94; - } - } -yy131: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy133; - if (yych <= '/') goto yy94; - goto yy134; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy134; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy134; - goto yy94; - } - } -yy132: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy134; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy134; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy134; - goto yy94; - } - } -yy133: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy135; - if (yych <= '/') goto yy94; - goto yy136; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy136; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy136; - goto yy94; - } - } -yy134: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy136; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy136; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy136; - goto yy94; - } - } -yy135: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy137; - if (yych <= '/') goto yy94; - goto yy138; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy138; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy138; - goto yy94; - } - } -yy136: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy138; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy138; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy138; - goto yy94; - } - } -yy137: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy139; - if (yych <= '/') goto yy94; - goto yy140; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy140; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy140; - goto yy94; - } - } -yy138: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy140; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy140; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy140; - goto yy94; - } - } -yy139: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy141; - if (yych <= '/') goto yy94; - goto yy142; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy142; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy142; - goto yy94; - } - } -yy140: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy142; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy142; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy142; - goto yy94; - } - } -yy141: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy143; - if (yych <= '/') goto yy94; - goto yy144; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy144; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy144; - goto yy94; - } - } -yy142: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy144; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy144; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy144; - goto yy94; - } - } -yy143: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy145; - if (yych <= '/') goto yy94; - goto yy146; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy146; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy146; - goto yy94; - } - } -yy144: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy146; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy146; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy146; - goto yy94; - } - } -yy145: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy147; - if (yych <= '/') goto yy94; - goto yy148; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy148; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy148; - goto yy94; - } - } -yy146: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy148; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy148; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy148; - goto yy94; - } - } -yy147: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy149; - if (yych <= '/') goto yy94; - goto yy150; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy150; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy150; - goto yy94; - } - } -yy148: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy150; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy150; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy150; - goto yy94; - } - } -yy149: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy151; - if (yych <= '/') goto yy94; - goto yy152; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy152; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy152; - goto yy94; - } - } -yy150: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy152; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy152; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy152; - goto yy94; - } - } -yy151: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy153; - if (yych <= '/') goto yy94; - goto yy154; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy154; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy154; - goto yy94; - } - } -yy152: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy154; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy154; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy154; - goto yy94; - } - } -yy153: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy155; - if (yych <= '/') goto yy94; - goto yy156; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy156; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy156; - goto yy94; - } - } -yy154: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy156; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy156; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy156; - goto yy94; - } - } -yy155: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy157; - if (yych <= '/') goto yy94; - goto yy158; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy158; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy158; - goto yy94; - } - } -yy156: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy158; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy158; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy158; - goto yy94; - } - } -yy157: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy159; - if (yych <= '/') goto yy94; - goto yy160; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy160; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy160; - goto yy94; - } - } -yy158: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy160; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy160; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy160; - goto yy94; - } - } -yy159: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy161; - if (yych <= '/') goto yy94; - goto yy162; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy162; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy162; - goto yy94; - } - } -yy160: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy162; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy162; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy162; - goto yy94; - } - } -yy161: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy163; - if (yych <= '/') goto yy94; - goto yy164; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy164; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy164; - goto yy94; - } - } -yy162: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy164; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy164; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy164; - goto yy94; - } - } -yy163: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy165; - if (yych <= '/') goto yy94; - goto yy166; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy166; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy166; - goto yy94; - } - } -yy164: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy166; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy166; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy166; - goto yy94; - } - } -yy165: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy167; - if (yych <= '/') goto yy94; - goto yy168; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy168; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy168; - goto yy94; - } - } -yy166: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy168; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy168; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy168; - goto yy94; - } - } -yy167: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy169; - if (yych <= '/') goto yy94; - goto yy170; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy170; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy170; - goto yy94; - } - } -yy168: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy170; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy170; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy170; - goto yy94; - } - } -yy169: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy171; - if (yych <= '/') goto yy94; - goto yy172; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy172; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy172; - goto yy94; - } - } -yy170: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy172; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy172; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy172; - goto yy94; - } - } -yy171: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy173; - if (yych <= '/') goto yy94; - goto yy174; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy174; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy174; - goto yy94; - } - } -yy172: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy174; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy174; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy174; - goto yy94; - } - } -yy173: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy175; - if (yych <= '/') goto yy94; - goto yy176; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy176; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy176; - goto yy94; - } - } -yy174: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy176; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy176; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy176; - goto yy94; - } - } -yy175: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy177; - if (yych <= '/') goto yy94; - goto yy178; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy178; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy178; - goto yy94; - } - } -yy176: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy178; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy178; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy178; - goto yy94; - } - } -yy177: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy179; - if (yych <= '/') goto yy94; - goto yy180; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy180; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy180; - goto yy94; - } - } -yy178: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy180; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy180; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy180; - goto yy94; - } - } -yy179: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy181; - if (yych <= '/') goto yy94; - goto yy182; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy182; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy182; - goto yy94; - } - } -yy180: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy182; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy182; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy182; - goto yy94; - } - } -yy181: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy183; - if (yych <= '/') goto yy94; - goto yy184; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy184; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy184; - goto yy94; - } - } -yy182: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy184; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy184; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy184; - goto yy94; - } - } -yy183: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy185; - if (yych <= '/') goto yy94; - goto yy186; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy186; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy186; - goto yy94; - } - } -yy184: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy186; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy186; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy186; - goto yy94; - } - } -yy185: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy187; - if (yych <= '/') goto yy94; - goto yy188; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy188; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy188; - goto yy94; - } - } -yy186: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy188; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy188; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy188; - goto yy94; - } - } -yy187: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy189; - if (yych <= '/') goto yy94; - goto yy190; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy190; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy190; - goto yy94; - } - } -yy188: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy190; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy190; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy190; - goto yy94; - } - } -yy189: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy191; - if (yych <= '/') goto yy94; - goto yy192; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy192; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy192; - goto yy94; - } - } -yy190: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy192; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy192; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy192; - goto yy94; - } - } -yy191: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy193; - if (yych <= '/') goto yy94; - goto yy194; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy194; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy194; - goto yy94; - } - } -yy192: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy194; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy194; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy194; - goto yy94; - } - } -yy193: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy195; - if (yych <= '/') goto yy94; - goto yy196; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy196; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy196; - goto yy94; - } - } -yy194: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy196; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy196; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy196; - goto yy94; - } - } -yy195: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy197; - if (yych <= '/') goto yy94; - goto yy198; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy198; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy198; - goto yy94; - } - } -yy196: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy198; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy198; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy198; - goto yy94; - } - } -yy197: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy199; - if (yych <= '/') goto yy94; - goto yy200; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy200; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy200; - goto yy94; - } - } -yy198: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy200; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy200; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy200; - goto yy94; - } - } -yy199: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy201; - if (yych <= '/') goto yy94; - goto yy202; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy202; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy202; - goto yy94; - } - } -yy200: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy202; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy202; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy202; - goto yy94; - } - } -yy201: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy203; - if (yych <= '/') goto yy94; - goto yy204; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy204; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy204; - goto yy94; - } - } -yy202: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy204; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy204; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy204; - goto yy94; - } - } -yy203: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy205; - if (yych <= '/') goto yy94; - goto yy206; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy206; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy206; - goto yy94; - } - } -yy204: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy206; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy206; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy206; - goto yy94; - } - } -yy205: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy207; - if (yych <= '/') goto yy94; - goto yy208; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy208; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy208; - goto yy94; - } - } -yy206: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy208; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy208; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy208; - goto yy94; - } - } -yy207: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy209; - if (yych <= '/') goto yy94; - goto yy210; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy210; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy210; - goto yy94; - } - } -yy208: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy210; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy210; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy210; - goto yy94; - } - } -yy209: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy211; - if (yych <= '/') goto yy94; - goto yy212; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy212; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy212; - goto yy94; - } - } -yy210: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy212; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy212; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy212; - goto yy94; - } - } -yy211: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy213; - if (yych <= '/') goto yy94; - goto yy214; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy214; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy214; - goto yy94; - } - } -yy212: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy214; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy214; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy214; - goto yy94; - } - } -yy213: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy215; - if (yych <= '/') goto yy94; - goto yy216; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy216; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy216; - goto yy94; - } - } -yy214: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy216; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy216; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy216; - goto yy94; - } - } -yy215: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy217; - if (yych <= '/') goto yy94; - goto yy218; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy218; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy218; - goto yy94; - } - } -yy216: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy218; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy218; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy218; - goto yy94; - } - } -yy217: - yych = *++p; - if (yych <= '9') { - if (yych == '-') goto yy219; - if (yych <= '/') goto yy94; - goto yy220; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy94; - goto yy220; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy220; - goto yy94; - } - } -yy218: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= ',') goto yy94; - if (yych >= '.') goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy220; - goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - goto yy220; - } else { - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy220; - goto yy94; - } - } -yy219: - yych = *++p; - if (yych <= '@') { - if (yych <= '/') goto yy94; - if (yych <= '9') goto yy221; - goto yy94; - } else { - if (yych <= 'Z') goto yy221; - if (yych <= '`') goto yy94; - if (yych <= 'z') goto yy221; - goto yy94; - } -yy220: - yych = *++p; - if (yych <= '=') { - if (yych <= '.') { - if (yych <= '-') goto yy94; - goto yy95; - } else { - if (yych <= '/') goto yy94; - if (yych >= ':') goto yy94; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy99; - if (yych <= '@') goto yy94; - } else { - if (yych <= '`') goto yy94; - if (yych >= '{') goto yy94; - } - } -yy221: - yych = *++p; - if (yych == '.') goto yy95; - if (yych == '>') goto yy99; - goto yy94; -} - -} - -// Try to match an HTML tag after first <, returning num of chars matched. -bufsize_t _scan_html_tag(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - /* table 1 .. 8: 0 */ - 0, 250, 250, 250, 250, 250, 250, 250, - 250, 235, 235, 235, 235, 235, 250, 250, - 250, 250, 250, 250, 250, 250, 250, 250, - 250, 250, 250, 250, 250, 250, 250, 250, - 235, 250, 202, 250, 250, 250, 250, 170, - 250, 250, 250, 250, 250, 246, 254, 250, - 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 250, 234, 234, 232, 250, - 250, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 250, 250, 122, 250, 254, - 234, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 254, 254, 254, 254, 254, - 254, 254, 254, 250, 250, 250, 250, 250, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - /* table 9 .. 11: 256 */ - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 192, 128, 128, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 128, 128, 128, 128, 128, 0, - 128, 224, 224, 224, 224, 224, 224, 224, - 224, 224, 224, 224, 224, 224, 224, 224, - 224, 224, 224, 224, 224, 224, 224, 224, - 224, 224, 224, 128, 128, 128, 128, 128, - 128, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 128, 128, 128, 128, 128, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= '>') { - if (yych <= '!') { - if (yych >= '!') goto yy226; - } else { - if (yych == '/') goto yy227; - } - } else { - if (yych <= 'Z') { - if (yych <= '?') goto yy228; - if (yych >= 'A') goto yy229; - } else { - if (yych <= '`') goto yy224; - if (yych <= 'z') goto yy229; - } - } -yy224: - ++p; -yy225: - { return 0; } -yy226: - yych = *(marker = ++p); - if (yybm[256+yych] & 32) { - goto yy232; - } - if (yych == '-') goto yy230; - if (yych <= '@') goto yy225; - if (yych <= '[') goto yy234; - goto yy225; -yy227: - yych = *(marker = ++p); - if (yych <= '@') goto yy225; - if (yych <= 'Z') goto yy235; - if (yych <= '`') goto yy225; - if (yych <= 'z') goto yy235; - goto yy225; -yy228: - yych = *(marker = ++p); - if (yych <= 0x00) goto yy225; - if (yych <= 0x7F) goto yy238; - if (yych <= 0xC1) goto yy225; - if (yych <= 0xF4) goto yy238; - goto yy225; -yy229: - yych = *(marker = ++p); - if (yych <= '.') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy225; - if (yych <= '\r') goto yy250; - goto yy225; - } else { - if (yych <= ' ') goto yy250; - if (yych == '-') goto yy250; - goto yy225; - } - } else { - if (yych <= '@') { - if (yych <= '9') goto yy250; - if (yych == '>') goto yy250; - goto yy225; - } else { - if (yych <= 'Z') goto yy250; - if (yych <= '`') goto yy225; - if (yych <= 'z') goto yy250; - goto yy225; - } - } -yy230: - yych = *++p; - if (yych == '-') goto yy254; -yy231: - p = marker; - goto yy225; -yy232: - yych = *++p; - if (yybm[256+yych] & 32) { - goto yy232; - } - if (yych <= 0x08) goto yy231; - if (yych <= '\r') goto yy255; - if (yych == ' ') goto yy255; - goto yy231; -yy234: - yych = *++p; - if (yych == 'C') goto yy257; - if (yych == 'c') goto yy257; - goto yy231; -yy235: - yych = *++p; - if (yybm[256+yych] & 64) { - goto yy235; - } - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy231; - if (yych <= '\r') goto yy258; - goto yy231; - } else { - if (yych <= ' ') goto yy258; - if (yych == '>') goto yy252; - goto yy231; - } -yy237: - yych = *++p; -yy238: - if (yybm[256+yych] & 128) { - goto yy237; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych >= '@') goto yy231; - } else { - if (yych <= 0xDF) goto yy240; - if (yych <= 0xE0) goto yy241; - goto yy242; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy243; - if (yych <= 0xEF) goto yy242; - goto yy244; - } else { - if (yych <= 0xF3) goto yy245; - if (yych <= 0xF4) goto yy246; - goto yy231; - } - } - yych = *++p; - if (yych <= 0xE0) { - if (yych <= '>') { - if (yych <= 0x00) goto yy231; - if (yych <= '=') goto yy237; - goto yy252; - } else { - if (yych <= 0x7F) goto yy237; - if (yych <= 0xC1) goto yy231; - if (yych >= 0xE0) goto yy241; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy243; - goto yy242; - } else { - if (yych <= 0xF0) goto yy244; - if (yych <= 0xF3) goto yy245; - if (yych <= 0xF4) goto yy246; - goto yy231; - } - } -yy240: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy237; - goto yy231; -yy241: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy240; - goto yy231; -yy242: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy240; - goto yy231; -yy243: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy240; - goto yy231; -yy244: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy242; - goto yy231; -yy245: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy242; - goto yy231; -yy246: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy242; - goto yy231; -yy247: - yych = *++p; - if (yybm[0+yych] & 1) { - goto yy247; - } - if (yych <= '>') { - if (yych <= '9') { - if (yych == '/') goto yy251; - goto yy231; - } else { - if (yych <= ':') goto yy260; - if (yych <= '=') goto yy231; - goto yy252; - } - } else { - if (yych <= '^') { - if (yych <= '@') goto yy231; - if (yych <= 'Z') goto yy260; - goto yy231; - } else { - if (yych == '`') goto yy231; - if (yych <= 'z') goto yy260; - goto yy231; - } - } -yy249: - yych = *++p; -yy250: - if (yybm[0+yych] & 1) { - goto yy247; - } - if (yych <= '=') { - if (yych <= '.') { - if (yych == '-') goto yy249; - goto yy231; - } else { - if (yych <= '/') goto yy251; - if (yych <= '9') goto yy249; - goto yy231; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy252; - if (yych <= '@') goto yy231; - goto yy249; - } else { - if (yych <= '`') goto yy231; - if (yych <= 'z') goto yy249; - goto yy231; - } - } -yy251: - yych = *++p; - if (yych != '>') goto yy231; -yy252: - ++p; - { return (bufsize_t)(p - start); } -yy254: - yych = *++p; - if (yych == '-') goto yy264; - if (yych == '>') goto yy231; - goto yy263; -yy255: - yych = *++p; - if (yybm[0+yych] & 2) { - goto yy255; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych <= '>') goto yy252; - goto yy231; - } else { - if (yych <= 0xDF) goto yy272; - if (yych <= 0xE0) goto yy273; - goto yy274; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy275; - if (yych <= 0xEF) goto yy274; - goto yy276; - } else { - if (yych <= 0xF3) goto yy277; - if (yych <= 0xF4) goto yy278; - goto yy231; - } - } -yy257: - yych = *++p; - if (yych == 'D') goto yy279; - if (yych == 'd') goto yy279; - goto yy231; -yy258: - yych = *++p; - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy231; - if (yych <= '\r') goto yy258; - goto yy231; - } else { - if (yych <= ' ') goto yy258; - if (yych == '>') goto yy252; - goto yy231; - } -yy260: - yych = *++p; - if (yybm[0+yych] & 4) { - goto yy260; - } - if (yych <= ',') { - if (yych <= '\r') { - if (yych <= 0x08) goto yy231; - goto yy280; - } else { - if (yych == ' ') goto yy280; - goto yy231; - } - } else { - if (yych <= '<') { - if (yych <= '/') goto yy251; - goto yy231; - } else { - if (yych <= '=') goto yy282; - if (yych <= '>') goto yy252; - goto yy231; - } - } -yy262: - yych = *++p; -yy263: - if (yybm[0+yych] & 8) { - goto yy262; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych <= '-') goto yy284; - goto yy231; - } else { - if (yych <= 0xDF) goto yy265; - if (yych <= 0xE0) goto yy266; - goto yy267; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy268; - if (yych <= 0xEF) goto yy267; - goto yy269; - } else { - if (yych <= 0xF3) goto yy270; - if (yych <= 0xF4) goto yy271; - goto yy231; - } - } -yy264: - yych = *++p; - if (yych == '-') goto yy251; - if (yych == '>') goto yy231; - goto yy263; -yy265: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy262; - goto yy231; -yy266: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy265; - goto yy231; -yy267: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy265; - goto yy231; -yy268: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy265; - goto yy231; -yy269: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy267; - goto yy231; -yy270: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy267; - goto yy231; -yy271: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy267; - goto yy231; -yy272: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy255; - goto yy231; -yy273: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy272; - goto yy231; -yy274: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy272; - goto yy231; -yy275: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy272; - goto yy231; -yy276: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy274; - goto yy231; -yy277: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy274; - goto yy231; -yy278: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy274; - goto yy231; -yy279: - yych = *++p; - if (yych == 'A') goto yy285; - if (yych == 'a') goto yy285; - goto yy231; -yy280: - yych = *++p; - if (yych <= '<') { - if (yych <= ' ') { - if (yych <= 0x08) goto yy231; - if (yych <= '\r') goto yy280; - if (yych <= 0x1F) goto yy231; - goto yy280; - } else { - if (yych <= '/') { - if (yych <= '.') goto yy231; - goto yy251; - } else { - if (yych == ':') goto yy260; - goto yy231; - } - } - } else { - if (yych <= 'Z') { - if (yych <= '=') goto yy282; - if (yych <= '>') goto yy252; - if (yych <= '@') goto yy231; - goto yy260; - } else { - if (yych <= '_') { - if (yych <= '^') goto yy231; - goto yy260; - } else { - if (yych <= '`') goto yy231; - if (yych <= 'z') goto yy260; - goto yy231; - } - } - } -yy282: - yych = *++p; - if (yybm[0+yych] & 16) { - goto yy286; - } - if (yych <= 0xE0) { - if (yych <= '"') { - if (yych <= 0x00) goto yy231; - if (yych <= ' ') goto yy282; - goto yy288; - } else { - if (yych <= '\'') goto yy290; - if (yych <= 0xC1) goto yy231; - if (yych <= 0xDF) goto yy292; - goto yy293; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy295; - goto yy294; - } else { - if (yych <= 0xF0) goto yy296; - if (yych <= 0xF3) goto yy297; - if (yych <= 0xF4) goto yy298; - goto yy231; - } - } -yy284: - yych = *++p; - if (yybm[0+yych] & 8) { - goto yy262; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych <= '-') goto yy251; - goto yy231; - } else { - if (yych <= 0xDF) goto yy265; - if (yych <= 0xE0) goto yy266; - goto yy267; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy268; - if (yych <= 0xEF) goto yy267; - goto yy269; - } else { - if (yych <= 0xF3) goto yy270; - if (yych <= 0xF4) goto yy271; - goto yy231; - } - } -yy285: - yych = *++p; - if (yych == 'T') goto yy299; - if (yych == 't') goto yy299; - goto yy231; -yy286: - yych = *++p; - if (yybm[0+yych] & 16) { - goto yy286; - } - if (yych <= 0xE0) { - if (yych <= '=') { - if (yych <= 0x00) goto yy231; - if (yych <= ' ') goto yy247; - goto yy231; - } else { - if (yych <= '>') goto yy252; - if (yych <= 0xC1) goto yy231; - if (yych <= 0xDF) goto yy292; - goto yy293; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy295; - goto yy294; - } else { - if (yych <= 0xF0) goto yy296; - if (yych <= 0xF3) goto yy297; - if (yych <= 0xF4) goto yy298; - goto yy231; - } - } -yy288: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy288; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych <= '"') goto yy300; - goto yy231; - } else { - if (yych <= 0xDF) goto yy301; - if (yych <= 0xE0) goto yy302; - goto yy303; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy304; - if (yych <= 0xEF) goto yy303; - goto yy305; - } else { - if (yych <= 0xF3) goto yy306; - if (yych <= 0xF4) goto yy307; - goto yy231; - } - } -yy290: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy290; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych <= '\'') goto yy300; - goto yy231; - } else { - if (yych <= 0xDF) goto yy308; - if (yych <= 0xE0) goto yy309; - goto yy310; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy311; - if (yych <= 0xEF) goto yy310; - goto yy312; - } else { - if (yych <= 0xF3) goto yy313; - if (yych <= 0xF4) goto yy314; - goto yy231; - } - } -yy292: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy286; - goto yy231; -yy293: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy292; - goto yy231; -yy294: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy292; - goto yy231; -yy295: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy292; - goto yy231; -yy296: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy294; - goto yy231; -yy297: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy294; - goto yy231; -yy298: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy294; - goto yy231; -yy299: - yych = *++p; - if (yych == 'A') goto yy315; - if (yych == 'a') goto yy315; - goto yy231; -yy300: - yych = *++p; - if (yybm[0+yych] & 1) { - goto yy247; - } - if (yych == '/') goto yy251; - if (yych == '>') goto yy252; - goto yy231; -yy301: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy288; - goto yy231; -yy302: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy301; - goto yy231; -yy303: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy301; - goto yy231; -yy304: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy301; - goto yy231; -yy305: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy303; - goto yy231; -yy306: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy303; - goto yy231; -yy307: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy303; - goto yy231; -yy308: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy290; - goto yy231; -yy309: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy308; - goto yy231; -yy310: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy308; - goto yy231; -yy311: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy308; - goto yy231; -yy312: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy310; - goto yy231; -yy313: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy310; - goto yy231; -yy314: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy310; - goto yy231; -yy315: - yych = *++p; - if (yych != '[') goto yy231; -yy316: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy316; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych >= '^') goto yy231; - } else { - if (yych <= 0xDF) goto yy319; - if (yych <= 0xE0) goto yy320; - goto yy321; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy322; - if (yych <= 0xEF) goto yy321; - goto yy323; - } else { - if (yych <= 0xF3) goto yy324; - if (yych <= 0xF4) goto yy325; - goto yy231; - } - } - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy316; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy231; - if (yych <= ']') goto yy326; - goto yy231; - } else { - if (yych <= 0xDF) goto yy319; - if (yych <= 0xE0) goto yy320; - goto yy321; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy322; - if (yych <= 0xEF) goto yy321; - goto yy323; - } else { - if (yych <= 0xF3) goto yy324; - if (yych <= 0xF4) goto yy325; - goto yy231; - } - } -yy319: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy316; - goto yy231; -yy320: - yych = *++p; - if (yych <= 0x9F) goto yy231; - if (yych <= 0xBF) goto yy319; - goto yy231; -yy321: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy319; - goto yy231; -yy322: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x9F) goto yy319; - goto yy231; -yy323: - yych = *++p; - if (yych <= 0x8F) goto yy231; - if (yych <= 0xBF) goto yy321; - goto yy231; -yy324: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0xBF) goto yy321; - goto yy231; -yy325: - yych = *++p; - if (yych <= 0x7F) goto yy231; - if (yych <= 0x8F) goto yy321; - goto yy231; -yy326: - yych = *++p; - if (yych <= 0xE0) { - if (yych <= '>') { - if (yych <= 0x00) goto yy231; - if (yych <= '=') goto yy316; - goto yy252; - } else { - if (yych <= 0x7F) goto yy316; - if (yych <= 0xC1) goto yy231; - if (yych <= 0xDF) goto yy319; - goto yy320; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy322; - goto yy321; - } else { - if (yych <= 0xF0) goto yy323; - if (yych <= 0xF3) goto yy324; - if (yych <= 0xF4) goto yy325; - goto yy231; - } - } -} - -} - -// Try to (liberally) match an HTML tag after first <, returning num of chars matched. -bufsize_t _scan_liberal_html_tag(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 0, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 128, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= 0xE0) { - if (yych <= '\n') { - if (yych <= 0x00) goto yy329; - if (yych <= '\t') goto yy331; - } else { - if (yych <= 0x7F) goto yy331; - if (yych <= 0xC1) goto yy329; - if (yych <= 0xDF) goto yy332; - goto yy333; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy335; - goto yy334; - } else { - if (yych <= 0xF0) goto yy336; - if (yych <= 0xF3) goto yy337; - if (yych <= 0xF4) goto yy338; - } - } -yy329: - ++p; -yy330: - { return 0; } -yy331: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '\n') { - if (yych <= 0x00) goto yy330; - if (yych <= '\t') goto yy340; - goto yy330; - } else { - if (yych <= 0x7F) goto yy340; - if (yych <= 0xC1) goto yy330; - if (yych <= 0xF4) goto yy340; - goto yy330; - } -yy332: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy330; - if (yych <= 0xBF) goto yy339; - goto yy330; -yy333: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x9F) goto yy330; - if (yych <= 0xBF) goto yy345; - goto yy330; -yy334: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy330; - if (yych <= 0xBF) goto yy345; - goto yy330; -yy335: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy330; - if (yych <= 0x9F) goto yy345; - goto yy330; -yy336: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x8F) goto yy330; - if (yych <= 0xBF) goto yy347; - goto yy330; -yy337: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy330; - if (yych <= 0xBF) goto yy347; - goto yy330; -yy338: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy330; - if (yych <= 0x8F) goto yy347; - goto yy330; -yy339: - yych = *++p; -yy340: - if (yybm[0+yych] & 64) { - goto yy339; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy341; - if (yych <= '>') goto yy342; - } else { - if (yych <= 0xDF) goto yy345; - if (yych <= 0xE0) goto yy346; - goto yy347; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy348; - if (yych <= 0xEF) goto yy347; - goto yy349; - } else { - if (yych <= 0xF3) goto yy350; - if (yych <= 0xF4) goto yy351; - } - } -yy341: - p = marker; - if (yyaccept == 0) { - goto yy330; - } else { - goto yy344; - } -yy342: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy339; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy344; - if (yych <= '>') goto yy342; - } else { - if (yych <= 0xDF) goto yy345; - if (yych <= 0xE0) goto yy346; - goto yy347; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy348; - if (yych <= 0xEF) goto yy347; - goto yy349; - } else { - if (yych <= 0xF3) goto yy350; - if (yych <= 0xF4) goto yy351; - } - } -yy344: - { return (bufsize_t)(p - start); } -yy345: - yych = *++p; - if (yych <= 0x7F) goto yy341; - if (yych <= 0xBF) goto yy339; - goto yy341; -yy346: - yych = *++p; - if (yych <= 0x9F) goto yy341; - if (yych <= 0xBF) goto yy345; - goto yy341; -yy347: - yych = *++p; - if (yych <= 0x7F) goto yy341; - if (yych <= 0xBF) goto yy345; - goto yy341; -yy348: - yych = *++p; - if (yych <= 0x7F) goto yy341; - if (yych <= 0x9F) goto yy345; - goto yy341; -yy349: - yych = *++p; - if (yych <= 0x8F) goto yy341; - if (yych <= 0xBF) goto yy347; - goto yy341; -yy350: - yych = *++p; - if (yych <= 0x7F) goto yy341; - if (yych <= 0xBF) goto yy347; - goto yy341; -yy351: - yych = *++p; - if (yych <= 0x7F) goto yy341; - if (yych <= 0x8F) goto yy347; - goto yy341; -} - -} - -// Try to match an HTML block tag start line, returning -// an integer code for the type of block (1-6, matching the spec). -// #7 is handled by a separate function, below. -bufsize_t _scan_html_block_start(const unsigned char *p) -{ - const unsigned char *marker = NULL; - -{ - unsigned char yych; - yych = *p; - if (yych == '<') goto yy356; - ++p; -yy355: - { return 0; } -yy356: - yych = *(marker = ++p); - switch (yych) { - case '!': goto yy357; - case '/': goto yy359; - case '?': goto yy360; - case 'A': - case 'a': goto yy362; - case 'B': - case 'b': goto yy363; - case 'C': - case 'c': goto yy364; - case 'D': - case 'd': goto yy365; - case 'F': - case 'f': goto yy366; - case 'H': - case 'h': goto yy367; - case 'I': - case 'i': goto yy368; - case 'L': - case 'l': goto yy369; - case 'M': - case 'm': goto yy370; - case 'N': - case 'n': goto yy371; - case 'O': - case 'o': goto yy372; - case 'P': - case 'p': goto yy373; - case 'S': - case 's': goto yy374; - case 'T': - case 't': goto yy375; - case 'U': - case 'u': goto yy376; - default: goto yy355; - } -yy357: - yych = *++p; - if (yych <= '@') { - if (yych == '-') goto yy377; - } else { - if (yych <= 'Z') goto yy378; - if (yych <= '[') goto yy380; - } -yy358: - p = marker; - goto yy355; -yy359: - yych = *++p; - switch (yych) { - case 'A': - case 'a': goto yy362; - case 'B': - case 'b': goto yy363; - case 'C': - case 'c': goto yy364; - case 'D': - case 'd': goto yy365; - case 'F': - case 'f': goto yy366; - case 'H': - case 'h': goto yy367; - case 'I': - case 'i': goto yy368; - case 'L': - case 'l': goto yy369; - case 'M': - case 'm': goto yy370; - case 'N': - case 'n': goto yy371; - case 'O': - case 'o': goto yy372; - case 'P': - case 'p': goto yy381; - case 'S': - case 's': goto yy382; - case 'T': - case 't': goto yy375; - case 'U': - case 'u': goto yy376; - default: goto yy358; - } -yy360: - ++p; - { return 3; } -yy362: - yych = *++p; - if (yych <= 'S') { - if (yych <= 'D') { - if (yych <= 'C') goto yy358; - goto yy383; - } else { - if (yych <= 'Q') goto yy358; - if (yych <= 'R') goto yy384; - goto yy385; - } - } else { - if (yych <= 'q') { - if (yych == 'd') goto yy383; - goto yy358; - } else { - if (yych <= 'r') goto yy384; - if (yych <= 's') goto yy385; - goto yy358; - } - } -yy363: - yych = *++p; - if (yych <= 'O') { - if (yych <= 'K') { - if (yych == 'A') goto yy386; - goto yy358; - } else { - if (yych <= 'L') goto yy387; - if (yych <= 'N') goto yy358; - goto yy388; - } - } else { - if (yych <= 'k') { - if (yych == 'a') goto yy386; - goto yy358; - } else { - if (yych <= 'l') goto yy387; - if (yych == 'o') goto yy388; - goto yy358; - } - } -yy364: - yych = *++p; - if (yych <= 'O') { - if (yych <= 'D') { - if (yych == 'A') goto yy389; - goto yy358; - } else { - if (yych <= 'E') goto yy390; - if (yych <= 'N') goto yy358; - goto yy391; - } - } else { - if (yych <= 'd') { - if (yych == 'a') goto yy389; - goto yy358; - } else { - if (yych <= 'e') goto yy390; - if (yych == 'o') goto yy391; - goto yy358; - } - } -yy365: - yych = *++p; - switch (yych) { - case 'D': - case 'L': - case 'T': - case 'd': - case 'l': - case 't': goto yy392; - case 'E': - case 'e': goto yy393; - case 'I': - case 'i': goto yy394; - default: goto yy358; - } -yy366: - yych = *++p; - if (yych <= 'R') { - if (yych <= 'N') { - if (yych == 'I') goto yy395; - goto yy358; - } else { - if (yych <= 'O') goto yy396; - if (yych <= 'Q') goto yy358; - goto yy397; - } - } else { - if (yych <= 'n') { - if (yych == 'i') goto yy395; - goto yy358; - } else { - if (yych <= 'o') goto yy396; - if (yych == 'r') goto yy397; - goto yy358; - } - } -yy367: - yych = *++p; - if (yych <= 'S') { - if (yych <= 'D') { - if (yych <= '0') goto yy358; - if (yych <= '6') goto yy392; - goto yy358; - } else { - if (yych <= 'E') goto yy398; - if (yych == 'R') goto yy392; - goto yy358; - } - } else { - if (yych <= 'q') { - if (yych <= 'T') goto yy399; - if (yych == 'e') goto yy398; - goto yy358; - } else { - if (yych <= 'r') goto yy392; - if (yych == 't') goto yy399; - goto yy358; - } - } -yy368: - yych = *++p; - if (yych == 'F') goto yy400; - if (yych == 'f') goto yy400; - goto yy358; -yy369: - yych = *++p; - if (yych <= 'I') { - if (yych == 'E') goto yy401; - if (yych <= 'H') goto yy358; - goto yy402; - } else { - if (yych <= 'e') { - if (yych <= 'd') goto yy358; - goto yy401; - } else { - if (yych == 'i') goto yy402; - goto yy358; - } - } -yy370: - yych = *++p; - if (yych <= 'E') { - if (yych == 'A') goto yy403; - if (yych <= 'D') goto yy358; - goto yy404; - } else { - if (yych <= 'a') { - if (yych <= '`') goto yy358; - goto yy403; - } else { - if (yych == 'e') goto yy404; - goto yy358; - } - } -yy371: - yych = *++p; - if (yych <= 'O') { - if (yych == 'A') goto yy405; - if (yych <= 'N') goto yy358; - goto yy406; - } else { - if (yych <= 'a') { - if (yych <= '`') goto yy358; - goto yy405; - } else { - if (yych == 'o') goto yy406; - goto yy358; - } - } -yy372: - yych = *++p; - if (yych <= 'P') { - if (yych == 'L') goto yy392; - if (yych <= 'O') goto yy358; - goto yy407; - } else { - if (yych <= 'l') { - if (yych <= 'k') goto yy358; - goto yy392; - } else { - if (yych == 'p') goto yy407; - goto yy358; - } - } -yy373: - yych = *++p; - if (yych <= '>') { - if (yych <= ' ') { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - if (yych <= 0x1F) goto yy358; - goto yy408; - } else { - if (yych == '/') goto yy410; - if (yych <= '=') goto yy358; - goto yy408; - } - } else { - if (yych <= 'R') { - if (yych == 'A') goto yy411; - if (yych <= 'Q') goto yy358; - goto yy412; - } else { - if (yych <= 'a') { - if (yych <= '`') goto yy358; - goto yy411; - } else { - if (yych == 'r') goto yy412; - goto yy358; - } - } - } -yy374: - yych = *++p; - if (yych <= 'U') { - if (yych <= 'D') { - if (yych == 'C') goto yy413; - goto yy358; - } else { - if (yych <= 'E') goto yy414; - if (yych <= 'S') goto yy358; - if (yych <= 'T') goto yy415; - goto yy416; - } - } else { - if (yych <= 'e') { - if (yych == 'c') goto yy413; - if (yych <= 'd') goto yy358; - goto yy414; - } else { - if (yych <= 's') goto yy358; - if (yych <= 't') goto yy415; - if (yych <= 'u') goto yy416; - goto yy358; - } - } -yy375: - yych = *++p; - switch (yych) { - case 'A': - case 'a': goto yy417; - case 'B': - case 'b': goto yy418; - case 'D': - case 'd': goto yy392; - case 'F': - case 'f': goto yy419; - case 'H': - case 'h': goto yy420; - case 'I': - case 'i': goto yy421; - case 'R': - case 'r': goto yy422; - default: goto yy358; - } -yy376: - yych = *++p; - if (yych == 'L') goto yy392; - if (yych == 'l') goto yy392; - goto yy358; -yy377: - yych = *++p; - if (yych == '-') goto yy423; - goto yy358; -yy378: - ++p; - { return 4; } -yy380: - yych = *++p; - if (yych == 'C') goto yy425; - if (yych == 'c') goto yy425; - goto yy358; -yy381: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= '@') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'A') goto yy411; - if (yych == 'a') goto yy411; - goto yy358; - } - } -yy382: - yych = *++p; - if (yych <= 'U') { - if (yych == 'E') goto yy414; - if (yych <= 'T') goto yy358; - goto yy416; - } else { - if (yych <= 'e') { - if (yych <= 'd') goto yy358; - goto yy414; - } else { - if (yych == 'u') goto yy416; - goto yy358; - } - } -yy383: - yych = *++p; - if (yych == 'D') goto yy426; - if (yych == 'd') goto yy426; - goto yy358; -yy384: - yych = *++p; - if (yych == 'T') goto yy427; - if (yych == 't') goto yy427; - goto yy358; -yy385: - yych = *++p; - if (yych == 'I') goto yy428; - if (yych == 'i') goto yy428; - goto yy358; -yy386: - yych = *++p; - if (yych == 'S') goto yy429; - if (yych == 's') goto yy429; - goto yy358; -yy387: - yych = *++p; - if (yych == 'O') goto yy430; - if (yych == 'o') goto yy430; - goto yy358; -yy388: - yych = *++p; - if (yych == 'D') goto yy431; - if (yych == 'd') goto yy431; - goto yy358; -yy389: - yych = *++p; - if (yych == 'P') goto yy432; - if (yych == 'p') goto yy432; - goto yy358; -yy390: - yych = *++p; - if (yych == 'N') goto yy433; - if (yych == 'n') goto yy433; - goto yy358; -yy391: - yych = *++p; - if (yych == 'L') goto yy434; - if (yych == 'l') goto yy434; - goto yy358; -yy392: - yych = *++p; - if (yych <= ' ') { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - if (yych <= 0x1F) goto yy358; - goto yy408; - } else { - if (yych <= '/') { - if (yych <= '.') goto yy358; - goto yy410; - } else { - if (yych == '>') goto yy408; - goto yy358; - } - } -yy393: - yych = *++p; - if (yych == 'T') goto yy435; - if (yych == 't') goto yy435; - goto yy358; -yy394: - yych = *++p; - if (yych <= 'V') { - if (yych <= 'Q') { - if (yych == 'A') goto yy436; - goto yy358; - } else { - if (yych <= 'R') goto yy392; - if (yych <= 'U') goto yy358; - goto yy392; - } - } else { - if (yych <= 'q') { - if (yych == 'a') goto yy436; - goto yy358; - } else { - if (yych <= 'r') goto yy392; - if (yych == 'v') goto yy392; - goto yy358; - } - } -yy395: - yych = *++p; - if (yych <= 'G') { - if (yych == 'E') goto yy437; - if (yych <= 'F') goto yy358; - goto yy438; - } else { - if (yych <= 'e') { - if (yych <= 'd') goto yy358; - goto yy437; - } else { - if (yych == 'g') goto yy438; - goto yy358; - } - } -yy396: - yych = *++p; - if (yych <= 'R') { - if (yych == 'O') goto yy433; - if (yych <= 'Q') goto yy358; - goto yy439; - } else { - if (yych <= 'o') { - if (yych <= 'n') goto yy358; - goto yy433; - } else { - if (yych == 'r') goto yy439; - goto yy358; - } - } -yy397: - yych = *++p; - if (yych == 'A') goto yy440; - if (yych == 'a') goto yy440; - goto yy358; -yy398: - yych = *++p; - if (yych == 'A') goto yy441; - if (yych == 'a') goto yy441; - goto yy358; -yy399: - yych = *++p; - if (yych == 'M') goto yy376; - if (yych == 'm') goto yy376; - goto yy358; -yy400: - yych = *++p; - if (yych == 'R') goto yy442; - if (yych == 'r') goto yy442; - goto yy358; -yy401: - yych = *++p; - if (yych == 'G') goto yy443; - if (yych == 'g') goto yy443; - goto yy358; -yy402: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'M') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'N') goto yy444; - if (yych == 'n') goto yy444; - goto yy358; - } - } -yy403: - yych = *++p; - if (yych == 'I') goto yy445; - if (yych == 'i') goto yy445; - goto yy358; -yy404: - yych = *++p; - if (yych == 'N') goto yy446; - if (yych == 'n') goto yy446; - goto yy358; -yy405: - yych = *++p; - if (yych == 'V') goto yy392; - if (yych == 'v') goto yy392; - goto yy358; -yy406: - yych = *++p; - if (yych == 'F') goto yy447; - if (yych == 'f') goto yy447; - goto yy358; -yy407: - yych = *++p; - if (yych == 'T') goto yy448; - if (yych == 't') goto yy448; - goto yy358; -yy408: - ++p; - { return 6; } -yy410: - yych = *++p; - if (yych == '>') goto yy408; - goto yy358; -yy411: - yych = *++p; - if (yych == 'R') goto yy449; - if (yych == 'r') goto yy449; - goto yy358; -yy412: - yych = *++p; - if (yych == 'E') goto yy450; - if (yych == 'e') goto yy450; - goto yy358; -yy413: - yych = *++p; - if (yych == 'R') goto yy451; - if (yych == 'r') goto yy451; - goto yy358; -yy414: - yych = *++p; - if (yych == 'C') goto yy432; - if (yych == 'c') goto yy432; - goto yy358; -yy415: - yych = *++p; - if (yych == 'Y') goto yy452; - if (yych == 'y') goto yy452; - goto yy358; -yy416: - yych = *++p; - if (yych == 'M') goto yy453; - if (yych == 'm') goto yy453; - goto yy358; -yy417: - yych = *++p; - if (yych == 'B') goto yy454; - if (yych == 'b') goto yy454; - goto yy358; -yy418: - yych = *++p; - if (yych == 'O') goto yy388; - if (yych == 'o') goto yy388; - goto yy358; -yy419: - yych = *++p; - if (yych == 'O') goto yy455; - if (yych == 'o') goto yy455; - goto yy358; -yy420: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'D') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'E') goto yy456; - if (yych == 'e') goto yy456; - goto yy358; - } - } -yy421: - yych = *++p; - if (yych == 'T') goto yy454; - if (yych == 't') goto yy454; - goto yy358; -yy422: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= '@') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'A') goto yy457; - if (yych == 'a') goto yy457; - goto yy358; - } - } -yy423: - ++p; - { return 2; } -yy425: - yych = *++p; - if (yych == 'D') goto yy458; - if (yych == 'd') goto yy458; - goto yy358; -yy426: - yych = *++p; - if (yych == 'R') goto yy459; - if (yych == 'r') goto yy459; - goto yy358; -yy427: - yych = *++p; - if (yych == 'I') goto yy460; - if (yych == 'i') goto yy460; - goto yy358; -yy428: - yych = *++p; - if (yych == 'D') goto yy461; - if (yych == 'd') goto yy461; - goto yy358; -yy429: - yych = *++p; - if (yych == 'E') goto yy462; - if (yych == 'e') goto yy462; - goto yy358; -yy430: - yych = *++p; - if (yych == 'C') goto yy463; - if (yych == 'c') goto yy463; - goto yy358; -yy431: - yych = *++p; - if (yych == 'Y') goto yy392; - if (yych == 'y') goto yy392; - goto yy358; -yy432: - yych = *++p; - if (yych == 'T') goto yy464; - if (yych == 't') goto yy464; - goto yy358; -yy433: - yych = *++p; - if (yych == 'T') goto yy465; - if (yych == 't') goto yy465; - goto yy358; -yy434: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'F') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'G') goto yy466; - if (yych == 'g') goto yy466; - goto yy358; - } - } -yy435: - yych = *++p; - if (yych == 'A') goto yy467; - if (yych == 'a') goto yy467; - goto yy358; -yy436: - yych = *++p; - if (yych == 'L') goto yy468; - if (yych == 'l') goto yy468; - goto yy358; -yy437: - yych = *++p; - if (yych == 'L') goto yy469; - if (yych == 'l') goto yy469; - goto yy358; -yy438: - yych = *++p; - if (yych <= 'U') { - if (yych == 'C') goto yy470; - if (yych <= 'T') goto yy358; - goto yy471; - } else { - if (yych <= 'c') { - if (yych <= 'b') goto yy358; - goto yy470; - } else { - if (yych == 'u') goto yy471; - goto yy358; - } - } -yy439: - yych = *++p; - if (yych == 'M') goto yy392; - if (yych == 'm') goto yy392; - goto yy358; -yy440: - yych = *++p; - if (yych == 'M') goto yy472; - if (yych == 'm') goto yy472; - goto yy358; -yy441: - yych = *++p; - if (yych == 'D') goto yy473; - if (yych == 'd') goto yy473; - goto yy358; -yy442: - yych = *++p; - if (yych == 'A') goto yy474; - if (yych == 'a') goto yy474; - goto yy358; -yy443: - yych = *++p; - if (yych == 'E') goto yy475; - if (yych == 'e') goto yy475; - goto yy358; -yy444: - yych = *++p; - if (yych == 'K') goto yy392; - if (yych == 'k') goto yy392; - goto yy358; -yy445: - yych = *++p; - if (yych == 'N') goto yy392; - if (yych == 'n') goto yy392; - goto yy358; -yy446: - yych = *++p; - if (yych == 'U') goto yy476; - if (yych == 'u') goto yy476; - goto yy358; -yy447: - yych = *++p; - if (yych == 'R') goto yy477; - if (yych == 'r') goto yy477; - goto yy358; -yy448: - yych = *++p; - if (yych <= 'I') { - if (yych == 'G') goto yy466; - if (yych <= 'H') goto yy358; - goto yy478; - } else { - if (yych <= 'g') { - if (yych <= 'f') goto yy358; - goto yy466; - } else { - if (yych == 'i') goto yy478; - goto yy358; - } - } -yy449: - yych = *++p; - if (yych == 'A') goto yy439; - if (yych == 'a') goto yy439; - goto yy358; -yy450: - yych = *++p; - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy479; - goto yy358; - } else { - if (yych <= ' ') goto yy479; - if (yych == '>') goto yy479; - goto yy358; - } -yy451: - yych = *++p; - if (yych == 'I') goto yy481; - if (yych == 'i') goto yy481; - goto yy358; -yy452: - yych = *++p; - if (yych == 'L') goto yy412; - if (yych == 'l') goto yy412; - goto yy358; -yy453: - yych = *++p; - if (yych == 'M') goto yy482; - if (yych == 'm') goto yy482; - goto yy358; -yy454: - yych = *++p; - if (yych == 'L') goto yy461; - if (yych == 'l') goto yy461; - goto yy358; -yy455: - yych = *++p; - if (yych == 'O') goto yy483; - if (yych == 'o') goto yy483; - goto yy358; -yy456: - yych = *++p; - if (yych == 'A') goto yy484; - if (yych == 'a') goto yy484; - goto yy358; -yy457: - yych = *++p; - if (yych == 'C') goto yy444; - if (yych == 'c') goto yy444; - goto yy358; -yy458: - yych = *++p; - if (yych == 'A') goto yy485; - if (yych == 'a') goto yy485; - goto yy358; -yy459: - yych = *++p; - if (yych == 'E') goto yy486; - if (yych == 'e') goto yy486; - goto yy358; -yy460: - yych = *++p; - if (yych == 'C') goto yy454; - if (yych == 'c') goto yy454; - goto yy358; -yy461: - yych = *++p; - if (yych == 'E') goto yy392; - if (yych == 'e') goto yy392; - goto yy358; -yy462: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'E') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'F') goto yy487; - if (yych == 'f') goto yy487; - goto yy358; - } - } -yy463: - yych = *++p; - if (yych == 'K') goto yy488; - if (yych == 'k') goto yy488; - goto yy358; -yy464: - yych = *++p; - if (yych == 'I') goto yy478; - if (yych == 'i') goto yy478; - goto yy358; -yy465: - yych = *++p; - if (yych == 'E') goto yy489; - if (yych == 'e') goto yy489; - goto yy358; -yy466: - yych = *++p; - if (yych == 'R') goto yy490; - if (yych == 'r') goto yy490; - goto yy358; -yy467: - yych = *++p; - if (yych == 'I') goto yy491; - if (yych == 'i') goto yy491; - goto yy358; -yy468: - yych = *++p; - if (yych == 'O') goto yy492; - if (yych == 'o') goto yy492; - goto yy358; -yy469: - yych = *++p; - if (yych == 'D') goto yy493; - if (yych == 'd') goto yy493; - goto yy358; -yy470: - yych = *++p; - if (yych == 'A') goto yy389; - if (yych == 'a') goto yy389; - goto yy358; -yy471: - yych = *++p; - if (yych == 'R') goto yy461; - if (yych == 'r') goto yy461; - goto yy358; -yy472: - yych = *++p; - if (yych == 'E') goto yy494; - if (yych == 'e') goto yy494; - goto yy358; -yy473: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'D') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'E') goto yy489; - if (yych == 'e') goto yy489; - goto yy358; - } - } -yy474: - yych = *++p; - if (yych == 'M') goto yy461; - if (yych == 'm') goto yy461; - goto yy358; -yy475: - yych = *++p; - if (yych == 'N') goto yy484; - if (yych == 'n') goto yy484; - goto yy358; -yy476: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'H') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'I') goto yy495; - if (yych == 'i') goto yy495; - goto yy358; - } - } -yy477: - yych = *++p; - if (yych == 'A') goto yy496; - if (yych == 'a') goto yy496; - goto yy358; -yy478: - yych = *++p; - if (yych == 'O') goto yy445; - if (yych == 'o') goto yy445; - goto yy358; -yy479: - ++p; - { return 1; } -yy481: - yych = *++p; - if (yych == 'P') goto yy497; - if (yych == 'p') goto yy497; - goto yy358; -yy482: - yych = *++p; - if (yych == 'A') goto yy498; - if (yych == 'a') goto yy498; - goto yy358; -yy483: - yych = *++p; - if (yych == 'T') goto yy392; - if (yych == 't') goto yy392; - goto yy358; -yy484: - yych = *++p; - if (yych == 'D') goto yy392; - if (yych == 'd') goto yy392; - goto yy358; -yy485: - yych = *++p; - if (yych == 'T') goto yy499; - if (yych == 't') goto yy499; - goto yy358; -yy486: - yych = *++p; - if (yych == 'S') goto yy500; - if (yych == 's') goto yy500; - goto yy358; -yy487: - yych = *++p; - if (yych == 'O') goto yy501; - if (yych == 'o') goto yy501; - goto yy358; -yy488: - yych = *++p; - if (yych == 'Q') goto yy502; - if (yych == 'q') goto yy502; - goto yy358; -yy489: - yych = *++p; - if (yych == 'R') goto yy392; - if (yych == 'r') goto yy392; - goto yy358; -yy490: - yych = *++p; - if (yych == 'O') goto yy503; - if (yych == 'o') goto yy503; - goto yy358; -yy491: - yych = *++p; - if (yych == 'L') goto yy500; - if (yych == 'l') goto yy500; - goto yy358; -yy492: - yych = *++p; - if (yych == 'G') goto yy392; - if (yych == 'g') goto yy392; - goto yy358; -yy493: - yych = *++p; - if (yych == 'S') goto yy504; - if (yych == 's') goto yy504; - goto yy358; -yy494: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy358; - if (yych <= '\r') goto yy408; - goto yy358; - } else { - if (yych <= ' ') goto yy408; - if (yych <= '.') goto yy358; - goto yy410; - } - } else { - if (yych <= 'R') { - if (yych == '>') goto yy408; - goto yy358; - } else { - if (yych <= 'S') goto yy504; - if (yych == 's') goto yy504; - goto yy358; - } - } -yy495: - yych = *++p; - if (yych == 'T') goto yy505; - if (yych == 't') goto yy505; - goto yy358; -yy496: - yych = *++p; - if (yych == 'M') goto yy506; - if (yych == 'm') goto yy506; - goto yy358; -yy497: - yych = *++p; - if (yych == 'T') goto yy450; - if (yych == 't') goto yy450; - goto yy358; -yy498: - yych = *++p; - if (yych == 'R') goto yy431; - if (yych == 'r') goto yy431; - goto yy358; -yy499: - yych = *++p; - if (yych == 'A') goto yy507; - if (yych == 'a') goto yy507; - goto yy358; -yy500: - yych = *++p; - if (yych == 'S') goto yy392; - if (yych == 's') goto yy392; - goto yy358; -yy501: - yych = *++p; - if (yych == 'N') goto yy483; - if (yych == 'n') goto yy483; - goto yy358; -yy502: - yych = *++p; - if (yych == 'U') goto yy508; - if (yych == 'u') goto yy508; - goto yy358; -yy503: - yych = *++p; - if (yych == 'U') goto yy509; - if (yych == 'u') goto yy509; - goto yy358; -yy504: - yych = *++p; - if (yych == 'E') goto yy483; - if (yych == 'e') goto yy483; - goto yy358; -yy505: - yych = *++p; - if (yych == 'E') goto yy439; - if (yych == 'e') goto yy439; - goto yy358; -yy506: - yych = *++p; - if (yych == 'E') goto yy500; - if (yych == 'e') goto yy500; - goto yy358; -yy507: - yych = *++p; - if (yych == '[') goto yy510; - goto yy358; -yy508: - yych = *++p; - if (yych == 'O') goto yy512; - if (yych == 'o') goto yy512; - goto yy358; -yy509: - yych = *++p; - if (yych == 'P') goto yy392; - if (yych == 'p') goto yy392; - goto yy358; -yy510: - ++p; - { return 5; } -yy512: - yych = *++p; - if (yych == 'T') goto yy461; - if (yych == 't') goto yy461; - goto yy358; -} - -} - -// Try to match an HTML block tag start line of type 7, returning -// 7 if successful, 0 if not. -bufsize_t _scan_html_block_start_7(const unsigned char *p) -{ - const unsigned char *marker = NULL; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 224, 224, 224, 224, 224, 224, 224, - 224, 198, 210, 194, 198, 194, 224, 224, - 224, 224, 224, 224, 224, 224, 224, 224, - 224, 224, 224, 224, 224, 224, 224, 224, - 198, 224, 128, 224, 224, 224, 224, 64, - 224, 224, 224, 224, 224, 233, 232, 224, - 233, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 232, 224, 192, 192, 192, 224, - 224, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 224, 224, 224, 224, 232, - 192, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 233, 233, 233, 233, 233, - 233, 233, 233, 224, 224, 224, 224, 224, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych == '<') goto yy517; - ++p; -yy516: - { return 0; } -yy517: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '@') { - if (yych != '/') goto yy516; - } else { - if (yych <= 'Z') goto yy520; - if (yych <= '`') goto yy516; - if (yych <= 'z') goto yy520; - goto yy516; - } - yych = *++p; - if (yych <= '@') goto yy519; - if (yych <= 'Z') goto yy522; - if (yych <= '`') goto yy519; - if (yych <= 'z') goto yy522; -yy519: - p = marker; - if (yyaccept == 0) { - goto yy516; - } else { - goto yy535; - } -yy520: - yych = *++p; - if (yybm[0+yych] & 2) { - goto yy524; - } - if (yych <= '=') { - if (yych <= '.') { - if (yych == '-') goto yy520; - goto yy519; - } else { - if (yych <= '/') goto yy526; - if (yych <= '9') goto yy520; - goto yy519; - } - } else { - if (yych <= 'Z') { - if (yych <= '>') goto yy527; - if (yych <= '@') goto yy519; - goto yy520; - } else { - if (yych <= '`') goto yy519; - if (yych <= 'z') goto yy520; - goto yy519; - } - } -yy522: - yych = *++p; - if (yych <= '/') { - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy519; - if (yych <= '\r') goto yy529; - goto yy519; - } else { - if (yych <= ' ') goto yy529; - if (yych == '-') goto yy522; - goto yy519; - } - } else { - if (yych <= '@') { - if (yych <= '9') goto yy522; - if (yych == '>') goto yy527; - goto yy519; - } else { - if (yych <= 'Z') goto yy522; - if (yych <= '`') goto yy519; - if (yych <= 'z') goto yy522; - goto yy519; - } - } -yy524: - yych = *++p; - if (yybm[0+yych] & 2) { - goto yy524; - } - if (yych <= '>') { - if (yych <= '9') { - if (yych != '/') goto yy519; - } else { - if (yych <= ':') goto yy531; - if (yych <= '=') goto yy519; - goto yy527; - } - } else { - if (yych <= '^') { - if (yych <= '@') goto yy519; - if (yych <= 'Z') goto yy531; - goto yy519; - } else { - if (yych == '`') goto yy519; - if (yych <= 'z') goto yy531; - goto yy519; - } - } -yy526: - yych = *++p; - if (yych != '>') goto yy519; -yy527: - yych = *++p; - if (yybm[0+yych] & 4) { - goto yy527; - } - if (yych <= 0x08) goto yy519; - if (yych <= '\n') goto yy533; - if (yych <= '\v') goto yy519; - if (yych <= '\r') goto yy536; - goto yy519; -yy529: - yych = *++p; - if (yych <= 0x1F) { - if (yych <= 0x08) goto yy519; - if (yych <= '\r') goto yy529; - goto yy519; - } else { - if (yych <= ' ') goto yy529; - if (yych == '>') goto yy527; - goto yy519; - } -yy531: - yych = *++p; - if (yybm[0+yych] & 8) { - goto yy531; - } - if (yych <= ',') { - if (yych <= '\r') { - if (yych <= 0x08) goto yy519; - goto yy537; - } else { - if (yych == ' ') goto yy537; - goto yy519; - } - } else { - if (yych <= '<') { - if (yych <= '/') goto yy526; - goto yy519; - } else { - if (yych <= '=') goto yy539; - if (yych <= '>') goto yy527; - goto yy519; - } - } -yy533: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 4) { - goto yy527; - } - if (yych <= 0x08) goto yy535; - if (yych <= '\n') goto yy533; - if (yych <= '\v') goto yy535; - if (yych <= '\r') goto yy536; -yy535: - { return 7; } -yy536: - ++p; - goto yy535; -yy537: - yych = *++p; - if (yych <= '<') { - if (yych <= ' ') { - if (yych <= 0x08) goto yy519; - if (yych <= '\r') goto yy537; - if (yych <= 0x1F) goto yy519; - goto yy537; - } else { - if (yych <= '/') { - if (yych <= '.') goto yy519; - goto yy526; - } else { - if (yych == ':') goto yy531; - goto yy519; - } - } - } else { - if (yych <= 'Z') { - if (yych <= '=') goto yy539; - if (yych <= '>') goto yy527; - if (yych <= '@') goto yy519; - goto yy531; - } else { - if (yych <= '_') { - if (yych <= '^') goto yy519; - goto yy531; - } else { - if (yych <= '`') goto yy519; - if (yych <= 'z') goto yy531; - goto yy519; - } - } - } -yy539: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy541; - } - if (yych <= 0xE0) { - if (yych <= '"') { - if (yych <= 0x00) goto yy519; - if (yych <= ' ') goto yy539; - goto yy543; - } else { - if (yych <= '\'') goto yy545; - if (yych <= 0xC1) goto yy519; - if (yych <= 0xDF) goto yy547; - goto yy548; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy550; - goto yy549; - } else { - if (yych <= 0xF0) goto yy551; - if (yych <= 0xF3) goto yy552; - if (yych <= 0xF4) goto yy553; - goto yy519; - } - } -yy541: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy541; - } - if (yych <= 0xE0) { - if (yych <= '=') { - if (yych <= 0x00) goto yy519; - if (yych <= ' ') goto yy524; - goto yy519; - } else { - if (yych <= '>') goto yy527; - if (yych <= 0xC1) goto yy519; - if (yych <= 0xDF) goto yy547; - goto yy548; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy550; - goto yy549; - } else { - if (yych <= 0xF0) goto yy551; - if (yych <= 0xF3) goto yy552; - if (yych <= 0xF4) goto yy553; - goto yy519; - } - } -yy543: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy543; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy519; - if (yych <= '"') goto yy554; - goto yy519; - } else { - if (yych <= 0xDF) goto yy555; - if (yych <= 0xE0) goto yy556; - goto yy557; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy558; - if (yych <= 0xEF) goto yy557; - goto yy559; - } else { - if (yych <= 0xF3) goto yy560; - if (yych <= 0xF4) goto yy561; - goto yy519; - } - } -yy545: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy545; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy519; - if (yych <= '\'') goto yy554; - goto yy519; - } else { - if (yych <= 0xDF) goto yy562; - if (yych <= 0xE0) goto yy563; - goto yy564; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy565; - if (yych <= 0xEF) goto yy564; - goto yy566; - } else { - if (yych <= 0xF3) goto yy567; - if (yych <= 0xF4) goto yy568; - goto yy519; - } - } -yy547: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy541; - goto yy519; -yy548: - yych = *++p; - if (yych <= 0x9F) goto yy519; - if (yych <= 0xBF) goto yy547; - goto yy519; -yy549: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy547; - goto yy519; -yy550: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0x9F) goto yy547; - goto yy519; -yy551: - yych = *++p; - if (yych <= 0x8F) goto yy519; - if (yych <= 0xBF) goto yy549; - goto yy519; -yy552: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy549; - goto yy519; -yy553: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0x8F) goto yy549; - goto yy519; -yy554: - yych = *++p; - if (yybm[0+yych] & 2) { - goto yy524; - } - if (yych == '/') goto yy526; - if (yych == '>') goto yy527; - goto yy519; -yy555: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy543; - goto yy519; -yy556: - yych = *++p; - if (yych <= 0x9F) goto yy519; - if (yych <= 0xBF) goto yy555; - goto yy519; -yy557: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy555; - goto yy519; -yy558: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0x9F) goto yy555; - goto yy519; -yy559: - yych = *++p; - if (yych <= 0x8F) goto yy519; - if (yych <= 0xBF) goto yy557; - goto yy519; -yy560: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy557; - goto yy519; -yy561: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0x8F) goto yy557; - goto yy519; -yy562: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy545; - goto yy519; -yy563: - yych = *++p; - if (yych <= 0x9F) goto yy519; - if (yych <= 0xBF) goto yy562; - goto yy519; -yy564: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy562; - goto yy519; -yy565: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0x9F) goto yy562; - goto yy519; -yy566: - yych = *++p; - if (yych <= 0x8F) goto yy519; - if (yych <= 0xBF) goto yy564; - goto yy519; -yy567: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0xBF) goto yy564; - goto yy519; -yy568: - yych = *++p; - if (yych <= 0x7F) goto yy519; - if (yych <= 0x8F) goto yy564; - goto yy519; -} - -} - -// Try to match an HTML block end line of type 1 -bufsize_t _scan_html_block_end_1(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 0, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 128, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= 0xDF) { - if (yych <= ';') { - if (yych <= 0x00) goto yy571; - if (yych != '\n') goto yy573; - } else { - if (yych <= '<') goto yy574; - if (yych <= 0x7F) goto yy573; - if (yych >= 0xC2) goto yy575; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy576; - if (yych == 0xED) goto yy578; - goto yy577; - } else { - if (yych <= 0xF0) goto yy579; - if (yych <= 0xF3) goto yy580; - if (yych <= 0xF4) goto yy581; - } - } -yy571: - ++p; -yy572: - { return 0; } -yy573: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '\n') { - if (yych <= 0x00) goto yy572; - if (yych <= '\t') goto yy583; - goto yy572; - } else { - if (yych <= 0x7F) goto yy583; - if (yych <= 0xC1) goto yy572; - if (yych <= 0xF4) goto yy583; - goto yy572; - } -yy574: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '.') { - if (yych <= 0x00) goto yy572; - if (yych == '\n') goto yy572; - goto yy583; - } else { - if (yych <= 0x7F) { - if (yych <= '/') goto yy594; - goto yy583; - } else { - if (yych <= 0xC1) goto yy572; - if (yych <= 0xF4) goto yy583; - goto yy572; - } - } -yy575: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy572; - if (yych <= 0xBF) goto yy582; - goto yy572; -yy576: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x9F) goto yy572; - if (yych <= 0xBF) goto yy587; - goto yy572; -yy577: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy572; - if (yych <= 0xBF) goto yy587; - goto yy572; -yy578: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy572; - if (yych <= 0x9F) goto yy587; - goto yy572; -yy579: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x8F) goto yy572; - if (yych <= 0xBF) goto yy589; - goto yy572; -yy580: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy572; - if (yych <= 0xBF) goto yy589; - goto yy572; -yy581: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy572; - if (yych <= 0x8F) goto yy589; - goto yy572; -yy582: - yych = *++p; -yy583: - if (yybm[0+yych] & 64) { - goto yy582; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy584; - if (yych <= '<') goto yy585; - } else { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - goto yy589; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy590; - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - } - } -yy584: - p = marker; - if (yyaccept == 0) { - goto yy572; - } else { - goto yy604; - } -yy585: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xDF) { - if (yych <= '.') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= '/') goto yy594; - if (yych <= 0x7F) goto yy582; - if (yych <= 0xC1) goto yy584; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy588; - if (yych == 0xED) goto yy590; - goto yy589; - } else { - if (yych <= 0xF0) goto yy591; - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } -yy587: - yych = *++p; - if (yych <= 0x7F) goto yy584; - if (yych <= 0xBF) goto yy582; - goto yy584; -yy588: - yych = *++p; - if (yych <= 0x9F) goto yy584; - if (yych <= 0xBF) goto yy587; - goto yy584; -yy589: - yych = *++p; - if (yych <= 0x7F) goto yy584; - if (yych <= 0xBF) goto yy587; - goto yy584; -yy590: - yych = *++p; - if (yych <= 0x7F) goto yy584; - if (yych <= 0x9F) goto yy587; - goto yy584; -yy591: - yych = *++p; - if (yych <= 0x8F) goto yy584; - if (yych <= 0xBF) goto yy589; - goto yy584; -yy592: - yych = *++p; - if (yych <= 0x7F) goto yy584; - if (yych <= 0xBF) goto yy589; - goto yy584; -yy593: - yych = *++p; - if (yych <= 0x7F) goto yy584; - if (yych <= 0x8F) goto yy589; - goto yy584; -yy594: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 's') { - if (yych <= 'P') { - if (yych <= '\t') { - if (yych <= 0x00) goto yy584; - goto yy582; - } else { - if (yych <= '\n') goto yy584; - if (yych <= 'O') goto yy582; - } - } else { - if (yych <= 'o') { - if (yych == 'S') goto yy596; - goto yy582; - } else { - if (yych <= 'p') goto yy595; - if (yych <= 'r') goto yy582; - goto yy596; - } - } - } else { - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x7F) goto yy582; - goto yy584; - } else { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - goto yy589; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy590; - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy595: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'Q') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'q') { - if (yych <= 'R') goto yy597; - goto yy582; - } else { - if (yych <= 'r') goto yy597; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy596: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 't') { - if (yych <= 'C') { - if (yych <= '\t') { - if (yych <= 0x00) goto yy584; - goto yy582; - } else { - if (yych <= '\n') goto yy584; - if (yych <= 'B') goto yy582; - goto yy598; - } - } else { - if (yych <= 'b') { - if (yych == 'T') goto yy599; - goto yy582; - } else { - if (yych <= 'c') goto yy598; - if (yych <= 's') goto yy582; - goto yy599; - } - } - } else { - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x7F) goto yy582; - goto yy584; - } else { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - goto yy589; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy590; - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy597: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'D') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'd') { - if (yych <= 'E') goto yy600; - goto yy582; - } else { - if (yych <= 'e') goto yy600; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy598: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'Q') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'q') { - if (yych <= 'R') goto yy601; - goto yy582; - } else { - if (yych <= 'r') goto yy601; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy599: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'X') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'x') { - if (yych <= 'Y') goto yy602; - goto yy582; - } else { - if (yych <= 'y') goto yy602; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy600: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xDF) { - if (yych <= '=') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= '>') goto yy603; - if (yych <= 0x7F) goto yy582; - if (yych <= 0xC1) goto yy584; - goto yy587; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy588; - if (yych == 0xED) goto yy590; - goto yy589; - } else { - if (yych <= 0xF0) goto yy591; - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } -yy601: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'H') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'h') { - if (yych <= 'I') goto yy605; - goto yy582; - } else { - if (yych <= 'i') goto yy605; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy602: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'K') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'k') { - if (yych <= 'L') goto yy597; - goto yy582; - } else { - if (yych <= 'l') goto yy597; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy603: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy582; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy604; - if (yych <= '<') goto yy585; - } else { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - goto yy589; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy590; - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - } - } -yy604: - { return (bufsize_t)(p - start); } -yy605: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'O') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 'o') { - if (yych >= 'Q') goto yy582; - } else { - if (yych <= 'p') goto yy606; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -yy606: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy585; - } - if (yych <= 0xC1) { - if (yych <= 'S') { - if (yych <= 0x00) goto yy584; - if (yych == '\n') goto yy584; - goto yy582; - } else { - if (yych <= 's') { - if (yych <= 'T') goto yy600; - goto yy582; - } else { - if (yych <= 't') goto yy600; - if (yych <= 0x7F) goto yy582; - goto yy584; - } - } - } else { - if (yych <= 0xED) { - if (yych <= 0xDF) goto yy587; - if (yych <= 0xE0) goto yy588; - if (yych <= 0xEC) goto yy589; - goto yy590; - } else { - if (yych <= 0xF0) { - if (yych <= 0xEF) goto yy589; - goto yy591; - } else { - if (yych <= 0xF3) goto yy592; - if (yych <= 0xF4) goto yy593; - goto yy584; - } - } - } -} - -} - -// Try to match an HTML block end line of type 2 -bufsize_t _scan_html_block_end_2(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 0, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 128, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= 0xDF) { - if (yych <= ',') { - if (yych <= 0x00) goto yy609; - if (yych != '\n') goto yy611; - } else { - if (yych <= '-') goto yy612; - if (yych <= 0x7F) goto yy611; - if (yych >= 0xC2) goto yy613; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy614; - if (yych == 0xED) goto yy616; - goto yy615; - } else { - if (yych <= 0xF0) goto yy617; - if (yych <= 0xF3) goto yy618; - if (yych <= 0xF4) goto yy619; - } - } -yy609: - ++p; -yy610: - { return 0; } -yy611: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '\n') { - if (yych <= 0x00) goto yy610; - if (yych <= '\t') goto yy621; - goto yy610; - } else { - if (yych <= 0x7F) goto yy621; - if (yych <= 0xC1) goto yy610; - if (yych <= 0xF4) goto yy621; - goto yy610; - } -yy612: - yyaccept = 0; - yych = *(marker = ++p); - if (yybm[0+yych] & 128) { - goto yy631; - } - if (yych <= '\n') { - if (yych <= 0x00) goto yy610; - if (yych <= '\t') goto yy621; - goto yy610; - } else { - if (yych <= 0x7F) goto yy621; - if (yych <= 0xC1) goto yy610; - if (yych <= 0xF4) goto yy621; - goto yy610; - } -yy613: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy610; - if (yych <= 0xBF) goto yy620; - goto yy610; -yy614: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x9F) goto yy610; - if (yych <= 0xBF) goto yy624; - goto yy610; -yy615: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy610; - if (yych <= 0xBF) goto yy624; - goto yy610; -yy616: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy610; - if (yych <= 0x9F) goto yy624; - goto yy610; -yy617: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x8F) goto yy610; - if (yych <= 0xBF) goto yy626; - goto yy610; -yy618: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy610; - if (yych <= 0xBF) goto yy626; - goto yy610; -yy619: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy610; - if (yych <= 0x8F) goto yy626; - goto yy610; -yy620: - yych = *++p; -yy621: - if (yybm[0+yych] & 64) { - goto yy620; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy622; - if (yych <= '-') goto yy623; - } else { - if (yych <= 0xDF) goto yy624; - if (yych <= 0xE0) goto yy625; - goto yy626; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy627; - if (yych <= 0xEF) goto yy626; - goto yy628; - } else { - if (yych <= 0xF3) goto yy629; - if (yych <= 0xF4) goto yy630; - } - } -yy622: - p = marker; - if (yyaccept == 0) { - goto yy610; - } else { - goto yy634; - } -yy623: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy620; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy622; - if (yych <= '-') goto yy631; - goto yy622; - } else { - if (yych <= 0xDF) goto yy624; - if (yych <= 0xE0) goto yy625; - goto yy626; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy627; - if (yych <= 0xEF) goto yy626; - goto yy628; - } else { - if (yych <= 0xF3) goto yy629; - if (yych <= 0xF4) goto yy630; - goto yy622; - } - } -yy624: - yych = *++p; - if (yych <= 0x7F) goto yy622; - if (yych <= 0xBF) goto yy620; - goto yy622; -yy625: - yych = *++p; - if (yych <= 0x9F) goto yy622; - if (yych <= 0xBF) goto yy624; - goto yy622; -yy626: - yych = *++p; - if (yych <= 0x7F) goto yy622; - if (yych <= 0xBF) goto yy624; - goto yy622; -yy627: - yych = *++p; - if (yych <= 0x7F) goto yy622; - if (yych <= 0x9F) goto yy624; - goto yy622; -yy628: - yych = *++p; - if (yych <= 0x8F) goto yy622; - if (yych <= 0xBF) goto yy626; - goto yy622; -yy629: - yych = *++p; - if (yych <= 0x7F) goto yy622; - if (yych <= 0xBF) goto yy626; - goto yy622; -yy630: - yych = *++p; - if (yych <= 0x7F) goto yy622; - if (yych <= 0x8F) goto yy626; - goto yy622; -yy631: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy631; - } - if (yych <= 0xDF) { - if (yych <= '=') { - if (yych <= 0x00) goto yy622; - if (yych == '\n') goto yy622; - goto yy620; - } else { - if (yych <= '>') goto yy633; - if (yych <= 0x7F) goto yy620; - if (yych <= 0xC1) goto yy622; - goto yy624; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy625; - if (yych == 0xED) goto yy627; - goto yy626; - } else { - if (yych <= 0xF0) goto yy628; - if (yych <= 0xF3) goto yy629; - if (yych <= 0xF4) goto yy630; - goto yy622; - } - } -yy633: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy620; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy634; - if (yych <= '-') goto yy623; - } else { - if (yych <= 0xDF) goto yy624; - if (yych <= 0xE0) goto yy625; - goto yy626; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy627; - if (yych <= 0xEF) goto yy626; - goto yy628; - } else { - if (yych <= 0xF3) goto yy629; - if (yych <= 0xF4) goto yy630; - } - } -yy634: - { return (bufsize_t)(p - start); } -} - -} - -// Try to match an HTML block end line of type 3 -bufsize_t _scan_html_block_end_3(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 0, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 128, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= 0xDF) { - if (yych <= '>') { - if (yych <= 0x00) goto yy637; - if (yych != '\n') goto yy639; - } else { - if (yych <= '?') goto yy640; - if (yych <= 0x7F) goto yy639; - if (yych >= 0xC2) goto yy641; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy642; - if (yych == 0xED) goto yy644; - goto yy643; - } else { - if (yych <= 0xF0) goto yy645; - if (yych <= 0xF3) goto yy646; - if (yych <= 0xF4) goto yy647; - } - } -yy637: - ++p; -yy638: - { return 0; } -yy639: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '\n') { - if (yych <= 0x00) goto yy638; - if (yych <= '\t') goto yy649; - goto yy638; - } else { - if (yych <= 0x7F) goto yy649; - if (yych <= 0xC1) goto yy638; - if (yych <= 0xF4) goto yy649; - goto yy638; - } -yy640: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '=') { - if (yych <= 0x00) goto yy638; - if (yych == '\n') goto yy638; - goto yy649; - } else { - if (yych <= 0x7F) { - if (yych <= '>') goto yy660; - goto yy649; - } else { - if (yych <= 0xC1) goto yy638; - if (yych <= 0xF4) goto yy649; - goto yy638; - } - } -yy641: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy638; - if (yych <= 0xBF) goto yy648; - goto yy638; -yy642: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x9F) goto yy638; - if (yych <= 0xBF) goto yy653; - goto yy638; -yy643: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy638; - if (yych <= 0xBF) goto yy653; - goto yy638; -yy644: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy638; - if (yych <= 0x9F) goto yy653; - goto yy638; -yy645: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x8F) goto yy638; - if (yych <= 0xBF) goto yy655; - goto yy638; -yy646: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy638; - if (yych <= 0xBF) goto yy655; - goto yy638; -yy647: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy638; - if (yych <= 0x8F) goto yy655; - goto yy638; -yy648: - yych = *++p; -yy649: - if (yybm[0+yych] & 64) { - goto yy648; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy650; - if (yych <= '?') goto yy651; - } else { - if (yych <= 0xDF) goto yy653; - if (yych <= 0xE0) goto yy654; - goto yy655; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy656; - if (yych <= 0xEF) goto yy655; - goto yy657; - } else { - if (yych <= 0xF3) goto yy658; - if (yych <= 0xF4) goto yy659; - } - } -yy650: - p = marker; - if (yyaccept == 0) { - goto yy638; - } else { - goto yy661; - } -yy651: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy651; - } - if (yych <= 0xDF) { - if (yych <= '=') { - if (yych <= 0x00) goto yy650; - if (yych == '\n') goto yy650; - goto yy648; - } else { - if (yych <= '>') goto yy660; - if (yych <= 0x7F) goto yy648; - if (yych <= 0xC1) goto yy650; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy654; - if (yych == 0xED) goto yy656; - goto yy655; - } else { - if (yych <= 0xF0) goto yy657; - if (yych <= 0xF3) goto yy658; - if (yych <= 0xF4) goto yy659; - goto yy650; - } - } -yy653: - yych = *++p; - if (yych <= 0x7F) goto yy650; - if (yych <= 0xBF) goto yy648; - goto yy650; -yy654: - yych = *++p; - if (yych <= 0x9F) goto yy650; - if (yych <= 0xBF) goto yy653; - goto yy650; -yy655: - yych = *++p; - if (yych <= 0x7F) goto yy650; - if (yych <= 0xBF) goto yy653; - goto yy650; -yy656: - yych = *++p; - if (yych <= 0x7F) goto yy650; - if (yych <= 0x9F) goto yy653; - goto yy650; -yy657: - yych = *++p; - if (yych <= 0x8F) goto yy650; - if (yych <= 0xBF) goto yy655; - goto yy650; -yy658: - yych = *++p; - if (yych <= 0x7F) goto yy650; - if (yych <= 0xBF) goto yy655; - goto yy650; -yy659: - yych = *++p; - if (yych <= 0x7F) goto yy650; - if (yych <= 0x8F) goto yy655; - goto yy650; -yy660: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy648; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy661; - if (yych <= '?') goto yy651; - } else { - if (yych <= 0xDF) goto yy653; - if (yych <= 0xE0) goto yy654; - goto yy655; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy656; - if (yych <= 0xEF) goto yy655; - goto yy657; - } else { - if (yych <= 0xF3) goto yy658; - if (yych <= 0xF4) goto yy659; - } - } -yy661: - { return (bufsize_t)(p - start); } -} - -} - -// Try to match an HTML block end line of type 4 -bufsize_t _scan_html_block_end_4(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 0, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 64, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 128, 128, 128, 128, 128, 128, 128, 128, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yybm[0+yych] & 64) { - goto yy667; - } - if (yych <= 0xE0) { - if (yych <= '\n') { - if (yych <= 0x00) goto yy664; - if (yych <= '\t') goto yy666; - } else { - if (yych <= 0x7F) goto yy666; - if (yych <= 0xC1) goto yy664; - if (yych <= 0xDF) goto yy670; - goto yy671; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy673; - goto yy672; - } else { - if (yych <= 0xF0) goto yy674; - if (yych <= 0xF3) goto yy675; - if (yych <= 0xF4) goto yy676; - } - } -yy664: - ++p; -yy665: - { return 0; } -yy666: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '\n') { - if (yych <= 0x00) goto yy665; - if (yych <= '\t') goto yy678; - goto yy665; - } else { - if (yych <= 0x7F) goto yy678; - if (yych <= 0xC1) goto yy665; - if (yych <= 0xF4) goto yy678; - goto yy665; - } -yy667: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 128) { - goto yy677; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy669; - if (yych <= '>') goto yy667; - } else { - if (yych <= 0xDF) goto yy680; - if (yych <= 0xE0) goto yy681; - goto yy682; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy683; - if (yych <= 0xEF) goto yy682; - goto yy684; - } else { - if (yych <= 0xF3) goto yy685; - if (yych <= 0xF4) goto yy686; - } - } -yy669: - { return (bufsize_t)(p - start); } -yy670: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy665; - if (yych <= 0xBF) goto yy677; - goto yy665; -yy671: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x9F) goto yy665; - if (yych <= 0xBF) goto yy680; - goto yy665; -yy672: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy665; - if (yych <= 0xBF) goto yy680; - goto yy665; -yy673: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy665; - if (yych <= 0x9F) goto yy680; - goto yy665; -yy674: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x8F) goto yy665; - if (yych <= 0xBF) goto yy682; - goto yy665; -yy675: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy665; - if (yych <= 0xBF) goto yy682; - goto yy665; -yy676: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy665; - if (yych <= 0x8F) goto yy682; - goto yy665; -yy677: - yych = *++p; -yy678: - if (yybm[0+yych] & 128) { - goto yy677; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy679; - if (yych <= '>') goto yy667; - } else { - if (yych <= 0xDF) goto yy680; - if (yych <= 0xE0) goto yy681; - goto yy682; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy683; - if (yych <= 0xEF) goto yy682; - goto yy684; - } else { - if (yych <= 0xF3) goto yy685; - if (yych <= 0xF4) goto yy686; - } - } -yy679: - p = marker; - if (yyaccept == 0) { - goto yy665; - } else { - goto yy669; - } -yy680: - yych = *++p; - if (yych <= 0x7F) goto yy679; - if (yych <= 0xBF) goto yy677; - goto yy679; -yy681: - yych = *++p; - if (yych <= 0x9F) goto yy679; - if (yych <= 0xBF) goto yy680; - goto yy679; -yy682: - yych = *++p; - if (yych <= 0x7F) goto yy679; - if (yych <= 0xBF) goto yy680; - goto yy679; -yy683: - yych = *++p; - if (yych <= 0x7F) goto yy679; - if (yych <= 0x9F) goto yy680; - goto yy679; -yy684: - yych = *++p; - if (yych <= 0x8F) goto yy679; - if (yych <= 0xBF) goto yy682; - goto yy679; -yy685: - yych = *++p; - if (yych <= 0x7F) goto yy679; - if (yych <= 0xBF) goto yy682; - goto yy679; -yy686: - yych = *++p; - if (yych <= 0x7F) goto yy679; - if (yych <= 0x8F) goto yy682; - goto yy679; -} - -} - -// Try to match an HTML block end line of type 5 -bufsize_t _scan_html_block_end_5(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 0, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 128, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= 0xDF) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy689; - if (yych != '\n') goto yy691; - } else { - if (yych <= ']') goto yy692; - if (yych <= 0x7F) goto yy691; - if (yych >= 0xC2) goto yy693; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy694; - if (yych == 0xED) goto yy696; - goto yy695; - } else { - if (yych <= 0xF0) goto yy697; - if (yych <= 0xF3) goto yy698; - if (yych <= 0xF4) goto yy699; - } - } -yy689: - ++p; -yy690: - { return 0; } -yy691: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '\n') { - if (yych <= 0x00) goto yy690; - if (yych <= '\t') goto yy701; - goto yy690; - } else { - if (yych <= 0x7F) goto yy701; - if (yych <= 0xC1) goto yy690; - if (yych <= 0xF4) goto yy701; - goto yy690; - } -yy692: - yyaccept = 0; - yych = *(marker = ++p); - if (yybm[0+yych] & 128) { - goto yy711; - } - if (yych <= '\n') { - if (yych <= 0x00) goto yy690; - if (yych <= '\t') goto yy701; - goto yy690; - } else { - if (yych <= 0x7F) goto yy701; - if (yych <= 0xC1) goto yy690; - if (yych <= 0xF4) goto yy701; - goto yy690; - } -yy693: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy690; - if (yych <= 0xBF) goto yy700; - goto yy690; -yy694: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x9F) goto yy690; - if (yych <= 0xBF) goto yy704; - goto yy690; -yy695: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy690; - if (yych <= 0xBF) goto yy704; - goto yy690; -yy696: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy690; - if (yych <= 0x9F) goto yy704; - goto yy690; -yy697: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x8F) goto yy690; - if (yych <= 0xBF) goto yy706; - goto yy690; -yy698: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy690; - if (yych <= 0xBF) goto yy706; - goto yy690; -yy699: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x7F) goto yy690; - if (yych <= 0x8F) goto yy706; - goto yy690; -yy700: - yych = *++p; -yy701: - if (yybm[0+yych] & 64) { - goto yy700; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy702; - if (yych <= ']') goto yy703; - } else { - if (yych <= 0xDF) goto yy704; - if (yych <= 0xE0) goto yy705; - goto yy706; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy707; - if (yych <= 0xEF) goto yy706; - goto yy708; - } else { - if (yych <= 0xF3) goto yy709; - if (yych <= 0xF4) goto yy710; - } - } -yy702: - p = marker; - if (yyaccept == 0) { - goto yy690; - } else { - goto yy714; - } -yy703: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy700; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy702; - if (yych <= ']') goto yy711; - goto yy702; - } else { - if (yych <= 0xDF) goto yy704; - if (yych <= 0xE0) goto yy705; - goto yy706; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy707; - if (yych <= 0xEF) goto yy706; - goto yy708; - } else { - if (yych <= 0xF3) goto yy709; - if (yych <= 0xF4) goto yy710; - goto yy702; - } - } -yy704: - yych = *++p; - if (yych <= 0x7F) goto yy702; - if (yych <= 0xBF) goto yy700; - goto yy702; -yy705: - yych = *++p; - if (yych <= 0x9F) goto yy702; - if (yych <= 0xBF) goto yy704; - goto yy702; -yy706: - yych = *++p; - if (yych <= 0x7F) goto yy702; - if (yych <= 0xBF) goto yy704; - goto yy702; -yy707: - yych = *++p; - if (yych <= 0x7F) goto yy702; - if (yych <= 0x9F) goto yy704; - goto yy702; -yy708: - yych = *++p; - if (yych <= 0x8F) goto yy702; - if (yych <= 0xBF) goto yy706; - goto yy702; -yy709: - yych = *++p; - if (yych <= 0x7F) goto yy702; - if (yych <= 0xBF) goto yy706; - goto yy702; -yy710: - yych = *++p; - if (yych <= 0x7F) goto yy702; - if (yych <= 0x8F) goto yy706; - goto yy702; -yy711: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy711; - } - if (yych <= 0xDF) { - if (yych <= '=') { - if (yych <= 0x00) goto yy702; - if (yych == '\n') goto yy702; - goto yy700; - } else { - if (yych <= '>') goto yy713; - if (yych <= 0x7F) goto yy700; - if (yych <= 0xC1) goto yy702; - goto yy704; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy705; - if (yych == 0xED) goto yy707; - goto yy706; - } else { - if (yych <= 0xF0) goto yy708; - if (yych <= 0xF3) goto yy709; - if (yych <= 0xF4) goto yy710; - goto yy702; - } - } -yy713: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy700; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= '\n') goto yy714; - if (yych <= ']') goto yy703; - } else { - if (yych <= 0xDF) goto yy704; - if (yych <= 0xE0) goto yy705; - goto yy706; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy707; - if (yych <= 0xEF) goto yy706; - goto yy708; - } else { - if (yych <= 0xF3) goto yy709; - if (yych <= 0xF4) goto yy710; - } - } -yy714: - { return (bufsize_t)(p - start); } -} - -} - -// Try to match a link title (in single quotes, in double quotes, or -// in parentheses), returning number of chars matched. Allow one -// level of internal nesting (quotes within quotes). -bufsize_t _scan_link_title(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - static const unsigned char yybm[] = { - 0, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 192, 208, 208, 208, 208, 144, - 80, 80, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 32, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 208, 208, 208, 208, 208, 208, 208, 208, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych <= '&') { - if (yych == '"') goto yy719; - } else { - if (yych <= '\'') goto yy720; - if (yych <= '(') goto yy721; - } - ++p; -yy718: - { return 0; } -yy719: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x00) goto yy718; - if (yych <= 0x7F) goto yy723; - if (yych <= 0xC1) goto yy718; - if (yych <= 0xF4) goto yy723; - goto yy718; -yy720: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= 0x00) goto yy718; - if (yych <= 0x7F) goto yy737; - if (yych <= 0xC1) goto yy718; - if (yych <= 0xF4) goto yy737; - goto yy718; -yy721: - yyaccept = 0; - yych = *(marker = ++p); - if (yych <= '(') { - if (yych <= 0x00) goto yy718; - if (yych <= '\'') goto yy750; - goto yy718; - } else { - if (yych <= 0x7F) goto yy750; - if (yych <= 0xC1) goto yy718; - if (yych <= 0xF4) goto yy750; - goto yy718; - } -yy722: - yych = *++p; -yy723: - if (yybm[0+yych] & 16) { - goto yy722; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy724; - if (yych <= '"') goto yy725; - goto yy727; - } else { - if (yych <= 0xC1) goto yy724; - if (yych <= 0xDF) goto yy729; - goto yy730; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy732; - goto yy731; - } else { - if (yych <= 0xF0) goto yy733; - if (yych <= 0xF3) goto yy734; - if (yych <= 0xF4) goto yy735; - } - } -yy724: - p = marker; - if (yyaccept <= 1) { - if (yyaccept == 0) { - goto yy718; - } else { - goto yy726; - } - } else { - if (yyaccept == 2) { - goto yy739; - } else { - goto yy752; - } - } -yy725: - ++p; -yy726: - { return (bufsize_t)(p - start); } -yy727: - yych = *++p; - if (yybm[0+yych] & 16) { - goto yy722; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy724; - if (yych <= '"') goto yy762; - goto yy727; - } else { - if (yych <= 0xC1) goto yy724; - if (yych >= 0xE0) goto yy730; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy732; - goto yy731; - } else { - if (yych <= 0xF0) goto yy733; - if (yych <= 0xF3) goto yy734; - if (yych <= 0xF4) goto yy735; - goto yy724; - } - } -yy729: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy722; - goto yy724; -yy730: - yych = *++p; - if (yych <= 0x9F) goto yy724; - if (yych <= 0xBF) goto yy729; - goto yy724; -yy731: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy729; - goto yy724; -yy732: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0x9F) goto yy729; - goto yy724; -yy733: - yych = *++p; - if (yych <= 0x8F) goto yy724; - if (yych <= 0xBF) goto yy731; - goto yy724; -yy734: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy731; - goto yy724; -yy735: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0x8F) goto yy731; - goto yy724; -yy736: - yych = *++p; -yy737: - if (yybm[0+yych] & 64) { - goto yy736; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy724; - if (yych >= '(') goto yy740; - } else { - if (yych <= 0xC1) goto yy724; - if (yych <= 0xDF) goto yy742; - goto yy743; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy745; - goto yy744; - } else { - if (yych <= 0xF0) goto yy746; - if (yych <= 0xF3) goto yy747; - if (yych <= 0xF4) goto yy748; - goto yy724; - } - } -yy738: - ++p; -yy739: - { return (bufsize_t)(p - start); } -yy740: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy736; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy724; - if (yych <= '\'') goto yy763; - goto yy740; - } else { - if (yych <= 0xC1) goto yy724; - if (yych >= 0xE0) goto yy743; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy745; - goto yy744; - } else { - if (yych <= 0xF0) goto yy746; - if (yych <= 0xF3) goto yy747; - if (yych <= 0xF4) goto yy748; - goto yy724; - } - } -yy742: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy736; - goto yy724; -yy743: - yych = *++p; - if (yych <= 0x9F) goto yy724; - if (yych <= 0xBF) goto yy742; - goto yy724; -yy744: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy742; - goto yy724; -yy745: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0x9F) goto yy742; - goto yy724; -yy746: - yych = *++p; - if (yych <= 0x8F) goto yy724; - if (yych <= 0xBF) goto yy744; - goto yy724; -yy747: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy744; - goto yy724; -yy748: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0x8F) goto yy744; - goto yy724; -yy749: - yych = *++p; -yy750: - if (yybm[0+yych] & 128) { - goto yy749; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= '(') goto yy724; - if (yych >= '*') goto yy753; - } else { - if (yych <= 0xC1) goto yy724; - if (yych <= 0xDF) goto yy755; - goto yy756; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy758; - goto yy757; - } else { - if (yych <= 0xF0) goto yy759; - if (yych <= 0xF3) goto yy760; - if (yych <= 0xF4) goto yy761; - goto yy724; - } - } -yy751: - ++p; -yy752: - { return (bufsize_t)(p - start); } -yy753: - yych = *++p; - if (yych <= 0xDF) { - if (yych <= '[') { - if (yych <= 0x00) goto yy724; - if (yych == ')') goto yy764; - goto yy749; - } else { - if (yych <= '\\') goto yy753; - if (yych <= 0x7F) goto yy749; - if (yych <= 0xC1) goto yy724; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) goto yy756; - if (yych == 0xED) goto yy758; - goto yy757; - } else { - if (yych <= 0xF0) goto yy759; - if (yych <= 0xF3) goto yy760; - if (yych <= 0xF4) goto yy761; - goto yy724; - } - } -yy755: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy749; - goto yy724; -yy756: - yych = *++p; - if (yych <= 0x9F) goto yy724; - if (yych <= 0xBF) goto yy755; - goto yy724; -yy757: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy755; - goto yy724; -yy758: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0x9F) goto yy755; - goto yy724; -yy759: - yych = *++p; - if (yych <= 0x8F) goto yy724; - if (yych <= 0xBF) goto yy757; - goto yy724; -yy760: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0xBF) goto yy757; - goto yy724; -yy761: - yych = *++p; - if (yych <= 0x7F) goto yy724; - if (yych <= 0x8F) goto yy757; - goto yy724; -yy762: - yyaccept = 1; - yych = *(marker = ++p); - if (yybm[0+yych] & 16) { - goto yy722; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy726; - if (yych <= '"') goto yy725; - goto yy727; - } else { - if (yych <= 0xC1) goto yy726; - if (yych <= 0xDF) goto yy729; - goto yy730; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy732; - goto yy731; - } else { - if (yych <= 0xF0) goto yy733; - if (yych <= 0xF3) goto yy734; - if (yych <= 0xF4) goto yy735; - goto yy726; - } - } -yy763: - yyaccept = 2; - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy736; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= 0x00) goto yy739; - if (yych <= '\'') goto yy738; - goto yy740; - } else { - if (yych <= 0xC1) goto yy739; - if (yych <= 0xDF) goto yy742; - goto yy743; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy745; - goto yy744; - } else { - if (yych <= 0xF0) goto yy746; - if (yych <= 0xF3) goto yy747; - if (yych <= 0xF4) goto yy748; - goto yy739; - } - } -yy764: - yyaccept = 3; - yych = *(marker = ++p); - if (yybm[0+yych] & 128) { - goto yy749; - } - if (yych <= 0xE0) { - if (yych <= '\\') { - if (yych <= '(') goto yy752; - if (yych <= ')') goto yy751; - goto yy753; - } else { - if (yych <= 0xC1) goto yy752; - if (yych <= 0xDF) goto yy755; - goto yy756; - } - } else { - if (yych <= 0xEF) { - if (yych == 0xED) goto yy758; - goto yy757; - } else { - if (yych <= 0xF0) goto yy759; - if (yych <= 0xF3) goto yy760; - if (yych <= 0xF4) goto yy761; - goto yy752; - } - } -} - -} - -// Match space characters, including newlines. -bufsize_t _scan_spacechars(const unsigned char *p) -{ - const unsigned char *start = p; \ - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 128, 128, 128, 128, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yybm[0+yych] & 128) { - goto yy769; - } - ++p; - { return 0; } -yy769: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy769; - } - { return (bufsize_t)(p - start); } -} - -} - -// Match ATX heading start. -bufsize_t _scan_atx_heading_start(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych == '#') goto yy776; - ++p; -yy775: - { return 0; } -yy776: - yych = *(marker = ++p); - if (yybm[0+yych] & 128) { - goto yy777; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy775; - if (yych <= '\n') goto yy780; - goto yy775; - } else { - if (yych <= '\r') goto yy780; - if (yych == '#') goto yy781; - goto yy775; - } -yy777: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy777; - } -yy779: - { return (bufsize_t)(p - start); } -yy780: - ++p; - goto yy779; -yy781: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy777; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy782; - if (yych <= '\n') goto yy780; - } else { - if (yych <= '\r') goto yy780; - if (yych == '#') goto yy783; - } -yy782: - p = marker; - goto yy775; -yy783: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy777; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy782; - if (yych <= '\n') goto yy780; - goto yy782; - } else { - if (yych <= '\r') goto yy780; - if (yych != '#') goto yy782; - } - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy777; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy782; - if (yych <= '\n') goto yy780; - goto yy782; - } else { - if (yych <= '\r') goto yy780; - if (yych != '#') goto yy782; - } - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy777; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy782; - if (yych <= '\n') goto yy780; - goto yy782; - } else { - if (yych <= '\r') goto yy780; - if (yych != '#') goto yy782; - } - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy777; - } - if (yych <= 0x08) goto yy782; - if (yych <= '\n') goto yy780; - if (yych == '\r') goto yy780; - goto yy782; -} - -} - -// Match setext heading line. Return 1 for level-1 heading, -// 2 for level-2, 0 for no match. -bufsize_t _scan_setext_heading_line(const unsigned char *p) -{ - const unsigned char *marker = NULL; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 32, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 64, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 128, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych == '-') goto yy791; - if (yych == '=') goto yy792; - ++p; -yy790: - { return 0; } -yy791: - yych = *(marker = ++p); - if (yybm[0+yych] & 64) { - goto yy798; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy790; - if (yych <= '\n') goto yy794; - goto yy790; - } else { - if (yych <= '\r') goto yy794; - if (yych == ' ') goto yy794; - goto yy790; - } -yy792: - yych = *(marker = ++p); - if (yybm[0+yych] & 128) { - goto yy804; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy790; - if (yych <= '\n') goto yy801; - goto yy790; - } else { - if (yych <= '\r') goto yy801; - if (yych == ' ') goto yy801; - goto yy790; - } -yy793: - yych = *++p; -yy794: - if (yybm[0+yych] & 32) { - goto yy793; - } - if (yych <= 0x08) goto yy795; - if (yych <= '\n') goto yy796; - if (yych == '\r') goto yy796; -yy795: - p = marker; - goto yy790; -yy796: - ++p; - { return 2; } -yy798: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy793; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy795; - if (yych <= '\n') goto yy796; - goto yy795; - } else { - if (yych <= '\r') goto yy796; - if (yych == '-') goto yy798; - goto yy795; - } -yy800: - yych = *++p; -yy801: - if (yych <= '\f') { - if (yych <= 0x08) goto yy795; - if (yych <= '\t') goto yy800; - if (yych >= '\v') goto yy795; - } else { - if (yych <= '\r') goto yy802; - if (yych == ' ') goto yy800; - goto yy795; - } -yy802: - ++p; - { return 1; } -yy804: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy804; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy795; - if (yych <= '\t') goto yy800; - if (yych <= '\n') goto yy802; - goto yy795; - } else { - if (yych <= '\r') goto yy802; - if (yych == ' ') goto yy800; - goto yy795; - } -} - -} - -// Scan an opening code fence. -bufsize_t _scan_open_code_fence(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 0, 192, 192, 0, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 144, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 192, 192, - 192, 192, 192, 192, 192, 192, 224, 192, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych == '`') goto yy810; - if (yych == '~') goto yy811; - ++p; -yy809: - { return 0; } -yy810: - yych = *(marker = ++p); - if (yych == '`') goto yy812; - goto yy809; -yy811: - yych = *(marker = ++p); - if (yych == '~') goto yy814; - goto yy809; -yy812: - yych = *++p; - if (yybm[0+yych] & 16) { - goto yy815; - } -yy813: - p = marker; - goto yy809; -yy814: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy817; - } - goto yy813; -yy815: - yych = *++p; - if (yybm[0+yych] & 16) { - goto yy815; - } - if (yych <= 0xDF) { - if (yych <= '\f') { - if (yych <= 0x00) goto yy813; - if (yych == '\n') { - marker = p; - goto yy821; - } - marker = p; - goto yy819; - } else { - if (yych <= '\r') { - marker = p; - goto yy821; - } - if (yych <= 0x7F) { - marker = p; - goto yy819; - } - if (yych <= 0xC1) goto yy813; - marker = p; - goto yy823; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) { - marker = p; - goto yy824; - } - if (yych == 0xED) { - marker = p; - goto yy826; - } - marker = p; - goto yy825; - } else { - if (yych <= 0xF0) { - marker = p; - goto yy827; - } - if (yych <= 0xF3) { - marker = p; - goto yy828; - } - if (yych <= 0xF4) { - marker = p; - goto yy829; - } - goto yy813; - } - } -yy817: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy817; - } - if (yych <= 0xDF) { - if (yych <= '\f') { - if (yych <= 0x00) goto yy813; - if (yych == '\n') { - marker = p; - goto yy832; - } - marker = p; - goto yy830; - } else { - if (yych <= '\r') { - marker = p; - goto yy832; - } - if (yych <= 0x7F) { - marker = p; - goto yy830; - } - if (yych <= 0xC1) goto yy813; - marker = p; - goto yy834; - } - } else { - if (yych <= 0xEF) { - if (yych <= 0xE0) { - marker = p; - goto yy835; - } - if (yych == 0xED) { - marker = p; - goto yy837; - } - marker = p; - goto yy836; - } else { - if (yych <= 0xF0) { - marker = p; - goto yy838; - } - if (yych <= 0xF3) { - marker = p; - goto yy839; - } - if (yych <= 0xF4) { - marker = p; - goto yy840; - } - goto yy813; - } - } -yy819: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy819; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy813; - if (yych >= 0x0E) goto yy813; - } else { - if (yych <= 0xDF) goto yy823; - if (yych <= 0xE0) goto yy824; - goto yy825; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy826; - if (yych <= 0xEF) goto yy825; - goto yy827; - } else { - if (yych <= 0xF3) goto yy828; - if (yych <= 0xF4) goto yy829; - goto yy813; - } - } -yy821: - ++p; - p = marker; - { return (bufsize_t)(p - start); } -yy823: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0xBF) goto yy819; - goto yy813; -yy824: - yych = *++p; - if (yych <= 0x9F) goto yy813; - if (yych <= 0xBF) goto yy823; - goto yy813; -yy825: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0xBF) goto yy823; - goto yy813; -yy826: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0x9F) goto yy823; - goto yy813; -yy827: - yych = *++p; - if (yych <= 0x8F) goto yy813; - if (yych <= 0xBF) goto yy825; - goto yy813; -yy828: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0xBF) goto yy825; - goto yy813; -yy829: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0x8F) goto yy825; - goto yy813; -yy830: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy830; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= 0x00) goto yy813; - if (yych >= 0x0E) goto yy813; - } else { - if (yych <= 0xDF) goto yy834; - if (yych <= 0xE0) goto yy835; - goto yy836; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy837; - if (yych <= 0xEF) goto yy836; - goto yy838; - } else { - if (yych <= 0xF3) goto yy839; - if (yych <= 0xF4) goto yy840; - goto yy813; - } - } -yy832: - ++p; - p = marker; - { return (bufsize_t)(p - start); } -yy834: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0xBF) goto yy830; - goto yy813; -yy835: - yych = *++p; - if (yych <= 0x9F) goto yy813; - if (yych <= 0xBF) goto yy834; - goto yy813; -yy836: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0xBF) goto yy834; - goto yy813; -yy837: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0x9F) goto yy834; - goto yy813; -yy838: - yych = *++p; - if (yych <= 0x8F) goto yy813; - if (yych <= 0xBF) goto yy836; - goto yy813; -yy839: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0xBF) goto yy836; - goto yy813; -yy840: - yych = *++p; - if (yych <= 0x7F) goto yy813; - if (yych <= 0x8F) goto yy836; - goto yy813; -} - -} - -// Scan a closing code fence with length at least len. -bufsize_t _scan_close_code_fence(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 128, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 128, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 32, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 64, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych == '`') goto yy845; - if (yych == '~') goto yy846; - ++p; -yy844: - { return 0; } -yy845: - yych = *(marker = ++p); - if (yych == '`') goto yy847; - goto yy844; -yy846: - yych = *(marker = ++p); - if (yych == '~') goto yy849; - goto yy844; -yy847: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy850; - } -yy848: - p = marker; - goto yy844; -yy849: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy852; - } - goto yy848; -yy850: - yych = *++p; - if (yybm[0+yych] & 32) { - goto yy850; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy848; - if (yych <= '\t') { - marker = p; - goto yy854; - } - if (yych <= '\n') { - marker = p; - goto yy856; - } - goto yy848; - } else { - if (yych <= '\r') { - marker = p; - goto yy856; - } - if (yych == ' ') { - marker = p; - goto yy854; - } - goto yy848; - } -yy852: - yych = *++p; - if (yybm[0+yych] & 64) { - goto yy852; - } - if (yych <= '\f') { - if (yych <= 0x08) goto yy848; - if (yych <= '\t') { - marker = p; - goto yy858; - } - if (yych <= '\n') { - marker = p; - goto yy860; - } - goto yy848; - } else { - if (yych <= '\r') { - marker = p; - goto yy860; - } - if (yych == ' ') { - marker = p; - goto yy858; - } - goto yy848; - } -yy854: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy854; - } - if (yych <= 0x08) goto yy848; - if (yych <= '\n') goto yy856; - if (yych != '\r') goto yy848; -yy856: - ++p; - p = marker; - { return (bufsize_t)(p - start); } -yy858: - yych = *++p; - if (yych <= '\f') { - if (yych <= 0x08) goto yy848; - if (yych <= '\t') goto yy858; - if (yych >= '\v') goto yy848; - } else { - if (yych <= '\r') goto yy860; - if (yych == ' ') goto yy858; - goto yy848; - } -yy860: - ++p; - p = marker; - { return (bufsize_t)(p - start); } -} - -} - -// Scans an entity. -// Returns number of chars matched. -bufsize_t _scan_entity(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - yych = *p; - if (yych == '&') goto yy866; - ++p; -yy865: - { return 0; } -yy866: - yych = *(marker = ++p); - if (yych <= '@') { - if (yych != '#') goto yy865; - } else { - if (yych <= 'Z') goto yy869; - if (yych <= '`') goto yy865; - if (yych <= 'z') goto yy869; - goto yy865; - } - yych = *++p; - if (yych <= 'W') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy870; - } else { - if (yych <= 'X') goto yy871; - if (yych == 'x') goto yy871; - } -yy868: - p = marker; - goto yy865; -yy869: - yych = *++p; - if (yych <= '@') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy872; - goto yy868; - } else { - if (yych <= 'Z') goto yy872; - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy872; - goto yy868; - } -yy870: - yych = *++p; - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy873; - if (yych == ';') goto yy874; - goto yy868; -yy871: - yych = *++p; - if (yych <= '@') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy876; - goto yy868; - } else { - if (yych <= 'F') goto yy876; - if (yych <= '`') goto yy868; - if (yych <= 'f') goto yy876; - goto yy868; - } -yy872: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy877; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy877; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy877; - goto yy868; - } - } -yy873: - yych = *++p; - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy878; - if (yych != ';') goto yy868; -yy874: - ++p; - { return (bufsize_t)(p - start); } -yy876: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy879; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'F') { - if (yych <= '@') goto yy868; - goto yy879; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'f') goto yy879; - goto yy868; - } - } -yy877: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy880; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy880; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy880; - goto yy868; - } - } -yy878: - yych = *++p; - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy881; - if (yych == ';') goto yy874; - goto yy868; -yy879: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy882; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'F') { - if (yych <= '@') goto yy868; - goto yy882; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'f') goto yy882; - goto yy868; - } - } -yy880: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy883; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy883; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy883; - goto yy868; - } - } -yy881: - yych = *++p; - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy884; - if (yych == ';') goto yy874; - goto yy868; -yy882: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy885; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'F') { - if (yych <= '@') goto yy868; - goto yy885; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'f') goto yy885; - goto yy868; - } - } -yy883: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy886; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy886; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy886; - goto yy868; - } - } -yy884: - yych = *++p; - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy887; - if (yych == ';') goto yy874; - goto yy868; -yy885: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy888; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'F') { - if (yych <= '@') goto yy868; - goto yy888; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'f') goto yy888; - goto yy868; - } - } -yy886: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy889; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy889; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy889; - goto yy868; - } - } -yy887: - yych = *++p; - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy890; - if (yych == ';') goto yy874; - goto yy868; -yy888: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy890; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'F') { - if (yych <= '@') goto yy868; - goto yy890; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'f') goto yy890; - goto yy868; - } - } -yy889: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy891; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy891; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy891; - goto yy868; - } - } -yy890: - yych = *++p; - if (yych == ';') goto yy874; - goto yy868; -yy891: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy892; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy892: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy893; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy893: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy894; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy894: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy895; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy895: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy896; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy896: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy897; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy897: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy898; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy898: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy899; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy899: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy900; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy900: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy901; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy901: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy902; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy902: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy903; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy903: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy904; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy904: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy905; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy905: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy906; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy906: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy907; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy907: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy908; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy908: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy909; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy909: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy910; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy910: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy911; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy911: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy912; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy912: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy913; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy913: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy914; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - } else { - if (yych <= '`') goto yy868; - if (yych >= '{') goto yy868; - } - } -yy914: - yych = *++p; - if (yych <= ';') { - if (yych <= '/') goto yy868; - if (yych <= '9') goto yy890; - if (yych <= ':') goto yy868; - goto yy874; - } else { - if (yych <= 'Z') { - if (yych <= '@') goto yy868; - goto yy890; - } else { - if (yych <= '`') goto yy868; - if (yych <= 'z') goto yy890; - goto yy868; - } - } -} - -} - -// Returns positive value if a URL begins in a way that is potentially -// dangerous, with javascript:, vbscript:, file:, or data:, otherwise 0. -bufsize_t _scan_dangerous_url(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - unsigned int yyaccept = 0; - yych = *p; - if (yych <= 'V') { - if (yych <= 'F') { - if (yych == 'D') goto yy919; - if (yych >= 'F') goto yy920; - } else { - if (yych == 'J') goto yy921; - if (yych >= 'V') goto yy922; - } - } else { - if (yych <= 'f') { - if (yych == 'd') goto yy919; - if (yych >= 'f') goto yy920; - } else { - if (yych <= 'j') { - if (yych >= 'j') goto yy921; - } else { - if (yych == 'v') goto yy922; - } - } - } - ++p; -yy918: - { return 0; } -yy919: - yyaccept = 0; - yych = *(marker = ++p); - if (yych == 'A') goto yy923; - if (yych == 'a') goto yy923; - goto yy918; -yy920: - yyaccept = 0; - yych = *(marker = ++p); - if (yych == 'I') goto yy925; - if (yych == 'i') goto yy925; - goto yy918; -yy921: - yyaccept = 0; - yych = *(marker = ++p); - if (yych == 'A') goto yy926; - if (yych == 'a') goto yy926; - goto yy918; -yy922: - yyaccept = 0; - yych = *(marker = ++p); - if (yych == 'B') goto yy927; - if (yych == 'b') goto yy927; - goto yy918; -yy923: - yych = *++p; - if (yych == 'T') goto yy928; - if (yych == 't') goto yy928; -yy924: - p = marker; - if (yyaccept == 0) { - goto yy918; - } else { - goto yy936; - } -yy925: - yych = *++p; - if (yych == 'L') goto yy929; - if (yych == 'l') goto yy929; - goto yy924; -yy926: - yych = *++p; - if (yych == 'V') goto yy930; - if (yych == 'v') goto yy930; - goto yy924; -yy927: - yych = *++p; - if (yych == 'S') goto yy931; - if (yych == 's') goto yy931; - goto yy924; -yy928: - yych = *++p; - if (yych == 'A') goto yy932; - if (yych == 'a') goto yy932; - goto yy924; -yy929: - yych = *++p; - if (yych == 'E') goto yy933; - if (yych == 'e') goto yy933; - goto yy924; -yy930: - yych = *++p; - if (yych == 'A') goto yy927; - if (yych == 'a') goto yy927; - goto yy924; -yy931: - yych = *++p; - if (yych == 'C') goto yy934; - if (yych == 'c') goto yy934; - goto yy924; -yy932: - yych = *++p; - if (yych == ':') goto yy935; - goto yy924; -yy933: - yych = *++p; - if (yych == ':') goto yy937; - goto yy924; -yy934: - yych = *++p; - if (yych == 'R') goto yy938; - if (yych == 'r') goto yy938; - goto yy924; -yy935: - yyaccept = 1; - yych = *(marker = ++p); - if (yych == 'I') goto yy939; - if (yych == 'i') goto yy939; -yy936: - { return (bufsize_t)(p - start); } -yy937: - ++p; - goto yy936; -yy938: - yych = *++p; - if (yych == 'I') goto yy940; - if (yych == 'i') goto yy940; - goto yy924; -yy939: - yych = *++p; - if (yych == 'M') goto yy941; - if (yych == 'm') goto yy941; - goto yy924; -yy940: - yych = *++p; - if (yych == 'P') goto yy942; - if (yych == 'p') goto yy942; - goto yy924; -yy941: - yych = *++p; - if (yych == 'A') goto yy943; - if (yych == 'a') goto yy943; - goto yy924; -yy942: - yych = *++p; - if (yych == 'T') goto yy933; - if (yych == 't') goto yy933; - goto yy924; -yy943: - yych = *++p; - if (yych == 'G') goto yy944; - if (yych != 'g') goto yy924; -yy944: - yych = *++p; - if (yych == 'E') goto yy945; - if (yych != 'e') goto yy924; -yy945: - yych = *++p; - if (yych != '/') goto yy924; - yych = *++p; - if (yych <= 'W') { - if (yych <= 'J') { - if (yych == 'G') goto yy947; - if (yych <= 'I') goto yy924; - goto yy948; - } else { - if (yych == 'P') goto yy949; - if (yych <= 'V') goto yy924; - goto yy950; - } - } else { - if (yych <= 'j') { - if (yych == 'g') goto yy947; - if (yych <= 'i') goto yy924; - goto yy948; - } else { - if (yych <= 'p') { - if (yych <= 'o') goto yy924; - goto yy949; - } else { - if (yych == 'w') goto yy950; - goto yy924; - } - } - } -yy947: - yych = *++p; - if (yych == 'I') goto yy951; - if (yych == 'i') goto yy951; - goto yy924; -yy948: - yych = *++p; - if (yych == 'P') goto yy952; - if (yych == 'p') goto yy952; - goto yy924; -yy949: - yych = *++p; - if (yych == 'N') goto yy953; - if (yych == 'n') goto yy953; - goto yy924; -yy950: - yych = *++p; - if (yych == 'E') goto yy954; - if (yych == 'e') goto yy954; - goto yy924; -yy951: - yych = *++p; - if (yych == 'F') goto yy955; - if (yych == 'f') goto yy955; - goto yy924; -yy952: - yych = *++p; - if (yych == 'E') goto yy953; - if (yych != 'e') goto yy924; -yy953: - yych = *++p; - if (yych == 'G') goto yy955; - if (yych == 'g') goto yy955; - goto yy924; -yy954: - yych = *++p; - if (yych == 'B') goto yy957; - if (yych == 'b') goto yy957; - goto yy924; -yy955: - ++p; - { return 0; } -yy957: - yych = *++p; - if (yych == 'P') goto yy955; - if (yych == 'p') goto yy955; - goto yy924; -} - -} - -// Scans a footnote definition opening. -bufsize_t _scan_footnote_definition(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; - -{ - unsigned char yych; - static const unsigned char yybm[] = { - 0, 64, 64, 64, 64, 64, 64, 64, - 64, 128, 0, 64, 64, 0, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 128, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 0, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 64, 64, 64, 64, 64, 64, 64, 64, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - }; - yych = *p; - if (yych == '[') goto yy962; - ++p; -yy961: - { return 0; } -yy962: - yych = *(marker = ++p); - if (yych != '^') goto yy961; - yych = *++p; - if (yych != ']') goto yy966; -yy964: - p = marker; - goto yy961; -yy965: - yych = *++p; -yy966: - if (yybm[0+yych] & 64) { - goto yy965; - } - if (yych <= 0xEC) { - if (yych <= 0xC1) { - if (yych <= ' ') goto yy964; - if (yych <= ']') goto yy974; - goto yy964; - } else { - if (yych <= 0xDF) goto yy967; - if (yych <= 0xE0) goto yy968; - goto yy969; - } - } else { - if (yych <= 0xF0) { - if (yych <= 0xED) goto yy970; - if (yych <= 0xEF) goto yy969; - goto yy971; - } else { - if (yych <= 0xF3) goto yy972; - if (yych <= 0xF4) goto yy973; - goto yy964; - } - } -yy967: - yych = *++p; - if (yych <= 0x7F) goto yy964; - if (yych <= 0xBF) goto yy965; - goto yy964; -yy968: - yych = *++p; - if (yych <= 0x9F) goto yy964; - if (yych <= 0xBF) goto yy967; - goto yy964; -yy969: - yych = *++p; - if (yych <= 0x7F) goto yy964; - if (yych <= 0xBF) goto yy967; - goto yy964; -yy970: - yych = *++p; - if (yych <= 0x7F) goto yy964; - if (yych <= 0x9F) goto yy967; - goto yy964; -yy971: - yych = *++p; - if (yych <= 0x8F) goto yy964; - if (yych <= 0xBF) goto yy969; - goto yy964; -yy972: - yych = *++p; - if (yych <= 0x7F) goto yy964; - if (yych <= 0xBF) goto yy969; - goto yy964; -yy973: - yych = *++p; - if (yych <= 0x7F) goto yy964; - if (yych <= 0x8F) goto yy969; - goto yy964; -yy974: - yych = *++p; - if (yych != ':') goto yy964; -yy975: - yych = *++p; - if (yybm[0+yych] & 128) { - goto yy975; - } - { return (bufsize_t)(p - start); } -} - -} diff --git a/ext/commonmarker/scanners.h b/ext/commonmarker/scanners.h deleted file mode 100644 index 8861f8dd..00000000 --- a/ext/commonmarker/scanners.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef CMARK_SCANNERS_H -#define CMARK_SCANNERS_H - -#include "cmark-gfm.h" -#include "chunk.h" - -#ifdef __cplusplus -extern "C" { -#endif - -bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c, - bufsize_t offset); -bufsize_t _scan_scheme(const unsigned char *p); -bufsize_t _scan_autolink_uri(const unsigned char *p); -bufsize_t _scan_autolink_email(const unsigned char *p); -bufsize_t _scan_html_tag(const unsigned char *p); -bufsize_t _scan_liberal_html_tag(const unsigned char *p); -bufsize_t _scan_html_block_start(const unsigned char *p); -bufsize_t _scan_html_block_start_7(const unsigned char *p); -bufsize_t _scan_html_block_end_1(const unsigned char *p); -bufsize_t _scan_html_block_end_2(const unsigned char *p); -bufsize_t _scan_html_block_end_3(const unsigned char *p); -bufsize_t _scan_html_block_end_4(const unsigned char *p); -bufsize_t _scan_html_block_end_5(const unsigned char *p); -bufsize_t _scan_link_title(const unsigned char *p); -bufsize_t _scan_spacechars(const unsigned char *p); -bufsize_t _scan_atx_heading_start(const unsigned char *p); -bufsize_t _scan_setext_heading_line(const unsigned char *p); -bufsize_t _scan_open_code_fence(const unsigned char *p); -bufsize_t _scan_close_code_fence(const unsigned char *p); -bufsize_t _scan_entity(const unsigned char *p); -bufsize_t _scan_dangerous_url(const unsigned char *p); -bufsize_t _scan_footnote_definition(const unsigned char *p); - -#define scan_scheme(c, n) _scan_at(&_scan_scheme, c, n) -#define scan_autolink_uri(c, n) _scan_at(&_scan_autolink_uri, c, n) -#define scan_autolink_email(c, n) _scan_at(&_scan_autolink_email, c, n) -#define scan_html_tag(c, n) _scan_at(&_scan_html_tag, c, n) -#define scan_liberal_html_tag(c, n) _scan_at(&_scan_liberal_html_tag, c, n) -#define scan_html_block_start(c, n) _scan_at(&_scan_html_block_start, c, n) -#define scan_html_block_start_7(c, n) _scan_at(&_scan_html_block_start_7, c, n) -#define scan_html_block_end_1(c, n) _scan_at(&_scan_html_block_end_1, c, n) -#define scan_html_block_end_2(c, n) _scan_at(&_scan_html_block_end_2, c, n) -#define scan_html_block_end_3(c, n) _scan_at(&_scan_html_block_end_3, c, n) -#define scan_html_block_end_4(c, n) _scan_at(&_scan_html_block_end_4, c, n) -#define scan_html_block_end_5(c, n) _scan_at(&_scan_html_block_end_5, c, n) -#define scan_link_title(c, n) _scan_at(&_scan_link_title, c, n) -#define scan_spacechars(c, n) _scan_at(&_scan_spacechars, c, n) -#define scan_atx_heading_start(c, n) _scan_at(&_scan_atx_heading_start, c, n) -#define scan_setext_heading_line(c, n) \ - _scan_at(&_scan_setext_heading_line, c, n) -#define scan_open_code_fence(c, n) _scan_at(&_scan_open_code_fence, c, n) -#define scan_close_code_fence(c, n) _scan_at(&_scan_close_code_fence, c, n) -#define scan_entity(c, n) _scan_at(&_scan_entity, c, n) -#define scan_dangerous_url(c, n) _scan_at(&_scan_dangerous_url, c, n) -#define scan_footnote_definition(c, n) _scan_at(&_scan_footnote_definition, c, n) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/scanners.re b/ext/commonmarker/scanners.re deleted file mode 100644 index 5af8b7b1..00000000 --- a/ext/commonmarker/scanners.re +++ /dev/null @@ -1,341 +0,0 @@ -#include -#include "chunk.h" -#include "scanners.h" - -bufsize_t _scan_at(bufsize_t (*scanner)(const unsigned char *), cmark_chunk *c, bufsize_t offset) -{ - bufsize_t res; - unsigned char *ptr = (unsigned char *)c->data; - - if (ptr == NULL || offset > c->len) { - return 0; - } else { - unsigned char lim = ptr[c->len]; - - ptr[c->len] = '\0'; - res = scanner(ptr + offset); - ptr[c->len] = lim; - } - - return res; -} - -/*!re2c - re2c:define:YYCTYPE = "unsigned char"; - re2c:define:YYCURSOR = p; - re2c:define:YYMARKER = marker; - re2c:define:YYCTXMARKER = marker; - re2c:yyfill:enable = 0; - - wordchar = [^\x00-\x20]; - - spacechar = [ \t\v\f\r\n]; - - reg_char = [^\\()\x00-\x20]; - - escaped_char = [\\][!"#$%&'()*+,./:;<=>?@[\\\]^_`{|}~-]; - - tagname = [A-Za-z][A-Za-z0-9-]*; - - blocktagname = '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'|'meta'|'nav'|'noframes'|'ol'|'optgroup'|'option'|'p'|'param'|'section'|'source'|'title'|'summary'|'table'|'tbody'|'td'|'tfoot'|'th'|'thead'|'title'|'tr'|'track'|'ul'; - - attributename = [a-zA-Z_:][a-zA-Z0-9:._-]*; - - unquotedvalue = [^"'=<>`\x00]+; - singlequotedvalue = ['][^'\x00]*[']; - doublequotedvalue = ["][^"\x00]*["]; - - attributevalue = unquotedvalue | singlequotedvalue | doublequotedvalue; - - attributevaluespec = spacechar* [=] spacechar* attributevalue; - - attribute = spacechar+ attributename attributevaluespec?; - - opentag = tagname attribute* spacechar* [/]? [>]; - closetag = [/] tagname spacechar* [>]; - - htmlcomment = "!---->" | ("!--" ([-]? [^\x00>-]) ([-]? [^\x00-])* "-->"); - - processinginstruction = "?" ([^?>\x00]+ | [?][^>\x00] | [>])* "?>"; - - declaration = "!" [A-Z]+ spacechar+ [^>\x00]* ">"; - - cdata = "![CDATA[" ([^\]\x00]+ | "]" [^\]\x00] | "]]" [^>\x00])* "]]>"; - - htmltag = opentag | closetag | htmlcomment | processinginstruction | - declaration | cdata; - - in_parens_nosp = [(] (reg_char|escaped_char|[\\])* [)]; - - in_double_quotes = ["] (escaped_char|[^"\x00])* ["]; - in_single_quotes = ['] (escaped_char|[^'\x00])* [']; - in_parens = [(] (escaped_char|[^)\x00])* [)]; - - scheme = [A-Za-z][A-Za-z0-9.+-]{1,31}; -*/ - -// Try to match a scheme including colon. -bufsize_t _scan_scheme(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - scheme [:] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match URI autolink after first <, returning number of chars matched. -bufsize_t _scan_autolink_uri(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - scheme [:][^\x00-\x20<>]*[>] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match email autolink after first <, returning num of chars matched. -bufsize_t _scan_autolink_email(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [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])?)* - [>] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match an HTML tag after first <, returning num of chars matched. -bufsize_t _scan_html_tag(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - htmltag { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to (liberally) match an HTML tag after first <, returning num of chars matched. -bufsize_t _scan_liberal_html_tag(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [^\n\x00]+ [>] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match an HTML block tag start line, returning -// an integer code for the type of block (1-6, matching the spec). -// #7 is handled by a separate function, below. -bufsize_t _scan_html_block_start(const unsigned char *p) -{ - const unsigned char *marker = NULL; -/*!re2c - [<] ('script'|'pre'|'style') (spacechar | [>]) { return 1; } - '' { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match an HTML block end line of type 3 -bufsize_t _scan_html_block_end_3(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [^\n\x00]* '?>' { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match an HTML block end line of type 4 -bufsize_t _scan_html_block_end_4(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [^\n\x00]* '>' { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match an HTML block end line of type 5 -bufsize_t _scan_html_block_end_5(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [^\n\x00]* ']]>' { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Try to match a link title (in single quotes, in double quotes, or -// in parentheses), returning number of chars matched. Allow one -// level of internal nesting (quotes within quotes). -bufsize_t _scan_link_title(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - ["] (escaped_char|[^"\x00])* ["] { return (bufsize_t)(p - start); } - ['] (escaped_char|[^'\x00])* ['] { return (bufsize_t)(p - start); } - [(] (escaped_char|[^)\x00])* [)] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Match space characters, including newlines. -bufsize_t _scan_spacechars(const unsigned char *p) -{ - const unsigned char *start = p; \ -/*!re2c - [ \t\v\f\r\n]+ { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Match ATX heading start. -bufsize_t _scan_atx_heading_start(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [#]{1,6} ([ \t]+|[\r\n]) { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Match setext heading line. Return 1 for level-1 heading, -// 2 for level-2, 0 for no match. -bufsize_t _scan_setext_heading_line(const unsigned char *p) -{ - const unsigned char *marker = NULL; -/*!re2c - [=]+ [ \t]* [\r\n] { return 1; } - [-]+ [ \t]* [\r\n] { return 2; } - * { return 0; } -*/ -} - -// Scan a thematic break line: "...three or more hyphens, asterisks, -// or underscores on a line by themselves. If you wish, you may use -// spaces between the hyphens or asterisks." -bufsize_t _scan_thematic_break(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - ([*][ \t]*){3,} [ \t]* [\r\n] { return (bufsize_t)(p - start); } - ([_][ \t]*){3,} [ \t]* [\r\n] { return (bufsize_t)(p - start); } - ([-][ \t]*){3,} [ \t]* [\r\n] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Scan an opening code fence. -bufsize_t _scan_open_code_fence(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [`]{3,} / [^`\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); } - [~]{3,} / [^~\r\n\x00]*[\r\n] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Scan a closing code fence with length at least len. -bufsize_t _scan_close_code_fence(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [`]{3,} / [ \t]*[\r\n] { return (bufsize_t)(p - start); } - [~]{3,} / [ \t]*[\r\n] { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Scans an entity. -// Returns number of chars matched. -bufsize_t _scan_entity(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - [&] ([#] ([Xx][A-Fa-f0-9]{1,8}|[0-9]{1,8}) |[A-Za-z][A-Za-z0-9]{1,31} ) [;] - { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Returns positive value if a URL begins in a way that is potentially -// dangerous, with javascript:, vbscript:, file:, or data:, otherwise 0. -bufsize_t _scan_dangerous_url(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - 'data:image/' ('png'|'gif'|'jpeg'|'webp') { return 0; } - 'javascript:' | 'vbscript:' | 'file:' | 'data:' { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} - -// Scans a footnote definition opening. -bufsize_t _scan_footnote_definition(const unsigned char *p) -{ - const unsigned char *marker = NULL; - const unsigned char *start = p; -/*!re2c - '[^' ([^\] \r\n\x00\t]+) ']:' [ \t]* { return (bufsize_t)(p - start); } - * { return 0; } -*/ -} diff --git a/ext/commonmarker/strikethrough.c b/ext/commonmarker/strikethrough.c deleted file mode 100644 index 8145d23b..00000000 --- a/ext/commonmarker/strikethrough.c +++ /dev/null @@ -1,167 +0,0 @@ -#include "strikethrough.h" -#include -#include - -cmark_node_type CMARK_NODE_STRIKETHROUGH; - -static cmark_node *match(cmark_syntax_extension *self, cmark_parser *parser, - cmark_node *parent, unsigned char character, - cmark_inline_parser *inline_parser) { - cmark_node *res = NULL; - int left_flanking, right_flanking, punct_before, punct_after, delims; - char buffer[101]; - - if (character != '~') - return NULL; - - delims = cmark_inline_parser_scan_delimiters( - inline_parser, sizeof(buffer) - 1, '~', - &left_flanking, - &right_flanking, &punct_before, &punct_after); - - memset(buffer, '~', delims); - buffer[delims] = 0; - - res = cmark_node_new_with_mem(CMARK_NODE_TEXT, parser->mem); - cmark_node_set_literal(res, buffer); - res->start_line = res->end_line = cmark_inline_parser_get_line(inline_parser); - res->start_column = cmark_inline_parser_get_column(inline_parser) - delims; - - if ((left_flanking || right_flanking) && - (delims == 2 || (!(parser->options & CMARK_OPT_STRIKETHROUGH_DOUBLE_TILDE) && delims == 1))) { - cmark_inline_parser_push_delimiter(inline_parser, character, left_flanking, - right_flanking, res); - } - - return res; -} - -static delimiter *insert(cmark_syntax_extension *self, cmark_parser *parser, - cmark_inline_parser *inline_parser, delimiter *opener, - delimiter *closer) { - cmark_node *strikethrough; - cmark_node *tmp, *next; - delimiter *delim, *tmp_delim; - delimiter *res = closer->next; - - strikethrough = opener->inl_text; - - if (opener->inl_text->as.literal.len != closer->inl_text->as.literal.len) - goto done; - - if (!cmark_node_set_type(strikethrough, CMARK_NODE_STRIKETHROUGH)) - goto done; - - cmark_node_set_syntax_extension(strikethrough, self); - - tmp = cmark_node_next(opener->inl_text); - - while (tmp) { - if (tmp == closer->inl_text) - break; - next = cmark_node_next(tmp); - cmark_node_append_child(strikethrough, tmp); - tmp = next; - } - - strikethrough->end_column = closer->inl_text->start_column + closer->inl_text->as.literal.len - 1; - cmark_node_free(closer->inl_text); - - delim = closer; - while (delim != NULL && delim != opener) { - tmp_delim = delim->previous; - cmark_inline_parser_remove_delimiter(inline_parser, delim); - delim = tmp_delim; - } - - cmark_inline_parser_remove_delimiter(inline_parser, opener); - -done: - return res; -} - -static const char *get_type_string(cmark_syntax_extension *extension, - cmark_node *node) { - return node->type == CMARK_NODE_STRIKETHROUGH ? "strikethrough" : ""; -} - -static int can_contain(cmark_syntax_extension *extension, cmark_node *node, - cmark_node_type child_type) { - if (node->type != CMARK_NODE_STRIKETHROUGH) - return false; - - return CMARK_NODE_TYPE_INLINE_P(child_type); -} - -static void commonmark_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - renderer->out(renderer, node, "~~", false, LITERAL); -} - -static void latex_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - // requires \usepackage{ulem} - bool entering = (ev_type == CMARK_EVENT_ENTER); - if (entering) { - renderer->out(renderer, node, "\\sout{", false, LITERAL); - } else { - renderer->out(renderer, node, "}", false, LITERAL); - } -} - -static void man_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - if (entering) { - renderer->cr(renderer); - renderer->out(renderer, node, ".ST \"", false, LITERAL); - } else { - renderer->out(renderer, node, "\"", false, LITERAL); - renderer->cr(renderer); - } -} - -static void html_render(cmark_syntax_extension *extension, - cmark_html_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - if (entering) { - cmark_strbuf_puts(renderer->html, ""); - } else { - cmark_strbuf_puts(renderer->html, ""); - } -} - -static void plaintext_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - renderer->out(renderer, node, "~", false, LITERAL); -} - -cmark_syntax_extension *create_strikethrough_extension(void) { - cmark_syntax_extension *ext = cmark_syntax_extension_new("strikethrough"); - cmark_llist *special_chars = NULL; - - cmark_syntax_extension_set_get_type_string_func(ext, get_type_string); - cmark_syntax_extension_set_can_contain_func(ext, can_contain); - cmark_syntax_extension_set_commonmark_render_func(ext, commonmark_render); - cmark_syntax_extension_set_latex_render_func(ext, latex_render); - cmark_syntax_extension_set_man_render_func(ext, man_render); - cmark_syntax_extension_set_html_render_func(ext, html_render); - cmark_syntax_extension_set_plaintext_render_func(ext, plaintext_render); - CMARK_NODE_STRIKETHROUGH = cmark_syntax_extension_add_node(1); - - cmark_syntax_extension_set_match_inline_func(ext, match); - cmark_syntax_extension_set_inline_from_delim_func(ext, insert); - - cmark_mem *mem = cmark_get_default_mem_allocator(); - special_chars = cmark_llist_append(mem, special_chars, (void *)'~'); - cmark_syntax_extension_set_special_inline_chars(ext, special_chars); - - cmark_syntax_extension_set_emphasis(ext, 1); - - return ext; -} diff --git a/ext/commonmarker/strikethrough.h b/ext/commonmarker/strikethrough.h deleted file mode 100644 index a52a2b4a..00000000 --- a/ext/commonmarker/strikethrough.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef CMARK_GFM_STRIKETHROUGH_H -#define CMARK_GFM_STRIKETHROUGH_H - -#include "cmark-gfm-core-extensions.h" - -extern cmark_node_type CMARK_NODE_STRIKETHROUGH; -cmark_syntax_extension *create_strikethrough_extension(void); - -#endif diff --git a/ext/commonmarker/syntax_extension.c b/ext/commonmarker/syntax_extension.c deleted file mode 100644 index d24fe43e..00000000 --- a/ext/commonmarker/syntax_extension.c +++ /dev/null @@ -1,149 +0,0 @@ -#include -#include - -#include "cmark-gfm.h" -#include "syntax_extension.h" -#include "buffer.h" - -extern cmark_mem CMARK_DEFAULT_MEM_ALLOCATOR; - -static cmark_mem *_mem = &CMARK_DEFAULT_MEM_ALLOCATOR; - -void cmark_syntax_extension_free(cmark_mem *mem, cmark_syntax_extension *extension) { - if (extension->free_function && extension->priv) { - extension->free_function(mem, extension->priv); - } - - cmark_llist_free(mem, extension->special_inline_chars); - mem->free(extension->name); - mem->free(extension); -} - -cmark_syntax_extension *cmark_syntax_extension_new(const char *name) { - cmark_syntax_extension *res = (cmark_syntax_extension *) _mem->calloc(1, sizeof(cmark_syntax_extension)); - res->name = (char *) _mem->calloc(1, sizeof(char) * (strlen(name)) + 1); - strcpy(res->name, name); - return res; -} - -cmark_node_type cmark_syntax_extension_add_node(int is_inline) { - cmark_node_type *ref = !is_inline ? &CMARK_NODE_LAST_BLOCK : &CMARK_NODE_LAST_INLINE; - - if ((*ref & CMARK_NODE_VALUE_MASK) == CMARK_NODE_VALUE_MASK) { - assert(false); - return (cmark_node_type) 0; - } - - return *ref = (cmark_node_type) ((int) *ref + 1); -} - -void cmark_syntax_extension_set_emphasis(cmark_syntax_extension *extension, - int emphasis) { - extension->emphasis = emphasis == 1; -} - -void cmark_syntax_extension_set_open_block_func(cmark_syntax_extension *extension, - cmark_open_block_func func) { - extension->try_opening_block = func; -} - -void cmark_syntax_extension_set_match_block_func(cmark_syntax_extension *extension, - cmark_match_block_func func) { - extension->last_block_matches = func; -} - -void cmark_syntax_extension_set_match_inline_func(cmark_syntax_extension *extension, - cmark_match_inline_func func) { - extension->match_inline = func; -} - -void cmark_syntax_extension_set_inline_from_delim_func(cmark_syntax_extension *extension, - cmark_inline_from_delim_func func) { - extension->insert_inline_from_delim = func; -} - -void cmark_syntax_extension_set_special_inline_chars(cmark_syntax_extension *extension, - cmark_llist *special_chars) { - extension->special_inline_chars = special_chars; -} - -void cmark_syntax_extension_set_get_type_string_func(cmark_syntax_extension *extension, - cmark_get_type_string_func func) { - extension->get_type_string_func = func; -} - -void cmark_syntax_extension_set_can_contain_func(cmark_syntax_extension *extension, - cmark_can_contain_func func) { - extension->can_contain_func = func; -} - -void cmark_syntax_extension_set_contains_inlines_func(cmark_syntax_extension *extension, - cmark_contains_inlines_func func) { - extension->contains_inlines_func = func; -} - -void cmark_syntax_extension_set_commonmark_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func) { - extension->commonmark_render_func = func; -} - -void cmark_syntax_extension_set_plaintext_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func) { - extension->plaintext_render_func = func; -} - -void cmark_syntax_extension_set_latex_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func) { - extension->latex_render_func = func; -} - -void cmark_syntax_extension_set_xml_attr_func(cmark_syntax_extension *extension, - cmark_xml_attr_func func) { - extension->xml_attr_func = func; -} - -void cmark_syntax_extension_set_man_render_func(cmark_syntax_extension *extension, - cmark_common_render_func func) { - extension->man_render_func = func; -} - -void cmark_syntax_extension_set_html_render_func(cmark_syntax_extension *extension, - cmark_html_render_func func) { - extension->html_render_func = func; -} - -void cmark_syntax_extension_set_html_filter_func(cmark_syntax_extension *extension, - cmark_html_filter_func func) { - extension->html_filter_func = func; -} - -void cmark_syntax_extension_set_postprocess_func(cmark_syntax_extension *extension, - cmark_postprocess_func func) { - extension->postprocess_func = func; -} - -void cmark_syntax_extension_set_private(cmark_syntax_extension *extension, - void *priv, - cmark_free_func free_func) { - extension->priv = priv; - extension->free_function = free_func; -} - -void *cmark_syntax_extension_get_private(cmark_syntax_extension *extension) { - return extension->priv; -} - -void cmark_syntax_extension_set_opaque_alloc_func(cmark_syntax_extension *extension, - cmark_opaque_alloc_func func) { - extension->opaque_alloc_func = func; -} - -void cmark_syntax_extension_set_opaque_free_func(cmark_syntax_extension *extension, - cmark_opaque_free_func func) { - extension->opaque_free_func = func; -} - -void cmark_syntax_extension_set_commonmark_escape_func(cmark_syntax_extension *extension, - cmark_commonmark_escape_func func) { - extension->commonmark_escape_func = func; -} diff --git a/ext/commonmarker/syntax_extension.h b/ext/commonmarker/syntax_extension.h deleted file mode 100644 index a5fe11e5..00000000 --- a/ext/commonmarker/syntax_extension.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef CMARK_SYNTAX_EXTENSION_H -#define CMARK_SYNTAX_EXTENSION_H - -#include "cmark-gfm.h" -#include "cmark-gfm-extension_api.h" -#include "config.h" - -struct cmark_syntax_extension { - cmark_match_block_func last_block_matches; - cmark_open_block_func try_opening_block; - cmark_match_inline_func match_inline; - cmark_inline_from_delim_func insert_inline_from_delim; - cmark_llist * special_inline_chars; - char * name; - void * priv; - bool emphasis; - cmark_free_func free_function; - cmark_get_type_string_func get_type_string_func; - cmark_can_contain_func can_contain_func; - cmark_contains_inlines_func contains_inlines_func; - cmark_common_render_func commonmark_render_func; - cmark_common_render_func plaintext_render_func; - cmark_common_render_func latex_render_func; - cmark_xml_attr_func xml_attr_func; - cmark_common_render_func man_render_func; - cmark_html_render_func html_render_func; - cmark_html_filter_func html_filter_func; - cmark_postprocess_func postprocess_func; - cmark_opaque_alloc_func opaque_alloc_func; - cmark_opaque_free_func opaque_free_func; - cmark_commonmark_escape_func commonmark_escape_func; -}; - -#endif diff --git a/ext/commonmarker/table.c b/ext/commonmarker/table.c deleted file mode 100644 index b9bf4840..00000000 --- a/ext/commonmarker/table.c +++ /dev/null @@ -1,848 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "ext_scanners.h" -#include "strikethrough.h" -#include "table.h" -#include "cmark-gfm-core-extensions.h" - -cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW, - CMARK_NODE_TABLE_CELL; - -typedef struct { - uint16_t n_columns; - int paragraph_offset; - cmark_llist *cells; -} table_row; - -typedef struct { - uint16_t n_columns; - uint8_t *alignments; -} node_table; - -typedef struct { - bool is_header; -} node_table_row; - -typedef struct { - cmark_strbuf *buf; - int start_offset, end_offset, internal_offset; -} node_cell; - -static void free_table_cell(cmark_mem *mem, void *data) { - node_cell *cell = (node_cell *)data; - cmark_strbuf_free((cmark_strbuf *)cell->buf); - mem->free(cell->buf); - mem->free(cell); -} - -static void free_table_row(cmark_mem *mem, table_row *row) { - if (!row) - return; - - cmark_llist_free_full(mem, row->cells, (cmark_free_func)free_table_cell); - - mem->free(row); -} - -static void free_node_table(cmark_mem *mem, void *ptr) { - node_table *t = (node_table *)ptr; - mem->free(t->alignments); - mem->free(t); -} - -static void free_node_table_row(cmark_mem *mem, void *ptr) { - mem->free(ptr); -} - -static int get_n_table_columns(cmark_node *node) { - if (!node || node->type != CMARK_NODE_TABLE) - return -1; - - return (int)((node_table *)node->as.opaque)->n_columns; -} - -static int set_n_table_columns(cmark_node *node, uint16_t n_columns) { - if (!node || node->type != CMARK_NODE_TABLE) - return 0; - - ((node_table *)node->as.opaque)->n_columns = n_columns; - return 1; -} - -static uint8_t *get_table_alignments(cmark_node *node) { - if (!node || node->type != CMARK_NODE_TABLE) - return 0; - - return ((node_table *)node->as.opaque)->alignments; -} - -static int set_table_alignments(cmark_node *node, uint8_t *alignments) { - if (!node || node->type != CMARK_NODE_TABLE) - return 0; - - ((node_table *)node->as.opaque)->alignments = alignments; - return 1; -} - -static cmark_strbuf *unescape_pipes(cmark_mem *mem, unsigned char *string, bufsize_t len) -{ - cmark_strbuf *res = (cmark_strbuf *)mem->calloc(1, sizeof(cmark_strbuf)); - bufsize_t r, w; - - cmark_strbuf_init(mem, res, len + 1); - cmark_strbuf_put(res, string, len); - cmark_strbuf_putc(res, '\0'); - - for (r = 0, w = 0; r < len; ++r) { - if (res->ptr[r] == '\\' && res->ptr[r + 1] == '|') - r++; - - res->ptr[w++] = res->ptr[r]; - } - - cmark_strbuf_truncate(res, w); - - return res; -} - -static table_row *row_from_string(cmark_syntax_extension *self, - cmark_parser *parser, unsigned char *string, - int len) { - // Parses a single table row. It has the following form: - // `delim? table_cell (delim table_cell)* delim? newline` - // Note that cells are allowed to be empty. - // - // From the GitHub-flavored Markdown specification: - // - // > Each row consists of cells containing arbitrary text, in which inlines - // > are parsed, separated by pipes (|). A leading and trailing pipe is also - // > recommended for clarity of reading, and if there’s otherwise parsing - // > ambiguity. - - table_row *row = NULL; - bufsize_t cell_matched = 1, pipe_matched = 1, offset; - int expect_more_cells = 1; - int row_end_offset = 0; - int int_overflow_abort = 0; - - row = (table_row *)parser->mem->calloc(1, sizeof(table_row)); - row->n_columns = 0; - row->cells = NULL; - - // Scan past the (optional) leading pipe. - offset = scan_table_cell_end(string, len, 0); - - // Parse the cells of the row. Stop if we reach the end of the input, or if we - // cannot detect any more cells. - while (offset < len && expect_more_cells) { - cell_matched = scan_table_cell(string, len, offset); - pipe_matched = scan_table_cell_end(string, len, offset + cell_matched); - - if (cell_matched || pipe_matched) { - // We are guaranteed to have a cell, since (1) either we found some - // content and cell_matched, or (2) we found an empty cell followed by a - // pipe. - cmark_strbuf *cell_buf = unescape_pipes(parser->mem, string + offset, - cell_matched); - cmark_strbuf_trim(cell_buf); - - node_cell *cell = (node_cell *)parser->mem->calloc(1, sizeof(*cell)); - cell->buf = cell_buf; - cell->start_offset = offset; - cell->end_offset = offset + cell_matched - 1; - - while (cell->start_offset > 0 && string[cell->start_offset - 1] != '|') { - --cell->start_offset; - ++cell->internal_offset; - } - - // make sure we never wrap row->n_columns - // offset will != len and our exit will clean up as intended - if (row->n_columns == UINT16_MAX) { - int_overflow_abort = 1; - break; - } - row->n_columns += 1; - row->cells = cmark_llist_append(parser->mem, row->cells, cell); - } - - offset += cell_matched + pipe_matched; - - if (pipe_matched) { - expect_more_cells = 1; - } else { - // We've scanned the last cell. Check if we have reached the end of the row - row_end_offset = scan_table_row_end(string, len, offset); - offset += row_end_offset; - - // If the end of the row is not the end of the input, - // the row is not a real row but potentially part of the paragraph - // preceding the table. - if (row_end_offset && offset != len) { - row->paragraph_offset = offset; - - cmark_llist_free_full(parser->mem, row->cells, (cmark_free_func)free_table_cell); - row->cells = NULL; - row->n_columns = 0; - - // Scan past the (optional) leading pipe. - offset += scan_table_cell_end(string, len, offset); - - expect_more_cells = 1; - } else { - expect_more_cells = 0; - } - } - } - - if (offset != len || row->n_columns == 0 || int_overflow_abort) { - free_table_row(parser->mem, row); - row = NULL; - } - - return row; -} - -static void try_inserting_table_header_paragraph(cmark_parser *parser, - cmark_node *parent_container, - unsigned char *parent_string, - int paragraph_offset) { - cmark_node *paragraph; - cmark_strbuf *paragraph_content; - - paragraph = cmark_node_new_with_mem(CMARK_NODE_PARAGRAPH, parser->mem); - - paragraph_content = unescape_pipes(parser->mem, parent_string, paragraph_offset); - cmark_strbuf_trim(paragraph_content); - cmark_node_set_string_content(paragraph, (char *) paragraph_content->ptr); - cmark_strbuf_free(paragraph_content); - parser->mem->free(paragraph_content); - - if (!cmark_node_insert_before(parent_container, paragraph)) { - parser->mem->free(paragraph); - } -} - -static cmark_node *try_opening_table_header(cmark_syntax_extension *self, - cmark_parser *parser, - cmark_node *parent_container, - unsigned char *input, int len) { - cmark_node *table_header; - table_row *header_row = NULL; - table_row *marker_row = NULL; - node_table_row *ntr; - const char *parent_string; - uint16_t i; - - if (!scan_table_start(input, len, cmark_parser_get_first_nonspace(parser))) { - return parent_container; - } - - // Since scan_table_start was successful, we must have a marker row. - marker_row = row_from_string(self, parser, - input + cmark_parser_get_first_nonspace(parser), - len - cmark_parser_get_first_nonspace(parser)); - // assert may be optimized out, don't rely on it for security boundaries - if (!marker_row) { - return parent_container; - } - - assert(marker_row); - - cmark_arena_push(); - - // Check for a matching header row. We call `row_from_string` with the entire - // (potentially long) parent container as input, but this should be safe since - // `row_from_string` bails out early if it does not find a row. - parent_string = cmark_node_get_string_content(parent_container); - header_row = row_from_string(self, parser, (unsigned char *)parent_string, - (int)strlen(parent_string)); - if (!header_row || header_row->n_columns != marker_row->n_columns) { - free_table_row(parser->mem, marker_row); - free_table_row(parser->mem, header_row); - cmark_arena_pop(); - return parent_container; - } - - if (cmark_arena_pop()) { - marker_row = row_from_string( - self, parser, input + cmark_parser_get_first_nonspace(parser), - len - cmark_parser_get_first_nonspace(parser)); - header_row = row_from_string(self, parser, (unsigned char *)parent_string, - (int)strlen(parent_string)); - // row_from_string can return NULL, add additional check to ensure n_columns match - if (!marker_row || !header_row || header_row->n_columns != marker_row->n_columns) { - free_table_row(parser->mem, marker_row); - free_table_row(parser->mem, header_row); - return parent_container; - } - } - - if (!cmark_node_set_type(parent_container, CMARK_NODE_TABLE)) { - free_table_row(parser->mem, header_row); - free_table_row(parser->mem, marker_row); - return parent_container; - } - - if (header_row->paragraph_offset) { - try_inserting_table_header_paragraph(parser, parent_container, (unsigned char *)parent_string, - header_row->paragraph_offset); - } - - cmark_node_set_syntax_extension(parent_container, self); - parent_container->as.opaque = parser->mem->calloc(1, sizeof(node_table)); - set_n_table_columns(parent_container, header_row->n_columns); - - // allocate alignments based on marker_row->n_columns - // since we populate the alignments array based on marker_row->cells - uint8_t *alignments = - (uint8_t *)parser->mem->calloc(marker_row->n_columns, sizeof(uint8_t)); - cmark_llist *it = marker_row->cells; - for (i = 0; it; it = it->next, ++i) { - node_cell *node = (node_cell *)it->data; - bool left = node->buf->ptr[0] == ':', right = node->buf->ptr[node->buf->size - 1] == ':'; - - if (left && right) - alignments[i] = 'c'; - else if (left) - alignments[i] = 'l'; - else if (right) - alignments[i] = 'r'; - } - set_table_alignments(parent_container, alignments); - - table_header = - cmark_parser_add_child(parser, parent_container, CMARK_NODE_TABLE_ROW, - parent_container->start_column); - cmark_node_set_syntax_extension(table_header, self); - table_header->end_column = parent_container->start_column + (int)strlen(parent_string) - 2; - table_header->start_line = table_header->end_line = parent_container->start_line; - - table_header->as.opaque = ntr = (node_table_row *)parser->mem->calloc(1, sizeof(node_table_row)); - ntr->is_header = true; - - { - cmark_llist *tmp; - - for (tmp = header_row->cells; tmp; tmp = tmp->next) { - node_cell *cell = (node_cell *) tmp->data; - cmark_node *header_cell = cmark_parser_add_child(parser, table_header, - CMARK_NODE_TABLE_CELL, parent_container->start_column + cell->start_offset); - header_cell->start_line = header_cell->end_line = parent_container->start_line; - header_cell->internal_offset = cell->internal_offset; - header_cell->end_column = parent_container->start_column + cell->end_offset; - cmark_node_set_string_content(header_cell, (char *) cell->buf->ptr); - cmark_node_set_syntax_extension(header_cell, self); - } - } - - cmark_parser_advance_offset( - parser, (char *)input, - (int)strlen((char *)input) - 1 - cmark_parser_get_offset(parser), false); - - free_table_row(parser->mem, header_row); - free_table_row(parser->mem, marker_row); - return parent_container; -} - -static cmark_node *try_opening_table_row(cmark_syntax_extension *self, - cmark_parser *parser, - cmark_node *parent_container, - unsigned char *input, int len) { - cmark_node *table_row_block; - table_row *row; - - if (cmark_parser_is_blank(parser)) - return NULL; - - table_row_block = - cmark_parser_add_child(parser, parent_container, CMARK_NODE_TABLE_ROW, - parent_container->start_column); - cmark_node_set_syntax_extension(table_row_block, self); - table_row_block->end_column = parent_container->end_column; - table_row_block->as.opaque = parser->mem->calloc(1, sizeof(node_table_row)); - - row = row_from_string(self, parser, input + cmark_parser_get_first_nonspace(parser), - len - cmark_parser_get_first_nonspace(parser)); - - if (!row) { - // clean up the dangling node - cmark_node_free(table_row_block); - return NULL; - } - - { - cmark_llist *tmp; - int i, table_columns = get_n_table_columns(parent_container); - - for (tmp = row->cells, i = 0; tmp && i < table_columns; tmp = tmp->next, ++i) { - node_cell *cell = (node_cell *) tmp->data; - cmark_node *node = cmark_parser_add_child(parser, table_row_block, - CMARK_NODE_TABLE_CELL, parent_container->start_column + cell->start_offset); - node->internal_offset = cell->internal_offset; - node->end_column = parent_container->start_column + cell->end_offset; - cmark_node_set_string_content(node, (char *) cell->buf->ptr); - cmark_node_set_syntax_extension(node, self); - } - - for (; i < table_columns; ++i) { - cmark_node *node = cmark_parser_add_child( - parser, table_row_block, CMARK_NODE_TABLE_CELL, 0); - cmark_node_set_syntax_extension(node, self); - } - } - - free_table_row(parser->mem, row); - - cmark_parser_advance_offset(parser, (char *)input, - len - 1 - cmark_parser_get_offset(parser), false); - - return table_row_block; -} - -static cmark_node *try_opening_table_block(cmark_syntax_extension *self, - int indented, cmark_parser *parser, - cmark_node *parent_container, - unsigned char *input, int len) { - cmark_node_type parent_type = cmark_node_get_type(parent_container); - - if (!indented && parent_type == CMARK_NODE_PARAGRAPH) { - return try_opening_table_header(self, parser, parent_container, input, len); - } else if (!indented && parent_type == CMARK_NODE_TABLE) { - return try_opening_table_row(self, parser, parent_container, input, len); - } - - return NULL; -} - -static int matches(cmark_syntax_extension *self, cmark_parser *parser, - unsigned char *input, int len, - cmark_node *parent_container) { - int res = 0; - - if (cmark_node_get_type(parent_container) == CMARK_NODE_TABLE) { - cmark_arena_push(); - table_row *new_row = row_from_string( - self, parser, input + cmark_parser_get_first_nonspace(parser), - len - cmark_parser_get_first_nonspace(parser)); - if (new_row && new_row->n_columns) - res = 1; - free_table_row(parser->mem, new_row); - cmark_arena_pop(); - } - - return res; -} - -static const char *get_type_string(cmark_syntax_extension *self, - cmark_node *node) { - if (node->type == CMARK_NODE_TABLE) { - return "table"; - } else if (node->type == CMARK_NODE_TABLE_ROW) { - if (((node_table_row *)node->as.opaque)->is_header) - return "table_header"; - else - return "table_row"; - } else if (node->type == CMARK_NODE_TABLE_CELL) { - return "table_cell"; - } - - return ""; -} - -static int can_contain(cmark_syntax_extension *extension, cmark_node *node, - cmark_node_type child_type) { - if (node->type == CMARK_NODE_TABLE) { - return child_type == CMARK_NODE_TABLE_ROW; - } else if (node->type == CMARK_NODE_TABLE_ROW) { - return child_type == CMARK_NODE_TABLE_CELL; - } else if (node->type == CMARK_NODE_TABLE_CELL) { - return child_type == CMARK_NODE_TEXT || child_type == CMARK_NODE_CODE || - child_type == CMARK_NODE_EMPH || child_type == CMARK_NODE_STRONG || - child_type == CMARK_NODE_LINK || child_type == CMARK_NODE_IMAGE || - child_type == CMARK_NODE_STRIKETHROUGH || - child_type == CMARK_NODE_HTML_INLINE || - child_type == CMARK_NODE_FOOTNOTE_REFERENCE; - } - return false; -} - -static int contains_inlines(cmark_syntax_extension *extension, - cmark_node *node) { - return node->type == CMARK_NODE_TABLE_CELL; -} - -static void commonmark_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - - if (node->type == CMARK_NODE_TABLE) { - renderer->blankline(renderer); - } else if (node->type == CMARK_NODE_TABLE_ROW) { - if (entering) { - renderer->cr(renderer); - renderer->out(renderer, node, "|", false, LITERAL); - } - } else if (node->type == CMARK_NODE_TABLE_CELL) { - if (entering) { - renderer->out(renderer, node, " ", false, LITERAL); - } else { - renderer->out(renderer, node, " |", false, LITERAL); - if (((node_table_row *)node->parent->as.opaque)->is_header && - !node->next) { - int i; - uint8_t *alignments = get_table_alignments(node->parent->parent); - uint16_t n_cols = - ((node_table *)node->parent->parent->as.opaque)->n_columns; - renderer->cr(renderer); - renderer->out(renderer, node, "|", false, LITERAL); - for (i = 0; i < n_cols; i++) { - switch (alignments[i]) { - case 0: renderer->out(renderer, node, " --- |", false, LITERAL); break; - case 'l': renderer->out(renderer, node, " :-- |", false, LITERAL); break; - case 'c': renderer->out(renderer, node, " :-: |", false, LITERAL); break; - case 'r': renderer->out(renderer, node, " --: |", false, LITERAL); break; - } - } - renderer->cr(renderer); - } - } - } else { - assert(false); - } -} - -static void latex_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - - if (node->type == CMARK_NODE_TABLE) { - if (entering) { - int i; - uint16_t n_cols; - uint8_t *alignments = get_table_alignments(node); - - renderer->cr(renderer); - renderer->out(renderer, node, "\\begin{table}", false, LITERAL); - renderer->cr(renderer); - renderer->out(renderer, node, "\\begin{tabular}{", false, LITERAL); - - n_cols = ((node_table *)node->as.opaque)->n_columns; - for (i = 0; i < n_cols; i++) { - switch(alignments[i]) { - case 0: - case 'l': - renderer->out(renderer, node, "l", false, LITERAL); - break; - case 'c': - renderer->out(renderer, node, "c", false, LITERAL); - break; - case 'r': - renderer->out(renderer, node, "r", false, LITERAL); - break; - } - } - renderer->out(renderer, node, "}", false, LITERAL); - renderer->cr(renderer); - } else { - renderer->out(renderer, node, "\\end{tabular}", false, LITERAL); - renderer->cr(renderer); - renderer->out(renderer, node, "\\end{table}", false, LITERAL); - renderer->cr(renderer); - } - } else if (node->type == CMARK_NODE_TABLE_ROW) { - if (!entering) { - renderer->cr(renderer); - } - } else if (node->type == CMARK_NODE_TABLE_CELL) { - if (!entering) { - if (node->next) { - renderer->out(renderer, node, " & ", false, LITERAL); - } else { - renderer->out(renderer, node, " \\\\", false, LITERAL); - } - } - } else { - assert(false); - } -} - -static const char *xml_attr(cmark_syntax_extension *extension, - cmark_node *node) { - if (node->type == CMARK_NODE_TABLE_CELL) { - if (cmark_gfm_extensions_get_table_row_is_header(node->parent)) { - uint8_t *alignments = get_table_alignments(node->parent->parent); - int i = 0; - cmark_node *n; - for (n = node->parent->first_child; n; n = n->next, ++i) - if (n == node) - break; - switch (alignments[i]) { - case 'l': return " align=\"left\""; - case 'c': return " align=\"center\""; - case 'r': return " align=\"right\""; - } - } - } - - return NULL; -} - -static void man_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - - if (node->type == CMARK_NODE_TABLE) { - if (entering) { - int i; - uint16_t n_cols; - uint8_t *alignments = get_table_alignments(node); - - renderer->cr(renderer); - renderer->out(renderer, node, ".TS", false, LITERAL); - renderer->cr(renderer); - renderer->out(renderer, node, "tab(@);", false, LITERAL); - renderer->cr(renderer); - - n_cols = ((node_table *)node->as.opaque)->n_columns; - - for (i = 0; i < n_cols; i++) { - switch (alignments[i]) { - case 'l': - renderer->out(renderer, node, "l", false, LITERAL); - break; - case 0: - case 'c': - renderer->out(renderer, node, "c", false, LITERAL); - break; - case 'r': - renderer->out(renderer, node, "r", false, LITERAL); - break; - } - } - - if (n_cols) { - renderer->out(renderer, node, ".", false, LITERAL); - renderer->cr(renderer); - } - } else { - renderer->out(renderer, node, ".TE", false, LITERAL); - renderer->cr(renderer); - } - } else if (node->type == CMARK_NODE_TABLE_ROW) { - if (!entering) { - renderer->cr(renderer); - } - } else if (node->type == CMARK_NODE_TABLE_CELL) { - if (!entering && node->next) { - renderer->out(renderer, node, "@", false, LITERAL); - } - } else { - assert(false); - } -} - -static void html_table_add_align(cmark_strbuf* html, const char* align, int options) { - if (options & CMARK_OPT_TABLE_PREFER_STYLE_ATTRIBUTES) { - cmark_strbuf_puts(html, " style=\"text-align: "); - cmark_strbuf_puts(html, align); - cmark_strbuf_puts(html, "\""); - } else { - cmark_strbuf_puts(html, " align=\""); - cmark_strbuf_puts(html, align); - cmark_strbuf_puts(html, "\""); - } -} - -struct html_table_state { - unsigned need_closing_table_body : 1; - unsigned in_table_header : 1; -}; - -static void html_render(cmark_syntax_extension *extension, - cmark_html_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - cmark_strbuf *html = renderer->html; - cmark_node *n; - - // XXX: we just monopolise renderer->opaque. - struct html_table_state *table_state = - (struct html_table_state *)&renderer->opaque; - - if (node->type == CMARK_NODE_TABLE) { - if (entering) { - cmark_html_render_cr(html); - cmark_strbuf_puts(html, "'); - table_state->need_closing_table_body = false; - } else { - if (table_state->need_closing_table_body) { - cmark_html_render_cr(html); - cmark_strbuf_puts(html, ""); - cmark_html_render_cr(html); - } - table_state->need_closing_table_body = false; - cmark_html_render_cr(html); - cmark_strbuf_puts(html, ""); - cmark_html_render_cr(html); - } - } else if (node->type == CMARK_NODE_TABLE_ROW) { - if (entering) { - cmark_html_render_cr(html); - if (((node_table_row *)node->as.opaque)->is_header) { - table_state->in_table_header = 1; - cmark_strbuf_puts(html, ""); - cmark_html_render_cr(html); - } else if (!table_state->need_closing_table_body) { - cmark_strbuf_puts(html, ""); - cmark_html_render_cr(html); - table_state->need_closing_table_body = 1; - } - cmark_strbuf_puts(html, "'); - } else { - cmark_html_render_cr(html); - cmark_strbuf_puts(html, ""); - if (((node_table_row *)node->as.opaque)->is_header) { - cmark_html_render_cr(html); - cmark_strbuf_puts(html, ""); - table_state->in_table_header = false; - } - } - } else if (node->type == CMARK_NODE_TABLE_CELL) { - uint8_t *alignments = get_table_alignments(node->parent->parent); - if (entering) { - cmark_html_render_cr(html); - if (table_state->in_table_header) { - cmark_strbuf_puts(html, "parent->first_child; n; n = n->next, ++i) - if (n == node) - break; - - switch (alignments[i]) { - case 'l': html_table_add_align(html, "left", options); break; - case 'c': html_table_add_align(html, "center", options); break; - case 'r': html_table_add_align(html, "right", options); break; - } - - cmark_html_render_sourcepos(node, html, options); - cmark_strbuf_putc(html, '>'); - } else { - if (table_state->in_table_header) { - cmark_strbuf_puts(html, ""); - } else { - cmark_strbuf_puts(html, ""); - } - } - } else { - assert(false); - } -} - -static void opaque_alloc(cmark_syntax_extension *self, cmark_mem *mem, cmark_node *node) { - if (node->type == CMARK_NODE_TABLE) { - node->as.opaque = mem->calloc(1, sizeof(node_table)); - } else if (node->type == CMARK_NODE_TABLE_ROW) { - node->as.opaque = mem->calloc(1, sizeof(node_table_row)); - } else if (node->type == CMARK_NODE_TABLE_CELL) { - node->as.opaque = mem->calloc(1, sizeof(node_cell)); - } -} - -static void opaque_free(cmark_syntax_extension *self, cmark_mem *mem, cmark_node *node) { - if (node->type == CMARK_NODE_TABLE) { - free_node_table(mem, node->as.opaque); - } else if (node->type == CMARK_NODE_TABLE_ROW) { - free_node_table_row(mem, node->as.opaque); - } -} - -static int escape(cmark_syntax_extension *self, cmark_node *node, int c) { - return - node->type != CMARK_NODE_TABLE && - node->type != CMARK_NODE_TABLE_ROW && - node->type != CMARK_NODE_TABLE_CELL && - c == '|'; -} - -cmark_syntax_extension *create_table_extension(void) { - cmark_syntax_extension *self = cmark_syntax_extension_new("table"); - - cmark_syntax_extension_set_match_block_func(self, matches); - cmark_syntax_extension_set_open_block_func(self, try_opening_table_block); - cmark_syntax_extension_set_get_type_string_func(self, get_type_string); - cmark_syntax_extension_set_can_contain_func(self, can_contain); - cmark_syntax_extension_set_contains_inlines_func(self, contains_inlines); - cmark_syntax_extension_set_commonmark_render_func(self, commonmark_render); - cmark_syntax_extension_set_plaintext_render_func(self, commonmark_render); - cmark_syntax_extension_set_latex_render_func(self, latex_render); - cmark_syntax_extension_set_xml_attr_func(self, xml_attr); - cmark_syntax_extension_set_man_render_func(self, man_render); - cmark_syntax_extension_set_html_render_func(self, html_render); - cmark_syntax_extension_set_opaque_alloc_func(self, opaque_alloc); - cmark_syntax_extension_set_opaque_free_func(self, opaque_free); - cmark_syntax_extension_set_commonmark_escape_func(self, escape); - CMARK_NODE_TABLE = cmark_syntax_extension_add_node(0); - CMARK_NODE_TABLE_ROW = cmark_syntax_extension_add_node(0); - CMARK_NODE_TABLE_CELL = cmark_syntax_extension_add_node(0); - - return self; -} - -uint16_t cmark_gfm_extensions_get_table_columns(cmark_node *node) { - if (node->type != CMARK_NODE_TABLE) - return 0; - - return ((node_table *)node->as.opaque)->n_columns; -} - -uint8_t *cmark_gfm_extensions_get_table_alignments(cmark_node *node) { - if (node->type != CMARK_NODE_TABLE) - return 0; - - return ((node_table *)node->as.opaque)->alignments; -} - -int cmark_gfm_extensions_set_table_columns(cmark_node *node, uint16_t n_columns) { - return set_n_table_columns(node, n_columns); -} - -int cmark_gfm_extensions_set_table_alignments(cmark_node *node, uint16_t ncols, uint8_t *alignments) { - uint8_t *a = (uint8_t *)cmark_node_mem(node)->calloc(1, ncols); - memcpy(a, alignments, ncols); - return set_table_alignments(node, a); -} - -int cmark_gfm_extensions_get_table_row_is_header(cmark_node *node) -{ - if (!node || node->type != CMARK_NODE_TABLE_ROW) - return 0; - - return ((node_table_row *)node->as.opaque)->is_header; -} - -int cmark_gfm_extensions_set_table_row_is_header(cmark_node *node, int is_header) -{ - if (!node || node->type != CMARK_NODE_TABLE_ROW) - return 0; - - ((node_table_row *)node->as.opaque)->is_header = (is_header != 0); - return 1; -} diff --git a/ext/commonmarker/table.h b/ext/commonmarker/table.h deleted file mode 100644 index f6a0634f..00000000 --- a/ext/commonmarker/table.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef CMARK_GFM_TABLE_H -#define CMARK_GFM_TABLE_H - -#include "cmark-gfm-core-extensions.h" - - -extern cmark_node_type CMARK_NODE_TABLE, CMARK_NODE_TABLE_ROW, - CMARK_NODE_TABLE_CELL; - -cmark_syntax_extension *create_table_extension(void); - -#endif diff --git a/ext/commonmarker/tagfilter.c b/ext/commonmarker/tagfilter.c deleted file mode 100644 index 262352e0..00000000 --- a/ext/commonmarker/tagfilter.c +++ /dev/null @@ -1,60 +0,0 @@ -#include "tagfilter.h" -#include -#include - -static const char *blacklist[] = { - "title", "textarea", "style", "xmp", "iframe", - "noembed", "noframes", "script", "plaintext", NULL, -}; - -static int is_tag(const unsigned char *tag_data, size_t tag_size, - const char *tagname) { - size_t i; - - if (tag_size < 3 || tag_data[0] != '<') - return 0; - - i = 1; - - if (tag_data[i] == '/') { - i++; - } - - for (; i < tag_size; ++i, ++tagname) { - if (*tagname == 0) - break; - - if (tolower(tag_data[i]) != *tagname) - return 0; - } - - if (i == tag_size) - return 0; - - if (cmark_isspace(tag_data[i]) || tag_data[i] == '>') - return 1; - - if (tag_data[i] == '/' && tag_size >= i + 2 && tag_data[i + 1] == '>') - return 1; - - return 0; -} - -static int filter(cmark_syntax_extension *ext, const unsigned char *tag, - size_t tag_len) { - const char **it; - - for (it = blacklist; *it; ++it) { - if (is_tag(tag, tag_len, *it)) { - return 0; - } - } - - return 1; -} - -cmark_syntax_extension *create_tagfilter_extension(void) { - cmark_syntax_extension *ext = cmark_syntax_extension_new("tagfilter"); - cmark_syntax_extension_set_html_filter_func(ext, filter); - return ext; -} diff --git a/ext/commonmarker/tagfilter.h b/ext/commonmarker/tagfilter.h deleted file mode 100644 index 9a5f388d..00000000 --- a/ext/commonmarker/tagfilter.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef CMARK_GFM_TAGFILTER_H -#define CMARK_GFM_TAGFILTER_H - -#include "cmark-gfm-core-extensions.h" - -cmark_syntax_extension *create_tagfilter_extension(void); - -#endif diff --git a/ext/commonmarker/tasklist.c b/ext/commonmarker/tasklist.c deleted file mode 100644 index 7bef4549..00000000 --- a/ext/commonmarker/tasklist.c +++ /dev/null @@ -1,156 +0,0 @@ -#include "tasklist.h" -#include -#include -#include -#include "ext_scanners.h" - -typedef enum { - CMARK_TASKLIST_NOCHECKED, - CMARK_TASKLIST_CHECKED, -} cmark_tasklist_type; - -// Local constants -static const char *TYPE_STRING = "tasklist"; - -static const char *get_type_string(cmark_syntax_extension *extension, cmark_node *node) { - return TYPE_STRING; -} - - -// Return 1 if state was set, 0 otherwise -int cmark_gfm_extensions_set_tasklist_item_checked(cmark_node *node, bool is_checked) { - // The node has to exist, and be an extension, and actually be the right type in order to get the value. - if (!node || !node->extension || strcmp(cmark_node_get_type_string(node), TYPE_STRING)) - return 0; - - node->as.list.checked = is_checked; - return 1; -} - -bool cmark_gfm_extensions_get_tasklist_item_checked(cmark_node *node) { - if (!node || !node->extension || strcmp(cmark_node_get_type_string(node), TYPE_STRING)) - return false; - - if (node->as.list.checked) { - return true; - } - else { - return false; - } -} - -static bool parse_node_item_prefix(cmark_parser *parser, const char *input, - cmark_node *container) { - bool res = false; - - if (parser->indent >= - container->as.list.marker_offset + container->as.list.padding) { - cmark_parser_advance_offset(parser, input, container->as.list.marker_offset + - container->as.list.padding, - true); - res = true; - } else if (parser->blank && container->first_child != NULL) { - // if container->first_child is NULL, then the opening line - // of the list item was blank after the list marker; in this - // case, we are done with the list item. - cmark_parser_advance_offset(parser, input, parser->first_nonspace - parser->offset, - false); - res = true; - } - return res; -} - -static int matches(cmark_syntax_extension *self, cmark_parser *parser, - unsigned char *input, int len, - cmark_node *parent_container) { - return parse_node_item_prefix(parser, (const char*)input, parent_container); -} - -static int can_contain(cmark_syntax_extension *extension, cmark_node *node, - cmark_node_type child_type) { - return (node->type == CMARK_NODE_ITEM) ? 1 : 0; -} - -static cmark_node *open_tasklist_item(cmark_syntax_extension *self, - int indented, cmark_parser *parser, - cmark_node *parent_container, - unsigned char *input, int len) { - cmark_node_type node_type = cmark_node_get_type(parent_container); - if (node_type != CMARK_NODE_ITEM) { - return NULL; - } - - bufsize_t matched = scan_tasklist(input, len, 0); - if (!matched) { - return NULL; - } - - cmark_node_set_syntax_extension(parent_container, self); - cmark_parser_advance_offset(parser, (char *)input, 3, false); - - // Either an upper or lower case X means the task is completed. - parent_container->as.list.checked = (strstr((char*)input, "[x]") || strstr((char*)input, "[X]")); - - return NULL; -} - -static void commonmark_render(cmark_syntax_extension *extension, - cmark_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - if (entering) { - renderer->cr(renderer); - if (node->as.list.checked) { - renderer->out(renderer, node, "- [x] ", false, LITERAL); - } else { - renderer->out(renderer, node, "- [ ] ", false, LITERAL); - } - cmark_strbuf_puts(renderer->prefix, " "); - } else { - cmark_strbuf_truncate(renderer->prefix, renderer->prefix->size - 2); - renderer->cr(renderer); - } -} - -static void html_render(cmark_syntax_extension *extension, - cmark_html_renderer *renderer, cmark_node *node, - cmark_event_type ev_type, int options) { - bool entering = (ev_type == CMARK_EVENT_ENTER); - if (entering) { - cmark_html_render_cr(renderer->html); - cmark_strbuf_puts(renderer->html, "html, options); - cmark_strbuf_putc(renderer->html, '>'); - if (node->as.list.checked) { - cmark_strbuf_puts(renderer->html, " "); - } else { - cmark_strbuf_puts(renderer->html, " "); - } - } else { - cmark_strbuf_puts(renderer->html, "\n"); - } -} - -static const char *xml_attr(cmark_syntax_extension *extension, - cmark_node *node) { - if (node->as.list.checked) { - return " completed=\"true\""; - } else { - return " completed=\"false\""; - } -} - -cmark_syntax_extension *create_tasklist_extension(void) { - cmark_syntax_extension *ext = cmark_syntax_extension_new("tasklist"); - - cmark_syntax_extension_set_match_block_func(ext, matches); - cmark_syntax_extension_set_get_type_string_func(ext, get_type_string); - cmark_syntax_extension_set_open_block_func(ext, open_tasklist_item); - cmark_syntax_extension_set_can_contain_func(ext, can_contain); - cmark_syntax_extension_set_commonmark_render_func(ext, commonmark_render); - cmark_syntax_extension_set_plaintext_render_func(ext, commonmark_render); - cmark_syntax_extension_set_html_render_func(ext, html_render); - cmark_syntax_extension_set_xml_attr_func(ext, xml_attr); - - return ext; -} diff --git a/ext/commonmarker/tasklist.h b/ext/commonmarker/tasklist.h deleted file mode 100644 index 26e9d96d..00000000 --- a/ext/commonmarker/tasklist.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef TASKLIST_H -#define TASKLIST_H - -#include "cmark-gfm-core-extensions.h" - -cmark_syntax_extension *create_tasklist_extension(void); - -#endif diff --git a/ext/commonmarker/utf8.c b/ext/commonmarker/utf8.c deleted file mode 100644 index c29bbf77..00000000 --- a/ext/commonmarker/utf8.c +++ /dev/null @@ -1,317 +0,0 @@ -#include -#include -#include - -#include "cmark_ctype.h" -#include "utf8.h" - -static const int8_t utf8proc_utf8class[256] = { - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, - 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, - 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0}; - -static void encode_unknown(cmark_strbuf *buf) { - static const uint8_t repl[] = {239, 191, 189}; - cmark_strbuf_put(buf, repl, 3); -} - -static int utf8proc_charlen(const uint8_t *str, bufsize_t str_len) { - int length, i; - - if (!str_len) - return 0; - - length = utf8proc_utf8class[str[0]]; - - if (!length) - return -1; - - if (str_len >= 0 && (bufsize_t)length > str_len) - return -str_len; - - for (i = 1; i < length; i++) { - if ((str[i] & 0xC0) != 0x80) - return -i; - } - - return length; -} - -// Validate a single UTF-8 character according to RFC 3629. -static int utf8proc_valid(const uint8_t *str, bufsize_t str_len) { - int length = utf8proc_utf8class[str[0]]; - - if (!length) - return -1; - - if ((bufsize_t)length > str_len) - return -str_len; - - switch (length) { - case 2: - if ((str[1] & 0xC0) != 0x80) - return -1; - if (str[0] < 0xC2) { - // Overlong - return -length; - } - break; - - case 3: - if ((str[1] & 0xC0) != 0x80) - return -1; - if ((str[2] & 0xC0) != 0x80) - return -2; - if (str[0] == 0xE0) { - if (str[1] < 0xA0) { - // Overlong - return -length; - } - } else if (str[0] == 0xED) { - if (str[1] >= 0xA0) { - // Surrogate - return -length; - } - } - break; - - case 4: - if ((str[1] & 0xC0) != 0x80) - return -1; - if ((str[2] & 0xC0) != 0x80) - return -2; - if ((str[3] & 0xC0) != 0x80) - return -3; - if (str[0] == 0xF0) { - if (str[1] < 0x90) { - // Overlong - return -length; - } - } else if (str[0] >= 0xF4) { - if (str[0] > 0xF4 || str[1] >= 0x90) { - // Above 0x10FFFF - return -length; - } - } - break; - } - - return length; -} - -void cmark_utf8proc_check(cmark_strbuf *ob, const uint8_t *line, - bufsize_t size) { - bufsize_t i = 0; - - while (i < size) { - bufsize_t org = i; - int charlen = 0; - - while (i < size) { - if (line[i] < 0x80 && line[i] != 0) { - i++; - } else if (line[i] >= 0x80) { - charlen = utf8proc_valid(line + i, size - i); - if (charlen < 0) { - charlen = -charlen; - break; - } - i += charlen; - } else if (line[i] == 0) { - // ASCII NUL is technically valid but rejected - // for security reasons. - charlen = 1; - break; - } - } - - if (i > org) { - cmark_strbuf_put(ob, line + org, i - org); - } - - if (i >= size) { - break; - } else { - // Invalid UTF-8 - encode_unknown(ob); - i += charlen; - } - } -} - -int cmark_utf8proc_iterate(const uint8_t *str, bufsize_t str_len, - int32_t *dst) { - int length; - int32_t uc = -1; - - *dst = -1; - length = utf8proc_charlen(str, str_len); - if (length < 0) - return -1; - - switch (length) { - case 1: - uc = str[0]; - break; - case 2: - uc = ((str[0] & 0x1F) << 6) + (str[1] & 0x3F); - if (uc < 0x80) - uc = -1; - break; - case 3: - uc = ((str[0] & 0x0F) << 12) + ((str[1] & 0x3F) << 6) + (str[2] & 0x3F); - if (uc < 0x800 || (uc >= 0xD800 && uc < 0xE000)) - uc = -1; - break; - case 4: - uc = ((str[0] & 0x07) << 18) + ((str[1] & 0x3F) << 12) + - ((str[2] & 0x3F) << 6) + (str[3] & 0x3F); - if (uc < 0x10000 || uc >= 0x110000) - uc = -1; - break; - } - - if (uc < 0) - return -1; - - *dst = uc; - return length; -} - -void cmark_utf8proc_encode_char(int32_t uc, cmark_strbuf *buf) { - uint8_t dst[4]; - bufsize_t len = 0; - - assert(uc >= 0); - - if (uc < 0x80) { - dst[0] = (uint8_t)(uc); - len = 1; - } else if (uc < 0x800) { - dst[0] = (uint8_t)(0xC0 + (uc >> 6)); - dst[1] = 0x80 + (uc & 0x3F); - len = 2; - } else if (uc == 0xFFFF) { - dst[0] = 0xFF; - len = 1; - } else if (uc == 0xFFFE) { - dst[0] = 0xFE; - len = 1; - } else if (uc < 0x10000) { - dst[0] = (uint8_t)(0xE0 + (uc >> 12)); - dst[1] = 0x80 + ((uc >> 6) & 0x3F); - dst[2] = 0x80 + (uc & 0x3F); - len = 3; - } else if (uc < 0x110000) { - dst[0] = (uint8_t)(0xF0 + (uc >> 18)); - dst[1] = 0x80 + ((uc >> 12) & 0x3F); - dst[2] = 0x80 + ((uc >> 6) & 0x3F); - dst[3] = 0x80 + (uc & 0x3F); - len = 4; - } else { - encode_unknown(buf); - return; - } - - cmark_strbuf_put(buf, dst, len); -} - -void cmark_utf8proc_case_fold(cmark_strbuf *dest, const uint8_t *str, - bufsize_t len) { - int32_t c; - -#define bufpush(x) cmark_utf8proc_encode_char(x, dest) - - while (len > 0) { - bufsize_t char_len = cmark_utf8proc_iterate(str, len, &c); - - if (char_len >= 0) { -#include "case_fold_switch.inc" - } else { - encode_unknown(dest); - char_len = -char_len; - } - - str += char_len; - len -= char_len; - } -} - -// matches anything in the Zs class, plus LF, CR, TAB, FF. -int cmark_utf8proc_is_space(int32_t uc) { - return (uc == 9 || uc == 10 || uc == 12 || uc == 13 || uc == 32 || - uc == 160 || uc == 5760 || (uc >= 8192 && uc <= 8202) || uc == 8239 || - uc == 8287 || uc == 12288); -} - -// matches anything in the P[cdefios] classes. -int cmark_utf8proc_is_punctuation(int32_t uc) { - return ( - (uc < 128 && cmark_ispunct((char)uc)) || uc == 161 || uc == 167 || - uc == 171 || uc == 182 || uc == 183 || uc == 187 || uc == 191 || - uc == 894 || uc == 903 || (uc >= 1370 && uc <= 1375) || uc == 1417 || - uc == 1418 || uc == 1470 || uc == 1472 || uc == 1475 || uc == 1478 || - uc == 1523 || uc == 1524 || uc == 1545 || uc == 1546 || uc == 1548 || - uc == 1549 || uc == 1563 || uc == 1566 || uc == 1567 || - (uc >= 1642 && uc <= 1645) || uc == 1748 || (uc >= 1792 && uc <= 1805) || - (uc >= 2039 && uc <= 2041) || (uc >= 2096 && uc <= 2110) || uc == 2142 || - uc == 2404 || uc == 2405 || uc == 2416 || uc == 2800 || uc == 3572 || - uc == 3663 || uc == 3674 || uc == 3675 || (uc >= 3844 && uc <= 3858) || - uc == 3860 || (uc >= 3898 && uc <= 3901) || uc == 3973 || - (uc >= 4048 && uc <= 4052) || uc == 4057 || uc == 4058 || - (uc >= 4170 && uc <= 4175) || uc == 4347 || (uc >= 4960 && uc <= 4968) || - uc == 5120 || uc == 5741 || uc == 5742 || uc == 5787 || uc == 5788 || - (uc >= 5867 && uc <= 5869) || uc == 5941 || uc == 5942 || - (uc >= 6100 && uc <= 6102) || (uc >= 6104 && uc <= 6106) || - (uc >= 6144 && uc <= 6154) || uc == 6468 || uc == 6469 || uc == 6686 || - uc == 6687 || (uc >= 6816 && uc <= 6822) || (uc >= 6824 && uc <= 6829) || - (uc >= 7002 && uc <= 7008) || (uc >= 7164 && uc <= 7167) || - (uc >= 7227 && uc <= 7231) || uc == 7294 || uc == 7295 || - (uc >= 7360 && uc <= 7367) || uc == 7379 || (uc >= 8208 && uc <= 8231) || - (uc >= 8240 && uc <= 8259) || (uc >= 8261 && uc <= 8273) || - (uc >= 8275 && uc <= 8286) || uc == 8317 || uc == 8318 || uc == 8333 || - uc == 8334 || (uc >= 8968 && uc <= 8971) || uc == 9001 || uc == 9002 || - (uc >= 10088 && uc <= 10101) || uc == 10181 || uc == 10182 || - (uc >= 10214 && uc <= 10223) || (uc >= 10627 && uc <= 10648) || - (uc >= 10712 && uc <= 10715) || uc == 10748 || uc == 10749 || - (uc >= 11513 && uc <= 11516) || uc == 11518 || uc == 11519 || - uc == 11632 || (uc >= 11776 && uc <= 11822) || - (uc >= 11824 && uc <= 11842) || (uc >= 12289 && uc <= 12291) || - (uc >= 12296 && uc <= 12305) || (uc >= 12308 && uc <= 12319) || - uc == 12336 || uc == 12349 || uc == 12448 || uc == 12539 || uc == 42238 || - uc == 42239 || (uc >= 42509 && uc <= 42511) || uc == 42611 || - uc == 42622 || (uc >= 42738 && uc <= 42743) || - (uc >= 43124 && uc <= 43127) || uc == 43214 || uc == 43215 || - (uc >= 43256 && uc <= 43258) || uc == 43310 || uc == 43311 || - uc == 43359 || (uc >= 43457 && uc <= 43469) || uc == 43486 || - uc == 43487 || (uc >= 43612 && uc <= 43615) || uc == 43742 || - uc == 43743 || uc == 43760 || uc == 43761 || uc == 44011 || uc == 64830 || - uc == 64831 || (uc >= 65040 && uc <= 65049) || - (uc >= 65072 && uc <= 65106) || (uc >= 65108 && uc <= 65121) || - uc == 65123 || uc == 65128 || uc == 65130 || uc == 65131 || - (uc >= 65281 && uc <= 65283) || (uc >= 65285 && uc <= 65290) || - (uc >= 65292 && uc <= 65295) || uc == 65306 || uc == 65307 || - uc == 65311 || uc == 65312 || (uc >= 65339 && uc <= 65341) || - uc == 65343 || uc == 65371 || uc == 65373 || - (uc >= 65375 && uc <= 65381) || (uc >= 65792 && uc <= 65794) || - uc == 66463 || uc == 66512 || uc == 66927 || uc == 67671 || uc == 67871 || - uc == 67903 || (uc >= 68176 && uc <= 68184) || uc == 68223 || - (uc >= 68336 && uc <= 68342) || (uc >= 68409 && uc <= 68415) || - (uc >= 68505 && uc <= 68508) || (uc >= 69703 && uc <= 69709) || - uc == 69819 || uc == 69820 || (uc >= 69822 && uc <= 69825) || - (uc >= 69952 && uc <= 69955) || uc == 70004 || uc == 70005 || - (uc >= 70085 && uc <= 70088) || uc == 70093 || - (uc >= 70200 && uc <= 70205) || uc == 70854 || - (uc >= 71105 && uc <= 71113) || (uc >= 71233 && uc <= 71235) || - (uc >= 74864 && uc <= 74868) || uc == 92782 || uc == 92783 || - uc == 92917 || (uc >= 92983 && uc <= 92987) || uc == 92996 || - uc == 113823); -} diff --git a/ext/commonmarker/utf8.h b/ext/commonmarker/utf8.h deleted file mode 100644 index 04ec1611..00000000 --- a/ext/commonmarker/utf8.h +++ /dev/null @@ -1,35 +0,0 @@ -#ifndef CMARK_UTF8_H -#define CMARK_UTF8_H - -#include -#include "buffer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -CMARK_GFM_EXPORT -void cmark_utf8proc_case_fold(cmark_strbuf *dest, const uint8_t *str, - bufsize_t len); - -CMARK_GFM_EXPORT -void cmark_utf8proc_encode_char(int32_t uc, cmark_strbuf *buf); - -CMARK_GFM_EXPORT -int cmark_utf8proc_iterate(const uint8_t *str, bufsize_t str_len, int32_t *dst); - -CMARK_GFM_EXPORT -void cmark_utf8proc_check(cmark_strbuf *dest, const uint8_t *line, - bufsize_t size); - -CMARK_GFM_EXPORT -int cmark_utf8proc_is_space(int32_t uc); - -CMARK_GFM_EXPORT -int cmark_utf8proc_is_punctuation(int32_t uc); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/ext/commonmarker/xml.c b/ext/commonmarker/xml.c deleted file mode 100644 index 2975bf96..00000000 --- a/ext/commonmarker/xml.c +++ /dev/null @@ -1,181 +0,0 @@ -#include -#include -#include -#include - -#include "config.h" -#include "cmark-gfm.h" -#include "node.h" -#include "buffer.h" -#include "houdini.h" -#include "syntax_extension.h" - -#define BUFFER_SIZE 100 - -// Functions to convert cmark_nodes to XML strings. - -static void escape_xml(cmark_strbuf *dest, const unsigned char *source, - bufsize_t length) { - houdini_escape_html0(dest, source, length, 0); -} - -struct render_state { - cmark_strbuf *xml; - int indent; -}; - -static CMARK_INLINE void indent(struct render_state *state) { - int i; - for (i = 0; i < state->indent; i++) { - cmark_strbuf_putc(state->xml, ' '); - } -} - -static int S_render_node(cmark_node *node, cmark_event_type ev_type, - struct render_state *state, int options) { - cmark_strbuf *xml = state->xml; - bool literal = false; - cmark_delim_type delim; - bool entering = (ev_type == CMARK_EVENT_ENTER); - char buffer[BUFFER_SIZE]; - - if (entering) { - indent(state); - cmark_strbuf_putc(xml, '<'); - cmark_strbuf_puts(xml, cmark_node_get_type_string(node)); - - if (options & CMARK_OPT_SOURCEPOS && node->start_line != 0) { - snprintf(buffer, BUFFER_SIZE, " sourcepos=\"%d:%d-%d:%d\"", - node->start_line, node->start_column, node->end_line, - node->end_column); - cmark_strbuf_puts(xml, buffer); - } - - if (node->extension && node->extension->xml_attr_func) { - const char* r = node->extension->xml_attr_func(node->extension, node); - if (r != NULL) - cmark_strbuf_puts(xml, r); - } - - literal = false; - - switch (node->type) { - case CMARK_NODE_DOCUMENT: - cmark_strbuf_puts(xml, " xmlns=\"http://commonmark.org/xml/1.0\""); - break; - case CMARK_NODE_TEXT: - case CMARK_NODE_CODE: - case CMARK_NODE_HTML_BLOCK: - case CMARK_NODE_HTML_INLINE: - cmark_strbuf_puts(xml, " xml:space=\"preserve\">"); - escape_xml(xml, node->as.literal.data, node->as.literal.len); - cmark_strbuf_puts(xml, "as.heading.level); - cmark_strbuf_puts(xml, buffer); - break; - case CMARK_NODE_CODE_BLOCK: - if (node->as.code.info.len > 0) { - cmark_strbuf_puts(xml, " info=\""); - escape_xml(xml, node->as.code.info.data, node->as.code.info.len); - cmark_strbuf_putc(xml, '"'); - } - cmark_strbuf_puts(xml, " xml:space=\"preserve\">"); - escape_xml(xml, node->as.code.literal.data, node->as.code.literal.len); - cmark_strbuf_puts(xml, "as.custom.on_enter.data, - node->as.custom.on_enter.len); - cmark_strbuf_putc(xml, '"'); - cmark_strbuf_puts(xml, " on_exit=\""); - escape_xml(xml, node->as.custom.on_exit.data, - node->as.custom.on_exit.len); - cmark_strbuf_putc(xml, '"'); - break; - case CMARK_NODE_LINK: - case CMARK_NODE_IMAGE: - cmark_strbuf_puts(xml, " destination=\""); - escape_xml(xml, node->as.link.url.data, node->as.link.url.len); - cmark_strbuf_putc(xml, '"'); - cmark_strbuf_puts(xml, " title=\""); - escape_xml(xml, node->as.link.title.data, node->as.link.title.len); - cmark_strbuf_putc(xml, '"'); - break; - default: - break; - } - if (node->first_child) { - state->indent += 2; - } else if (!literal) { - cmark_strbuf_puts(xml, " /"); - } - cmark_strbuf_puts(xml, ">\n"); - - } else if (node->first_child) { - state->indent -= 2; - indent(state); - cmark_strbuf_puts(xml, "\n"); - } - - return 1; -} - -char *cmark_render_xml(cmark_node *root, int options) { - return cmark_render_xml_with_mem(root, options, cmark_node_mem(root)); -} - -char *cmark_render_xml_with_mem(cmark_node *root, int options, cmark_mem *mem) { - char *result; - cmark_strbuf xml = CMARK_BUF_INIT(mem); - cmark_event_type ev_type; - cmark_node *cur; - struct render_state state = {&xml, 0}; - - cmark_iter *iter = cmark_iter_new(root); - - cmark_strbuf_puts(state.xml, "\n"); - cmark_strbuf_puts(state.xml, - "\n"); - while ((ev_type = cmark_iter_next(iter)) != CMARK_EVENT_DONE) { - cur = cmark_iter_get_node(iter); - S_render_node(cur, ev_type, &state, options); - } - result = (char *)cmark_strbuf_detach(&xml); - - cmark_iter_free(iter); - return result; -} diff --git a/lib/commonmarker.rb b/lib/commonmarker.rb index edfc0e57..f1306be4 100755 --- a/lib/commonmarker.rb +++ b/lib/commonmarker.rb @@ -1,18 +1,26 @@ #!/usr/bin/env ruby # frozen_string_literal: true -require "commonmarker/commonmarker" +begin + # load the precompiled extension file + ruby_version = /(\d+\.\d+)/.match(::RUBY_VERSION) + require_relative "commonmarker/#{ruby_version}/commonmarker" +rescue LoadError + # fall back to the extension compiled upon installation. + require "commonmarker/commonmarker" +end + require "commonmarker/config" -require "commonmarker/node" require "commonmarker/renderer" -require "commonmarker/renderer/html_renderer" require "commonmarker/version" -begin +if ENV.fetch("DEBUG", false) require "awesome_print" -rescue LoadError; end # rubocop:disable Lint/SuppressedException -module CommonMarker - # Public: Parses a Markdown string into an HTML string. + require "debug" +end + +module Commonmarker + # Public: Parses a CommonMark string into an HTML string. # # text - A {String} of text # option - Either a {Symbol} or {Array of Symbol}s indicating the render options @@ -22,22 +30,7 @@ module CommonMarker def self.render_html(text, options = :DEFAULT, extensions = []) raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) - opts = Config.process_options(options, :render) - Node.markdown_to_html(text.encode("UTF-8"), opts, extensions) - end - - # Public: Parses a Markdown string into a `document` node. - # - # string - {String} to be parsed - # option - A {Symbol} or {Array of Symbol}s indicating the parse options - # extensions - An {Array of Symbol}s indicating the extensions to use - # - # Returns the `document` node. - def self.render_doc(text, options = :DEFAULT, extensions = []) - raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) - - opts = Config.process_options(options, :parse) - text = text.encode("UTF-8") - Node.parse_document(text, text.bytesize, opts, extensions) + # opts = Config.process_options(options, :render) + self.commonmark_to_html(text.encode("UTF-8"), 0) end end diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index 59f02790..dbd8acd3 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -module CommonMarker +module Commonmarker # For Ruby::Enum, these must be classes, not modules module Config # See https://github.com/github/cmark-gfm/blob/master/src/cmark-gfm.h#L673 diff --git a/lib/commonmarker/node.rb b/lib/commonmarker/node.rb deleted file mode 100644 index ea2a1995..00000000 --- a/lib/commonmarker/node.rb +++ /dev/null @@ -1,83 +0,0 @@ -# frozen_string_literal: true - -require "commonmarker/node/inspect" - -module CommonMarker - class Node - include Enumerable - include Inspect - - # Public: An iterator that "walks the tree," descending into children recursively. - # - # blk - A {Proc} representing the action to take for each child - def walk(&block) - return enum_for(:walk) unless block - - yield self - each do |child| - child.walk(&block) - end - end - - # Public: Convert the node to an HTML string. - # - # options - A {Symbol} or {Array of Symbol}s indicating the render options - # extensions - An {Array of Symbol}s indicating the extensions to use - # - # Returns a {String}. - def to_html(options = :DEFAULT, extensions = []) - opts = Config.process_options(options, :render) - _render_html(opts, extensions).force_encoding("utf-8") - end - - # Public: Convert the node to an XML string. - # - # options - A {Symbol} or {Array of Symbol}s indicating the render options - # - # Returns a {String}. - def to_xml(options = :DEFAULT) - opts = Config.process_options(options, :render) - _render_xml(opts).force_encoding("utf-8") - end - - # Public: Convert the node to a CommonMark string. - # - # options - A {Symbol} or {Array of Symbol}s indicating the render options - # width - Column to wrap the output at - # - # Returns a {String}. - def to_commonmark(options = :DEFAULT, width = 120) - opts = Config.process_options(options, :render) - _render_commonmark(opts, width).force_encoding("utf-8") - end - - # Public: Convert the node to a plain text string. - # - # options - A {Symbol} or {Array of Symbol}s indicating the render options - # width - Column to wrap the output at - # - # Returns a {String}. - def to_plaintext(options = :DEFAULT, width = 120) - opts = Config.process_options(options, :render) - _render_plaintext(opts, width).force_encoding("utf-8") - end - - # Public: Iterate over the children (if any) of the current pointer. - def each - return enum_for(:each) unless block_given? - - child = first_child - while child - nextchild = child.next - yield child - child = nextchild - end - end - - # Deprecated: Please use `each` instead - def each_child(&block) - warn("[DEPRECATION] `each_child` is deprecated. Please use `each` instead.") - each(&block) - end - end -end diff --git a/lib/commonmarker/node/inspect.rb b/lib/commonmarker/node/inspect.rb deleted file mode 100644 index f80f3db5..00000000 --- a/lib/commonmarker/node/inspect.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -require "pp" - -module CommonMarker - class Node - module Inspect - PP_INDENT_SIZE = 2 - - def inspect - PP.pp(self, +"", Float::INFINITY) - end - - # @param printer [PrettyPrint] pp - def pretty_print(printer) - printer.group(PP_INDENT_SIZE, "#<#{self.class}(#{type}):", ">") do - printer.breakable - - attrs = [:sourcepos, :string_content, :url, :title, :header_level, :list_type, :list_start, :list_tight, :fence_info].map do |name| - [name, __send__(name)] - rescue NodeError - nil - end.compact - - printer.seplist(attrs) do |name, value| - printer.text("#{name}=") - printer.pp(value) - end - - if first_child - printer.breakable - printer.group(PP_INDENT_SIZE) do - children = [] - node = first_child - while node - children << node - node = node.next - end - printer.text("children=") - printer.pp(children) - end - end - end - end - end - end -end diff --git a/lib/commonmarker/renderer.rb b/lib/commonmarker/renderer.rb index 3be353e6..74f0825a 100644 --- a/lib/commonmarker/renderer.rb +++ b/lib/commonmarker/renderer.rb @@ -3,133 +3,7 @@ require "set" require "stringio" -module CommonMarker +module Commonmarker class Renderer - attr_accessor :in_tight, :warnings, :in_plain - - def initialize(options: :DEFAULT, extensions: []) - @opts = Config.process_options(options, :render) - @stream = StringIO.new(+"") - @need_blocksep = false - @warnings = Set.new([]) - @in_tight = false - @in_plain = false - @tagfilter = extensions.include?(:tagfilter) - end - - def out(*args) - args.each do |arg| - case arg - when :children - @node.each { |child| out(child) } - when Array - arg.each { |x| render(x) } - when Node - render(arg) - else - @stream.write(arg) - end - end - end - - def render(node) - @node = node - if node.type == :document - document(node) - @stream.string - elsif @in_plain && node.type != :text && node.type != :softbreak - node.each { |child| render(child) } - else - begin - send(node.type, node) - rescue NoMethodError => e - @warnings.add("WARNING: #{node.type} not implemented.") - raise e - end - end - end - - def document(_node) - out(:children) - end - - def code_block(node) - code_block(node) - end - - def reference_def(_node); end - - def cr - return if @stream.string.empty? || @stream.string[-1] == "\n" - - out("\n") - end - - def blocksep - out("\n") - end - - def containersep - cr unless @in_tight - end - - def block - cr - yield - cr - end - - def container(starter, ender) - out(starter) - yield - out(ender) - end - - def plain - old_in_plain = @in_plain - @in_plain = true - yield - @in_plain = old_in_plain - end - - private - - def escape_href(str) - @node.html_escape_href(str) - end - - def escape_html(str) - @node.html_escape_html(str) - end - - def tagfilter(str) - if @tagfilter - str.gsub( - %r{ - < - ( - title|textarea|style|xmp|iframe| - noembed|noframes|script|plaintext - ) - (?=\s|>|/>) - }xi, - '<\1' - ) - else - str - end - end - - def sourcepos(node) - return "" unless option_enabled?(:SOURCEPOS) - - s = node.sourcepos - " data-sourcepos=\"#{s[:start_line]}:#{s[:start_column]}-" \ - "#{s[:end_line]}:#{s[:end_column]}\"" - end - - def option_enabled?(opt) - (@opts & CommonMarker::Config::OPTS.dig(:render, opt)) != 0 - end end end diff --git a/lib/commonmarker/renderer/html_renderer.rb b/lib/commonmarker/renderer/html_renderer.rb deleted file mode 100644 index df10042d..00000000 --- a/lib/commonmarker/renderer/html_renderer.rb +++ /dev/null @@ -1,252 +0,0 @@ -# frozen_string_literal: true - -module CommonMarker - class HtmlRenderer < Renderer - def document(_) - super - out("\n\n") if @written_footnote_ix - end - - def header(node) - block do - out("", :children, - "") - end - end - - def paragraph(node) - if @in_tight && node.parent.type != :blockquote - out(:children) - else - block do - container("", "

") do - out(:children) - if node.parent.type == :footnote_definition && node.next.nil? - out(" ") - out_footnote_backref - end - end - end - end - end - - def list(node) - old_in_tight = @in_tight - @in_tight = node.list_tight - - block do - if node.list_type == :bullet_list - container("\n", "") do - out(:children) - end - else - start = if node.list_start == 1 - "\n" - else - "
    \n" - end - container(start, "
") do - out(:children) - end - end - end - - @in_tight = old_in_tight - end - - def list_item(node) - block do - tasklist_data = tasklist(node) - container("#{" " if tasklist?(node)}", "") do - out(:children) - end - end - end - - def tasklist(node) - return "" unless tasklist?(node) - - state = if checked?(node) - 'checked="" disabled=""' - else - 'disabled=""' - end - ">\n", "") do - out(:children) - end - end - end - - def hrule(node) - block do - out("") - end - end - - def code_block(node) - block do - if option_enabled?(:GITHUB_PRE_LANG) - out("") - else - out("') - else - out(">") - end - end - out(escape_html(node.string_content)) - out("
") - end - end - - def html(node) - block do - if option_enabled?(:UNSAFE) - out(tagfilter(node.string_content)) - else - out("") - end - end - end - - def inline_html(node) - if option_enabled?(:UNSAFE) - out(tagfilter(node.string_content)) - else - out("") - end - end - - def emph(_) - out("", :children, "") - end - - def strong(_) - out("", :children, "") - end - - def link(node) - out('", :children, "") - end - - def image(node) - out('', :children, '") - end - - def text(node) - out(escape_html(node.string_content)) - end - - def code(node) - out("") - out(escape_html(node.string_content)) - out("") - end - - def linebreak(_node) - out("
\n") - end - - def softbreak(_) - if option_enabled?(:HARDBREAKS) - out("
\n") - elsif option_enabled?(:NOBREAKS) - out(" ") - else - out("\n") - end - end - - def table(node) - @alignments = node.table_alignments - @needs_close_tbody = false - out("\n", :children) - out("\n") if @needs_close_tbody - out("\n") - end - - def table_header(node) - @column_index = 0 - - @in_header = true - out("\n\n", :children, "\n\n") - @in_header = false - end - - def table_row(node) - @column_index = 0 - if !@in_header && !@needs_close_tbody - @needs_close_tbody = true - out("\n") - end - out("\n", :children, "\n") - end - - def table_cell(node) - align = case @alignments[@column_index] - when :left then ' align="left"' - when :right then ' align="right"' - when :center then ' align="center"' - else; "" - end - out(@in_header ? "" : "", :children, @in_header ? "\n" : "\n") - @column_index += 1 - end - - def strikethrough(_) - out("", :children, "") - end - - def footnote_reference(node) - out("#{node.string_content}") - end - - def footnote_definition(_) - unless @footnote_ix - out("
\n
    \n") - @footnote_ix = 0 - end - - @footnote_ix += 1 - out("
  1. \n", :children) - out("\n") if out_footnote_backref - out("
  2. \n") - #
- #
- end - - private - - def out_footnote_backref - return false if @written_footnote_ix == @footnote_ix - - @written_footnote_ix = @footnote_ix - - out("") - true - end - - def tasklist?(node) - node.type_string == "tasklist" - end - - def checked?(node) - node.tasklist_item_checked? - end - end -end diff --git a/lib/commonmarker/version.rb b/lib/commonmarker/version.rb index 7b7fb291..44f01b41 100644 --- a/lib/commonmarker/version.rb +++ b/lib/commonmarker/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true -module CommonMarker +module Commonmarker VERSION = "0.23.5" end diff --git a/rakelib/benchmark.rake b/rakelib/benchmark.rake new file mode 100644 index 00000000..322776b4 --- /dev/null +++ b/rakelib/benchmark.rake @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +desc "Run benchmarks" +task :benchmark do + if ENV["FETCH_PROGIT"] + %x(rm -rf test/progit) + %x(git clone https://github.com/progit/progit.git test/progit) + langs = ["ar", "az", "be", "ca", "cs", "de", "en", "eo", "es", "es-ni", "fa", "fi", "fr", "hi", "hu", "id", "it", "ja", "ko", "mk", "nl", "no-nb", "pl", "pt-br", "ro", "ru", "sr", "th", "tr", "uk", "vi", "zh", "zh-tw"] + langs.each do |lang| + %x(cat test/progit/#{lang}/*/*.markdown >> test/benchinput.md) + end + end + $LOAD_PATH.unshift("lib") + load "test/benchmark.rb" +end diff --git a/rakelib/compile.rake b/rakelib/compile.rake new file mode 100644 index 00000000..2775a7f9 --- /dev/null +++ b/rakelib/compile.rake @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require "rake/clean" +require "rake/extensiontask" + +CROSS_RUBIES = ["3.1.0", "3.0.0", "2.7.0"] +CROSS_PLATFORMS = [ + "x64-mingw32", + "x64-mingw-ucrt", + "x86-linux", + "x86_64-linux", + "aarch64-linux", + "x86_64-darwin", + "arm64-darwin", +] +ENV["RUBY_CC_VERSION"] = CROSS_RUBIES.join(":") + +Rake::ExtensionTask.new("commonmarker", COMMONMARKER_SPEC) do |ext| + ext.lib_dir = File.join("lib", "commonmarker") + ext.cross_compile = true + ext.cross_platform = CROSS_PLATFORMS + ext.cross_config_options << "--enable-cross-build" # so extconf.rb knows we're cross-compiling + ext.cross_compiling do |spec| + # remove things not needed for precompiled gems + spec.dependencies.reject! { |dep| dep.name == "mini_portile2" } + spec.files.reject! { |file| File.fnmatch?("*.tar.gz", file) } + end +end + +namespace "gem" do + CROSS_PLATFORMS.each do |platform| + desc "build native gem for #{platform}" + task platform do + RakeCompilerDock.sh(<<~EOF, platform: platform) + gem install bundler --no-document && + bundle && + bundle exec rake gem:#{platform}:buildit + EOF + end + + namespace platform do + # this runs in the rake-compiler-dock docker container + task "buildit" do + # use Task#invoke because the pkg/*gem task is defined at runtime + Rake::Task["native:#{platform}"].invoke + Rake::Task["pkg/#{COMMONMARKER_SPEC.full_name}-#{Gem::Platform.new(platform)}.gem"].invoke + end + end + end +end diff --git a/rakelib/docs.rake b/rakelib/docs.rake new file mode 100644 index 00000000..6232c6b9 --- /dev/null +++ b/rakelib/docs.rake @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require "date" +require "rdoc/task" + +namespace :docs do + desc "Generate API documentation" + RDoc::Task.new do |rd| + rd.rdoc_dir = "docs" + rd.main = "README.md" + rd.rdoc_files.include("README.md", "lib/**/*.rb", "ext/commonmarker/commonmarker.c") + + rd.options << "--markup tomdoc" + rd.options << "--inline-source" + rd.options << "--line-numbers" + rd.options << "--all" + rd.options << "--fileboxes" + end + + desc "Generate the documentation and run a web server" + task serve: [:rdoc] do + require "webrick" + + puts "Navigate to http://localhost:3000 to see the docs" + + server = WEBrick::HTTPServer.new(Port: 3000) + server.mount("/", WEBrick::HTTPServlet::FileHandler, "docs") + trap("INT") { server.stop } + server.start + end + + desc "Generate and publish docs to gh-pages" + task publish: [:rdoc] do + require "tmpdir" + require "shellwords" + + Dir.mktmpdir do |tmp| + system "mv docs/* #{tmp}" + system "git checkout origin/gh-pages" + system "rm -rf *" + system "mv #{tmp}/* ." + message = Shellwords.escape("Site updated at #{Time.now.utc}") + system "git add ." + system "git commit -am #{message}" + system "git push origin gh-pages --force" + system "git checkout master" + system "echo yolo" + end + end +end diff --git a/rakelib/format.rake b/rakelib/format.rake new file mode 100644 index 00000000..3cbea48b --- /dev/null +++ b/rakelib/format.rake @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +require "rubocop/rake_task" + +RuboCop::RakeTask.new(:rubocop) + +desc "Match C style of cmark" +task :format do + sh "clang-format -style llvm -i ext/commonmarker/*.c ext/commonmarker/*.h" +end diff --git a/rakelib/test.rake b/rakelib/test.rake new file mode 100644 index 00000000..1e19be2e --- /dev/null +++ b/rakelib/test.rake @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require "rake/testtask" + +Rake::TestTask.new("test:unit") do |t| + t.libs << "lib" + t.libs << "test" + t.pattern = "test/test_basics.rb" + t.verbose = true + t.warning = false +end + +desc "Run unit tests" +task "test:unit" => :compile + +desc "Run unit and conformance tests" +task test: ["test:unit"] diff --git a/test/benchmark.rb b/test/benchmark.rb index e51eda58..4de063da 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -16,11 +16,11 @@ end x.report("commonmarker with to_html") do - CommonMarker.render_html(benchinput) + Commonmarker.render_html(benchinput) end x.report("commonmarker with to_xml") do - CommonMarker.render_html(benchinput) + Commonmarker.render_html(benchinput) end x.report("commonmarker with ruby HtmlRenderer") do diff --git a/test/fixtures/upstream/smart_punct.txt b/test/fixtures/upstream/smart_punct.txt new file mode 100644 index 00000000..fd55e622 --- /dev/null +++ b/test/fixtures/upstream/smart_punct.txt @@ -0,0 +1,177 @@ +## 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." +. +

“Hello,” said the spider. +“‘Shelob’ is my name.”

+```````````````````````````````` + +```````````````````````````````` example +'A', 'B', and 'C' are letters. +. +

‘A’, ‘B’, and ‘C’ are letters.

+```````````````````````````````` + +```````````````````````````````` example +'Oak,' 'elm,' and 'beech' are names of trees. +So is 'pine.' +. +

‘Oak,’ ‘elm,’ and ‘beech’ are names of trees. +So is ‘pine.’

+```````````````````````````````` + +```````````````````````````````` example +'He said, "I want to go."' +. +

‘He said, “I want to go.”’

+```````````````````````````````` + +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? +. +

Were you alive in the 70’s?

+```````````````````````````````` + +```````````````````````````````` example +Here is some quoted '`code`' and a "[quoted link](url)". +. +

Here is some quoted ‘code’ and a “quoted link”.

+```````````````````````````````` + +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' +. +

’tis the season to be ‘jolly’

+```````````````````````````````` + +Multiple apostrophes should not be marked as open/closing quotes. + +```````````````````````````````` example +'We'll use Jane's boat and John's truck,' Jenna said. +. +

‘We’ll use Jane’s boat and John’s truck,’ Jenna said.

+```````````````````````````````` + +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." +. +

“A paragraph with no closing quote.

+

“Second paragraph by same speaker, in fiction.”

+```````````````````````````````` + +A quote following a `]` or `)` character cannot +be an open quote: + +```````````````````````````````` example +[a]'s b' +. +

[a]’s b’

+```````````````````````````````` + +Quotes that are escaped come out as literal straight +quotes: + +```````````````````````````````` example +\"This is not smart.\" +This isn\'t either. +5\'8\" +. +

"This is not smart." +This isn't either. +5'8"

+```````````````````````````````` + +Two hyphens form an en-dash, three an em-dash. + +```````````````````````````````` example +Some dashes: em---em +en--en +em --- em +en -- en +2--3 +. +

Some dashes: em—em +en–en +em — em +en – en +2–3

+```````````````````````````````` + +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-------------. +. +

one- +two– +three— +four–– +five—– +six—— +seven—–– +eight–––– +nine——— +thirteen———––.

+```````````````````````````````` + +Hyphens can be escaped: + +```````````````````````````````` example +Escaped hyphens: \-- \-\-\-. +. +

Escaped hyphens: -- ---.

+```````````````````````````````` + +Three periods form an ellipsis: + +```````````````````````````````` example +Ellipses...and...and.... +. +

Ellipses…and…and….

+```````````````````````````````` + +Periods can be escaped if ellipsis-formation +is not wanted: + +```````````````````````````````` example +No ellipses\.\.\. +. +

No ellipses...

+```````````````````````````````` diff --git a/test/fixtures/upstream/spec.txt b/test/fixtures/upstream/spec.txt new file mode 100644 index 00000000..80427610 --- /dev/null +++ b/test/fixtures/upstream/spec.txt @@ -0,0 +1,9756 @@ +--- +title: CommonMark Spec +author: John MacFarlane +version: 0.30 +date: '2021-06-19' +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. +> () + +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 `

` 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. + +Note that not every feature of the HTML samples is mandated by +the spec. For example, the spec says what counts as a link +destination, but it doesn't mandate that non-ASCII characters in +the URL be percent-encoded. To use the automatic tests, +implementers will need to provide a renderer that conforms to +the expectations of the spec examples (percent-encoding +non-ASCII characters in URLs). But a conforming implementation +can use a different renderer and may choose not to +percent-encode non-ASCII characters in URLs. + +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 line feed (`U+000A`) or carriage return (`U+000D`), +followed by a [line ending] or by the end of file. + +A [line ending](@) is a line feed (`U+000A`), a carriage return +(`U+000D`) not followed by a line feed, or a carriage return and a +following line feed. + +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 [Unicode whitespace character](@) is +any code point in the Unicode `Zs` general category, or a tab (`U+0009`), +line feed (`U+000A`), form feed (`U+000C`), or carriage return (`U+000D`). + +[Unicode whitespace](@) is a sequence of one or more +[Unicode whitespace characters]. + +A [tab](@) is `U+0009`. + +A [space](@) is `U+0020`. + +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 [Unicode 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 spaces help 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 +. +

foo→baz→→bim
+
+```````````````````````````````` + +```````````````````````````````` example + →foo→baz→→bim +. +
foo→baz→→bim
+
+```````````````````````````````` + +```````````````````````````````` example + a→a + ὐ→a +. +
a→a
+ὐ→a
+
+```````````````````````````````` + +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 +. +
    +
  • +

    foo

    +

    bar

    +
  • +
+```````````````````````````````` + +```````````````````````````````` example +- foo + +→→bar +. +
    +
  • +

    foo

    +
      bar
    +
    +
  • +
+```````````````````````````````` + +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 +. +
+
  foo
+
+
+```````````````````````````````` + +```````````````````````````````` example +-→→foo +. +
    +
  • +
      foo
    +
    +
  • +
+```````````````````````````````` + + +```````````````````````````````` example + foo +→bar +. +
foo
+bar
+
+```````````````````````````````` + +```````````````````````````````` example + - foo + - bar +→ - baz +. +
    +
  • foo +
      +
    • bar +
        +
      • baz
      • +
      +
    • +
    +
  • +
+```````````````````````````````` + +```````````````````````````````` example +#→Foo +. +

Foo

+```````````````````````````````` + +```````````````````````````````` example +*→*→*→ +. +
+```````````````````````````````` + + +## 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 +\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~ +. +

!"#$%&'()*+,-./:;<=>?@[\]^_`{|}~

+```````````````````````````````` + + +Backslashes before other characters are treated as literal +backslashes: + +```````````````````````````````` example +\→\A\a\ \3\φ\« +. +

\→\A\a\ \3\φ\«

+```````````````````````````````` + + +Escaped characters are treated as regular characters and do +not have their usual Markdown meanings: + +```````````````````````````````` example +\*not emphasized* +\
not a tag +\[not a link](/foo) +\`not code` +1\. not a list +\* not a list +\# not a heading +\[foo]: /url "not a reference" +\ö not a character entity +. +

*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

+```````````````````````````````` + + +If a backslash is itself escaped, the following character is not: + +```````````````````````````````` example +\\*emphasis* +. +

\emphasis

+```````````````````````````````` + + +A backslash at the end of the line is a [hard line break]: + +```````````````````````````````` example +foo\ +bar +. +

foo
+bar

+```````````````````````````````` + + +Backslash escapes do not work in code blocks, code spans, autolinks, or +raw HTML: + +```````````````````````````````` example +`` \[\` `` +. +

\[\`

+```````````````````````````````` + + +```````````````````````````````` example + \[\] +. +
\[\]
+
+```````````````````````````````` + + +```````````````````````````````` example +~~~ +\[\] +~~~ +. +
\[\]
+
+```````````````````````````````` + + +```````````````````````````````` example + +. +

http://example.com?find=\*

+```````````````````````````````` + + +```````````````````````````````` example + +. + +```````````````````````````````` + + +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") +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +[foo] + +[foo]: /bar\* "ti\*tle" +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +``` foo\+bar +foo +``` +. +
foo
+
+```````````````````````````````` + + +## 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 `*` can be used + in place of a literal `*` character, `*` 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 +is used as an authoritative source for the valid entity +references and their corresponding code points. + +```````````````````````````````` example +  & © Æ Ď +¾ ℋ ⅆ +∲ ≧̸ +. +

& © Æ Ď +¾ ℋ ⅆ +∲ ≧̸

+```````````````````````````````` + + +[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 +# Ӓ Ϡ � +. +

# Ӓ Ϡ �

+```````````````````````````````` + + +[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 +" ആ ಫ +. +

" ആ ಫ

+```````````````````````````````` + + +Here are some nonentities: + +```````````````````````````````` example +  &x; &#; &#x; +� +&#abcdef0; +&ThisIsNotDefined; &hi?; +. +

&nbsp &x; &#; &#x; +&#87654321; +&#abcdef0; +&ThisIsNotDefined; &hi?;

+```````````````````````````````` + + +Although HTML5 does accept some entity references +without a trailing semicolon (such as `©`), these are not +recognized here, because it makes the grammar too ambiguous: + +```````````````````````````````` example +© +. +

&copy

+```````````````````````````````` + + +Strings that are not on the list of HTML5 named entities are not +recognized as entity references either: + +```````````````````````````````` example +&MadeUpEntity; +. +

&MadeUpEntity;

+```````````````````````````````` + + +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 + +. + +```````````````````````````````` + + +```````````````````````````````` example +[foo](/föö "föö") +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +[foo] + +[foo]: /föö "föö" +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +``` föö +foo +``` +. +
foo
+
+```````````````````````````````` + + +Entity and numeric character references are treated as literal +text in code spans and code blocks: + +```````````````````````````````` example +`föö` +. +

f&ouml;&ouml;

+```````````````````````````````` + + +```````````````````````````````` example + föfö +. +
f&ouml;f&ouml;
+
+```````````````````````````````` + + +Entity and numeric character references cannot be used +in place of symbols indicating structure in CommonMark +documents. + +```````````````````````````````` example +*foo* +*foo* +. +

*foo* +foo

+```````````````````````````````` + +```````````````````````````````` example +* foo + +* foo +. +

* foo

+
    +
  • foo
  • +
+```````````````````````````````` + +```````````````````````````````` example +foo bar +. +

foo + +bar

+```````````````````````````````` + +```````````````````````````````` example + foo +. +

→foo

+```````````````````````````````` + + +```````````````````````````````` example +[a](url "tit") +. +

[a](url "tit")

+```````````````````````````````` + + + +# 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` +. +
    +
  • `one
  • +
  • two`
  • +
+```````````````````````````````` + + +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](#container-blocks), +which can contain other blocks, and [leaf blocks](#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 optionally up to three 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 +*** +--- +___ +. +
+
+
+```````````````````````````````` + + +Wrong characters: + +```````````````````````````````` example ++++ +. +

+++

+```````````````````````````````` + + +```````````````````````````````` example +=== +. +

===

+```````````````````````````````` + + +Not enough characters: + +```````````````````````````````` example +-- +** +__ +. +

-- +** +__

+```````````````````````````````` + + +Up to three spaces of indentation are allowed: + +```````````````````````````````` example + *** + *** + *** +. +
+
+
+```````````````````````````````` + + +Four spaces of indentation is too many: + +```````````````````````````````` example + *** +. +
***
+
+```````````````````````````````` + + +```````````````````````````````` example +Foo + *** +. +

Foo +***

+```````````````````````````````` + + +More than three characters may be used: + +```````````````````````````````` example +_____________________________________ +. +
+```````````````````````````````` + + +Spaces and tabs are allowed between the characters: + +```````````````````````````````` example + - - - +. +
+```````````````````````````````` + + +```````````````````````````````` example + ** * ** * ** * ** +. +
+```````````````````````````````` + + +```````````````````````````````` example +- - - - +. +
+```````````````````````````````` + + +Spaces and tabs are allowed at the end: + +```````````````````````````````` example +- - - - +. +
+```````````````````````````````` + + +However, no other characters may occur in the line: + +```````````````````````````````` example +_ _ _ _ a + +a------ + +---a--- +. +

_ _ _ _ a

+

a------

+

---a---

+```````````````````````````````` + + +It is required that all of the characters other than spaces or tabs be the same. +So, this is not a thematic break: + +```````````````````````````````` example + *-* +. +

-

+```````````````````````````````` + + +Thematic breaks do not need blank lines before or after: + +```````````````````````````````` example +- foo +*** +- bar +. +
    +
  • foo
  • +
+
+
    +
  • bar
  • +
+```````````````````````````````` + + +Thematic breaks can interrupt a paragraph: + +```````````````````````````````` example +Foo +*** +bar +. +

Foo

+
+

bar

+```````````````````````````````` + + +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 +. +

Foo

+

bar

+```````````````````````````````` + + +When both a thematic break and a list item are possible +interpretations of a line, the thematic break takes precedence: + +```````````````````````````````` example +* Foo +* * * +* Bar +. +
    +
  • Foo
  • +
+
+
    +
  • Bar
  • +
+```````````````````````````````` + + +If you want a thematic break in a list item, use a different bullet: + +```````````````````````````````` example +- Foo +- * * * +. +
    +
  • Foo
  • +
  • +
    +
  • +
+```````````````````````````````` + + +## 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 spaces or tabs, or +by the end of line. The optional closing sequence of `#`s must be preceded by +spaces or tabs and may be followed by spaces or tabs only. The opening +`#` character may be preceded by up to three spaces of indentation. The raw +contents of the heading are stripped of leading and trailing space or tabs +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 +. +

foo

+

foo

+

foo

+

foo

+
foo
+
foo
+```````````````````````````````` + + +More than six `#` characters is not a heading: + +```````````````````````````````` example +####### foo +. +

####### foo

+```````````````````````````````` + + +At least one space or tab 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 +. +

#5 bolt

+

#hashtag

+```````````````````````````````` + + +This is not a heading, because the first `#` is escaped: + +```````````````````````````````` example +\## foo +. +

## foo

+```````````````````````````````` + + +Contents are parsed as inlines: + +```````````````````````````````` example +# foo *bar* \*baz\* +. +

foo bar *baz*

+```````````````````````````````` + + +Leading and trailing spaces or tabs are ignored in parsing inline content: + +```````````````````````````````` example +# foo +. +

foo

+```````````````````````````````` + + +Up to three spaces of indentation are allowed: + +```````````````````````````````` example + ### foo + ## foo + # foo +. +

foo

+

foo

+

foo

+```````````````````````````````` + + +Four spaces of indentation is too many: + +```````````````````````````````` example + # foo +. +
# foo
+
+```````````````````````````````` + + +```````````````````````````````` example +foo + # bar +. +

foo +# bar

+```````````````````````````````` + + +A closing sequence of `#` characters is optional: + +```````````````````````````````` example +## foo ## + ### bar ### +. +

foo

+

bar

+```````````````````````````````` + + +It need not be the same length as the opening sequence: + +```````````````````````````````` example +# foo ################################## +##### foo ## +. +

foo

+
foo
+```````````````````````````````` + + +Spaces or tabs are allowed after the closing sequence: + +```````````````````````````````` example +### foo ### +. +

foo

+```````````````````````````````` + + +A sequence of `#` characters with anything but spaces or tabs following it +is not a closing sequence, but counts as part of the contents of the +heading: + +```````````````````````````````` example +### foo ### b +. +

foo ### b

+```````````````````````````````` + + +The closing sequence must be preceded by a space or tab: + +```````````````````````````````` example +# foo# +. +

foo#

+```````````````````````````````` + + +Backslash-escaped `#` characters do not count as part +of the closing sequence: + +```````````````````````````````` example +### foo \### +## foo #\## +# foo \# +. +

foo ###

+

foo ###

+

foo #

+```````````````````````````````` + + +ATX headings need not be separated from surrounding content by blank +lines, and they can interrupt paragraphs: + +```````````````````````````````` example +**** +## foo +**** +. +
+

foo

+
+```````````````````````````````` + + +```````````````````````````````` example +Foo bar +# baz +Bar foo +. +

Foo bar

+

baz

+

Bar foo

+```````````````````````````````` + + +ATX headings can be empty: + +```````````````````````````````` example +## +# +### ### +. +

+

+

+```````````````````````````````` + + +## Setext headings + +A [setext heading](@) consists of one or more +lines of text, not interrupted by a blank line, of which the first line does not +have more than 3 spaces of 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 of indentation and any number of trailing spaces or tabs. 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* +--------- +. +

Foo bar

+

Foo bar

+```````````````````````````````` + + +The content of the header may span more than one line: + +```````````````````````````````` example +Foo *bar +baz* +==== +. +

Foo bar +baz

+```````````````````````````````` + +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 +spaces or tabs. + +```````````````````````````````` example + Foo *bar +baz*→ +==== +. +

Foo bar +baz

+```````````````````````````````` + + +The underlining can be any length: + +```````````````````````````````` example +Foo +------------------------- + +Foo += +. +

Foo

+

Foo

+```````````````````````````````` + + +The heading content can be preceded by up to three spaces of indentation, and +need not line up with the underlining: + +```````````````````````````````` example + Foo +--- + + Foo +----- + + Foo + === +. +

Foo

+

Foo

+

Foo

+```````````````````````````````` + + +Four spaces of indentation is too many: + +```````````````````````````````` example + Foo + --- + + Foo +--- +. +
Foo
+---
+
+Foo
+
+
+```````````````````````````````` + + +The setext heading underline can be preceded by up to three spaces of +indentation, and may have trailing spaces or tabs: + +```````````````````````````````` example +Foo + ---- +. +

Foo

+```````````````````````````````` + + +Four spaces of indentation is too many: + +```````````````````````````````` example +Foo + --- +. +

Foo +---

+```````````````````````````````` + + +The setext heading underline cannot contain internal spaces or tabs: + +```````````````````````````````` example +Foo += = + +Foo +--- - +. +

Foo += =

+

Foo

+
+```````````````````````````````` + + +Trailing spaces or tabs in the content line do not cause a hard line break: + +```````````````````````````````` example +Foo +----- +. +

Foo

+```````````````````````````````` + + +Nor does a backslash at the end: + +```````````````````````````````` example +Foo\ +---- +. +

Foo\

+```````````````````````````````` + + +Since indicators of block structure take precedence over +indicators of inline structure, the following are setext headings: + +```````````````````````````````` example +`Foo +---- +` + + +. +

`Foo

+

`

+

<a title="a lot

+

of dashes"/>

+```````````````````````````````` + + +The setext heading underline cannot be a [lazy continuation +line] in a list item or block quote: + +```````````````````````````````` example +> Foo +--- +. +
+

Foo

+
+
+```````````````````````````````` + + +```````````````````````````````` example +> foo +bar +=== +. +
+

foo +bar +===

+
+```````````````````````````````` + + +```````````````````````````````` example +- Foo +--- +. +
    +
  • Foo
  • +
+
+```````````````````````````````` + + +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 +--- +. +

Foo +Bar

+```````````````````````````````` + + +But in general a blank line is not required before or after +setext headings: + +```````````````````````````````` example +--- +Foo +--- +Bar +--- +Baz +. +
+

Foo

+

Bar

+

Baz

+```````````````````````````````` + + +Setext headings cannot be empty: + +```````````````````````````````` example + +==== +. +

====

+```````````````````````````````` + + +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 +--- +--- +. +
+
+```````````````````````````````` + + +```````````````````````````````` example +- foo +----- +. +
    +
  • foo
  • +
+
+```````````````````````````````` + + +```````````````````````````````` example + foo +--- +. +
foo
+
+
+```````````````````````````````` + + +```````````````````````````````` example +> foo +----- +. +
+

foo

+
+
+```````````````````````````````` + + +If you want a heading with `> foo` as its literal text, you can +use backslash escapes: + +```````````````````````````````` example +\> foo +------ +. +

> foo

+```````````````````````````````` + + +**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 +. +

Foo

+

bar

+

baz

+```````````````````````````````` + + +Authors who want interpretation 2 can put blank lines around +the thematic break, + +```````````````````````````````` example +Foo +bar + +--- + +baz +. +

Foo +bar

+
+

baz

+```````````````````````````````` + + +or use a thematic break that cannot count as a [setext heading +underline], such as + +```````````````````````````````` example +Foo +bar +* * * +baz +. +

Foo +bar

+
+

baz

+```````````````````````````````` + + +Authors who want interpretation 3 can use backslash escapes: + +```````````````````````````````` example +Foo +bar +\--- +baz +. +

Foo +bar +--- +baz

+```````````````````````````````` + + +## 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 preceded by four or more spaces of indentation. 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 +. +
a simple
+  indented code block
+
+```````````````````````````````` + + +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 +. +
    +
  • +

    foo

    +

    bar

    +
  • +
+```````````````````````````````` + + +```````````````````````````````` example +1. foo + + - bar +. +
    +
  1. +

    foo

    +
      +
    • bar
    • +
    +
  2. +
+```````````````````````````````` + + + +The contents of a code block are literal text, and do not get parsed +as Markdown: + +```````````````````````````````` example +
+ *hi* + + - one +. +
<a/>
+*hi*
+
+- one
+
+```````````````````````````````` + + +Here we have three chunks separated by blank lines: + +```````````````````````````````` example + chunk1 + + chunk2 + + + + chunk3 +. +
chunk1
+
+chunk2
+
+
+
+chunk3
+
+```````````````````````````````` + + +Any initial spaces or tabs beyond four spaces of indentation will be included in +the content, even in interior blank lines: + +```````````````````````````````` example + chunk1 + + chunk2 +. +
chunk1
+
+  chunk2
+
+```````````````````````````````` + + +An indented code block cannot interrupt a paragraph. (This +allows hanging indents and the like.) + +```````````````````````````````` example +Foo + bar + +. +

Foo +bar

+```````````````````````````````` + + +However, any non-blank line with fewer than four spaces of indentation ends +the code block immediately. So a paragraph may occur immediately +after indented code: + +```````````````````````````````` example + foo +bar +. +
foo
+
+

bar

+```````````````````````````````` + + +And indented code can occur immediately before and after other kinds of +blocks: + +```````````````````````````````` example +# Heading + foo +Heading +------ + foo +---- +. +

Heading

+
foo
+
+

Heading

+
foo
+
+
+```````````````````````````````` + + +The first line can be preceded by more than four spaces of indentation: + +```````````````````````````````` example + foo + bar +. +
    foo
+bar
+
+```````````````````````````````` + + +Blank lines preceding or following an indented code block +are not included in it: + +```````````````````````````````` example + + + foo + + +. +
foo
+
+```````````````````````````````` + + +Trailing spaces or tabs are included in the code block's content: + +```````````````````````````````` example + foo +. +
foo
+
+```````````````````````````````` + + + +## 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, preceded by up to three spaces of indentation. + +The line with the opening code fence may optionally contain some text +following the code fence; this is trimmed of leading and trailing +spaces or tabs 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 +preceded by N spaces of indentation, 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 N spaces or less, all +of the indentation is removed.) + +The closing code fence may be preceded by up to three spaces of indentation, and +may be followed only by spaces or tabs, 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 +``` +< + > +``` +. +
<
+ >
+
+```````````````````````````````` + + +With tildes: + +```````````````````````````````` example +~~~ +< + > +~~~ +. +
<
+ >
+
+```````````````````````````````` + +Fewer than three backticks is not enough: + +```````````````````````````````` example +`` +foo +`` +. +

foo

+```````````````````````````````` + +The closing code fence must use the same character as the opening +fence: + +```````````````````````````````` example +``` +aaa +~~~ +``` +. +
aaa
+~~~
+
+```````````````````````````````` + + +```````````````````````````````` example +~~~ +aaa +``` +~~~ +. +
aaa
+```
+
+```````````````````````````````` + + +The closing code fence must be at least as long as the opening fence: + +```````````````````````````````` example +```` +aaa +``` +`````` +. +
aaa
+```
+
+```````````````````````````````` + + +```````````````````````````````` example +~~~~ +aaa +~~~ +~~~~ +. +
aaa
+~~~
+
+```````````````````````````````` + + +Unclosed code blocks are closed by the end of the document +(or the enclosing [block quote][block quotes] or [list item][list items]): + +```````````````````````````````` example +``` +. +
+```````````````````````````````` + + +```````````````````````````````` example +````` + +``` +aaa +. +

+```
+aaa
+
+```````````````````````````````` + + +```````````````````````````````` example +> ``` +> aaa + +bbb +. +
+
aaa
+
+
+

bbb

+```````````````````````````````` + + +A code block can have all empty lines as its content: + +```````````````````````````````` example +``` + + +``` +. +

+
+
+```````````````````````````````` + + +A code block can be empty: + +```````````````````````````````` example +``` +``` +. +
+```````````````````````````````` + + +Fences can be indented. If the opening fence is indented, +content lines will have equivalent opening indentation removed, +if present: + +```````````````````````````````` example + ``` + aaa +aaa +``` +. +
aaa
+aaa
+
+```````````````````````````````` + + +```````````````````````````````` example + ``` +aaa + aaa +aaa + ``` +. +
aaa
+aaa
+aaa
+
+```````````````````````````````` + + +```````````````````````````````` example + ``` + aaa + aaa + aaa + ``` +. +
aaa
+ aaa
+aaa
+
+```````````````````````````````` + + +Four spaces of indentation is too many: + +```````````````````````````````` example + ``` + aaa + ``` +. +
```
+aaa
+```
+
+```````````````````````````````` + + +Closing fences may be preceded by up to three spaces of indentation, and their +indentation need not match that of the opening fence: + +```````````````````````````````` example +``` +aaa + ``` +. +
aaa
+
+```````````````````````````````` + + +```````````````````````````````` example + ``` +aaa + ``` +. +
aaa
+
+```````````````````````````````` + + +This is not a closing fence, because it is indented 4 spaces: + +```````````````````````````````` example +``` +aaa + ``` +. +
aaa
+    ```
+
+```````````````````````````````` + + + +Code fences (opening and closing) cannot contain internal spaces or tabs: + +```````````````````````````````` example +``` ``` +aaa +. +

+aaa

+```````````````````````````````` + + +```````````````````````````````` example +~~~~~~ +aaa +~~~ ~~ +. +
aaa
+~~~ ~~
+
+```````````````````````````````` + + +Fenced code blocks can interrupt paragraphs, and can be followed +directly by paragraphs, without a blank line between: + +```````````````````````````````` example +foo +``` +bar +``` +baz +. +

foo

+
bar
+
+

baz

+```````````````````````````````` + + +Other blocks can also occur before and after fenced code blocks +without an intervening blank line: + +```````````````````````````````` example +foo +--- +~~~ +bar +~~~ +# baz +. +

foo

+
bar
+
+

baz

+```````````````````````````````` + + +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 +``` +. +
def foo(x)
+  return 3
+end
+
+```````````````````````````````` + + +```````````````````````````````` example +~~~~ ruby startline=3 $%@#$ +def foo(x) + return 3 +end +~~~~~~~ +. +
def foo(x)
+  return 3
+end
+
+```````````````````````````````` + + +```````````````````````````````` example +````; +```` +. +
+```````````````````````````````` + + +[Info strings] for backtick code blocks cannot contain backticks: + +```````````````````````````````` example +``` aa ``` +foo +. +

aa +foo

+```````````````````````````````` + + +[Info strings] for tilde code blocks can contain backticks and tildes: + +```````````````````````````````` example +~~~ aa ``` ~~~ +foo +~~~ +. +
foo
+
+```````````````````````````````` + + +Closing code fences cannot have [info strings]: + +```````````````````````````````` example +``` +``` aaa +``` +. +
``` aaa
+
+```````````````````````````````` + + + +## 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 optional spaces of 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 ``, or the end of the line.\ +**End condition:** line contains an end tag +``, ``, ``, or `` (case-insensitive; it +need not match the start tag). + +2. **Start condition:** line begins with the string ``. + +3. **Start condition:** line begins with the string ``. + +4. **Start condition:** line begins with the string ``. + +5. **Start condition:** line begins with the string +``. + +6. **Start condition:** line begins the string `<` or ``, 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 `pre`, `script`, +`style`, or `textarea`) or a complete [closing tag], +followed by zero or more spaces and tabs, followed by 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, `
` within an HTML block started by `` 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
+
+
+**Hello**,
+
+_world_.
+
+
+. +
+
+**Hello**,
+

world. +

+
+```````````````````````````````` + +In this case, the HTML block is terminated by the blank line — 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 + + + + +
+ hi +
+ +okay. +. + + + + +
+ hi +
+

okay.

+```````````````````````````````` + + +```````````````````````````````` example +
+*foo* +```````````````````````````````` + + +Here we have two HTML blocks with a Markdown paragraph between them: + +```````````````````````````````` example +
+ +*Markdown* + +
+. +
+

Markdown

+
+```````````````````````````````` + + +The tag on the first line can be partial, as long +as it is split where there would be whitespace: + +```````````````````````````````` example +
+
+. +
+
+```````````````````````````````` + + +```````````````````````````````` example +
+
+. +
+
+```````````````````````````````` + + +An open tag need not be closed: +```````````````````````````````` example +
+*foo* + +*bar* +. +
+*foo* +

bar

+```````````````````````````````` + + + +A partial tag need not even be completed (garbage +in, garbage out): + +```````````````````````````````` example +
+. + +```````````````````````````````` + + +```````````````````````````````` example +
+foo +
+. +
+foo +
+```````````````````````````````` + + +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 +
+``` c +int x = 33; +``` +. +
+``` 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 + +*bar* + +. + +*bar* + +```````````````````````````````` + + +In type 7 blocks, the [tag name] can be anything: + +```````````````````````````````` example + +*bar* + +. + +*bar* + +```````````````````````````````` + + +```````````````````````````````` example + +*bar* + +. + +*bar* + +```````````````````````````````` + + +```````````````````````````````` example + +*bar* +. + +*bar* +```````````````````````````````` + + +These rules are designed to allow us to work with tags that +can function as either block-level or inline-level tags. +The `` tag is a nice example. We can surround content with +`` tags in three different ways. In this case, we get a raw +HTML block, because the `` tag is on a line by itself: + +```````````````````````````````` example + +*foo* + +. + +*foo* + +```````````````````````````````` + + +In this case, we get a raw HTML block that just includes +the `` tag (because it ends with the following blank +line). So the contents get interpreted as CommonMark: + +```````````````````````````````` example + + +*foo* + + +. + +

foo

+
+```````````````````````````````` + + +Finally, in this case, the `` 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 +*foo* +. +

foo

+```````````````````````````````` + + +HTML tags designed to contain literal content +(`pre`, `script`, `style`, `textarea`), 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 +

+import Text.HTML.TagSoup
+
+main :: IO ()
+main = print $ parseTags tags
+
+okay +. +

+import Text.HTML.TagSoup
+
+main :: IO ()
+main = print $ parseTags tags
+
+

okay

+```````````````````````````````` + + +A script tag (type 1): + +```````````````````````````````` example + +okay +. + +

okay

+```````````````````````````````` + + +A textarea tag (type 1): + +```````````````````````````````` example + +. + +```````````````````````````````` + +A style tag (type 1): + +```````````````````````````````` example + +okay +. + +

okay

+```````````````````````````````` + + +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 + +*foo* +. + +

foo

+```````````````````````````````` + + +```````````````````````````````` example +*bar* +*baz* +. +*bar* +

baz

+```````````````````````````````` + + +Note that anything on the last line after the +end tag will be included in the [HTML block]: + +```````````````````````````````` example +1. *bar* +. +1. *bar* +```````````````````````````````` + + +A comment (type 2): + +```````````````````````````````` example + +okay +. + +

okay

+```````````````````````````````` + + + +A processing instruction (type 3): + +```````````````````````````````` example +'; + +?> +okay +. +'; + +?> +

okay

+```````````````````````````````` + + +A declaration (type 4): + +```````````````````````````````` example + +. + +```````````````````````````````` + + +CDATA (type 5): + +```````````````````````````````` example + +okay +. + +

okay

+```````````````````````````````` + + +The opening tag can be preceded by up to three spaces of indentation, but not +four: + +```````````````````````````````` example + + + +. + +
<!-- foo -->
+
+```````````````````````````````` + + +```````````````````````````````` example +
+ +
+. +
+
<div>
+
+```````````````````````````````` + + +An HTML block of types 1--6 can interrupt a paragraph, and need not be +preceded by a blank line. + +```````````````````````````````` example +Foo +
+bar +
+. +

Foo

+
+bar +
+```````````````````````````````` + + +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 +
+bar +
+*foo* +. +
+bar +
+*foo* +```````````````````````````````` + + +HTML blocks of type 7 cannot interrupt a paragraph: + +```````````````````````````````` example +Foo + +baz +. +

Foo + +baz

+```````````````````````````````` + + +This rule differs from John Gruber's original Markdown syntax +specification, which says: + +> The only restrictions are that block-level HTML elements — +> e.g. `
`, ``, `
`, `

`, etc. — must be separated from +> surrounding content by blank lines, and the start and end tags of the +> block should not be indented with spaces or tabs. + +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 +

+ +*Emphasized* text. + +
+. +
+

Emphasized text.

+
+```````````````````````````````` + + +```````````````````````````````` example +
+*Emphasized* text. +
+. +
+*Emphasized* text. +
+```````````````````````````````` + + +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 +
+ + + + + + + +
+Hi +
+. + + + + +
+Hi +
+```````````````````````````````` + + +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 + + + + + + + + +
+ Hi +
+. + + +
<td>
+  Hi
+</td>
+
+ +
+```````````````````````````````` + + +Fortunately, blank lines are usually not necessary and can be +deleted. The exception is inside `
` tags, but as described
+[above][HTML blocks], raw HTML blocks starting with `
`
+*can* contain blank lines.
+
+## Link reference definitions
+
+A [link reference definition](@)
+consists of a [link label], optionally preceded by up to three spaces of
+indentation, followed
+by a colon (`:`), optional spaces or tabs (including up to one
+[line ending]), a [link destination],
+optional spaces or tabs (including up to one
+[line ending]), and an optional [link
+title], which if it is present must be separated
+from the [link destination] by spaces or tabs.
+No further character may occur.
+
+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]
+.
+

foo

+```````````````````````````````` + + +```````````````````````````````` example + [foo]: + /url + 'the title' + +[foo] +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +[Foo*bar\]]:my_(url) 'title (with parens)' + +[Foo*bar\]] +. +

Foo*bar]

+```````````````````````````````` + + +```````````````````````````````` example +[Foo bar]: + +'title' + +[Foo bar] +. +

Foo bar

+```````````````````````````````` + + +The title may extend over multiple lines: + +```````````````````````````````` example +[foo]: /url ' +title +line1 +line2 +' + +[foo] +. +

foo

+```````````````````````````````` + + +However, it may not contain a [blank line]: + +```````````````````````````````` example +[foo]: /url 'title + +with blank line' + +[foo] +. +

[foo]: /url 'title

+

with blank line'

+

[foo]

+```````````````````````````````` + + +The title may be omitted: + +```````````````````````````````` example +[foo]: +/url + +[foo] +. +

foo

+```````````````````````````````` + + +The link destination may not be omitted: + +```````````````````````````````` example +[foo]: + +[foo] +. +

[foo]:

+

[foo]

+```````````````````````````````` + + However, an empty link destination may be specified using + angle brackets: + +```````````````````````````````` example +[foo]: <> + +[foo] +. +

foo

+```````````````````````````````` + +The title must be separated from the link destination by +spaces or tabs: + +```````````````````````````````` example +[foo]: (baz) + +[foo] +. +

[foo]: (baz)

+

[foo]

+```````````````````````````````` + + +Both title and destination can contain backslash escapes +and literal backslashes: + +```````````````````````````````` example +[foo]: /url\bar\*baz "foo\"bar\baz" + +[foo] +. +

foo

+```````````````````````````````` + + +A link can come before its corresponding definition: + +```````````````````````````````` example +[foo] + +[foo]: url +. +

foo

+```````````````````````````````` + + +If there are several matching definitions, the first one takes +precedence: + +```````````````````````````````` example +[foo] + +[foo]: first +[foo]: second +. +

foo

+```````````````````````````````` + + +As noted in the section on [Links], matching of labels is +case-insensitive (see [matches]). + +```````````````````````````````` example +[FOO]: /url + +[Foo] +. +

Foo

+```````````````````````````````` + + +```````````````````````````````` example +[ΑΓΩ]: /φου + +[αγω] +. +

αγω

+```````````````````````````````` + + +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 +. +```````````````````````````````` + + +Here is another one: + +```````````````````````````````` example +[ +foo +]: /url +bar +. +

bar

+```````````````````````````````` + + +This is not a link reference definition, because there are +characters other than spaces or tabs after the title: + +```````````````````````````````` example +[foo]: /url "title" ok +. +

[foo]: /url "title" ok

+```````````````````````````````` + + +This is a link reference definition, but it has no title: + +```````````````````````````````` example +[foo]: /url +"title" ok +. +

"title" ok

+```````````````````````````````` + + +This is not a link reference definition, because it is indented +four spaces: + +```````````````````````````````` example + [foo]: /url "title" + +[foo] +. +
[foo]: /url "title"
+
+

[foo]

+```````````````````````````````` + + +This is not a link reference definition, because it occurs inside +a code block: + +```````````````````````````````` example +``` +[foo]: /url +``` + +[foo] +. +
[foo]: /url
+
+

[foo]

+```````````````````````````````` + + +A [link reference definition] cannot interrupt a paragraph. + +```````````````````````````````` example +Foo +[bar]: /baz + +[bar] +. +

Foo +[bar]: /baz

+

[bar]

+```````````````````````````````` + + +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 +. +

Foo

+
+

bar

+
+```````````````````````````````` + +```````````````````````````````` example +[foo]: /url +bar +=== +[foo] +. +

bar

+

foo

+```````````````````````````````` + +```````````````````````````````` example +[foo]: /url +=== +[foo] +. +

=== +foo

+```````````````````````````````` + + +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] +. +

foo, +bar, +baz

+```````````````````````````````` + + +[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 +. +

foo

+
+
+```````````````````````````````` + + +## 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 +spaces or tabs. + +A simple example with two paragraphs: + +```````````````````````````````` example +aaa + +bbb +. +

aaa

+

bbb

+```````````````````````````````` + + +Paragraphs can contain multiple lines, but no blank lines: + +```````````````````````````````` example +aaa +bbb + +ccc +ddd +. +

aaa +bbb

+

ccc +ddd

+```````````````````````````````` + + +Multiple blank lines between paragraphs have no effect: + +```````````````````````````````` example +aaa + + +bbb +. +

aaa

+

bbb

+```````````````````````````````` + + +Leading spaces or tabs are skipped: + +```````````````````````````````` example + aaa + bbb +. +

aaa +bbb

+```````````````````````````````` + + +Lines after the first may be indented any amount, since indented +code blocks cannot interrupt paragraphs. + +```````````````````````````````` example +aaa + bbb + ccc +. +

aaa +bbb +ccc

+```````````````````````````````` + + +However, the first line may be preceded by up to three spaces of indentation. +Four spaces of indentation is too many: + +```````````````````````````````` example + aaa +bbb +. +

aaa +bbb

+```````````````````````````````` + + +```````````````````````````````` example + aaa +bbb +. +
aaa
+
+

bbb

+```````````````````````````````` + + +Final spaces or tabs 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 +. +

aaa
+bbb

+```````````````````````````````` + + +## 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 + + +. +

aaa

+

aaa

+```````````````````````````````` + + + +# 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](@), +optionally preceded by up to three spaces of indentation, +consists of (a) the character `>` together with a following space of +indentation, or (b) a single character `>` not followed by a space of +indentation. + +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 character other than a space or tab 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 +. +
+

Foo

+

bar +baz

+
+```````````````````````````````` + + +The space or tab after the `>` characters can be omitted: + +```````````````````````````````` example +># Foo +>bar +> baz +. +
+

Foo

+

bar +baz

+
+```````````````````````````````` + + +The `>` characters can be preceded by up to three spaces of indentation: + +```````````````````````````````` example + > # Foo + > bar + > baz +. +
+

Foo

+

bar +baz

+
+```````````````````````````````` + + +Four spaces of indentation is too many: + +```````````````````````````````` example + > # Foo + > bar + > baz +. +
> # Foo
+> bar
+> baz
+
+```````````````````````````````` + + +The Laziness clause allows us to omit the `>` before +[paragraph continuation text]: + +```````````````````````````````` example +> # Foo +> bar +baz +. +
+

Foo

+

bar +baz

+
+```````````````````````````````` + + +A block quote can contain some lazy and some non-lazy +continuation lines: + +```````````````````````````````` example +> bar +baz +> foo +. +
+

bar +baz +foo

+
+```````````````````````````````` + + +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 +--- +. +
+

foo

+
+
+```````````````````````````````` + + +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 +. +
+
    +
  • foo
  • +
+
+
    +
  • bar
  • +
+```````````````````````````````` + + +For the same reason, we can't omit the `> ` in front of +subsequent lines of an indented or fenced code block: + +```````````````````````````````` example +> foo + bar +. +
+
foo
+
+
+
bar
+
+```````````````````````````````` + + +```````````````````````````````` example +> ``` +foo +``` +. +
+
+
+

foo

+
+```````````````````````````````` + + +Note that in the following case, we have a [lazy +continuation line]: + +```````````````````````````````` example +> foo + - bar +. +
+

foo +- bar

+
+```````````````````````````````` + + +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 +> +. +
+
+```````````````````````````````` + + +```````````````````````````````` example +> +> +> +. +
+
+```````````````````````````````` + + +A block quote can have initial or final blank lines: + +```````````````````````````````` example +> +> foo +> +. +
+

foo

+
+```````````````````````````````` + + +A blank line always separates block quotes: + +```````````````````````````````` example +> foo + +> bar +. +
+

foo

+
+
+

bar

+
+```````````````````````````````` + + +(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 +. +
+

foo +bar

+
+```````````````````````````````` + + +To get a block quote with two paragraphs, use: + +```````````````````````````````` example +> foo +> +> bar +. +
+

foo

+

bar

+
+```````````````````````````````` + + +Block quotes can interrupt paragraphs: + +```````````````````````````````` example +foo +> bar +. +

foo

+
+

bar

+
+```````````````````````````````` + + +In general, blank lines are not needed before or after block +quotes: + +```````````````````````````````` example +> aaa +*** +> bbb +. +
+

aaa

+
+
+
+

bbb

+
+```````````````````````````````` + + +However, because of laziness, a blank line is needed between +a block quote and a following paragraph: + +```````````````````````````````` example +> bar +baz +. +
+

bar +baz

+
+```````````````````````````````` + + +```````````````````````````````` example +> bar + +baz +. +
+

bar

+
+

baz

+```````````````````````````````` + + +```````````````````````````````` example +> bar +> +baz +. +
+

bar

+
+

baz

+```````````````````````````````` + + +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 +. +
+
+
+

foo +bar

+
+
+
+```````````````````````````````` + + +```````````````````````````````` example +>>> foo +> bar +>>baz +. +
+
+
+

foo +bar +baz

+
+
+
+```````````````````````````````` + + +When including an indented code block in a block quote, +remember that the [block quote marker] includes +both the `>` and a following space of indentation. So *five spaces* are needed +after the `>`: + +```````````````````````````````` example +> code + +> not code +. +
+
code
+
+
+
+

not code

+
+```````````````````````````````` + + + +## 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 character other than a space or tab, and *M* is + a list marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces of indentation, + 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. +. +

A paragraph +with two lines.

+
indented code
+
+
+

A block quote.

+
+```````````````````````````````` + + +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. +. +
    +
  1. +

    A paragraph +with two lines.

    +
    indented code
    +
    +
    +

    A block quote.

    +
    +
  2. +
+```````````````````````````````` + + +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 of indentation, and there are three spaces between +the list marker and the next character other than a space or tab, 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 +. +
    +
  • one
  • +
+

two

+```````````````````````````````` + + +```````````````````````````````` example +- one + + two +. +
    +
  • +

    one

    +

    two

    +
  • +
+```````````````````````````````` + + +```````````````````````````````` example + - one + + two +. +
    +
  • one
  • +
+
 two
+
+```````````````````````````````` + + +```````````````````````````````` example + - one + + two +. +
    +
  • +

    one

    +

    two

    +
  • +
+```````````````````````````````` + + +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 character other than +a space or tab after the list marker. However, that is not quite right. +The spaces of indentation 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 +. +
+
+
    +
  1. +

    one

    +

    two

    +
  2. +
+
+
+```````````````````````````````` + + +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 +. +
+
+
    +
  • one
  • +
+

two

+
+
+```````````````````````````````` + + +Note that at least one space or tab is needed between the list marker and +any following content, so these are not list items: + +```````````````````````````````` example +-one + +2.two +. +

-one

+

2.two

+```````````````````````````````` + + +A list item may contain blocks that are separated by more than +one blank line. + +```````````````````````````````` example +- foo + + + bar +. +
    +
  • +

    foo

    +

    bar

    +
  • +
+```````````````````````````````` + + +A list item may contain any kind of block: + +```````````````````````````````` example +1. foo + + ``` + bar + ``` + + baz + + > bam +. +
    +
  1. +

    foo

    +
    bar
    +
    +

    baz

    +
    +

    bam

    +
    +
  2. +
+```````````````````````````````` + + +A list item that contains an indented code block will preserve +empty lines within the code block verbatim. + +```````````````````````````````` example +- Foo + + bar + + + baz +. +
    +
  • +

    Foo

    +
    bar
    +
    +
    +baz
    +
    +
  • +
+```````````````````````````````` + +Note that ordered list start numbers must be nine digits or less: + +```````````````````````````````` example +123456789. ok +. +
    +
  1. ok
  2. +
+```````````````````````````````` + + +```````````````````````````````` example +1234567890. not ok +. +

1234567890. not ok

+```````````````````````````````` + + +A start number may begin with 0s: + +```````````````````````````````` example +0. ok +. +
    +
  1. ok
  2. +
+```````````````````````````````` + + +```````````````````````````````` example +003. ok +. +
    +
  1. ok
  2. +
+```````````````````````````````` + + +A start number may not be negative: + +```````````````````````````````` example +-1. not ok +. +

-1. not ok

+```````````````````````````````` + + + +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 of indentation, 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 preceded by four spaces of indentation +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 +. +
    +
  • +

    foo

    +
    bar
    +
    +
  • +
+```````````````````````````````` + + +And in this case it is 11 spaces: + +```````````````````````````````` example + 10. foo + + bar +. +
    +
  1. +

    foo

    +
    bar
    +
    +
  2. +
+```````````````````````````````` + + +If the *first* block in the list item is an indented code block, +then by rule #2, the contents must be preceded by *one* space of indentation +after the list marker: + +```````````````````````````````` example + indented code + +paragraph + + more code +. +
indented code
+
+

paragraph

+
more code
+
+```````````````````````````````` + + +```````````````````````````````` example +1. indented code + + paragraph + + more code +. +
    +
  1. +
    indented code
    +
    +

    paragraph

    +
    more code
    +
    +
  2. +
+```````````````````````````````` + + +Note that an additional space of indentation is interpreted as space +inside the code block: + +```````````````````````````````` example +1. indented code + + paragraph + + more code +. +
    +
  1. +
     indented code
    +
    +

    paragraph

    +
    more code
    +
    +
  2. +
+```````````````````````````````` + + +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 +character other than a space or tab, and (b) cases in which +they begin with an indented code +block. In a case like the following, where the first block begins with +three spaces of indentation, the rules do not allow us to form a list item by +indenting the whole thing and prepending a list marker: + +```````````````````````````````` example + foo + +bar +. +

foo

+

bar

+```````````````````````````````` + + +```````````````````````````````` example +- foo + + bar +. +
    +
  • foo
  • +
+

bar

+```````````````````````````````` + + +This is not a significant restriction, because when a block is preceded by up to +three spaces of indentation, 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 +. +
    +
  • +

    foo

    +

    bar

    +
  • +
+```````````````````````````````` + + +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*, and *M* is a list marker of width *W*, + then the result of prepending *M* to the first line of *Ls*, and + preceding subsequent lines of *Ls* by *W + 1* spaces of indentation, 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 +. +
    +
  • foo
  • +
  • +
    bar
    +
    +
  • +
  • +
    baz
    +
    +
  • +
+```````````````````````````````` + +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 +. +
    +
  • foo
  • +
+```````````````````````````````` + + +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 +. +
    +
  • +
+

foo

+```````````````````````````````` + + +Here is an empty bullet list item: + +```````````````````````````````` example +- foo +- +- bar +. +
    +
  • foo
  • +
  • +
  • bar
  • +
+```````````````````````````````` + + +It does not matter whether there are spaces or tabs following the [list marker]: + +```````````````````````````````` example +- foo +- +- bar +. +
    +
  • foo
  • +
  • +
  • bar
  • +
+```````````````````````````````` + + +Here is an empty ordered list item: + +```````````````````````````````` example +1. foo +2. +3. bar +. +
    +
  1. foo
  2. +
  3. +
  4. bar
  5. +
+```````````````````````````````` + + +A list may start or end with an empty list item: + +```````````````````````````````` example +* +. +
    +
  • +
+```````````````````````````````` + +However, an empty list item cannot interrupt a paragraph: + +```````````````````````````````` example +foo +* + +foo +1. +. +

foo +*

+

foo +1.

+```````````````````````````````` + + +4. **Indentation.** If a sequence of lines *Ls* constitutes a list item + according to rule #1, #2, or #3, then the result of preceding each line + of *Ls* by up to three spaces of indentation (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. +. +
    +
  1. +

    A paragraph +with two lines.

    +
    indented code
    +
    +
    +

    A block quote.

    +
    +
  2. +
+```````````````````````````````` + + +Indented two spaces: + +```````````````````````````````` example + 1. A paragraph + with two lines. + + indented code + + > A block quote. +. +
    +
  1. +

    A paragraph +with two lines.

    +
    indented code
    +
    +
    +

    A block quote.

    +
    +
  2. +
+```````````````````````````````` + + +Indented three spaces: + +```````````````````````````````` example + 1. A paragraph + with two lines. + + indented code + + > A block quote. +. +
    +
  1. +

    A paragraph +with two lines.

    +
    indented code
    +
    +
    +

    A block quote.

    +
    +
  2. +
+```````````````````````````````` + + +Four spaces indent gives a code block: + +```````````````````````````````` example + 1. A paragraph + with two lines. + + indented code + + > A block quote. +. +
1.  A paragraph
+    with two lines.
+
+        indented code
+
+    > A block quote.
+
+```````````````````````````````` + + + +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 character other than a space or tab 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. +. +
    +
  1. +

    A paragraph +with two lines.

    +
    indented code
    +
    +
    +

    A block quote.

    +
    +
  2. +
+```````````````````````````````` + + +Indentation can be partially deleted: + +```````````````````````````````` example + 1. A paragraph + with two lines. +. +
    +
  1. A paragraph +with two lines.
  2. +
+```````````````````````````````` + + +These examples show how laziness can work in nested structures: + +```````````````````````````````` example +> 1. > Blockquote +continued here. +. +
+
    +
  1. +
    +

    Blockquote +continued here.

    +
    +
  2. +
+
+```````````````````````````````` + + +```````````````````````````````` example +> 1. > Blockquote +> continued here. +. +
+
    +
  1. +
    +

    Blockquote +continued here.

    +
    +
  2. +
+
+```````````````````````````````` + + + +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 of indentation 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 +. +
    +
  • foo +
      +
    • bar +
        +
      • baz +
          +
        • boo
        • +
        +
      • +
      +
    • +
    +
  • +
+```````````````````````````````` + + +One is not enough: + +```````````````````````````````` example +- foo + - bar + - baz + - boo +. +
    +
  • foo
  • +
  • bar
  • +
  • baz
  • +
  • boo
  • +
+```````````````````````````````` + + +Here we need four, because the list marker is wider: + +```````````````````````````````` example +10) foo + - bar +. +
    +
  1. foo +
      +
    • bar
    • +
    +
  2. +
+```````````````````````````````` + + +Three is not enough: + +```````````````````````````````` example +10) foo + - bar +. +
    +
  1. foo
  2. +
+
    +
  • bar
  • +
+```````````````````````````````` + + +A list may be the first block in a list item: + +```````````````````````````````` example +- - foo +. +
    +
  • +
      +
    • foo
    • +
    +
  • +
+```````````````````````````````` + + +```````````````````````````````` example +1. - 2. foo +. +
    +
  1. +
      +
    • +
        +
      1. foo
      2. +
      +
    • +
    +
  2. +
+```````````````````````````````` + + +A list item can contain a heading: + +```````````````````````````````` example +- # Foo +- Bar + --- + baz +. +
    +
  • +

    Foo

    +
  • +
  • +

    Bar

    +baz
  • +
+```````````````````````````````` + + +### 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 +
    +
  • foo
  • +
+

bar

+
    +
  • baz
  • +
+``` + +as the four-space rule demands, rather than a single list, + +``` html +
    +
  • +

    foo

    +

    bar

    +
      +
    • baz
    • +
    +
  • +
+``` + +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 up to three spaces of indentation for +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 +
    +
  • +

    one

    +

    two

    +
  • +
+``` + +and similarly + +``` markdown +> - one +> +> two +``` + +as + +``` html +
+
    +
  • +

    one

    +

    two

    +
  • +
+
+``` + +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 `

` tags, while paragraphs in a tight list are not.) + +Changing the bullet or ordered list delimiter starts a new list: + +```````````````````````````````` example +- foo +- bar ++ baz +. +

    +
  • foo
  • +
  • bar
  • +
+
    +
  • baz
  • +
+```````````````````````````````` + + +```````````````````````````````` example +1. foo +2. bar +3) baz +. +
    +
  1. foo
  2. +
  3. bar
  4. +
+
    +
  1. baz
  2. +
+```````````````````````````````` + + +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 +. +

Foo

+
    +
  • bar
  • +
  • baz
  • +
+```````````````````````````````` + +`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 `

` 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. +. +

The number of windows in my house is +14. The number of doors is 6.

+```````````````````````````````` + +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. +. +

The number of windows in my house is

+
    +
  1. The number of doors is 6.
  2. +
+```````````````````````````````` + +but this rule should prevent most spurious list captures. + +There can be any number of blank lines between items: + +```````````````````````````````` example +- foo + +- bar + + +- baz +. +
    +
  • +

    foo

    +
  • +
  • +

    bar

    +
  • +
  • +

    baz

    +
  • +
+```````````````````````````````` + +```````````````````````````````` example +- foo + - bar + - baz + + + bim +. +
    +
  • foo +
      +
    • bar +
        +
      • +

        baz

        +

        bim

        +
      • +
      +
    • +
    +
  • +
+```````````````````````````````` + + +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 +. +
    +
  • foo
  • +
  • bar
  • +
+ +
    +
  • baz
  • +
  • bim
  • +
+```````````````````````````````` + + +```````````````````````````````` example +- foo + + notcode + +- foo + + + + code +. +
    +
  • +

    foo

    +

    notcode

    +
  • +
  • +

    foo

    +
  • +
+ +
code
+
+```````````````````````````````` + + +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 +. +
    +
  • a
  • +
  • b
  • +
  • c
  • +
  • d
  • +
  • e
  • +
  • f
  • +
  • g
  • +
+```````````````````````````````` + + +```````````````````````````````` example +1. a + + 2. b + + 3. c +. +
    +
  1. +

    a

    +
  2. +
  3. +

    b

    +
  4. +
  5. +

    c

    +
  6. +
+```````````````````````````````` + +Note, however, that list items may not be preceded by more than +three spaces of indentation. Here `- e` is treated as a paragraph continuation +line, because it is indented more than three spaces: + +```````````````````````````````` example +- a + - b + - c + - d + - e +. +
    +
  • a
  • +
  • b
  • +
  • c
  • +
  • d +- e
  • +
+```````````````````````````````` + +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 +. +
    +
  1. +

    a

    +
  2. +
  3. +

    b

    +
  4. +
+
3. c
+
+```````````````````````````````` + + +This is a loose list, because there is a blank line between +two of the list items: + +```````````````````````````````` example +- a +- b + +- c +. +
    +
  • +

    a

    +
  • +
  • +

    b

    +
  • +
  • +

    c

    +
  • +
+```````````````````````````````` + + +So is this, with a empty second item: + +```````````````````````````````` example +* a +* + +* c +. +
    +
  • +

    a

    +
  • +
  • +
  • +

    c

    +
  • +
+```````````````````````````````` + + +These are loose lists, even though there are no blank lines 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 +. +
    +
  • +

    a

    +
  • +
  • +

    b

    +

    c

    +
  • +
  • +

    d

    +
  • +
+```````````````````````````````` + + +```````````````````````````````` example +- a +- b + + [ref]: /url +- d +. +
    +
  • +

    a

    +
  • +
  • +

    b

    +
  • +
  • +

    d

    +
  • +
+```````````````````````````````` + + +This is a tight list, because the blank lines are in a code block: + +```````````````````````````````` example +- a +- ``` + b + + + ``` +- c +. +
    +
  • a
  • +
  • +
    b
    +
    +
    +
    +
  • +
  • c
  • +
+```````````````````````````````` + + +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 +. +
    +
  • a +
      +
    • +

      b

      +

      c

      +
    • +
    +
  • +
  • d
  • +
+```````````````````````````````` + + +This is a tight list, because the blank line is inside the +block quote: + +```````````````````````````````` example +* a + > b + > +* c +. +
    +
  • a +
    +

    b

    +
    +
  • +
  • c
  • +
+```````````````````````````````` + + +This list is tight, because the consecutive block elements +are not separated by blank lines: + +```````````````````````````````` example +- a + > b + ``` + c + ``` +- d +. +
    +
  • a +
    +

    b

    +
    +
    c
    +
    +
  • +
  • d
  • +
+```````````````````````````````` + + +A single-paragraph list is tight: + +```````````````````````````````` example +- a +. +
    +
  • a
  • +
+```````````````````````````````` + + +```````````````````````````````` example +- a + - b +. +
    +
  • a +
      +
    • b
    • +
    +
  • +
+```````````````````````````````` + + +This list is loose, because of the blank line between the +two block elements in the list item: + +```````````````````````````````` example +1. ``` + foo + ``` + + bar +. +
    +
  1. +
    foo
    +
    +

    bar

    +
  2. +
+```````````````````````````````` + + +Here the outer list is loose, the inner list tight: + +```````````````````````````````` example +* foo + * bar + + baz +. +
    +
  • +

    foo

    +
      +
    • bar
    • +
    +

    baz

    +
  • +
+```````````````````````````````` + + +```````````````````````````````` example +- a + - b + - c + +- d + - e + - f +. +
    +
  • +

    a

    +
      +
    • b
    • +
    • c
    • +
    +
  • +
  • +

    d

    +
      +
    • e
    • +
    • f
    • +
    +
  • +
+```````````````````````````````` + + +# 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` +. +

hilo`

+```````````````````````````````` + +`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` +. +

foo

+```````````````````````````````` + + +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 `` +. +

foo ` bar

+```````````````````````````````` + + +This example shows the motivation for stripping leading and trailing +spaces: + +```````````````````````````````` example +` `` ` +. +

``

+```````````````````````````````` + +Note that only *one* space is stripped: + +```````````````````````````````` example +` `` ` +. +

``

+```````````````````````````````` + +The stripping only happens if the space is on both +sides of the string: + +```````````````````````````````` example +` a` +. +

a

+```````````````````````````````` + +Only [spaces], and not [unicode whitespace] in general, are +stripped in this way: + +```````````````````````````````` example +` b ` +. +

b

+```````````````````````````````` + +No stripping occurs if the code span contains only spaces: + +```````````````````````````````` example +` ` +` ` +. +

+

+```````````````````````````````` + + +[Line endings] are treated like spaces: + +```````````````````````````````` example +`` +foo +bar +baz +`` +. +

foo bar baz

+```````````````````````````````` + +```````````````````````````````` example +`` +foo +`` +. +

foo

+```````````````````````````````` + + +Interior spaces are not collapsed: + +```````````````````````````````` example +`foo bar +baz` +. +

foo bar baz

+```````````````````````````````` + +Note that browsers will typically collapse consecutive spaces +when rendering `` 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` +. +

foo\bar`

+```````````````````````````````` + + +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`` +. +

foo`bar

+```````````````````````````````` + +```````````````````````````````` example +` foo `` bar ` +. +

foo `` bar

+```````````````````````````````` + + +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`*` +. +

*foo*

+```````````````````````````````` + + +And this is not parsed as a link: + +```````````````````````````````` example +[not a `link](/foo`) +. +

[not a link](/foo)

+```````````````````````````````` + + +Code spans, HTML tags, and autolinks have the same precedence. +Thus, this is code: + +```````````````````````````````` example +`` +. +

<a href="">`

+```````````````````````````````` + + +But this is an HTML tag: + +```````````````````````````````` example +
` +. +

`

+```````````````````````````````` + + +And this is code: + +```````````````````````````````` example +`` +. +

<http://foo.bar.baz>`

+```````````````````````````````` + + +But this is an autolink: + +```````````````````````````````` example +` +. +

http://foo.bar.`baz`

+```````````````````````````````` + + +When a backtick string is not closed by a matching backtick string, +we just have literal backticks: + +```````````````````````````````` example +```foo`` +. +

```foo``

+```````````````````````````````` + + +```````````````````````````````` example +`foo +. +

`foo

+```````````````````````````````` + +The following case also illustrates the need for opening and +closing backtick strings to be equal in length: + +```````````````````````````````` example +`foo``bar`` +. +

`foobar

+```````````````````````````````` + + +## 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 +> `` tag; double `*`'s or `_`'s will be wrapped with an HTML `` +> 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 [Unicode punctuation character], or +(2b) followed by a [Unicode punctuation character] and +preceded by [Unicode whitespace] or a [Unicode 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 [Unicode punctuation character], or +(2b) preceded by a [Unicode punctuation character] and +followed by [Unicode whitespace] or a [Unicode 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 a [Unicode punctuation character]. + +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 a [Unicode punctuation character]. + +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 a [Unicode punctuation character]. + +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 a [Unicode punctuation character]. + +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 `...` is always preferred to + `...`. + +14. An interpretation `...` is always + preferred to `...`. + +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 `foo _bar baz_` rather + than `*foo bar* baz`. + +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 bar baz` + rather than `foo **bar baz`. + +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 `*foo*` rather than as + `[foo](bar)`. + +These rules can be illustrated through a series of examples. + +Rule 1: + +```````````````````````````````` example +*foo bar* +. +

foo bar

+```````````````````````````````` + + +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* +. +

a * foo bar*

+```````````````````````````````` + + +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"* +. +

a*"foo"*

+```````````````````````````````` + + +Unicode nonbreaking spaces count as whitespace, too: + +```````````````````````````````` example +* a * +. +

* a *

+```````````````````````````````` + + +Intraword emphasis with `*` is permitted: + +```````````````````````````````` example +foo*bar* +. +

foobar

+```````````````````````````````` + + +```````````````````````````````` example +5*6*78 +. +

5678

+```````````````````````````````` + + +Rule 2: + +```````````````````````````````` example +_foo bar_ +. +

foo bar

+```````````````````````````````` + + +This is not emphasis, because the opening `_` is followed by +whitespace: + +```````````````````````````````` example +_ foo bar_ +. +

_ foo bar_

+```````````````````````````````` + + +This is not emphasis, because the opening `_` is preceded +by an alphanumeric and followed by punctuation: + +```````````````````````````````` example +a_"foo"_ +. +

a_"foo"_

+```````````````````````````````` + + +Emphasis with `_` is not allowed inside words: + +```````````````````````````````` example +foo_bar_ +. +

foo_bar_

+```````````````````````````````` + + +```````````````````````````````` example +5_6_78 +. +

5_6_78

+```````````````````````````````` + + +```````````````````````````````` example +пристаням_стремятся_ +. +

пристаням_стремятся_

+```````````````````````````````` + + +Here `_` does not generate emphasis, because the first delimiter run +is right-flanking and the second left-flanking: + +```````````````````````````````` example +aa_"bb"_cc +. +

aa_"bb"_cc

+```````````````````````````````` + + +This is emphasis, even though the opening delimiter is +both left- and right-flanking, because it is preceded by +punctuation: + +```````````````````````````````` example +foo-_(bar)_ +. +

foo-(bar)

+```````````````````````````````` + + +Rule 3: + +This is not emphasis, because the closing delimiter does +not match the opening delimiter: + +```````````````````````````````` example +_foo* +. +

_foo*

+```````````````````````````````` + + +This is not emphasis, because the closing `*` is preceded by +whitespace: + +```````````````````````````````` example +*foo bar * +. +

*foo bar *

+```````````````````````````````` + + +A line ending also counts as whitespace: + +```````````````````````````````` example +*foo bar +* +. +

*foo bar +*

+```````````````````````````````` + + +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) +. +

*(*foo)

+```````````````````````````````` + + +The point of this restriction is more easily appreciated +with this example: + +```````````````````````````````` example +*(*foo*)* +. +

(foo)

+```````````````````````````````` + + +Intraword emphasis with `*` is allowed: + +```````````````````````````````` example +*foo*bar +. +

foobar

+```````````````````````````````` + + + +Rule 4: + +This is not emphasis, because the closing `_` is preceded by +whitespace: + +```````````````````````````````` example +_foo bar _ +. +

_foo bar _

+```````````````````````````````` + + +This is not emphasis, because the second `_` is +preceded by punctuation and followed by an alphanumeric: + +```````````````````````````````` example +_(_foo) +. +

_(_foo)

+```````````````````````````````` + + +This is emphasis within emphasis: + +```````````````````````````````` example +_(_foo_)_ +. +

(foo)

+```````````````````````````````` + + +Intraword emphasis is disallowed for `_`: + +```````````````````````````````` example +_foo_bar +. +

_foo_bar

+```````````````````````````````` + + +```````````````````````````````` example +_пристаням_стремятся +. +

_пристаням_стремятся

+```````````````````````````````` + + +```````````````````````````````` example +_foo_bar_baz_ +. +

foo_bar_baz

+```````````````````````````````` + + +This is emphasis, even though the closing delimiter is +both left- and right-flanking, because it is followed by +punctuation: + +```````````````````````````````` example +_(bar)_. +. +

(bar).

+```````````````````````````````` + + +Rule 5: + +```````````````````````````````` example +**foo bar** +. +

foo bar

+```````````````````````````````` + + +This is not strong emphasis, because the opening delimiter is +followed by whitespace: + +```````````````````````````````` example +** foo bar** +. +

** foo bar**

+```````````````````````````````` + + +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"** +. +

a**"foo"**

+```````````````````````````````` + + +Intraword strong emphasis with `**` is permitted: + +```````````````````````````````` example +foo**bar** +. +

foobar

+```````````````````````````````` + + +Rule 6: + +```````````````````````````````` example +__foo bar__ +. +

foo bar

+```````````````````````````````` + + +This is not strong emphasis, because the opening delimiter is +followed by whitespace: + +```````````````````````````````` example +__ foo bar__ +. +

__ foo bar__

+```````````````````````````````` + + +A line ending counts as whitespace: +```````````````````````````````` example +__ +foo bar__ +. +

__ +foo bar__

+```````````````````````````````` + + +This is not strong emphasis, because the opening `__` is preceded +by an alphanumeric and followed by punctuation: + +```````````````````````````````` example +a__"foo"__ +. +

a__"foo"__

+```````````````````````````````` + + +Intraword strong emphasis is forbidden with `__`: + +```````````````````````````````` example +foo__bar__ +. +

foo__bar__

+```````````````````````````````` + + +```````````````````````````````` example +5__6__78 +. +

5__6__78

+```````````````````````````````` + + +```````````````````````````````` example +пристаням__стремятся__ +. +

пристаням__стремятся__

+```````````````````````````````` + + +```````````````````````````````` example +__foo, __bar__, baz__ +. +

foo, bar, baz

+```````````````````````````````` + + +This is strong emphasis, even though the opening delimiter is +both left- and right-flanking, because it is preceded by +punctuation: + +```````````````````````````````` example +foo-__(bar)__ +. +

foo-(bar)

+```````````````````````````````` + + + +Rule 7: + +This is not strong emphasis, because the closing delimiter is preceded +by whitespace: + +```````````````````````````````` example +**foo bar ** +. +

**foo bar **

+```````````````````````````````` + + +(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) +. +

**(**foo)

+```````````````````````````````` + + +The point of this restriction is more easily appreciated +with these examples: + +```````````````````````````````` example +*(**foo**)* +. +

(foo)

+```````````````````````````````` + + +```````````````````````````````` example +**Gomphocarpus (*Gomphocarpus physocarpus*, syn. +*Asclepias physocarpa*)** +. +

Gomphocarpus (Gomphocarpus physocarpus, syn. +Asclepias physocarpa)

+```````````````````````````````` + + +```````````````````````````````` example +**foo "*bar*" foo** +. +

foo "bar" foo

+```````````````````````````````` + + +Intraword emphasis: + +```````````````````````````````` example +**foo**bar +. +

foobar

+```````````````````````````````` + + +Rule 8: + +This is not strong emphasis, because the closing delimiter is +preceded by whitespace: + +```````````````````````````````` example +__foo bar __ +. +

__foo bar __

+```````````````````````````````` + + +This is not strong emphasis, because the second `__` is +preceded by punctuation and followed by an alphanumeric: + +```````````````````````````````` example +__(__foo) +. +

__(__foo)

+```````````````````````````````` + + +The point of this restriction is more easily appreciated +with this example: + +```````````````````````````````` example +_(__foo__)_ +. +

(foo)

+```````````````````````````````` + + +Intraword strong emphasis is forbidden with `__`: + +```````````````````````````````` example +__foo__bar +. +

__foo__bar

+```````````````````````````````` + + +```````````````````````````````` example +__пристаням__стремятся +. +

__пристаням__стремятся

+```````````````````````````````` + + +```````````````````````````````` example +__foo__bar__baz__ +. +

foo__bar__baz

+```````````````````````````````` + + +This is strong emphasis, even though the closing delimiter is +both left- and right-flanking, because it is followed by +punctuation: + +```````````````````````````````` example +__(bar)__. +. +

(bar).

+```````````````````````````````` + + +Rule 9: + +Any nonempty sequence of inline elements can be the contents of an +emphasized span. + +```````````````````````````````` example +*foo [bar](/url)* +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +*foo +bar* +. +

foo +bar

+```````````````````````````````` + + +In particular, emphasis and strong emphasis can be nested +inside emphasis: + +```````````````````````````````` example +_foo __bar__ baz_ +. +

foo bar baz

+```````````````````````````````` + + +```````````````````````````````` example +_foo _bar_ baz_ +. +

foo bar baz

+```````````````````````````````` + + +```````````````````````````````` example +__foo_ bar_ +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +*foo *bar** +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +*foo **bar** baz* +. +

foo bar baz

+```````````````````````````````` + +```````````````````````````````` example +*foo**bar**baz* +. +

foobarbaz

+```````````````````````````````` + +Note that in the preceding case, the interpretation + +``` markdown +

foobarbaz

+``` + + +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* +. +

foo**bar

+```````````````````````````````` + + +The same condition ensures that the following +cases are all strong emphasis nested inside +emphasis, even when the interior whitespace is +omitted: + + +```````````````````````````````` example +***foo** bar* +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +*foo **bar*** +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +*foo**bar*** +. +

foobar

+```````````````````````````````` + + +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 +. +

foobarbaz

+```````````````````````````````` + +```````````````````````````````` example +foo******bar*********baz +. +

foobar***baz

+```````````````````````````````` + + +Indefinite levels of nesting are possible: + +```````````````````````````````` example +*foo **bar *baz* bim** bop* +. +

foo bar baz bim bop

+```````````````````````````````` + + +```````````````````````````````` example +*foo [*bar*](/url)* +. +

foo bar

+```````````````````````````````` + + +There can be no empty emphasis or strong emphasis: + +```````````````````````````````` example +** is not an empty emphasis +. +

** is not an empty emphasis

+```````````````````````````````` + + +```````````````````````````````` example +**** is not an empty strong emphasis +. +

**** is not an empty strong emphasis

+```````````````````````````````` + + + +Rule 10: + +Any nonempty sequence of inline elements can be the contents of an +strongly emphasized span. + +```````````````````````````````` example +**foo [bar](/url)** +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +**foo +bar** +. +

foo +bar

+```````````````````````````````` + + +In particular, emphasis and strong emphasis can be nested +inside strong emphasis: + +```````````````````````````````` example +__foo _bar_ baz__ +. +

foo bar baz

+```````````````````````````````` + + +```````````````````````````````` example +__foo __bar__ baz__ +. +

foo bar baz

+```````````````````````````````` + + +```````````````````````````````` example +____foo__ bar__ +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +**foo **bar**** +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +**foo *bar* baz** +. +

foo bar baz

+```````````````````````````````` + + +```````````````````````````````` example +**foo*bar*baz** +. +

foobarbaz

+```````````````````````````````` + + +```````````````````````````````` example +***foo* bar** +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +**foo *bar*** +. +

foo bar

+```````````````````````````````` + + +Indefinite levels of nesting are possible: + +```````````````````````````````` example +**foo *bar **baz** +bim* bop** +. +

foo bar baz +bim bop

+```````````````````````````````` + + +```````````````````````````````` example +**foo [*bar*](/url)** +. +

foo bar

+```````````````````````````````` + + +There can be no empty emphasis or strong emphasis: + +```````````````````````````````` example +__ is not an empty emphasis +. +

__ is not an empty emphasis

+```````````````````````````````` + + +```````````````````````````````` example +____ is not an empty strong emphasis +. +

____ is not an empty strong emphasis

+```````````````````````````````` + + + +Rule 11: + +```````````````````````````````` example +foo *** +. +

foo ***

+```````````````````````````````` + + +```````````````````````````````` example +foo *\** +. +

foo *

+```````````````````````````````` + + +```````````````````````````````` example +foo *_* +. +

foo _

+```````````````````````````````` + + +```````````````````````````````` example +foo ***** +. +

foo *****

+```````````````````````````````` + + +```````````````````````````````` example +foo **\*** +. +

foo *

+```````````````````````````````` + + +```````````````````````````````` example +foo **_** +. +

foo _

+```````````````````````````````` + + +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* +. +

*foo

+```````````````````````````````` + + +```````````````````````````````` example +*foo** +. +

foo*

+```````````````````````````````` + + +```````````````````````````````` example +***foo** +. +

*foo

+```````````````````````````````` + + +```````````````````````````````` example +****foo* +. +

***foo

+```````````````````````````````` + + +```````````````````````````````` example +**foo*** +. +

foo*

+```````````````````````````````` + + +```````````````````````````````` example +*foo**** +. +

foo***

+```````````````````````````````` + + + +Rule 12: + +```````````````````````````````` example +foo ___ +. +

foo ___

+```````````````````````````````` + + +```````````````````````````````` example +foo _\__ +. +

foo _

+```````````````````````````````` + + +```````````````````````````````` example +foo _*_ +. +

foo *

+```````````````````````````````` + + +```````````````````````````````` example +foo _____ +. +

foo _____

+```````````````````````````````` + + +```````````````````````````````` example +foo __\___ +. +

foo _

+```````````````````````````````` + + +```````````````````````````````` example +foo __*__ +. +

foo *

+```````````````````````````````` + + +```````````````````````````````` example +__foo_ +. +

_foo

+```````````````````````````````` + + +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__ +. +

foo_

+```````````````````````````````` + + +```````````````````````````````` example +___foo__ +. +

_foo

+```````````````````````````````` + + +```````````````````````````````` example +____foo_ +. +

___foo

+```````````````````````````````` + + +```````````````````````````````` example +__foo___ +. +

foo_

+```````````````````````````````` + + +```````````````````````````````` example +_foo____ +. +

foo___

+```````````````````````````````` + + +Rule 13 implies that if you want emphasis nested directly inside +emphasis, you must use different delimiters: + +```````````````````````````````` example +**foo** +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +*_foo_* +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +__foo__ +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +_*foo*_ +. +

foo

+```````````````````````````````` + + +However, strong emphasis within strong emphasis is possible without +switching delimiters: + +```````````````````````````````` example +****foo**** +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +____foo____ +. +

foo

+```````````````````````````````` + + + +Rule 13 can be applied to arbitrarily long sequences of +delimiters: + +```````````````````````````````` example +******foo****** +. +

foo

+```````````````````````````````` + + +Rule 14: + +```````````````````````````````` example +***foo*** +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +_____foo_____ +. +

foo

+```````````````````````````````` + + +Rule 15: + +```````````````````````````````` example +*foo _bar* baz_ +. +

foo _bar baz_

+```````````````````````````````` + + +```````````````````````````````` example +*foo __bar *baz bim__ bam* +. +

foo bar *baz bim bam

+```````````````````````````````` + + +Rule 16: + +```````````````````````````````` example +**foo **bar baz** +. +

**foo bar baz

+```````````````````````````````` + + +```````````````````````````````` example +*foo *bar baz* +. +

*foo bar baz

+```````````````````````````````` + + +Rule 17: + +```````````````````````````````` example +*[bar*](/url) +. +

*bar*

+```````````````````````````````` + + +```````````````````````````````` example +_foo [bar_](/url) +. +

_foo bar_

+```````````````````````````````` + + +```````````````````````````````` example +* +. +

*

+```````````````````````````````` + + +```````````````````````````````` example +** +. +

**

+```````````````````````````````` + + +```````````````````````````````` example +__ +. +

__

+```````````````````````````````` + + +```````````````````````````````` example +*a `*`* +. +

a *

+```````````````````````````````` + + +```````````````````````````````` example +_a `_`_ +. +

a _

+```````````````````````````````` + + +```````````````````````````````` example +**a +. +

**ahttp://foo.bar/?q=**

+```````````````````````````````` + + +```````````````````````````````` example +__a +. +

__ahttp://foo.bar/?q=__

+```````````````````````````````` + + + +## 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 endings 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 [space] character, 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 `(`, an optional [link destination], an optional +[link title], and a right parenthesis `)`. +These four components may be separated by spaces, tabs, and up to one line +ending. +If both [link destination] and [link title] are present, they *must* be +separated by spaces, tabs, and up to one line ending. + +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") +. +

link

+```````````````````````````````` + + +The title, the link text and even +the destination may be omitted: + +```````````````````````````````` example +[link](/uri) +. +

link

+```````````````````````````````` + +```````````````````````````````` example +[](./target.md) +. +

+```````````````````````````````` + + +```````````````````````````````` example +[link]() +. +

link

+```````````````````````````````` + + +```````````````````````````````` example +[link](<>) +. +

link

+```````````````````````````````` + + +```````````````````````````````` example +[]() +. +

+```````````````````````````````` + +The destination can only contain spaces if it is +enclosed in pointy brackets: + +```````````````````````````````` example +[link](/my uri) +. +

[link](/my uri)

+```````````````````````````````` + +```````````````````````````````` example +[link](
) +. +

link

+```````````````````````````````` + +The destination cannot contain line endings, +even if enclosed in pointy brackets: + +```````````````````````````````` example +[link](foo +bar) +. +

[link](foo +bar)

+```````````````````````````````` + +```````````````````````````````` example +[link]() +. +

[link]()

+```````````````````````````````` + +The destination can contain `)` if it is enclosed +in pointy brackets: + +```````````````````````````````` example +[a]() +. +

a

+```````````````````````````````` + +Pointy brackets that enclose links must be unescaped: + +```````````````````````````````` example +[link]() +. +

[link](<foo>)

+```````````````````````````````` + +These are not links, because the opening pointy bracket +is not matched properly: + +```````````````````````````````` example +[a]( +[a](c) +. +

[a](<b)c +[a](<b)c> +[a](c)

+```````````````````````````````` + +Parentheses inside the link destination may be escaped: + +```````````````````````````````` example +[link](\(foo\)) +. +

link

+```````````````````````````````` + +Any number of parentheses are allowed without escaping, as long as they are +balanced: + +```````````````````````````````` example +[link](foo(and(bar))) +. +

link

+```````````````````````````````` + +However, if you have unbalanced parentheses, you need to escape or use the +`<...>` form: + +```````````````````````````````` example +[link](foo(and(bar)) +. +

[link](foo(and(bar))

+```````````````````````````````` + + +```````````````````````````````` example +[link](foo\(and\(bar\)) +. +

link

+```````````````````````````````` + + +```````````````````````````````` example +[link]() +. +

link

+```````````````````````````````` + + +Parentheses and other symbols can also be escaped, as usual +in Markdown: + +```````````````````````````````` example +[link](foo\)\:) +. +

link

+```````````````````````````````` + + +A link can contain fragment identifiers and queries: + +```````````````````````````````` example +[link](#fragment) + +[link](http://example.com#fragment) + +[link](http://example.com?foo=3#frag) +. +

link

+

link

+

link

+```````````````````````````````` + + +Note that a backslash before a non-escapable character is +just a backslash: + +```````````````````````````````` example +[link](foo\bar) +. +

link

+```````````````````````````````` + + +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ä) +. +

link

+```````````````````````````````` + + +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") +. +

link

+```````````````````````````````` + + +Titles may be in single quotes, double quotes, or parentheses: + +```````````````````````````````` example +[link](/url "title") +[link](/url 'title') +[link](/url (title)) +. +

link +link +link

+```````````````````````````````` + + +Backslash escapes and entity and numeric character references +may be used in titles: + +```````````````````````````````` example +[link](/url "title \""") +. +

link

+```````````````````````````````` + + +Titles must be separated from the link using spaces, tabs, and up to one line +ending. +Other [Unicode whitespace] like non-breaking space doesn't work. + +```````````````````````````````` example +[link](/url "title") +. +

link

+```````````````````````````````` + + +Nested balanced quotes are not allowed without escaping: + +```````````````````````````````` example +[link](/url "title "and" title") +. +

[link](/url "title "and" title")

+```````````````````````````````` + + +But it is easy to work around this by using a different quote type: + +```````````````````````````````` example +[link](/url 'title "and" title') +. +

link

+```````````````````````````````` + + +(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.) + +Spaces, tabs, and up to one line ending is allowed around the destination and +title: + +```````````````````````````````` example +[link]( /uri + "title" ) +. +

link

+```````````````````````````````` + + +But it is not allowed between the link text and the +following parenthesis: + +```````````````````````````````` example +[link] (/uri) +. +

[link] (/uri)

+```````````````````````````````` + + +The link text may contain balanced brackets, but not unbalanced ones, +unless they are escaped: + +```````````````````````````````` example +[link [foo [bar]]](/uri) +. +

link [foo [bar]]

+```````````````````````````````` + + +```````````````````````````````` example +[link] bar](/uri) +. +

[link] bar](/uri)

+```````````````````````````````` + + +```````````````````````````````` example +[link [bar](/uri) +. +

[link bar

+```````````````````````````````` + + +```````````````````````````````` example +[link \[bar](/uri) +. +

link [bar

+```````````````````````````````` + + +The link text may contain inline content: + +```````````````````````````````` example +[link *foo **bar** `#`*](/uri) +. +

link foo bar #

+```````````````````````````````` + + +```````````````````````````````` example +[![moon](moon.jpg)](/uri) +. +

moon

+```````````````````````````````` + + +However, links may not contain other links, at any level of nesting. + +```````````````````````````````` example +[foo [bar](/uri)](/uri) +. +

[foo bar](/uri)

+```````````````````````````````` + + +```````````````````````````````` example +[foo *[bar [baz](/uri)](/uri)*](/uri) +. +

[foo [bar baz](/uri)](/uri)

+```````````````````````````````` + + +```````````````````````````````` example +![[[foo](uri1)](uri2)](uri3) +. +

[foo](uri2)

+```````````````````````````````` + + +These cases illustrate the precedence of link text grouping over +emphasis grouping: + +```````````````````````````````` example +*[foo*](/uri) +. +

*foo*

+```````````````````````````````` + + +```````````````````````````````` example +[foo *bar](baz*) +. +

foo *bar

+```````````````````````````````` + + +Note that brackets that *aren't* part of links do not take +precedence: + +```````````````````````````````` example +*foo [bar* baz] +. +

foo [bar baz]

+```````````````````````````````` + + +These cases illustrate the precedence of HTML tags, code spans, +and autolinks over link grouping: + +```````````````````````````````` example +[foo +. +

[foo

+```````````````````````````````` + + +```````````````````````````````` example +[foo`](/uri)` +. +

[foo](/uri)

+```````````````````````````````` + + +```````````````````````````````` example +[foo +. +

[foohttp://example.com/?search=](uri)

+```````````````````````````````` + + +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 character that is not a space, +tab, or line ending. +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 +spaces, tabs, and line endings, and collapse consecutive internal +spaces, tabs, and line endings 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" +. +

foo

+```````````````````````````````` + + +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 +. +

link [foo [bar]]

+```````````````````````````````` + + +```````````````````````````````` example +[link \[bar][ref] + +[ref]: /uri +. +

link [bar

+```````````````````````````````` + + +The link text may contain inline content: + +```````````````````````````````` example +[link *foo **bar** `#`*][ref] + +[ref]: /uri +. +

link foo bar #

+```````````````````````````````` + + +```````````````````````````````` example +[![moon](moon.jpg)][ref] + +[ref]: /uri +. +

moon

+```````````````````````````````` + + +However, links may not contain other links, at any level of nesting. + +```````````````````````````````` example +[foo [bar](/uri)][ref] + +[ref]: /uri +. +

[foo bar]ref

+```````````````````````````````` + + +```````````````````````````````` example +[foo *bar [baz][ref]*][ref] + +[ref]: /uri +. +

[foo bar baz]ref

+```````````````````````````````` + + +(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 +. +

*foo*

+```````````````````````````````` + + +```````````````````````````````` example +[foo *bar][ref]* + +[ref]: /uri +. +

foo *bar*

+```````````````````````````````` + + +These cases illustrate the precedence of HTML tags, code spans, +and autolinks over link grouping: + +```````````````````````````````` example +[foo + +[ref]: /uri +. +

[foo

+```````````````````````````````` + + +```````````````````````````````` example +[foo`][ref]` + +[ref]: /uri +. +

[foo][ref]

+```````````````````````````````` + + +```````````````````````````````` example +[foo + +[ref]: /uri +. +

[foohttp://example.com/?search=][ref]

+```````````````````````````````` + + +Matching is case-insensitive: + +```````````````````````````````` example +[foo][BaR] + +[bar]: /url "title" +. +

foo

+```````````````````````````````` + + +Unicode case fold is used: + +```````````````````````````````` example +[ẞ] + +[SS]: /url +. +

+```````````````````````````````` + + +Consecutive internal spaces, tabs, and line endings are treated as one space for +purposes of determining matching: + +```````````````````````````````` example +[Foo + bar]: /url + +[Baz][Foo bar] +. +

Baz

+```````````````````````````````` + + +No spaces, tabs, or line endings are allowed between the [link text] and the +[link label]: + +```````````````````````````````` example +[foo] [bar] + +[bar]: /url "title" +. +

[foo] bar

+```````````````````````````````` + + +```````````````````````````````` example +[foo] +[bar] + +[bar]: /url "title" +. +

[foo] +bar

+```````````````````````````````` + + +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] +. +

bar

+```````````````````````````````` + + +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 +. +

[bar][foo!]

+```````````````````````````````` + + +[Link labels] cannot contain brackets, unless they are +backslash-escaped: + +```````````````````````````````` example +[foo][ref[] + +[ref[]: /uri +. +

[foo][ref[]

+

[ref[]: /uri

+```````````````````````````````` + + +```````````````````````````````` example +[foo][ref[bar]] + +[ref[bar]]: /uri +. +

[foo][ref[bar]]

+

[ref[bar]]: /uri

+```````````````````````````````` + + +```````````````````````````````` example +[[[foo]]] + +[[[foo]]]: /url +. +

[[[foo]]]

+

[[[foo]]]: /url

+```````````````````````````````` + + +```````````````````````````````` example +[foo][ref\[] + +[ref\[]: /uri +. +

foo

+```````````````````````````````` + + +Note that in this example `]` is not backslash-escaped: + +```````````````````````````````` example +[bar\\]: /uri + +[bar\\] +. +

bar\

+```````````````````````````````` + + +A [link label] must contain at least one character that is not a space, tab, or +line ending: + +```````````````````````````````` example +[] + +[]: /uri +. +

[]

+

[]: /uri

+```````````````````````````````` + + +```````````````````````````````` example +[ + ] + +[ + ]: /uri +. +

[ +]

+

[ +]: /uri

+```````````````````````````````` + + +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" +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +[*foo* bar][] + +[*foo* bar]: /url "title" +. +

foo bar

+```````````````````````````````` + + +The link labels are case-insensitive: + +```````````````````````````````` example +[Foo][] + +[foo]: /url "title" +. +

Foo

+```````````````````````````````` + + + +As with full reference links, spaces, tabs, or line endings are not +allowed between the two sets of brackets: + +```````````````````````````````` example +[foo] +[] + +[foo]: /url "title" +. +

foo +[]

+```````````````````````````````` + + +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" +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +[*foo* bar] + +[*foo* bar]: /url "title" +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +[[*foo* bar]] + +[*foo* bar]: /url "title" +. +

[foo bar]

+```````````````````````````````` + + +```````````````````````````````` example +[[bar [foo] + +[foo]: /url +. +

[[bar foo

+```````````````````````````````` + + +The link labels are case-insensitive: + +```````````````````````````````` example +[Foo] + +[foo]: /url "title" +. +

Foo

+```````````````````````````````` + + +A space after the link text should be preserved: + +```````````````````````````````` example +[foo] bar + +[foo]: /url +. +

foo bar

+```````````````````````````````` + + +If you just want bracketed text, you can backslash-escape the +opening bracket to avoid links: + +```````````````````````````````` example +\[foo] + +[foo]: /url "title" +. +

[foo]

+```````````````````````````````` + + +Note that this is a link, because a link label ends with the first +following closing bracket: + +```````````````````````````````` example +[foo*]: /url + +*[foo*] +. +

*foo*

+```````````````````````````````` + + +Full and compact references take precedence over shortcut +references: + +```````````````````````````````` example +[foo][bar] + +[foo]: /url1 +[bar]: /url2 +. +

foo

+```````````````````````````````` + +```````````````````````````````` example +[foo][] + +[foo]: /url1 +. +

foo

+```````````````````````````````` + +Inline links also take precedence: + +```````````````````````````````` example +[foo]() + +[foo]: /url1 +. +

foo

+```````````````````````````````` + +```````````````````````````````` example +[foo](not a link) + +[foo]: /url1 +. +

foo(not a link)

+```````````````````````````````` + +In the following case `[bar][baz]` is parsed as a reference, +`[foo]` as normal text: + +```````````````````````````````` example +[foo][bar][baz] + +[baz]: /url +. +

[foo]bar

+```````````````````````````````` + + +Here, though, `[foo][bar]` is parsed as a reference, since +`[bar]` is defined: + +```````````````````````````````` example +[foo][bar][baz] + +[baz]: /url1 +[bar]: /url2 +. +

foobaz

+```````````````````````````````` + + +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 +. +

[foo]bar

+```````````````````````````````` + + + +## 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") +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +![foo *bar*] + +[foo *bar*]: train.jpg "train & tracks" +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +![foo ![bar](/url)](/url2) +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +![foo [bar](/url)](/url2) +. +

foo bar

+```````````````````````````````` + + +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 bar`. Only the plain string +content is rendered, without formatting. + +```````````````````````````````` example +![foo *bar*][] + +[foo *bar*]: train.jpg "train & tracks" +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +![foo *bar*][foobar] + +[FOOBAR]: train.jpg "train & tracks" +. +

foo bar

+```````````````````````````````` + + +```````````````````````````````` example +![foo](train.jpg) +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +My ![foo bar](/path/to/train.jpg "title" ) +. +

My foo bar

+```````````````````````````````` + + +```````````````````````````````` example +![foo]() +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +![](/url) +. +

+```````````````````````````````` + + +Reference-style: + +```````````````````````````````` example +![foo][bar] + +[bar]: /url +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +![foo][bar] + +[BAR]: /url +. +

foo

+```````````````````````````````` + + +Collapsed: + +```````````````````````````````` example +![foo][] + +[foo]: /url "title" +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +![*foo* bar][] + +[*foo* bar]: /url "title" +. +

foo bar

+```````````````````````````````` + + +The labels are case-insensitive: + +```````````````````````````````` example +![Foo][] + +[foo]: /url "title" +. +

Foo

+```````````````````````````````` + + +As with reference links, spaces, tabs, and line endings, are not allowed +between the two sets of brackets: + +```````````````````````````````` example +![foo] +[] + +[foo]: /url "title" +. +

foo +[]

+```````````````````````````````` + + +Shortcut: + +```````````````````````````````` example +![foo] + +[foo]: /url "title" +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +![*foo* bar] + +[*foo* bar]: /url "title" +. +

foo bar

+```````````````````````````````` + + +Note that link labels cannot contain unescaped brackets: + +```````````````````````````````` example +![[foo]] + +[[foo]]: /url "title" +. +

![[foo]]

+

[[foo]]: /url "title"

+```````````````````````````````` + + +The link labels are case-insensitive: + +```````````````````````````````` example +![Foo] + +[foo]: /url "title" +. +

Foo

+```````````````````````````````` + + +If you just want a literal `!` followed by bracketed text, you can +backslash-escape the opening `[`: + +```````````````````````````````` example +!\[foo] + +[foo]: /url "title" +. +

![foo]

+```````````````````````````````` + + +If you want a link after a literal `!`, backslash-escape the +`!`: + +```````````````````````````````` example +\![foo] + +[foo]: /url "title" +. +

!foo

+```````````````````````````````` + + +## 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], [space], `<`, 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

+```````````````````````````````` + + +```````````````````````````````` example + +. +

http://foo.bar.baz/test?q=hello&id=22&boolean

+```````````````````````````````` + + +```````````````````````````````` example + +. +

irc://foo.bar:2233/baz

+```````````````````````````````` + + +Uppercase is also fine: + +```````````````````````````````` example + +. +

MAILTO:FOO@BAR.BAZ

+```````````````````````````````` + + +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

+```````````````````````````````` + + +```````````````````````````````` example + +. +

made-up-scheme://foo,bar

+```````````````````````````````` + + +```````````````````````````````` example + +. +

http://../

+```````````````````````````````` + + +```````````````````````````````` example + +. +

localhost:5001/foo

+```````````````````````````````` + + +Spaces are not allowed in autolinks: + +```````````````````````````````` example + +. +

<http://foo.bar/baz bim>

+```````````````````````````````` + + +Backslash-escapes do not work inside autolinks: + +```````````````````````````````` example + +. +

http://example.com/\[\

+```````````````````````````````` + + +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

+```````````````````````````````` + + +```````````````````````````````` example + +. +

foo+special@Bar.baz-bar0.com

+```````````````````````````````` + + +Backslash-escapes do not work inside email autolinks: + +```````````````````````````````` example + +. +

<foo+@bar.example.com>

+```````````````````````````````` + + +These are not autolinks: + +```````````````````````````````` example +<> +. +

<>

+```````````````````````````````` + + +```````````````````````````````` example +< http://foo.bar > +. +

< http://foo.bar >

+```````````````````````````````` + + +```````````````````````````````` example + +. +

<m:abc>

+```````````````````````````````` + + +```````````````````````````````` example + +. +

<foo.bar.baz>

+```````````````````````````````` + + +```````````````````````````````` example +http://example.com +. +

http://example.com

+```````````````````````````````` + + +```````````````````````````````` example +foo@bar.example.com +. +

foo@bar.example.com

+```````````````````````````````` + + +## 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 spaces, tabs, and up to one line ending, +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 spaces, tabs, and up to one line ending, +a `=` character, optional spaces, tabs, and up to one line ending, +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 spaces, tabs, line endings, `"`, `'`, `=`, `<`, `>`, 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 spaces, tabs, and up to one line ending, +an optional `/` character, and a `>` character. + +A [closing tag](@) consists of the string ``. + +An [HTML comment](@) consists of ``, +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 ``, and the string +`?>`. + +A [declaration](@) consists of the string ``, and the character `>`. + +A [CDATA section](@) consists of +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 + +. +

+```````````````````````````````` + + +Empty elements: + +```````````````````````````````` example + +. +

+```````````````````````````````` + + +Whitespace is allowed: + +```````````````````````````````` example + +. +

+```````````````````````````````` + + +With attributes: + +```````````````````````````````` example + +. +

+```````````````````````````````` + + +Custom tag names can be used: + +```````````````````````````````` example +Foo +. +

Foo

+```````````````````````````````` + + +Illegal tag names, not parsed as HTML: + +```````````````````````````````` example +<33> <__> +. +

<33> <__>

+```````````````````````````````` + + +Illegal attribute names: + +```````````````````````````````` example +
+. +

<a h*#ref="hi">

+```````````````````````````````` + + +Illegal attribute values: + +```````````````````````````````` example +
+. +

</a href="foo">

+```````````````````````````````` + + +Comments: + +```````````````````````````````` example +foo +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +foo +. +

foo <!-- not a comment -- two hyphens -->

+```````````````````````````````` + + +Not comments: + +```````````````````````````````` example +foo foo --> + +foo +. +

foo <!--> foo -->

+

foo <!-- foo--->

+```````````````````````````````` + + +Processing instructions: + +```````````````````````````````` example +foo +. +

foo

+```````````````````````````````` + + +Declarations: + +```````````````````````````````` example +foo +. +

foo

+```````````````````````````````` + + +CDATA sections: + +```````````````````````````````` example +foo &<]]> +. +

foo &<]]>

+```````````````````````````````` + + +Entity and numeric character references are preserved in HTML +attributes: + +```````````````````````````````` example +foo
+. +

foo

+```````````````````````````````` + + +Backslash escapes do not work in HTML attributes: + +```````````````````````````````` example +foo +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example + +. +

<a href=""">

+```````````````````````````````` + + +## Hard line breaks + +A line ending (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 `
` tag): + +```````````````````````````````` example +foo +baz +. +

foo
+baz

+```````````````````````````````` + + +For a more visible alternative, a backslash before the +[line ending] may be used instead of two or more spaces: + +```````````````````````````````` example +foo\ +baz +. +

foo
+baz

+```````````````````````````````` + + +More than two spaces can be used: + +```````````````````````````````` example +foo +baz +. +

foo
+baz

+```````````````````````````````` + + +Leading spaces at the beginning of the next line are ignored: + +```````````````````````````````` example +foo + bar +. +

foo
+bar

+```````````````````````````````` + + +```````````````````````````````` example +foo\ + bar +. +

foo
+bar

+```````````````````````````````` + + +Hard line breaks can occur inside emphasis, links, and other constructs +that allow inline content: + +```````````````````````````````` example +*foo +bar* +. +

foo
+bar

+```````````````````````````````` + + +```````````````````````````````` example +*foo\ +bar* +. +

foo
+bar

+```````````````````````````````` + + +Hard line breaks do not occur inside code spans + +```````````````````````````````` example +`code +span` +. +

code span

+```````````````````````````````` + + +```````````````````````````````` example +`code\ +span` +. +

code\ span

+```````````````````````````````` + + +or HTML tags: + +```````````````````````````````` example +
+. +

+```````````````````````````````` + + +```````````````````````````````` example + +. +

+```````````````````````````````` + + +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\ +. +

foo\

+```````````````````````````````` + + +```````````````````````````````` example +foo +. +

foo

+```````````````````````````````` + + +```````````````````````````````` example +### foo\ +. +

foo\

+```````````````````````````````` + + +```````````````````````````````` example +### foo +. +

foo

+```````````````````````````````` + + +## Soft line breaks + +A regular line ending (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 soft line break 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 +. +

foo +baz

+```````````````````````````````` + + +Spaces at the end of the line and beginning of the next line are +removed: + +```````````````````````````````` example +foo + baz +. +

foo +baz

+```````````````````````````````` + + +A conforming parser may render a soft line break in HTML either as a +line ending 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 +. +

hello $.;'there

+```````````````````````````````` + + +```````````````````````````````` example +Foo χρῆν +. +

Foo χρῆν

+```````````````````````````````` + + +Internal spaces are preserved verbatim: + +```````````````````````````````` example +Multiple spaces +. +

Multiple spaces

+```````````````````````````````` + + + + +# 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 (`*`, `_`), indexed to the length of the closing delimiter run +(modulo 3) and to whether the closing delimiter can also be an +opener. 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/test/test_basics.rb b/test/test_basics.rb index 70bbe76b..d7e9d37e 100644 --- a/test/test_basics.rb +++ b/test/test_basics.rb @@ -3,33 +3,33 @@ require "test_helper" class TestBasics < Minitest::Test - def setup - @doc = CommonMarker.render_doc("Hi *there*") - end + # def setup + # @doc = Commonmarker.render_doc("Hi *there*") + # end - def test_to_html - assert_equal("

Hi there

\n", @doc.to_html) - end + # def test_to_html + # assert_equal("

Hi there

\n", @doc.to_html) + # end - def test_markdown_to_html - html = CommonMarker.render_html("Hi *there*") + def test_commonmark_to_html + html = Commonmarker.render_html("Hi *there*") assert_equal("

Hi there

\n", html) end - # basic test that just checks if every option is accepted & no errors are thrown - def test_accept_every_option - text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?" - parse_opt = [:SOURCEPOS, :UNSAFE, :VALIDATE_UTF8, :SMART, :LIBERAL_HTML_TAG, :FOOTNOTES, :STRIKETHROUGH_DOUBLE_TILDE] - render_opt = parse_opt + [:HARDBREAKS, :NOBREAKS, :GITHUB_PRE_LANG, :TABLE_PREFER_STYLE_ATTRIBUTES, :FULL_INFO_STRING] + # # basic test that just checks if every option is accepted & no errors are thrown + # def test_accept_every_option + # text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?" + # parse_opt = [:SOURCEPOS, :UNSAFE, :VALIDATE_UTF8, :SMART, :LIBERAL_HTML_TAG, :FOOTNOTES, :STRIKETHROUGH_DOUBLE_TILDE] + # render_opt = parse_opt + [:HARDBREAKS, :NOBREAKS, :GITHUB_PRE_LANG, :TABLE_PREFER_STYLE_ATTRIBUTES, :FULL_INFO_STRING] - extensions = [:table, :tasklist, :strikethrough, :autolink, :tagfilter] + # extensions = [:table, :tasklist, :strikethrough, :autolink, :tagfilter] - assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html) + # assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html) - # NOTE: how tho the doc returned has sourcepos info, by default the renderer - # won't emit it. for that we need to pass in the render opt - assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions)) + # # NOTE: how tho the doc returned has sourcepos info, by default the renderer + # # won't emit it. for that we need to pass in the render opt + # assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions)) - assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_html(text, parse_opt, extensions)) - end + # assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_html(text, parse_opt, extensions)) + # end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 498d2be1..72c95375 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,7 +5,7 @@ require "minitest/pride" require "minitest/focus" -include CommonMarker +include Commonmarker FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") @@ -30,7 +30,7 @@ def open_spec_file(filename) extensions = [] header_re = Regexp.new("#+ ") - filepath = File.join("ext", "commonmarker", "cmark-upstream", "test", filename) + filepath = File.join(FIXTURES_DIR, "upstream", filename) File.readlines(filepath, encoding: "utf-8").each do |line| line_number += 1 From 4026bb21d3f7464c19c12eee0a5d8be69eaf39da Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" Date: Sun, 17 Jul 2022 19:18:17 -0400 Subject: [PATCH 03/14] Well, it runs --- README.md | 180 ++---------------------- bin/commonmarker | 4 +- ext/commonmarker/commonmarker.c | 127 +++++++++++++++-- ext/commonmarker/commonmarker.h | 4 +- ext/commonmarker/extconf.rb | 14 +- lib/commonmarker.rb | 12 +- lib/commonmarker/config.rb | 89 +++++++----- rakelib/test.rake | 2 +- test/benchmark.rb | 10 +- test/test_attributes.rb | 24 ---- test/test_basics.rb | 33 ++--- test/test_commonmark.rb | 37 ----- test/test_doc.rb | 130 ------------------ test/test_encoding.rb | 14 +- test/test_extensions.rb | 29 ++-- test/test_footnotes.rb | 36 +---- test/test_gc.rb | 47 ------- test/test_helper.rb | 2 +- test/test_linebreaks.rb | 4 +- test/test_maliciousness.rb | 226 ++----------------------------- test/test_node.rb | 89 ------------ test/test_options.rb | 6 +- test/test_pathological_inputs.rb | 16 +-- test/test_plaintext.rb | 2 +- test/test_renderer.rb | 29 +--- test/test_smartpunct.rb | 27 ++-- test/test_spec.rb | 32 ++--- test/test_tasklists.rb | 9 +- test/test_xml.rb | 107 --------------- 29 files changed, 297 insertions(+), 1044 deletions(-) delete mode 100644 test/test_attributes.rb delete mode 100644 test/test_commonmark.rb delete mode 100644 test/test_doc.rb delete mode 100644 test/test_gc.rb delete mode 100644 test/test_node.rb delete mode 100644 test/test_xml.rb diff --git a/README.md b/README.md index 0eeb2058..de15bbed 100644 --- a/README.md +++ b/README.md @@ -29,98 +29,12 @@ Call `render_html` on a string to convert it to HTML: ``` ruby require 'commonmarker' -CommonMarker.render_html('Hi *there*', :DEFAULT) +CommonMarker.to_html('Hi *there*', :DEFAULT) #

Hi there

\n ``` The second argument is optional--[see below](#options) for more information. -### Generating a document - -You can also parse a string to receive a `Document` node. You can then print that node to HTML, iterate over the children, and other fun node stuff. For example: - -``` ruby -require 'commonmarker' - -doc = CommonMarker.render_doc('*Hello* world', :DEFAULT) -puts(doc.to_html) #

Hi there

\n - -doc.walk do |node| - puts node.type # [:document, :paragraph, :text, :emph, :text] -end -``` - -The second argument is optional--[see below](#options) for more information. - -#### Example: walking the AST - -You can use `walk` or `each` to iterate over nodes: - -- `walk` will iterate on a node and recursively iterate on a node's children. -- `each` will iterate on a node and its children, but no further. - -``` ruby -require 'commonmarker' - -# parse the files specified on the command line -doc = CommonMarker.render_doc("# The site\n\n [GitHub](https://www.github.com)") - -# Walk tree and print out URLs for links -doc.walk do |node| - if node.type == :link - printf("URL = %s\n", node.url) - end -end - -# Capitalize all regular text in headers -doc.walk do |node| - if node.type == :header - node.each do |subnode| - if subnode.type == :text - subnode.string_content = subnode.string_content.upcase - end - end - end -end - -# Transform links to regular text -doc.walk do |node| - if node.type == :link - node.insert_before(node.first_child) - node.delete - end -end -``` - -### Creating a custom renderer - -You can also derive a class from CommonMarker's `HtmlRenderer` class. This produces slower output, but is far more customizable. For example: - -``` ruby -class MyHtmlRenderer < CommonMarker::HtmlRenderer - def initialize - super - @headerid = 1 - end - - def header(node) - block do - out("", - :children, "") - @headerid += 1 - end - end -end - -myrenderer = MyHtmlRenderer.new -puts myrenderer.render(doc) - -# Print any warnings to STDERR -renderer.warnings.each do |w| - STDERR.write("#{w}\n") -end -``` - ## Options CommonMarker accepts the same options that CMark does, as symbols. Note that there is a distinction in CMark for "parse" options and "render" options, which are represented in the tables below. @@ -158,101 +72,28 @@ CommonMarker accepts the same options that CMark does, as symbols. Note that the ### Passing options -To apply a single option, pass it in as a symbol argument: +To apply an option, pass it as part of the hash: ``` ruby -CommonMarker.render_doc("\"Hello,\" said the spider.", :SMART) +CommonMarker.to_html("\"Hello,\" said the spider.", :SMART) #

“Hello,” said the spider.

\n -``` - -To have multiple options applied, pass in an array of symbols: -``` ruby -CommonMarker.render_html("\"'Shelob' is my name.\"", [:HARDBREAKS, :SOURCEPOS]) +CommonMarker.to_html("\"'Shelob' is my name.\"", [:HARDBREAKS, :SOURCEPOS]) ``` -For more information on these options, see [the CMark documentation](https://git.io/v7nh1). - -## Extensions - -Both `render_html` and `render_doc` take an optional third argument defining the extensions you want enabled as your CommonMark document is being processed. The documentation for these extensions are [defined in this spec](https://github.github.com/gfm/), and the rationale is provided [in this blog post](https://githubengineering.com/a-formal-spec-for-github-markdown/). - -The available extensions are: - -* `:table` - This provides support for tables. -* `:tasklist` - This provides support for task list items. -* `:strikethrough` - This provides support for strikethroughs. -* `:autolink` - This provides support for automatically converting URLs to anchor tags. -* `:tagfilter` - This escapes [several "unsafe" HTML tags](https://github.github.com/gfm/#disallowed-raw-html-extension-), causing them to not have any effect. +For more information on these options, see [the comrak documentation](https://github.com/kivikakk/comrak#usage). ## Output formats -Like CMark, CommonMarker can generate output in several formats: HTML, XML, plaintext, and CommonMark are currently supported. +Commonmarker can only generate output in one format: HTML. ### HTML -The default output format, HTML, will be generated when calling `to_html` or using `--to=html` on the command line. - ```ruby -doc = CommonMarker.render_doc('*Hello* world!', :DEFAULT) -puts(doc.to_html) - -

Hello world!

-``` - -### XML - -XML will be generated when calling `to_xml` or using `--to=xml` on the command line. - -```ruby -doc = CommonMarker.render_doc('*Hello* world!', :DEFAULT) -puts(doc.to_xml) - - - - - - - Hello - - world! - - -``` - -### Plaintext - -Plaintext will be generated when calling `to_plaintext` or using `--to=plaintext` on the command line. - -```ruby -doc = CommonMarker.render_doc('*Hello* world!', :DEFAULT) -puts(doc.to_plaintext) - -Hello world! -``` - -### Commonmark - -Commonmark will be generated when calling `to_commonmark` or using `--to=commonmark` on the command line. - -``` ruby -text = <<-TEXT -1. I am a numeric list. -2. I continue the list. -* Suddenly, an unordered list! -* What fun! -TEXT - -doc = CommonMarker.render_doc(text, :DEFAULT) -puts(doc.to_commonmark) - -1. I am a numeric list. -2. I continue the list. - - +html = CommonMarker.to_html('*Hello* world!', :DEFAULT) +puts(html) - - Suddenly, an unordered list\! - - What fun\! +#

Hello world!

``` ## Developing locally @@ -264,10 +105,11 @@ script/bootstrap bundle exec rake compile ``` -If there were no errors, you're done! Otherwise, make sure to follow the CMark dependency instructions. +If there were no errors, you're done! Otherwise, make sure to follow the comrak dependency instructions. ## Benchmarks +See [BENCHMARKS.md](BENCHMARKS.md) Some rough benchmarks: ``` diff --git a/bin/commonmarker b/bin/commonmarker index 3bfabe0f..ebfbd220 100755 --- a/bin/commonmarker +++ b/bin/commonmarker @@ -12,7 +12,7 @@ $LOAD_PATH.unshift File.expand_path('lib', root) def parse_options options = Struct.new(:active_extensions, :active_parse_options, :active_render_options, :output_format, :renderer) .new([], [:DEFAULT], [:DEFAULT], :html) - extensions = CommonMarker.extensions + extension_options = CommonMarker::Config::OPTS.fetch(:extension) parse_options = CommonMarker::Config::OPTS.fetch(:parse) render_options = CommonMarker::Config::OPTS.fetch(:render) format_options = CommonMarker::Config::OPTS.fetch(:format) @@ -99,7 +99,7 @@ options = parse_options abort("format '#{options.output_format}' does not support using the HtmlRenderer renderer") if options.renderer && options.output_format != :html -doc = CommonMarker.render_doc(ARGF.read, options.active_parse_options, options.active_extensions) +doc = Commonmarker.to_html(ARGF.read, options.active_parse_options) case options.output_format when :html diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c index 6832d502..9368b685 100644 --- a/ext/commonmarker/commonmarker.c +++ b/ext/commonmarker/commonmarker.c @@ -1,17 +1,127 @@ +#include "ruby.h" #include "commonmarker.h" -#include "comrak.h" +#include "comrak_ffi.h" -VALUE commonmarker_to_html(VALUE self, VALUE rb_commonmark_text, int options) { - Check_Type(rb_commonmark_text, T_STRING); +int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { + if (key == ID2SYM(rb_intern("strikethrough"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_strikethrough(config, val); + } + } else if (key == ID2SYM(rb_intern("tagfilter"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_tagfilter(config, val); + } + } else if (key == ID2SYM(rb_intern("table"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_table(config, val); + } + } else if (key == ID2SYM(rb_intern("autolink"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_autolink(config, val); + } + } else if (key == ID2SYM(rb_intern("tasklist"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_tasklist(config, val); + } + } else if (key == ID2SYM(rb_intern("superscript"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_superscript(config, val); + } + } else if (key == ID2SYM(rb_intern("header_ids"))) { + Check_Type(val, T_STRING); + comrak_set_extension_option_header_ids(config, StringValuePtr(val), + RSTRING_LEN(val)); - char *commonmark_text = StringValueCStr(rb_commonmark_text); + } else if (key == ID2SYM(rb_intern("footnotes"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_footnotes(config, val); + } + } else if (key == ID2SYM(rb_intern("description_lists"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_extension_option_description_lists(config, val); + } + } else if (key == ID2SYM(rb_intern("front_matter_delimiter"))) { + Check_Type(val, T_STRING); + comrak_set_extension_option_front_matter_delimiter( + config, StringValuePtr(val), RSTRING_LEN(val)); + } + return ST_CONTINUE; +} + +int iterate_render_options(VALUE key, VALUE val, comrak_options_t *config) { + if (key == ID2SYM(rb_intern("hardbreaks"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_render_option_hardbreaks(config, val); + } + } else if (key == ID2SYM(rb_intern("github_pre_lang"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_render_option_github_pre_lang(config, val); + } + } else if (key == ID2SYM(rb_intern("width"))) { + Check_Type(val, T_FIXNUM); + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_render_option_github_pre_lang(config, val); + } + } else if (key == ID2SYM(rb_intern("unsafe_"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_render_option_unsafe_(config, val); + } + } else if (key == ID2SYM(rb_intern("escape"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_render_option_escape(config, val); + } + } + + return ST_CONTINUE; +} + +int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { + if (key == ID2SYM(rb_intern("superscript"))) { + if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { + comrak_set_parse_option_smart(config, val); + } + } else if (key == ID2SYM(rb_intern("default_info_string"))) { + Check_Type(val, T_STRING); + + comrak_set_parse_option_default_info_string(config, StringValuePtr(val), + RSTRING_LEN(val)); + } + + return ST_CONTINUE; +} + +int iterate_options_hash(VALUE key, VALUE val, comrak_options_t *config) { + Check_Type(key, T_SYMBOL); + + // which options are we dealing with? + if (key == ID2SYM(rb_intern("parse"))) { + Check_Type(val, T_HASH); + rb_hash_foreach(val, iterate_parse_options, config); + } else if (key == ID2SYM(rb_intern("render"))) { + Check_Type(val, T_HASH); + rb_hash_foreach(val, iterate_render_options, config); + } else if (key == ID2SYM(rb_intern("extension"))) { + Check_Type(val, T_HASH); + rb_hash_foreach(val, iterate_extension_options, config); + } + + return ST_CONTINUE; +} + +VALUE commonmark_to_html(VALUE self, VALUE rb_commonmark, VALUE rb_options) { + Check_Type(rb_commonmark, T_STRING); + Check_Type(rb_options, T_HASH); + + char *commonmark = StringValueCStr(rb_commonmark); + + comrak_options_t *options = comrak_options_new(); + rb_hash_foreach(rb_options, iterate_options_hash, options); - comrak_options_t * default_options = comrak_options_new(); - comrak_str_t html = comrak_commonmark_to_html(commonmark_text, default_options); + comrak_str_t html = comrak_commonmark_to_html(commonmark, options); VALUE rb_html = rb_utf8_str_new(html.data, html.len); - comrak_options_free(default_options); + comrak_options_free(options); comrak_str_free(html); return rb_html; @@ -21,5 +131,6 @@ __attribute__((visibility("default"))) void Init_commonmarker() { VALUE module; module = rb_define_module("Commonmarker"); - rb_define_singleton_method(module, "commonmark_to_html", commonmarker_to_html, 2); + rb_define_singleton_method(module, "commonmark_to_html", commonmark_to_html, + 2); } diff --git a/ext/commonmarker/commonmarker.h b/ext/commonmarker/commonmarker.h index 19e9e8db..5bb38a7b 100644 --- a/ext/commonmarker/commonmarker.h +++ b/ext/commonmarker/commonmarker.h @@ -8,11 +8,11 @@ #include "ruby.h" #include "ruby/encoding.h" -#include "comrak.h" +#include "comrak_ffi.h" #define CSTR2SYM(s) (ID2SYM(rb_intern((s)))) void Init_commonmarker(); -VALUE commonmarker_to_html(VALUE self, VALUE rb_commonmark_text, int options); +VALUE commonmark_to_html(VALUE self, VALUE rb_commonmark, VALUE rb_options); #endif diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index a7099d84..799b84c5 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -4,7 +4,8 @@ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")) EXT_DIR = File.join(PACKAGE_ROOT_DIR, "ext", "commonmarker") CROSS_BUILD_P = enable_config("cross-build") -COMRAK_VERSION = "0.14.0" +# COMRAK_VERSION = "0.14.0" +COMRAK_VERSION = "fix-missing-smart-option" RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] ENV["CC"] = RbConfig::CONFIG["CC"] @@ -13,15 +14,16 @@ def darwin? RbConfig::CONFIG["target_os"].include?("darwin") end -# what follows is pretty miuch an abuse of miniportile2, but it works for now +# what follows is pretty much an abuse of miniportile2, but it works for now # i just need something to download files and run a cargo build; one day this should # be replaced with actual prepacked binaries. -TARBALL_URL = "https://github.com/kivikakk/comrak/archive/refs/tags/#{COMRAK_VERSION}.tar.gz" +# TARBALL_URL = "https://github.com/kivikakk/comrak/archive/refs/tags/#{COMRAK_VERSION}.tar.gz" +TARBALL_URL = "https://github.com/kivikakk/comrak/archive/refs/heads/#{COMRAK_VERSION}.tar.gz" MiniPortile.new("comrak", COMRAK_VERSION).tap do |recipe| recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") recipe.files = [{ url: TARBALL_URL, - sha256: "055fa44ef002a1a07853d3a4dd2a8c553a1dc58ff3809b4fa530ed35694d8571", + # sha256: "055fa44ef002a1a07853d3a4dd2a8c553a1dc58ff3809b4fa530ed35694d8571", }] # configure the environment that MiniPortile will use for subshells @@ -64,8 +66,8 @@ def darwin? $LIBS << ' -lcomrak_ffi' end -unless find_header("comrak.h") - abort("\nERROR: *** could not find comrak.h ***\n\n") +unless find_header("comrak_ffi.h") + abort("\nERROR: *** could not find comrak_ffi.h ***\n\n") end create_makefile("commonmarker/commonmarker") diff --git a/lib/commonmarker.rb b/lib/commonmarker.rb index f1306be4..1168536d 100755 --- a/lib/commonmarker.rb +++ b/lib/commonmarker.rb @@ -20,17 +20,17 @@ end module Commonmarker - # Public: Parses a CommonMark string into an HTML string. + # Public: Parses a CommonMark string into an HTML string. # # text - A {String} of text - # option - Either a {Symbol} or {Array of Symbol}s indicating the render options - # extensions - An {Array of Symbol}s indicating the extensions to use + # option - A {Hash} of render, parse, and extension options to transform the text. # # Returns a {String} of converted HTML. - def self.render_html(text, options = :DEFAULT, extensions = []) + def self.to_html(text, options: Commonmarker::Config::OPTS) raise TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) + raise TypeError, "options must be a Hash; got a #{options.class}!" unless options.is_a?(Hash) - # opts = Config.process_options(options, :render) - self.commonmark_to_html(text.encode("UTF-8"), 0) + opts = Config.process_options(options) + commonmark_to_html(text.encode("UTF-8"), opts) end end diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index dbd8acd3..3187752d 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -1,52 +1,69 @@ # frozen_string_literal: true module Commonmarker - # For Ruby::Enum, these must be classes, not modules module Config - # See https://github.com/github/cmark-gfm/blob/master/src/cmark-gfm.h#L673 + # For details, see + # https://github.com/kivikakk/comrak/blob/162ef9354deb2c9b4a4e05be495aa372ba5bb696/src/main.rs#L201 OPTS = { parse: { - DEFAULT: 0, - SOURCEPOS: (1 << 1), - UNSAFE: (1 << 17), - VALIDATE_UTF8: (1 << 9), - SMART: (1 << 10), - LIBERAL_HTML_TAG: (1 << 12), - FOOTNOTES: (1 << 13), - STRIKETHROUGH_DOUBLE_TILDE: (1 << 14), + smart: false, + default_info_string: "", }.freeze, render: { - DEFAULT: 0, - SOURCEPOS: (1 << 1), - HARDBREAKS: (1 << 2), - UNSAFE: (1 << 17), - NOBREAKS: (1 << 4), - VALIDATE_UTF8: (1 << 9), - SMART: (1 << 10), - GITHUB_PRE_LANG: (1 << 11), - LIBERAL_HTML_TAG: (1 << 12), - FOOTNOTES: (1 << 13), - STRIKETHROUGH_DOUBLE_TILDE: (1 << 14), - TABLE_PREFER_STYLE_ATTRIBUTES: (1 << 15), - FULL_INFO_STRING: (1 << 16), + hardbreaks: true, + github_pre_lang: true, + width: 80, + unsafe_: false, + escape: false, }.freeze, - format: [:html, :xml, :commonmark, :plaintext].freeze, + extension: { + strikethrough: true, + tagfilter: true, + table: true, + autolink: true, + tasklist: true, + superscript: false, + header_ids: "", + footnotes: false, + description_lists: false, + front_matter_delimiter: "", + }, + format: [:html].freeze, }.freeze - def self.process_options(option, type) - case option - when Symbol - OPTS.fetch(type).fetch(option) - when Array - raise TypeError if option.none? + def self.merged_with_defaults(options) + Commonmarker::Config::OPTS.merge(process_options(options)) + end + + def self.process_options(options) + { + parse: process_parse_options(options[:parse]), + render: process_render_options(options[:render]), + extension: process_extension_options(options[:extension]), + } + end + + BOOLS = [true, false] + ["parse", "render", "extension"].each do |type| + define_singleton_method :"process_#{type}_options" do |options| + Commonmarker::Config::OPTS[type.to_sym].each_with_object({}) do |(key, value), hash| + hash[key] = value && next if options.nil? # option not provided, go for the default + + if options.nil? || options[key].nil? # option not provided, go for the defaul + hash[key] = value + else + value_klass = value.class + if value_klass.is_a?(TrueClass) || value_klass.is_a?(FalseClass) + hash[key] = value if BOOLS.include?(value) + else + raise TypeError, "#{type}_options[:#{key}] must be a #{value.class}; got a #{options[key].class}" unless value.is_a?(value.class) - # neckbearding around. the map will both check the opts and then bitwise-OR it - OPTS.fetch(type).fetch_values(*option).inject(0, :|) - else - raise TypeError, "option type must be a valid symbol or array of symbols within the #{name}::OPTS[:#{type}] context" + hash[key] = options[key] + end + end + end end - rescue KeyError => e - raise TypeError, "option ':#{e.key}' does not exist for #{name}::OPTS[:#{type}]" + # private :"process_#{type}_options" end end end diff --git a/rakelib/test.rake b/rakelib/test.rake index 1e19be2e..711e2163 100644 --- a/rakelib/test.rake +++ b/rakelib/test.rake @@ -5,7 +5,7 @@ require "rake/testtask" Rake::TestTask.new("test:unit") do |t| t.libs << "lib" t.libs << "test" - t.pattern = "test/test_basics.rb" + t.pattern = "test/test_*.rb" t.verbose = true t.warning = false end diff --git a/test/benchmark.rb b/test/benchmark.rb index 4de063da..3b9ea977 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -20,15 +20,7 @@ end x.report("commonmarker with to_xml") do - Commonmarker.render_html(benchinput) - end - - x.report("commonmarker with ruby HtmlRenderer") do - CommonMarker::HtmlRenderer.new.render(CommonMarker.render_doc(benchinput)) - end - - x.report("commonmarker with render_doc.to_html") do - CommonMarker.render_doc(benchinput, :DEFAULT, [:autolink]).to_html(:DEFAULT, [:autolink]) + Commonmarker.to_html(benchinput) end x.report("kramdown") do diff --git a/test/test_attributes.rb b/test/test_attributes.rb deleted file mode 100644 index e5e3c903..00000000 --- a/test/test_attributes.rb +++ /dev/null @@ -1,24 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestAttributes < Minitest::Test - def setup - contents = fixtures_file("dingus.md") - @doc = CommonMarker.render_doc(contents.strip) - end - - def test_sourcepos - sourcepos = [] - - @doc.walk do |node| - sourcepos << node.sourcepos - end - - sourcepos.delete_if { |h| h.values.all?(&:zero?) } - - result = [{ start_line: 1, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 1, start_column: 1, end_line: 1, end_column: 17 }, { start_line: 1, start_column: 4, end_line: 1, end_column: 17 }, { start_line: 3, start_column: 1, end_line: 5, end_column: 36 }, { start_line: 3, start_column: 1, end_line: 3, end_column: 55 }, { start_line: 4, start_column: 1, end_line: 4, end_column: 53 }, { start_line: 4, start_column: 2, end_line: 4, end_column: 14 }, { start_line: 4, start_column: 54, end_line: 4, end_column: 58 }, { start_line: 5, start_column: 1, end_line: 5, end_column: 36 }, { start_line: 7, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 7, start_column: 1, end_line: 7, end_column: 11 }, { start_line: 7, start_column: 4, end_line: 7, end_column: 11 }, { start_line: 7, start_column: 4, end_line: 7, end_column: 11 }, { start_line: 8, start_column: 1, end_line: 10, end_column: 12 }, { start_line: 8, start_column: 4, end_line: 8, end_column: 11 }, { start_line: 8, start_column: 4, end_line: 8, end_column: 11 }, { start_line: 9, start_column: 4, end_line: 10, end_column: 12 }, { start_line: 9, start_column: 4, end_line: 9, end_column: 12 }, { start_line: 9, start_column: 6, end_line: 9, end_column: 12 }, { start_line: 9, start_column: 6, end_line: 9, end_column: 12 }, { start_line: 10, start_column: 4, end_line: 10, end_column: 12 }, { start_line: 10, start_column: 6, end_line: 10, end_column: 12 }, { start_line: 10, start_column: 6, end_line: 10, end_column: 12 }] - - assert_equal(result, sourcepos) - end -end diff --git a/test/test_basics.rb b/test/test_basics.rb index d7e9d37e..3c138906 100644 --- a/test/test_basics.rb +++ b/test/test_basics.rb @@ -3,33 +3,16 @@ require "test_helper" class TestBasics < Minitest::Test - # def setup - # @doc = Commonmarker.render_doc("Hi *there*") - # end - - # def test_to_html - # assert_equal("

Hi there

\n", @doc.to_html) - # end - - def test_commonmark_to_html - html = Commonmarker.render_html("Hi *there*") + def test_to_html + html = Commonmarker.to_html("Hi *there*") assert_equal("

Hi there

\n", html) end - # # basic test that just checks if every option is accepted & no errors are thrown - # def test_accept_every_option - # text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?" - # parse_opt = [:SOURCEPOS, :UNSAFE, :VALIDATE_UTF8, :SMART, :LIBERAL_HTML_TAG, :FOOTNOTES, :STRIKETHROUGH_DOUBLE_TILDE] - # render_opt = parse_opt + [:HARDBREAKS, :NOBREAKS, :GITHUB_PRE_LANG, :TABLE_PREFER_STYLE_ATTRIBUTES, :FULL_INFO_STRING] - - # extensions = [:table, :tasklist, :strikethrough, :autolink, :tagfilter] + # basic test that just checks that default option is accepted & no errors are thrown + def test_to_html_accept_default_options + text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?" - # assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html) - - # # NOTE: how tho the doc returned has sourcepos info, by default the renderer - # # won't emit it. for that we need to pass in the render opt - # assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_doc(text, parse_opt, extensions).to_html(render_opt, extensions)) - - # assert_equal("

Hello world – how are you today? I’m fine, ~yourself~?

\n", CommonMarker.render_html(text, parse_opt, extensions)) - # end + html = Commonmarker.to_html(text, options: Commonmarker::Config::OPTS) + assert_equal("

Hello world -- how are you today? I’m fine, ~yourself~?

\n", html) + end end diff --git a/test/test_commonmark.rb b/test/test_commonmark.rb deleted file mode 100644 index 0c8d00ca..00000000 --- a/test/test_commonmark.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestCommonmark < Minitest::Test - HTML_COMMENT = /\s?/.freeze - - def setup - @markdown = <<~MD - Hi *there*! - - 1. I am a numeric list. - 2. I continue the list. - * Suddenly, an unordered list! - * What fun! - - Okay, _enough_. - - | a | b | - | --- | --- | - | c | d | - MD - end - - def render_doc(doc) - CommonMarker.render_doc(doc, :DEFAULT, [:table]) - end - - def test_to_commonmark - compare = render_doc(@markdown).to_commonmark - - assert_equal(\ - render_doc(@markdown).to_html.squeeze(" ").gsub(HTML_COMMENT, ""), - render_doc(compare).to_html.squeeze(" ").gsub(HTML_COMMENT, "") - ) - end -end diff --git a/test/test_doc.rb b/test/test_doc.rb deleted file mode 100644 index 9b77a638..00000000 --- a/test/test_doc.rb +++ /dev/null @@ -1,130 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestDocNode < Minitest::Test - def setup - @doc = CommonMarker.render_doc("Hi *there*. This has __many nodes__!") - @first_child = @doc.first_child - @last_child = @doc.last_child - @link = CommonMarker.render_doc("[GitHub](https://www.github.com)").first_child.first_child - @image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")') - @image = @image.first_child.first_child - @header = CommonMarker.render_doc("### Header Three").first_child - @ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child - @ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child - @fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child - end - - def test_get_type - assert_equal(:document, @doc.type) - end - - def test_get_type_string - assert_equal("document", @doc.type_string) - end - - def test_get_first_child - assert_equal(:paragraph, @first_child.type) - end - - def test_get_next - assert_equal(:emph, @first_child.first_child.next.type) - end - - def test_insert_before - paragraph = Node.new(:paragraph) - assert(@first_child.insert_before(paragraph)) - assert_match("

\n

Hi there.", @doc.to_html) - end - - def test_insert_after - paragraph = Node.new(:paragraph) - assert(@first_child.insert_after(paragraph)) - assert_match("many nodes!

\n

\n", @doc.to_html) - end - - def test_prepend_child - code = Node.new(:code) - assert(@first_child.prepend_child(code)) - assert_match("

Hi there.", @doc.to_html) - end - - def test_append_child - strong = Node.new(:strong) - assert(@first_child.append_child(strong)) - assert_match("!

\n", @doc.to_html) - end - - def test_get_last_child - assert_equal(:paragraph, @last_child.type) - end - - def test_get_parent - assert_equal(:paragraph, @first_child.first_child.next.parent.type) - end - - def test_get_previous - assert_equal(:text, @first_child.first_child.next.previous.type) - end - - def test_get_url - assert_equal("https://www.github.com", @link.url) - end - - def test_set_url - assert_equal("https://www.mozilla.org", @link.url = "https://www.mozilla.org") - end - - def test_get_title - assert_equal("Favicon", @image.title) - end - - def test_set_title - assert_equal("Octocat", @image.title = "Octocat") - end - - def test_get_header_level - assert_equal(3, @header.header_level) - end - - def test_set_header_level - assert_equal(6, @header.header_level = 6) - end - - def test_get_list_type - assert_equal(:bullet_list, @ul_list.list_type) - assert_equal(:ordered_list, @ol_list.list_type) - end - - def test_set_list_type - assert_equal(:ordered_list, @ul_list.list_type = :ordered_list) - assert_equal(:bullet_list, @ol_list.list_type = :bullet_list) - end - - def test_get_list_start - assert_equal(1, @ol_list.list_start) - end - - def test_set_list_start - assert_equal(8, @ol_list.list_start = 8) - end - - def test_get_list_tight - assert(@ul_list.list_tight) - assert(@ol_list.list_tight) - end - - def test_set_list_tight - refute(@ul_list.list_tight = false) - refute(@ol_list.list_tight = false) - end - - def test_get_fence_info - assert_equal("ruby", @fence.fence_info) - end - - def test_set_fence_info - assert_equal("javascript", @fence.fence_info = "javascript") - end -end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index 35d5c33c..33c78f76 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -6,18 +6,14 @@ class TestEncoding < Minitest::Test # see http://git.io/vq4FR def test_encoding contents = fixtures_file("curly.md") - doc = CommonMarker.render_doc(contents, :SMART) - render = doc.to_html - assert_equal("

This curly quote “makes commonmarker throw an exception”.

", render.rstrip) + render = Commonmarker.to_html(contents, :SMART) - render = doc.to_xml - assert_includes(render, 'This curly quote “makes commonmarker throw an exception”.') + assert_equal("

This curly quote “makes commonmarker throw an exception”.

", render.rstrip) end def test_string_content_is_utf8 - doc = CommonMarker.render_doc("Hi *there*") - text = doc.first_child.last_child.first_child - assert_equal("there", text.string_content) - assert_equal("UTF-8", text.string_content.encoding.name) + html = Commonmarker.to_html("Hi *there*") + assert_equal("

Hi there", html) + assert_equal("UTF-8", html.encoding.name) end end diff --git a/test/test_extensions.rb b/test/test_extensions.rb index ced40e34..09549c04 100644 --- a/test/test_extensions.rb +++ b/test/test_extensions.rb @@ -8,31 +8,28 @@ def setup end def test_uses_specified_extensions - CommonMarker.render_html(@markdown, :DEFAULT, []).tap do |out| + Commonmarker.to_html(@markdown, :DEFAULT, []).tap do |out| assert_includes(out, "| a") assert_includes(out, "| x") assert_includes(out, "~~hi~~") end - CommonMarker.render_html(@markdown, :DEFAULT, [:table]).tap do |out| + Commonmarker.to_html(@markdown, :DEFAULT, [:table]).tap do |out| refute_includes(out, "| a") ["", "", "", "", "x"].each { |html| assert_includes(out, html) } assert_includes(out, "~~hi~~") end - CommonMarker.render_html(@markdown, :DEFAULT, [:strikethrough]).tap do |out| + Commonmarker.to_html(@markdown, :DEFAULT, [:strikethrough]).tap do |out| assert_includes(out, "| a") refute_includes(out, "~~hi~~") assert_includes(out, "hi") end - doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) - assert_equal("

~a~ b ~~~c~~~

\n", doc.to_html) - - html = CommonMarker.render_html("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) + html = Commonmarker.to_html("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) assert_equal("

~a~ b ~~~c~~~

\n", html) - CommonMarker.render_html(@markdown, :DEFAULT, [:table, :strikethrough]).tap do |out| + Commonmarker.to_html(@markdown, :DEFAULT, [:table, :strikethrough]).tap do |out| refute_includes(out, "| a") refute_includes(out, "| x") refute_includes(out, "~~hi~~") @@ -40,7 +37,7 @@ def test_uses_specified_extensions end def test_extensions_with_renderers - doc = CommonMarker.render_doc(@markdown, :DEFAULT, [:table]) + doc = Commonmarker.to_html(@markdown, :DEFAULT, [:table]) doc.to_html.tap do |out| refute_includes(out, "| a") @@ -54,23 +51,23 @@ def test_extensions_with_renderers assert_includes(out, "~~hi~~") end - doc = CommonMarker.render_doc("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) + doc = Commonmarker.to_html("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) assert_equal("

~a~ b ~~~c~~~

\n", HtmlRenderer.new.render(doc)) end def test_bad_extension_specifications - assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, "nope") } - assert_raises(TypeError) { CommonMarker.render_html(@markdown, :DEFAULT, ["table"]) } - assert_raises(ArgumentError) { CommonMarker.render_html(@markdown, :DEFAULT, [:table, :bad]) } + assert_raises(TypeError) { Commonmarker.to_html(@markdown, :DEFAULT, "nope") } + assert_raises(TypeError) { Commonmarker.to_html(@markdown, :DEFAULT, ["table"]) } + assert_raises(ArgumentError) { Commonmarker.to_html(@markdown, :DEFAULT, [:table, :bad]) } end def test_comments_are_kept_as_expected assert_equal(" <xmp>\n", - CommonMarker.render_html(" \n", :UNSAFE, [:tagfilter])) + Commonmarker.to_html("<!--hello--> <blah> <xmp>\n", :UNSAFE, [:tagfilter])) end def test_table_prefer_style_attributes - assert_equal(<<~HTML, CommonMarker.render_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, [:table])) + assert_equal(<<~HTML, Commonmarker.to_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, [:table])) <table> <thead> <tr> @@ -99,7 +96,7 @@ def test_table_prefer_style_attributes end def test_plaintext - assert_equal(<<~HTML, CommonMarker.render_doc(<<~MD, :DEFAULT, [:table, :strikethrough]).to_plaintext) + assert_equal(<<~HTML, Commonmarker.to_html(<<~MD, :DEFAULT, [:table, :strikethrough]).to_plaintext) Hello ~there~. | a | diff --git a/test/test_footnotes.rb b/test/test_footnotes.rb index 7cdfd93a..35013029 100644 --- a/test/test_footnotes.rb +++ b/test/test_footnotes.rb @@ -3,41 +3,7 @@ require "test_helper" class TestFootnotes < Minitest::Test - def setup - @doc = CommonMarker.render_doc("Hello[^hi].\n\n[^hi]: Hey!\n", :FOOTNOTES) - end - def test_to_html - expected = <<~HTML - <p>Hello<sup class="footnote-ref"><a href="#fn-hi" id="fnref-hi" data-footnote-ref>1</a></sup>.</p> - <section class="footnotes" data-footnotes> - <ol> - <li id="fn-hi"> - <p>Hey! <a href="#fnref-hi" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p> - </li> - </ol> - </section> - HTML - - assert_equal(expected, @doc.to_html) - end - - def test_html_renderer - expected = <<~HTML - <p>Hello<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup>.</p> - <section class="footnotes"> - <ol> - <li id="fn1"> - <p>Hey! <a href="#fnref1" class="footnote-backref">↩</a></p> - </li> - </ol> - </section> - HTML - - assert_equal(expected, CommonMarker::HtmlRenderer.new.render(@doc)) - end - - def test_render_html md = <<~MARKDOWN # footnotes Let's render some footnotes[^1] @@ -55,6 +21,6 @@ def test_render_html </ol> </section> HTML - assert_equal(expected, CommonMarker.render_html(md, :FOOTNOTES)) + assert_equal(expected, Commonmarker.to_html(md, :FOOTNOTES)) end end diff --git a/test/test_gc.rb b/test/test_gc.rb deleted file mode 100644 index 05456e45..00000000 --- a/test/test_gc.rb +++ /dev/null @@ -1,47 +0,0 @@ -# frozen_string_literal: true - -# rubocop:disable Lint/UselessAssignment -require "test_helper" - -class TestNode < Minitest::Test - # These tests are somewhat fragile. It would be better to allocate lots - # of memory after a GC run to make sure that potentially freed memory - # isn't valid by accident. - - def test_drop_parent_reference - doc = CommonMarker.render_doc("Hi *there*") - text = doc.first_child.last_child.first_child - doc = nil - GC.start - # Test that doc has not been freed. - assert_equal("there", text.string_content) - end - - def test_drop_child_reference - doc = CommonMarker.render_doc("Hi *there*") - text = doc.first_child.last_child.first_child - text = nil - GC.start - # Test that the cached child object is still valid. - text = doc.first_child.last_child.first_child - assert_equal("there", text.string_content) - end - - def test_remove_parent - doc = CommonMarker.render_doc("Hi *there*") - para = doc.first_child - para.delete - doc = nil - para = nil - # TODO: Test that the `para` node was actually freed after unlinking. - end - - def test_add_parent - doc = Node.new(:document) - hrule = Node.new(:hrule) - doc.append_child(hrule) - # If the hrule node was erroneously freed, this would result in a double - # free. - end -end -# rubocop:enable Lint/UselessAssignment diff --git a/test/test_helper.rb b/test/test_helper.rb index 72c95375..9485f8f7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -17,7 +17,7 @@ def make_bin(file, args = "") %x(ruby bin/commonmarker #{File.join(FIXTURES_DIR, file)} #{args}).chomp end -def open_spec_file(filename) +def load_spec_file(filename) line_number = 0 start_line = 0 end_line = 0 diff --git a/test/test_linebreaks.rb b/test/test_linebreaks.rb index f81b049c..b8c8d977 100644 --- a/test/test_linebreaks.rb +++ b/test/test_linebreaks.rb @@ -4,12 +4,12 @@ class TestLinebreaks < Minitest::Test def test_hardbreak_no_spaces - doc = CommonMarker.render_doc("foo\nbaz") + doc = Commonmarker.to_html("foo\nbaz") assert_equal("<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)) end def test_hardbreak_with_spaces - doc = CommonMarker.render_doc("foo \nbaz") + doc = Commonmarker.to_html("foo \nbaz") assert_equal("<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)) end end diff --git a/test/test_maliciousness.rb b/test/test_maliciousness.rb index 454cf50f..a842eece 100644 --- a/test/test_maliciousness.rb +++ b/test/test_maliciousness.rb @@ -4,248 +4,50 @@ module CommonMarker class TestMaliciousness < Minitest::Test - def setup - @doc = CommonMarker.render_doc("Hi *there*") - end - - def test_init_with_bad_type - assert_raises(TypeError) do - Node.new(123) - end - - assert_raises(NodeError) do - Node.new(:totes_fake) - end - - assert_raises(TypeError) do - Node.new([]) - end - - assert_raises(TypeError) do - Node.new([23]) - end - - assert_raises(TypeError) do - Node.new(nil) - end - end - def test_rendering_with_bad_type assert_raises(TypeError) do - CommonMarker.render_html("foo \n baz", 123) + Commonmarker.to_html(nil) end assert_raises(TypeError) do - CommonMarker.render_html("foo \n baz", :totes_fake) + Commonmarker.to_html(123) end assert_raises(TypeError) do - CommonMarker.render_html("foo \n baz", []) + Commonmarker.to_html([123]) end assert_raises(TypeError) do - CommonMarker.render_html("foo \n baz", [23]) + Commonmarker.to_html("foo \n baz", options: 123) end assert_raises(TypeError) do - CommonMarker.render_html("foo \n baz", nil) + Commonmarker.to_html("foo \n baz", options: :totes_fake) end assert_raises(TypeError) do - CommonMarker.render_html("foo \n baz", [:SMART, "totes_fake"]) + Commonmarker.to_html("foo \n baz", options: []) end assert_raises(TypeError) do - CommonMarker.render_html(123) + Commonmarker.to_html("foo \n baz", options: [23]) end assert_raises(TypeError) do - CommonMarker.render_html([123]) + Commonmarker.to_html("foo \n baz", options: nil) end assert_raises(TypeError) do - CommonMarker.render_html(nil) + Commonmarker.to_html("foo \n baz", options: [:SMART, "totes_fake"]) end - assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", 123) - end - - err = assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", :safe) - end - assert_equal("option ':safe' does not exist for CommonMarker::Config::OPTS[:parse]", err.message) - - assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", :totes_fake) - end - - assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", []) - end - - assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", [23]) - end - - assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", nil) - end - - assert_raises(TypeError) do - CommonMarker.render_doc("foo \n baz", [:SMART, "totes_fake"]) - end - - assert_raises(TypeError) do - CommonMarker.render_doc(123) - end - - assert_raises(TypeError) do - CommonMarker.render_doc([123]) - end - - assert_raises(TypeError) do - CommonMarker.render_doc(nil) - end - end - - def test_bad_set_string_content - assert_raises(TypeError) do - @doc.string_content = 123 - end end - def test_bad_walking - assert_nil(@doc.parent) - assert_nil(@doc.previous) - end - - def test_bad_insertion - code = Node.new(:code) - assert_raises(NodeError) do - @doc.insert_before(code) - end - - paragraph = Node.new(:paragraph) - assert_raises(NodeError) do - @doc.insert_after(paragraph) - end - - document = Node.new(:document) - assert_raises(NodeError) do - @doc.prepend_child(document) - end - - assert_raises(NodeError) do - @doc.append_child(document) - end - end - - def test_bad_url_get - assert_raises(NodeError) do - @doc.url - end - end - - def test_bad_url_set - assert_raises(NodeError) do - @doc.url = "123" - end - - link = CommonMarker.render_doc("[GitHub](https://www.github.com)").first_child.first_child - assert_raises(TypeError) do - link.url = 123 - end - end - - def test_bad_title_get - assert_raises(NodeError) do - @doc.title - end - end - - def test_bad_title_set - assert_raises(NodeError) do - @doc.title = "123" - end - - image = CommonMarker.render_doc('![alt text](https://github.com/favicon.ico "Favicon")') - image = image.first_child.first_child - assert_raises(TypeError) do - image.title = 123 - end - end - - def test_bad_header_level_get - assert_raises(NodeError) do - @doc.header_level - end - end - - def test_bad_header_level_set - assert_raises(NodeError) do - @doc.header_level = 1 - end - - header = CommonMarker.render_doc("### Header Three").first_child - assert_raises(TypeError) do - header.header_level = "123" - end - end - - def test_bad_list_type_get - assert_raises(NodeError) do - @doc.list_type - end - end - - def test_bad_list_type_set - assert_raises(NodeError) do - @doc.list_type = :bullet_list - end - - ul_list = CommonMarker.render_doc("* Bullet\n*Bullet").first_child - assert_raises(NodeError) do - ul_list.list_type = :fake - end - assert_raises(TypeError) do - ul_list.list_type = 1234 - end - end - - def test_bad_list_start_get - assert_raises(NodeError) do - @doc.list_start - end - end - - def test_bad_list_start_set - assert_raises(NodeError) do - @doc.list_start = 12 - end - - ol_list = CommonMarker.render_doc("1. One\n2. Two").first_child - assert_raises(TypeError) do - ol_list.list_start = :fake - end - end - - def test_bad_list_tight_get - assert_raises(NodeError) do - @doc.list_tight - end - end - - def test_bad_list_tight_set - assert_raises(NodeError) do - @doc.list_tight = false - end - end - - def test_bad_fence_info_get - assert_raises(NodeError) do - @doc.fence_info + def test_bad_options_value + err = assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: { parse: { smart: 111 }}) end + assert_equal("smart must be a FalseClass got a Number", err.message) end def test_bad_fence_info_set @@ -253,7 +55,7 @@ def test_bad_fence_info_set @doc.fence_info = "ruby" end - fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child + fence = Commonmarker.to_html("``` ruby\nputs 'wow'\n```").first_child assert_raises(TypeError) do fence.fence_info = 123 end diff --git a/test/test_node.rb b/test/test_node.rb deleted file mode 100644 index b21c4269..00000000 --- a/test/test_node.rb +++ /dev/null @@ -1,89 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestNode < Minitest::Test - def setup - @doc = CommonMarker.render_doc("Hi *there*, I am mostly text!") - end - - def test_walk - nodes = [] - @doc.walk do |node| - nodes << node.type - end - assert_equal([:document, :paragraph, :text, :emph, :text, :text], nodes) - end - - def test_each - nodes = [] - @doc.first_child.each do |node| - nodes << node.type - end - assert_equal([:text, :emph, :text], nodes) - end - - def test_deprecated_each_child - nodes = [] - _, err = capture_io do - @doc.first_child.each_child do |node| - nodes << node.type - end - end - assert_equal([:text, :emph, :text], nodes) - assert_match(/`each_child` is deprecated/, err) - end - - def test_select - nodes = @doc.first_child.select { |node| node.type == :text } - assert_equal(CommonMarker::Node, nodes.first.class) - assert_equal([:text, :text], nodes.map(&:type)) - end - - def test_map - nodes = @doc.first_child.map(&:type) - assert_equal([:text, :emph, :text], nodes) - end - - def test_insert_illegal - assert_raises(NodeError) do - @doc.insert_before(@doc) - end - end - - def test_to_html - assert_equal("<p>Hi <em>there</em>, I am mostly text!</p>\n", @doc.to_html) - end - - def test_html_renderer - renderer = HtmlRenderer.new - result = renderer.render(@doc) - assert_equal("<p>Hi <em>there</em>, I am mostly text!</p>\n", result) - end - - def test_walk_and_set_string_content - @doc.walk do |node| - node.string_content = "world" if node.type == :text && node.string_content == "there" - end - result = HtmlRenderer.new.render(@doc) - assert_equal("<p>Hi <em>world</em>, I am mostly text!</p>\n", result) - end - - def test_walk_and_delete_node - @doc.walk do |node| - if node.type == :emph - node.insert_before(node.first_child) - node.delete - end - end - assert_equal("<p>Hi there, I am mostly text!</p>\n", @doc.to_html) - end - - def test_inspect - assert_match(/#<CommonMarker::Node\(document\):/, @doc.inspect) - end - - def test_pretty_print - assert_match(/#<CommonMarker::Node\(document\):/, PP.pp(@doc, +"")) - end -end diff --git a/test/test_options.rb b/test/test_options.rb index 82e8151d..e7557d98 100644 --- a/test/test_options.rb +++ b/test/test_options.rb @@ -10,7 +10,7 @@ module Foo ``` MD - CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out| + Commonmarker.to_html(md, :FULL_INFO_STRING).tap do |out| assert_includes(out, '<pre><code class="language-ruby">') end @@ -20,7 +20,7 @@ module Foo ``` MD - CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out| + Commonmarker.to_html(md, :FULL_INFO_STRING).tap do |out| assert_includes(out, '<pre><code class="language-ruby" data-meta="my info string">') end @@ -30,7 +30,7 @@ module Foo ``` MD - CommonMarker.render_html(md, :FULL_INFO_STRING).tap do |out| + Commonmarker.to_html(md, :FULL_INFO_STRING).tap do |out| assert_includes(out, %(<pre><code class="language-ruby" data-meta="my � string">)) end end diff --git a/test/test_pathological_inputs.rb b/test/test_pathological_inputs.rb index eb8fca3e..7f247784 100644 --- a/test/test_pathological_inputs.rb +++ b/test/test_pathological_inputs.rb @@ -4,7 +4,7 @@ require "minitest/benchmark" if ENV["BENCH"] def markdown(str) - CommonMarker.render_doc(str).to_html + Commonmarker.to_html(str).to_html end # list of pairs consisting of input and a regex that must match the output. @@ -44,15 +44,15 @@ def markdown(str) Regexp.compile('abc\ufffd?de\ufffd?'),], } -pathological.each_pair do |name, description| - define_method("test_#{name}") do - input, = description - assert markdown(input) - end -end - if ENV["BENCH"] class PathologicalInputsPerformanceTest < Minitest::Benchmark + pathological.each_pair do |name, description| + define_method("test_#{name}") do + input, = description + assert markdown(input) + end + end + def test_bench_pathological_one assert_performance_linear(0.99) do |n| star = "*" * (n * 10) diff --git a/test/test_plaintext.rb b/test/test_plaintext.rb index 3ac425df..377da65c 100644 --- a/test/test_plaintext.rb +++ b/test/test_plaintext.rb @@ -21,7 +21,7 @@ def setup end def render_doc(doc) - CommonMarker.render_doc(doc, :DEFAULT, [:table]) + Commonmarker.to_html(doc, :DEFAULT, [:table]) end def test_to_commonmark diff --git a/test/test_renderer.rb b/test/test_renderer.rb index d3209a29..e2f69f45 100644 --- a/test/test_renderer.rb +++ b/test/test_renderer.rb @@ -3,16 +3,6 @@ require "test_helper" class TestRenderer < Minitest::Test - def setup - @doc = CommonMarker.render_doc("Hi *there*") - end - - def test_html_renderer - renderer = HtmlRenderer.new - result = renderer.render(@doc) - assert_equal("<p>Hi <em>there</em></p>\n", result) - end - def test_multiple_tables content = <<~DOC | Input | Expected | Actual | @@ -23,25 +13,8 @@ def test_multiple_tables | :------: | ---: | :------ | | Foo | Bar | Baz | DOC - doc = CommonMarker.render_doc(content, :DEFAULT, [:autolink, :table, :tagfilter]) + doc = Commonmarker.to_html(content, [:autolink, :table, :tagfilter]) results = CommonMarker::HtmlRenderer.new.render(doc) assert_equal(2, results.scan(/<tbody>/).size) end - - def test_escape_html_encoding - my_renderer = Class.new(HtmlRenderer) do - attr_reader :input_encoding, :output_encoding - - def text(node) - @input_encoding = node.string_content.encoding - escape_html(node.string_content).tap do |escaped| - @output_encoding = escaped.encoding - end - end - end - - renderer = my_renderer.new - assert_equal(Encoding::UTF_8, renderer.render(@doc).encoding) - assert_equal(renderer.input_encoding, renderer.output_encoding) - end end diff --git a/test/test_smartpunct.rb b/test/test_smartpunct.rb index c2e308ee..b523c873 100644 --- a/test/test_smartpunct.rb +++ b/test/test_smartpunct.rb @@ -3,25 +3,34 @@ require "test_helper" class SmartPunctTest < Minitest::Test - smart_punct = open_spec_file("smart_punct.txt") + smart_punct = load_spec_file("smart_punct.txt") smart_punct.each do |testcase| - doc = CommonMarker.render_doc(testcase[:markdown], :SMART) - html = CommonMarker.render_html(testcase[:markdown], :SMART) + opts = { + parse: { + smart: true, + }, + } define_method("test_smart_punct_example_#{testcase[:example]}") do - doc_rendered = doc.to_html.strip - html_rendered = html.strip + html = Commonmarker.to_html(testcase[:markdown], opts).strip - assert_equal testcase[:html], doc_rendered, testcase[:markdown] - assert_equal testcase[:html], html_rendered, testcase[:markdown] + assert_equal testcase[:html], html, testcase[:markdown] end end def test_smart_hardbreak_no_spaces_render_doc markdown = "\"foo\"\nbaz" result = "<p>“foo”<br />\nbaz</p>\n" - doc = CommonMarker.render_doc(markdown, :SMART) - assert_equal(result, doc.to_html([:HARDBREAKS])) + opts = { + parse: { + smart: true, + }, + render: { + hardbreaks: true, + }, + } + html = Commonmarker.commonmark_to_html(markdown, opts) + assert_equal(result, html) end end diff --git a/test/test_spec.rb b/test/test_spec.rb index 9ef865aa..f983ca68 100644 --- a/test/test_spec.rb +++ b/test/test_spec.rb @@ -4,27 +4,27 @@ require "json" class TestSpec < Minitest::Test - spec = open_spec_file("spec.txt") + spec = load_spec_file("spec.txt") spec.each do |testcase| - next if testcase[:extensions].include?(:disabled) - - doc = CommonMarker.render_doc(testcase[:markdown], :DEFAULT, testcase[:extensions]) - + html = Commonmarker.to_html(testcase[:markdown]) + focus define_method("test_to_html_example_#{testcase[:example]}") do - actual = doc.to_html(:UNSAFE, testcase[:extensions]).rstrip - assert_equal testcase[:html], actual, testcase[:markdown] - end + opts = { + render: { + unsafe_: true, + }, + extension: testcase[:extensions].each_with_object({}) do |ext, hash| + hash[ext] = true + end + } - define_method("test_html_renderer_example_#{testcase[:example]}") do - actual = HtmlRenderer.new(options: :UNSAFE, extensions: testcase[:extensions]).render(doc).rstrip + options = Commonmarker::Config.merged_with_defaults(opts) + options[:extension].delete(:header_ids) # this interefers with the spec.txt extension-less capability + actual = Commonmarker.to_html(testcase[:markdown].strip, options: options).rstrip + # debugger if actual != testcase[:html] + Commonmarker.to_html(testcase[:markdown].strip, options: options).rstrip assert_equal testcase[:html], actual, testcase[:markdown] end - - define_method("test_sourcepos_example_#{testcase[:example]}") do - lhs = doc.to_html([:UNSAFE, :SOURCEPOS], testcase[:extensions]).rstrip - rhs = HtmlRenderer.new(options: [:UNSAFE, :SOURCEPOS], extensions: testcase[:extensions]).render(doc).rstrip - assert_equal lhs, rhs, testcase[:markdown] - end end end diff --git a/test/test_tasklists.rb b/test/test_tasklists.rb index a135376a..c4202329 100644 --- a/test/test_tasklists.rb +++ b/test/test_tasklists.rb @@ -8,21 +8,18 @@ def setup - [x] Add task list - [ ] Define task list MD - @doc = CommonMarker.render_doc(text, :DEFAULT, [:tasklist]) + @html = Commonmarker.to_html(text, :DEFAULT, [:tasklist]) @expected = <<~HTML <ul> <li><input type="checkbox" checked="" disabled="" /> Add task list</li> <li><input type="checkbox" disabled="" /> Define task list</li> </ul> HTML + @doc = Nokogiri::HTML(@html) end def test_to_html - assert_equal(@expected, @doc.to_html) - end - - def test_html_renderer - assert_equal(@expected, CommonMarker::HtmlRenderer.new.render(@doc)) + assert_equal(@expected, @html) end def test_tasklist_state diff --git a/test/test_xml.rb b/test/test_xml.rb deleted file mode 100644 index 89848904..00000000 --- a/test/test_xml.rb +++ /dev/null @@ -1,107 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestXml < Minitest::Test - def setup - @markdown = <<~MD - Hi *there*! - - 1. I am a numeric list. - 2. I continue the list. - * Suddenly, an unordered list! - * What fun! - - Okay, _enough_. - - | a | b | - | --- | --- | - | c | d | - MD - end - - def render_doc(doc) - CommonMarker.render_doc(doc, :DEFAULT, [:table]) - end - - def test_to_xml - compare = render_doc(@markdown).to_xml(:SOURCEPOS) - - assert_equal(<<~XML, compare) - <?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE document SYSTEM "CommonMark.dtd"> - <document sourcepos="1:1-12:13" xmlns="http://commonmark.org/xml/1.0"> - <paragraph sourcepos="1:1-1:11"> - <text sourcepos="1:1-1:3" xml:space="preserve">Hi </text> - <emph sourcepos="1:4-1:10"> - <text sourcepos="1:5-1:9" xml:space="preserve">there</text> - </emph> - <text sourcepos="1:11-1:11" xml:space="preserve">!</text> - </paragraph> - <list sourcepos="3:1-4:23" type="ordered" start="1" delim="period" tight="true"> - <item sourcepos="3:1-3:23"> - <paragraph sourcepos="3:4-3:23"> - <text sourcepos="3:4-3:23" xml:space="preserve">I am a numeric list.</text> - </paragraph> - </item> - <item sourcepos="4:1-4:23"> - <paragraph sourcepos="4:4-4:23"> - <text sourcepos="4:4-4:23" xml:space="preserve">I continue the list.</text> - </paragraph> - </item> - </list> - <list sourcepos="5:1-7:0" type="bullet" tight="true"> - <item sourcepos="5:1-5:30"> - <paragraph sourcepos="5:3-5:30"> - <text sourcepos="5:3-5:30" xml:space="preserve">Suddenly, an unordered list!</text> - </paragraph> - </item> - <item sourcepos="6:1-7:0"> - <paragraph sourcepos="6:3-6:11"> - <text sourcepos="6:3-6:11" xml:space="preserve">What fun!</text> - </paragraph> - </item> - </list> - <paragraph sourcepos="8:1-8:15"> - <text sourcepos="8:1-8:6" xml:space="preserve">Okay, </text> - <emph sourcepos="8:7-8:14"> - <text sourcepos="8:8-8:13" xml:space="preserve">enough</text> - </emph> - <text sourcepos="8:15-8:15" xml:space="preserve">.</text> - </paragraph> - <table sourcepos="10:1-12:13"> - <table_header sourcepos="10:1-10:13"> - <table_cell sourcepos="10:2-10:6"> - <text sourcepos="10:3-10:3" xml:space="preserve">a</text> - </table_cell> - <table_cell sourcepos="10:8-10:12"> - <text sourcepos="10:9-10:9" xml:space="preserve">b</text> - </table_cell> - </table_header> - <table_row sourcepos="12:1-12:13"> - <table_cell sourcepos="12:2-12:6"> - <text sourcepos="12:3-12:3" xml:space="preserve">c</text> - </table_cell> - <table_cell sourcepos="12:8-12:12"> - <text sourcepos="12:9-12:9" xml:space="preserve">d</text> - </table_cell> - </table_row> - </table> - </document> - XML - end - - def test_to_xml_with_quotes - compare = render_doc('"quotes" should be escaped').to_xml(:DEFAULT) - - assert_equal(<<~XML, compare) - <?xml version="1.0" encoding="UTF-8"?> - <!DOCTYPE document SYSTEM "CommonMark.dtd"> - <document xmlns="http://commonmark.org/xml/1.0"> - <paragraph> - <text xml:space="preserve">&quot;quotes&quot; should be escaped</text> - </paragraph> - </document> - XML - end -end From 3bf9d87cab46fe46cc40c1c97dc8cf308d3a6755 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:07:16 -0400 Subject: [PATCH 04/14] Complete initial port :) --- bin/commonmarker | 118 - commonmarker.gemspec | 4 +- ext/commonmarker/commonmarker.c | 32 +- ext/commonmarker/extconf.rb | 10 +- lib/commonmarker.rb | 1 - lib/commonmarker/config.rb | 24 +- rakelib/compile.rake | 2 +- test/fixtures/upstream/spec.txt | 3676 +++++++++++++++++------------- test/test_basics.rb | 4 +- test/test_commands.rb | 72 - test/test_encoding.rb | 4 +- test/test_extensions.rb | 86 +- test/test_footnotes.rb | 11 +- test/test_format_commonmark.rb | 0 test/test_helper.rb | 2 + test/test_linebreaks.rb | 12 +- test/test_maliciousness.rb | 16 +- test/test_options.rb | 37 - test/test_pathological_inputs.rb | 138 +- test/test_plaintext.rb | 46 - test/test_renderer.rb | 20 - test/test_smartpunct.rb | 7 +- test/test_spec.rb | 10 +- test/test_tasklists.rb | 29 +- 24 files changed, 2224 insertions(+), 2137 deletions(-) delete mode 100755 bin/commonmarker delete mode 100644 test/test_commands.rb create mode 100644 test/test_format_commonmark.rb delete mode 100644 test/test_options.rb delete mode 100644 test/test_plaintext.rb delete mode 100644 test/test_renderer.rb diff --git a/bin/commonmarker b/bin/commonmarker deleted file mode 100755 index ebfbd220..00000000 --- a/bin/commonmarker +++ /dev/null @@ -1,118 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require 'optparse' - -$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib') -require 'commonmarker' - -root = File.expand_path('..', __dir__) -$LOAD_PATH.unshift File.expand_path('lib', root) - -def parse_options - options = Struct.new(:active_extensions, :active_parse_options, :active_render_options, :output_format, :renderer) - .new([], [:DEFAULT], [:DEFAULT], :html) - extension_options = CommonMarker::Config::OPTS.fetch(:extension) - parse_options = CommonMarker::Config::OPTS.fetch(:parse) - render_options = CommonMarker::Config::OPTS.fetch(:render) - format_options = CommonMarker::Config::OPTS.fetch(:format) - - option_parser = OptionParser.new do |opts| - opts.banner = 'Usage: commonmarker [--html-renderer] [--extension=EXTENSION]' - opts.separator ' [--to=FORMAT]' - opts.separator ' [--parse-option=OPTION]' - opts.separator ' [--render-option=OPTION]' - opts.separator ' [FILE..]' - opts.separator '' - opts.separator 'Convert one or more CommonMark files to HTML and write to standard output.' - opts.separator 'If no FILE argument is provided, text will be read from STDIN.' - opts.separator '' - - opts.on('--extension=EXTENSION', Array, 'Use EXTENSION for parsing and HTML output (unless --html-renderer is specified)') do |values| - values.each do |value| - if extensions.include?(value) - options.active_extensions << value.to_sym - else - abort("extension '#{value}' not found") - end - end - end - - opts.on('-h', '--help', 'Prints this help') do - puts opts - puts - puts "Available formats: #{format_options.join(', ')}" - puts "Available extentions: #{extensions.join(', ')}" - puts "Available parse options: #{parse_options.keys.join(', ')}" - puts "Available render options: #{render_options.keys.join(', ')}" - puts - puts 'See the README for more information on these.' - exit - end - - opts.on('-tFORMAT', '--to=FORMAT', String, 'Specify output FORMAT') do |value| - value = value.to_sym - if format_options.include?(value) - options.output_format = value - else - abort("format '#{value}' not found") - end - end - - opts.on('--html-renderer', 'Use the HtmlRenderer renderer rather than the native C renderer (only valid when format is html)') do - options.renderer = true - end - - opts.on('--parse-option=OPTION', Array, 'OPTION passed during parsing') do |values| - values.each do |value| - if parse_options.key?(value.to_sym) - options.active_parse_options << value.to_sym - else - abort("parse-option '#{value}' not found") - end - end - end - - opts.on('--render-option=OPTION', Array, 'OPTION passed during rendering') do |values| - values.each do |value| - if render_options.key?(value.to_sym) - options.active_render_options << value.to_sym - else - abort("render-option '#{value}' not found") - end - end - end - - opts.on('-v', '--version', 'Version information') do - puts "commonmarker #{CommonMarker::VERSION}" - exit - end - end - - option_parser.parse! - - options -end - -options = parse_options - -abort("format '#{options.output_format}' does not support using the HtmlRenderer renderer") if - options.renderer && options.output_format != :html - -doc = Commonmarker.to_html(ARGF.read, options.active_parse_options) - -case options.output_format -when :html - if options.renderer - renderer = CommonMarker::HtmlRenderer.new(options: options.active_render_options, extensions: options.active_extensions) - $stdout.write(renderer.render(doc)) - else - $stdout.write(doc.to_html(options.active_render_options, options.active_extensions)) - end -when :xml - $stdout.write(doc.to_xml(options.active_render_options)) -when :commonmark - $stdout.write(doc.to_commonmark(options.active_render_options)) -when :plaintext - $stdout.write(doc.to_plaintext(options.active_render_options)) -end diff --git a/commonmarker.gemspec b/commonmarker.gemspec index dba34d65..8c026317 100644 --- a/commonmarker.gemspec +++ b/commonmarker.gemspec @@ -13,12 +13,11 @@ Gem::Specification.new do |spec| spec.homepage = "https://github.com/gjtorikian/commonmarker" spec.license = "MIT" - spec.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec", "bin/commonmarker"] + spec.files = ["LICENSE.txt", "README.md", "Rakefile", "commonmarker.gemspec"] spec.files += Dir.glob("lib/**/*.rb") spec.files += Dir.glob("ext/commonmarker/*.*") spec.extensions = ["ext/commonmarker/extconf.rb"] - spec.executables = ["commonmarker"] spec.require_paths = ["lib", "ext"] spec.required_ruby_version = [">= 2.7", "< 4.0"] @@ -29,6 +28,7 @@ Gem::Specification.new do |spec| spec.add_development_dependency("json", "~> 2.3") spec.add_development_dependency("minitest", "~> 5.6") spec.add_development_dependency("minitest-focus", "~> 1.1") + spec.add_development_dependency("nokogiri", "~> 1.13") spec.add_development_dependency("rake") spec.add_development_dependency("rake-compiler", "~> 0.9") spec.add_development_dependency("rdoc", "~> 6.2") diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c index 9368b685..71509159 100644 --- a/ext/commonmarker/commonmarker.c +++ b/ext/commonmarker/commonmarker.c @@ -1,5 +1,7 @@ #include "ruby.h" + #include "commonmarker.h" + #include "comrak_ffi.h" int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { @@ -31,7 +33,6 @@ int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { Check_Type(val, T_STRING); comrak_set_extension_option_header_ids(config, StringValuePtr(val), RSTRING_LEN(val)); - } else if (key == ID2SYM(rb_intern("footnotes"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_extension_option_footnotes(config, val); @@ -45,6 +46,7 @@ int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { comrak_set_extension_option_front_matter_delimiter( config, StringValuePtr(val), RSTRING_LEN(val)); } + return ST_CONTINUE; } @@ -76,7 +78,7 @@ int iterate_render_options(VALUE key, VALUE val, comrak_options_t *config) { } int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { - if (key == ID2SYM(rb_intern("superscript"))) { + if (key == ID2SYM(rb_intern("smart"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_parse_option_smart(config, val); } @@ -90,19 +92,23 @@ int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_options_hash(VALUE key, VALUE val, comrak_options_t *config) { - Check_Type(key, T_SYMBOL); +int iterate_options_hash(VALUE rb_option_key, VALUE rb_option_val, comrak_options_t *config) { + Check_Type(rb_option_key, T_SYMBOL); // which options are we dealing with? - if (key == ID2SYM(rb_intern("parse"))) { - Check_Type(val, T_HASH); - rb_hash_foreach(val, iterate_parse_options, config); - } else if (key == ID2SYM(rb_intern("render"))) { - Check_Type(val, T_HASH); - rb_hash_foreach(val, iterate_render_options, config); - } else if (key == ID2SYM(rb_intern("extension"))) { - Check_Type(val, T_HASH); - rb_hash_foreach(val, iterate_extension_options, config); + if (rb_option_key == ID2SYM(rb_intern("parse"))) { + Check_Type(rb_option_val, T_HASH); + rb_hash_foreach(rb_option_val, iterate_parse_options, config); + } else if (rb_option_key == ID2SYM(rb_intern("render"))) { + Check_Type(rb_option_val, T_HASH); + rb_hash_foreach(rb_option_val, iterate_render_options, config); + } else if (rb_option_key == ID2SYM(rb_intern("extension"))) { + Check_Type(rb_option_val, T_HASH); + if (rb_hash_aref(rb_option_val, ID2SYM(rb_intern("header_ids"))) == Qnil) { + comrak_set_extension_option_header_ids(config, NULL, 0); + } + rb_hash_foreach(rb_option_val, iterate_extension_options, config); + } return ST_CONTINUE; diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index 799b84c5..db3939df 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -4,8 +4,6 @@ PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")) EXT_DIR = File.join(PACKAGE_ROOT_DIR, "ext", "commonmarker") CROSS_BUILD_P = enable_config("cross-build") -# COMRAK_VERSION = "0.14.0" -COMRAK_VERSION = "fix-missing-smart-option" RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] ENV["CC"] = RbConfig::CONFIG["CC"] @@ -17,8 +15,12 @@ def darwin? # what follows is pretty much an abuse of miniportile2, but it works for now # i just need something to download files and run a cargo build; one day this should # be replaced with actual prepacked binaries. -# TARBALL_URL = "https://github.com/kivikakk/comrak/archive/refs/tags/#{COMRAK_VERSION}.tar.gz" -TARBALL_URL = "https://github.com/kivikakk/comrak/archive/refs/heads/#{COMRAK_VERSION}.tar.gz" +USER = "kivikakk" +# COMRAK_VERSION = "0.14.0" +COMRAK_VERSION = "main" +# TARBALL_URL = "https://github.com/#{USER}/comrak/archive/refs/tags/#{COMRAK_VERSION}.tar.gz" +TARBALL_URL = "https://github.com/#{USER}/comrak/archive/refs/heads/#{COMRAK_VERSION}.tar.gz" + MiniPortile.new("comrak", COMRAK_VERSION).tap do |recipe| recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") recipe.files = [{ diff --git a/lib/commonmarker.rb b/lib/commonmarker.rb index 1168536d..93f73017 100755 --- a/lib/commonmarker.rb +++ b/lib/commonmarker.rb @@ -1,4 +1,3 @@ -#!/usr/bin/env ruby # frozen_string_literal: true begin diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index 3187752d..7ec8c3e0 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -47,19 +47,21 @@ def self.process_options(options) ["parse", "render", "extension"].each do |type| define_singleton_method :"process_#{type}_options" do |options| Commonmarker::Config::OPTS[type.to_sym].each_with_object({}) do |(key, value), hash| - hash[key] = value && next if options.nil? # option not provided, go for the default - - if options.nil? || options[key].nil? # option not provided, go for the defaul + if options.nil? # option not provided, go for the default hash[key] = value - else - value_klass = value.class - if value_klass.is_a?(TrueClass) || value_klass.is_a?(FalseClass) - hash[key] = value if BOOLS.include?(value) - else - raise TypeError, "#{type}_options[:#{key}] must be a #{value.class}; got a #{options[key].class}" unless value.is_a?(value.class) + next + end - hash[key] = options[key] - end + next if options[key].nil? + + value_klass = value.class + if BOOLS.include?(value) && BOOLS.include?(options[key]) + hash[key] = options[key] + elsif options[key].is_a?(value_klass) + hash[key] = options[key] + else + expected_type = BOOLS.include?(value) ? "Boolean" : value_klass.to_s + raise TypeError, "#{type}_options[:#{key}] must be a #{expected_type}; got #{options[key].class}" end end end diff --git a/rakelib/compile.rake b/rakelib/compile.rake index 2775a7f9..4742623d 100644 --- a/rakelib/compile.rake +++ b/rakelib/compile.rake @@ -39,7 +39,7 @@ namespace "gem" do end namespace platform do - # this runs in the rake-compiler-dock docker container + desc "builds gem within the rake-compiler-dock docker container" task "buildit" do # use Task#invoke because the pkg/*gem task is defined at runtime Rake::Task["native:#{platform}"].invoke diff --git a/test/fixtures/upstream/spec.txt b/test/fixtures/upstream/spec.txt index 80427610..73487aa4 100644 --- a/test/fixtures/upstream/spec.txt +++ b/test/fixtures/upstream/spec.txt @@ -1,13 +1,29 @@ --- -title: CommonMark Spec -author: John MacFarlane -version: 0.30 -date: '2021-06-19' +title: GitHub Flavored Markdown Spec +version: 0.29 +date: '2019-04-06' license: '[CC-BY-SA 4.0](http://creativecommons.org/licenses/by-sa/4.0/)' ... # Introduction +## What is GitHub Flavored Markdown? + +GitHub Flavored Markdown, often shortened as GFM, is the dialect of Markdown +that is currently supported for user content on GitHub.com and GitHub +Enterprise. + +This formal specification, based on the CommonMark Spec, defines the syntax and +semantics of this dialect. + +GFM is a strict superset of CommonMark. All the features which are supported in +GitHub user content and that are not specified on the original CommonMark Spec +are hence known as **extensions**, and highlighted as such. + +While GFM supports a wide range of inputs, it's worth noting that GitHub.com +and GitHub Enterprise perform additional post-processing and sanitization after +GFM is converted to HTML to ensure security and consistency of the website. + ## What is Markdown? Markdown is a plain text format for writing structured documents, @@ -270,16 +286,6 @@ 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. -Note that not every feature of the HTML samples is mandated by -the spec. For example, the spec says what counts as a link -destination, but it doesn't mandate that non-ASCII characters in -the URL be percent-encoded. To use the automatic tests, -implementers will need to provide a renderer that conforms to -the expectations of the spec examples (percent-encoding -non-ASCII characters in URLs). But a conforming implementation -can use a different renderer and may choose not to -percent-encode non-ASCII characters in URLs. - 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 @@ -304,47 +310,53 @@ 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 line feed (`U+000A`) or carriage return (`U+000D`), +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 line feed (`U+000A`), a carriage return -(`U+000D`) not followed by a line feed, or a carriage return and a -following line feed. +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`), -line feed (`U+000A`), form feed (`U+000C`), or carriage return (`U+000D`). +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 [tab](@) is `U+0009`. +[Unicode whitespace](@) is a sequence of one +or more [Unicode whitespace characters]. A [space](@) is `U+0020`. -An [ASCII control character](@) is a character between `U+0000–1F` (both -including) or `U+007F`. +A [non-whitespace character](@) is any character +that is not a [whitespace character]. An [ASCII punctuation character](@) is `!`, `"`, `#`, `$`, `%`, `&`, `'`, `(`, `)`, -`*`, `+`, `,`, `-`, `.`, `/` (U+0021–2F), +`*`, `+`, `,`, `-`, `.`, `/` (U+0021–2F), `:`, `;`, `<`, `=`, `>`, `?`, `@` (U+003A–0040), -`[`, `\`, `]`, `^`, `_`, `` ` `` (U+005B–0060), +`[`, `\`, `]`, `^`, `_`, `` ` `` (U+005B–0060), `{`, `|`, `}`, or `~` (U+007B–007E). -A [Unicode punctuation character](@) is an [ASCII +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 spaces help to define block structure, +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. @@ -482,1916 +494,1575 @@ bar For security reasons, the Unicode character `U+0000` must be replaced with the REPLACEMENT CHARACTER (`U+FFFD`). +# Blocks and inlines -## Backslash escapes +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. -Any ASCII punctuation character may be backslash-escaped: +## 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` . -<p>!&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[\]^_`{|}~</p> +<ul> +<li>`one</li> +<li>two`</li> +</ul> ```````````````````````````````` -Backslashes before other characters are treated as literal -backslashes: +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. -```````````````````````````````` example -\→\A\a\ \3\φ\« -. -<p>\→\A\a\ \3\φ\«</p> -```````````````````````````````` +## 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 -Escaped characters are treated as regular characters and do -not have their usual Markdown meanings: +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 -\*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> +<hr /> +<hr /> +<hr /> ```````````````````````````````` -If a backslash is itself escaped, the following character is not: +Wrong characters: ```````````````````````````````` example -\\*emphasis* ++++ . -<p>\<em>emphasis</em></p> +<p>+++</p> ```````````````````````````````` -A backslash at the end of the line is a [hard line break]: - ```````````````````````````````` example -foo\ -bar +=== . -<p>foo<br /> -bar</p> +<p>===</p> ```````````````````````````````` -Backslash escapes do not work in code blocks, code spans, autolinks, or -raw HTML: +Not enough characters: ```````````````````````````````` example -`` \[\` `` +-- +** +__ . -<p><code>\[\`</code></p> +<p>-- +** +__</p> ```````````````````````````````` +One to three spaces indent are allowed: + ```````````````````````````````` example - \[\] + *** + *** + *** . -<pre><code>\[\] -</code></pre> +<hr /> +<hr /> +<hr /> ```````````````````````````````` +Four spaces is too many: + ```````````````````````````````` example -~~~ -\[\] -~~~ + *** . -<pre><code>\[\] +<pre><code>*** </code></pre> ```````````````````````````````` ```````````````````````````````` example -<http://example.com?find=\*> +Foo + *** . -<p><a href="http://example.com?find=%5C*">http://example.com?find=\*</a></p> +<p>Foo +***</p> ```````````````````````````````` +More than three characters may be used: + ```````````````````````````````` example -<a href="/bar\/)"> +_____________________________________ . -<a href="/bar\/)"> +<hr /> ```````````````````````````````` -But they work in all other contexts, including URLs and link titles, -link references, and [info strings] in [fenced code blocks]: +Spaces are allowed between the characters: ```````````````````````````````` example -[foo](/bar\* "ti\*tle") + - - - . -<p><a href="/bar*" title="ti*tle">foo</a></p> +<hr /> ```````````````````````````````` ```````````````````````````````` example -[foo] - -[foo]: /bar\* "ti\*tle" + ** * ** * ** * ** . -<p><a href="/bar*" title="ti*tle">foo</a></p> +<hr /> ```````````````````````````````` ```````````````````````````````` example -``` foo\+bar -foo -``` +- - - - . -<pre><code class="language-foo+bar">foo -</code></pre> +<hr /> ```````````````````````````````` -## Entity and numeric character references +Spaces are allowed at the end: -Valid HTML entity references and numeric character references -can be used in place of the corresponding Unicode character, -with the following exceptions: +```````````````````````````````` example +- - - - +. +<hr /> +```````````````````````````````` -- 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. +However, no other characters may occur in the line: -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. +```````````````````````````````` example +_ _ _ _ a -[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. +a------ -```````````````````````````````` example -&nbsp; &amp; &copy; &AElig; &Dcaron; -&frac34; &HilbertSpace; &DifferentialD; -&ClockwiseContourIntegral; &ngE; +---a--- . -<p> &amp; © Æ Ď -¾ ℋ ⅆ -∲ ≧̸</p> +<p>_ _ _ _ a</p> +<p>a------</p> +<p>---a---</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`. +It is required that all of the [non-whitespace characters] be the same. +So, this is not a thematic break: ```````````````````````````````` example -&#35; &#1234; &#992; &#0; + *-* . -<p># Ӓ Ϡ �</p> +<p><em>-</em></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). +Thematic breaks do not need blank lines before or after: ```````````````````````````````` example -&#X22; &#XD06; &#xcab; +- foo +*** +- bar . -<p>&quot; ആ ಫ</p> +<ul> +<li>foo</li> +</ul> +<hr /> +<ul> +<li>bar</li> +</ul> ```````````````````````````````` -Here are some nonentities: +Thematic breaks can interrupt a paragraph: ```````````````````````````````` example -&nbsp &x; &#; &#x; -&#87654321; -&#abcdef0; -&ThisIsNotDefined; &hi?; +Foo +*** +bar . -<p>&amp;nbsp &amp;x; &amp;#; &amp;#x; -&amp;#87654321; -&amp;#abcdef0; -&amp;ThisIsNotDefined; &amp;hi?;</p> +<p>Foo</p> +<hr /> +<p>bar</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: +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 -&copy +Foo +--- +bar . -<p>&amp;copy</p> +<h2>Foo</h2> +<p>bar</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]: +When both a thematic break and a list item are possible +interpretations of a line, the thematic break takes precedence: ```````````````````````````````` example -<a href="&ouml;&ouml;.html"> +* Foo +* * * +* Bar . -<a href="&ouml;&ouml;.html"> +<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](/f&ouml;&ouml; "f&ouml;&ouml;") +- Foo +- * * * . -<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p> +<ul> +<li>Foo</li> +<li> +<hr /> +</li> +</ul> ```````````````````````````````` -```````````````````````````````` example -[foo] +## ATX headings -[foo]: /f&ouml;&ouml; "f&ouml;&ouml;" -. -<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p> -```````````````````````````````` +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 -``` f&ouml;&ouml; -foo -``` +# foo +## foo +### foo +#### foo +##### foo +###### foo . -<pre><code class="language-föö">foo -</code></pre> +<h1>foo</h1> +<h2>foo</h2> +<h3>foo</h3> +<h4>foo</h4> +<h5>foo</h5> +<h6>foo</h6> ```````````````````````````````` -Entity and numeric character references are treated as literal -text in code spans and code blocks: +More than six `#` characters is not a heading: ```````````````````````````````` example -`f&ouml;&ouml;` +####### foo . -<p><code>f&amp;ouml;&amp;ouml;</code></p> +<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 - f&ouml;f&ouml; +#5 bolt + +#hashtag . -<pre><code>f&amp;ouml;f&amp;ouml; -</code></pre> +<p>#5 bolt</p> +<p>#hashtag</p> ```````````````````````````````` -Entity and numeric character references cannot be used -in place of symbols indicating structure in CommonMark -documents. +This is not a heading, because the first `#` is escaped: ```````````````````````````````` example -&#42;foo&#42; -*foo* +\## foo . -<p>*foo* -<em>foo</em></p> +<p>## foo</p> ```````````````````````````````` -```````````````````````````````` example -&#42; foo -* foo -. -<p>* foo</p> -<ul> -<li>foo</li> -</ul> -```````````````````````````````` +Contents are parsed as inlines: ```````````````````````````````` example -foo&#10;&#10;bar +# foo *bar* \*baz\* . -<p>foo - -bar</p> +<h1>foo <em>bar</em> *baz*</h1> ```````````````````````````````` -```````````````````````````````` example -&#9;foo -. -<p>→foo</p> -```````````````````````````````` +Leading and trailing [whitespace] is ignored in parsing inline content: ```````````````````````````````` example -[a](url &quot;tit&quot;) +# foo . -<p>[a](url &quot;tit&quot;)</p> +<h1>foo</h1> ```````````````````````````````` - -# 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: +One to three spaces indentation are allowed: ```````````````````````````````` example -- `one -- two` + ### foo + ## foo + # foo . -<ul> -<li>`one</li> -<li>two`</li> -</ul> +<h3>foo</h3> +<h2>foo</h2> +<h1>foo</h1> ```````````````````````````````` -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](#container-blocks), -which can contain other blocks, and [leaf blocks](#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 optionally up to three 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](@). +Four spaces are too much: ```````````````````````````````` example -*** ---- -___ + # foo . -<hr /> -<hr /> -<hr /> +<pre><code># foo +</code></pre> ```````````````````````````````` -Wrong characters: - ```````````````````````````````` example -+++ +foo + # bar . -<p>+++</p> +<p>foo +# bar</p> ```````````````````````````````` +A closing sequence of `#` characters is optional: + ```````````````````````````````` example -=== +## foo ## + ### bar ### . -<p>===</p> +<h2>foo</h2> +<h3>bar</h3> ```````````````````````````````` -Not enough characters: +It need not be the same length as the opening sequence: ```````````````````````````````` example --- -** -__ +# foo ################################## +##### foo ## . -<p>-- -** -__</p> +<h1>foo</h1> +<h5>foo</h5> ```````````````````````````````` -Up to three spaces of indentation are allowed: +Spaces are allowed after the closing sequence: ```````````````````````````````` example - *** - *** - *** +### foo ### . -<hr /> -<hr /> -<hr /> +<h3>foo</h3> ```````````````````````````````` -Four spaces of indentation is too many: +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 . -<pre><code>*** -</code></pre> +<h3>foo ### b</h3> ```````````````````````````````` +The closing sequence must be preceded by a space: + ```````````````````````````````` example -Foo - *** +# foo# . -<p>Foo -***</p> +<h1>foo#</h1> ```````````````````````````````` -More than three characters may be used: +Backslash-escaped `#` characters do not count as part +of the closing sequence: ```````````````````````````````` example -_____________________________________ +### foo \### +## foo #\## +# foo \# . -<hr /> +<h3>foo ###</h3> +<h2>foo ###</h2> +<h1>foo #</h1> ```````````````````````````````` -Spaces and tabs are allowed between the characters: +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 . -<hr /> +<p>Foo bar</p> +<h1>baz</h1> +<p>Bar foo</p> ```````````````````````````````` -```````````````````````````````` example -- - - - -. -<hr /> -```````````````````````````````` - - -Spaces and tabs are allowed at the end: +ATX headings can be empty: ```````````````````````````````` example -- - - - +## +# +### ### . -<hr /> +<h2></h2> +<h1></h1> +<h3></h3> ```````````````````````````````` -However, no other characters may occur in the line: +## Setext headings -```````````````````````````````` example -_ _ _ _ a +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------ +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]. ----a--- -. -<p>_ _ _ _ a</p> -<p>a------</p> -<p>---a---</p> -```````````````````````````````` +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. -It is required that all of the characters other than spaces or tabs be the same. -So, this is not a thematic break: +Simple examples: ```````````````````````````````` example - *-* +Foo *bar* +========= + +Foo *bar* +--------- . -<p><em>-</em></p> +<h1>Foo <em>bar</em></h1> +<h2>Foo <em>bar</em></h2> ```````````````````````````````` -Thematic breaks do not need blank lines before or after: +The content of the header may span more than one line: ```````````````````````````````` example -- foo -*** -- bar +Foo *bar +baz* +==== . -<ul> -<li>foo</li> -</ul> -<hr /> -<ul> -<li>bar</li> -</ul> +<h1>Foo <em>bar +baz</em></h1> ```````````````````````````````` - -Thematic breaks can interrupt a paragraph: +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 + Foo *bar +baz*→ +==== . -<p>Foo</p> -<hr /> -<p>bar</p> +<h1>Foo <em>bar +baz</em></h1> ```````````````````````````````` -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: +The underlining can be any length: ```````````````````````````````` example Foo ---- -bar +------------------------- + +Foo += . <h2>Foo</h2> -<p>bar</p> +<h1>Foo</h1> ```````````````````````````````` -When both a thematic break and a list item are possible -interpretations of a line, the thematic break takes precedence: +The heading content can be indented up to three spaces, and need +not line up with the underlining: ```````````````````````````````` example -* Foo -* * * -* Bar + Foo +--- + + Foo +----- + + Foo + === . -<ul> -<li>Foo</li> -</ul> -<hr /> -<ul> -<li>Bar</li> -</ul> +<h2>Foo</h2> +<h2>Foo</h2> +<h1>Foo</h1> ```````````````````````````````` -If you want a thematic break in a list item, use a different bullet: +Four spaces indent is too much: ```````````````````````````````` example -- Foo -- * * * + Foo + --- + + Foo +--- . -<ul> -<li>Foo</li> -<li> +<pre><code>Foo +--- + +Foo +</code></pre> <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 spaces or tabs, or -by the end of line. The optional closing sequence of `#`s must be preceded by -spaces or tabs and may be followed by spaces or tabs only. The opening -`#` character may be preceded by up to three spaces of indentation. The raw -contents of the heading are stripped of leading and trailing space or tabs -before being parsed as inline content. The heading level is equal to the number -of `#` characters in the opening sequence. - -Simple headings: +The setext heading underline can be indented up to three spaces, and +may have trailing spaces: ```````````````````````````````` example -# foo -## foo -### foo -#### foo -##### foo -###### foo +Foo + ---- . -<h1>foo</h1> -<h2>foo</h2> -<h3>foo</h3> -<h4>foo</h4> -<h5>foo</h5> -<h6>foo</h6> +<h2>Foo</h2> ```````````````````````````````` -More than six `#` characters is not a heading: +Four spaces is too much: ```````````````````````````````` example -####### foo +Foo + --- . -<p>####### foo</p> +<p>Foo +---</p> ```````````````````````````````` -At least one space or tab 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: +The setext heading underline cannot contain internal spaces: ```````````````````````````````` example -#5 bolt +Foo += = -#hashtag +Foo +--- - . -<p>#5 bolt</p> -<p>#hashtag</p> +<p>Foo += =</p> +<p>Foo</p> +<hr /> ```````````````````````````````` -This is not a heading, because the first `#` is escaped: +Trailing spaces in the content line do not cause a line break: ```````````````````````````````` example -\## foo +Foo +----- . -<p>## foo</p> +<h2>Foo</h2> ```````````````````````````````` -Contents are parsed as inlines: +Nor does a backslash at the end: ```````````````````````````````` example -# foo *bar* \*baz\* +Foo\ +---- . -<h1>foo <em>bar</em> *baz*</h1> +<h2>Foo\</h2> ```````````````````````````````` -Leading and trailing spaces or tabs are ignored in parsing inline content: +Since indicators of block structure take precedence over +indicators of inline structure, the following are setext headings: ```````````````````````````````` example -# foo +`Foo +---- +` + +<a title="a lot +--- +of dashes"/> . -<h1>foo</h1> +<h2>`Foo</h2> +<p>`</p> +<h2>&lt;a title=&quot;a lot</h2> +<p>of dashes&quot;/&gt;</p> ```````````````````````````````` -Up to three spaces of indentation are allowed: +The setext heading underline cannot be a [lazy continuation +line] in a list item or block quote: ```````````````````````````````` example - ### foo - ## foo - # foo +> Foo +--- . -<h3>foo</h3> -<h2>foo</h2> -<h1>foo</h1> +<blockquote> +<p>Foo</p> +</blockquote> +<hr /> ```````````````````````````````` -Four spaces of indentation is too many: - ```````````````````````````````` example - # foo +> foo +bar +=== . -<pre><code># foo -</code></pre> +<blockquote> +<p>foo +bar +===</p> +</blockquote> ```````````````````````````````` ```````````````````````````````` example -foo - # bar +- Foo +--- . -<p>foo -# bar</p> +<ul> +<li>Foo</li> +</ul> +<hr /> ```````````````````````````````` -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: +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 ################################## -##### foo ## +Foo +Bar +--- . -<h1>foo</h1> -<h5>foo</h5> +<h2>Foo +Bar</h2> ```````````````````````````````` -Spaces or tabs are allowed after the closing sequence: +But in general a blank line is not required before or after +setext headings: ```````````````````````````````` example -### foo ### +--- +Foo +--- +Bar +--- +Baz . -<h3>foo</h3> +<hr /> +<h2>Foo</h2> +<h2>Bar</h2> +<p>Baz</p> ```````````````````````````````` -A sequence of `#` characters with anything but spaces or tabs following it -is not a closing sequence, but counts as part of the contents of the -heading: +Setext headings cannot be empty: ```````````````````````````````` example -### foo ### b + +==== . -<h3>foo ### b</h3> +<p>====</p> ```````````````````````````````` -The closing sequence must be preceded by a space or tab: +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 -# foo# +--- +--- . -<h1>foo#</h1> +<hr /> +<hr /> ```````````````````````````````` -Backslash-escaped `#` characters do not count as part -of the closing sequence: - ```````````````````````````````` example -### foo \### -## foo #\## -# foo \# +- foo +----- . -<h3>foo ###</h3> -<h2>foo ###</h2> -<h1>foo #</h1> +<ul> +<li>foo</li> +</ul> +<hr /> ```````````````````````````````` -ATX headings need not be separated from surrounding content by blank -lines, and they can interrupt paragraphs: - ```````````````````````````````` example -**** -## foo -**** + foo +--- . -<hr /> -<h2>foo</h2> +<pre><code>foo +</code></pre> <hr /> ```````````````````````````````` ```````````````````````````````` example -Foo bar -# baz -Bar foo +> foo +----- . -<p>Foo bar</p> -<h1>baz</h1> -<p>Bar foo</p> +<blockquote> +<p>foo</p> +</blockquote> +<hr /> ```````````````````````````````` -ATX headings can be empty: +If you want a heading with `> foo` as its literal text, you can +use backslash escapes: ```````````````````````````````` example -## -# -### ### +\> foo +------ . -<h2></h2> -<h1></h1> -<h3></h3> +<h2>&gt; foo</h2> ```````````````````````````````` -## Setext headings - -A [setext heading](@) consists of one or more -lines of text, not interrupted by a blank line, of which the first line does not -have more than 3 spaces of 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]. +**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 -A [setext heading underline](@) is a sequence of -`=` characters or a sequence of `-` characters, with no more than 3 -spaces of indentation and any number of trailing spaces or tabs. 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]. +``` markdown +Foo +bar +--- +baz +``` -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. +One can find four different interpretations: -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. +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" -Simple examples: +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* -========= +Foo -Foo *bar* ---------- +bar +--- +baz . -<h1>Foo <em>bar</em></h1> -<h2>Foo <em>bar</em></h2> +<p>Foo</p> +<h2>bar</h2> +<p>baz</p> ```````````````````````````````` -The content of the header may span more than one line: +Authors who want interpretation 2 can put blank lines around +the thematic break, ```````````````````````````````` example -Foo *bar -baz* -==== -. -<h1>Foo <em>bar -baz</em></h1> -```````````````````````````````` +Foo +bar -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 -spaces or tabs. +--- -```````````````````````````````` example - Foo *bar -baz*→ -==== +baz . -<h1>Foo <em>bar -baz</em></h1> +<p>Foo +bar</p> +<hr /> +<p>baz</p> ```````````````````````````````` -The underlining can be any length: +or use a thematic break that cannot count as a [setext heading +underline], such as ```````````````````````````````` example Foo -------------------------- - -Foo -= +bar +* * * +baz . -<h2>Foo</h2> -<h1>Foo</h1> +<p>Foo +bar</p> +<hr /> +<p>baz</p> ```````````````````````````````` -The heading content can be preceded by up to three spaces of indentation, and -need not line up with the underlining: +Authors who want interpretation 3 can use backslash escapes: ```````````````````````````````` example - Foo +Foo +bar +\--- +baz +. +<p>Foo +bar --- +baz</p> +```````````````````````````````` - Foo ------ - Foo - === -. -<h2>Foo</h2> -<h2>Foo</h2> -<h1>Foo</h1> -```````````````````````````````` +## 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]. -Four spaces of indentation is too many: +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 - Foo - --- - - Foo ---- + a simple + indented code block . -<pre><code>Foo ---- - -Foo +<pre><code>a simple + indented code block </code></pre> -<hr /> ```````````````````````````````` -The setext heading underline can be preceded by up to three spaces of -indentation, and may have trailing spaces or tabs: +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 - ---- -. -<h2>Foo</h2> -```````````````````````````````` - - -Four spaces of indentation is too many: + - foo -```````````````````````````````` example -Foo - --- + bar . -<p>Foo ----</p> +<ul> +<li> +<p>foo</p> +<p>bar</p> +</li> +</ul> ```````````````````````````````` -The setext heading underline cannot contain internal spaces or tabs: - ```````````````````````````````` example -Foo -= = +1. foo -Foo ---- - + - bar . -<p>Foo -= =</p> -<p>Foo</p> -<hr /> +<ol> +<li> +<p>foo</p> +<ul> +<li>bar</li> +</ul> +</li> +</ol> ```````````````````````````````` -Trailing spaces or tabs in the content line do not cause a hard line break: + +The contents of a code block are literal text, and do not get parsed +as Markdown: ```````````````````````````````` example -Foo ------ + <a/> + *hi* + + - one . -<h2>Foo</h2> +<pre><code>&lt;a/&gt; +*hi* + +- one +</code></pre> ```````````````````````````````` -Nor does a backslash at the end: +Here we have three chunks separated by blank lines: ```````````````````````````````` example -Foo\ ----- + chunk1 + + chunk2 + + + + chunk3 . -<h2>Foo\</h2> -```````````````````````````````` +<pre><code>chunk1 +chunk2 -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> +chunk3 +</code></pre> ```````````````````````````````` -The setext heading underline cannot be a [lazy continuation -line] in a list item or block quote: +Any initial spaces beyond four will be included in the content, even +in interior blank lines: ```````````````````````````````` example -> Foo ---- + chunk1 + + chunk2 . -<blockquote> -<p>Foo</p> -</blockquote> -<hr /> +<pre><code>chunk1 + + chunk2 +</code></pre> ```````````````````````````````` +An indented code block cannot interrupt a paragraph. (This +allows hanging indents and the like.) + ```````````````````````````````` example -> foo -bar -=== +Foo + bar + . -<blockquote> -<p>foo -bar -===</p> -</blockquote> +<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 ---- + foo +bar . -<ul> -<li>Foo</li> -</ul> -<hr /> +<pre><code>foo +</code></pre> +<p>bar</p> ```````````````````````````````` -A blank line is needed between a paragraph and a following -setext heading, since otherwise the paragraph becomes part -of the heading's content: +And indented code can occur immediately before and after other kinds of +blocks: ```````````````````````````````` example -Foo -Bar ---- +# Heading + foo +Heading +------ + foo +---- . -<h2>Foo -Bar</h2> +<h1>Heading</h1> +<pre><code>foo +</code></pre> +<h2>Heading</h2> +<pre><code>foo +</code></pre> +<hr /> ```````````````````````````````` -But in general a blank line is not required before or after -setext headings: +The first line can be indented more than four spaces: ```````````````````````````````` example ---- -Foo ---- -Bar ---- -Baz + foo + bar . -<hr /> -<h2>Foo</h2> -<h2>Bar</h2> -<p>Baz</p> +<pre><code> foo +bar +</code></pre> ```````````````````````````````` -Setext headings cannot be empty: +Blank lines preceding or following an indented code block +are not included in it: ```````````````````````````````` example -==== + + foo + + . -<p>====</p> +<pre><code>foo +</code></pre> ```````````````````````````````` -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: +Trailing spaces are included in the code block's content: ```````````````````````````````` example ---- ---- + foo . -<hr /> -<hr /> +<pre><code>foo +</code></pre> ```````````````````````````````` -```````````````````````````````` example -- foo ------ -. -<ul> -<li>foo</li> -</ul> -<hr /> -```````````````````````````````` +## 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 - foo ---- +``` +< + > +``` . -<pre><code>foo +<pre><code>&lt; + &gt; </code></pre> -<hr /> ```````````````````````````````` +With tildes: + ```````````````````````````````` example -> foo ------ +~~~ +< + > +~~~ . -<blockquote> -<p>foo</p> -</blockquote> -<hr /> +<pre><code>&lt; + &gt; +</code></pre> ```````````````````````````````` - -If you want a heading with `> foo` as its literal text, you can -use backslash escapes: +Fewer than three backticks is not enough: ```````````````````````````````` example -\> foo ------- +`` +foo +`` . -<h2>&gt; foo</h2> +<p><code>foo</code></p> ```````````````````````````````` - -**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: +The closing code fence must use the same character as the opening +fence: ```````````````````````````````` example -Foo - -bar ---- -baz +``` +aaa +~~~ +``` . -<p>Foo</p> -<h2>bar</h2> -<p>baz</p> +<pre><code>aaa +~~~ +</code></pre> ```````````````````````````````` -Authors who want interpretation 2 can put blank lines around -the thematic break, - ```````````````````````````````` example -Foo -bar - ---- - -baz +~~~ +aaa +``` +~~~ . -<p>Foo -bar</p> -<hr /> -<p>baz</p> +<pre><code>aaa +``` +</code></pre> ```````````````````````````````` -or use a thematic break that cannot count as a [setext heading -underline], such as +The closing code fence must be at least as long as the opening fence: ```````````````````````````````` example -Foo -bar -* * * -baz +```` +aaa +``` +`````` . -<p>Foo -bar</p> -<hr /> -<p>baz</p> +<pre><code>aaa +``` +</code></pre> ```````````````````````````````` -Authors who want interpretation 3 can use backslash escapes: - ```````````````````````````````` example -Foo -bar -\--- -baz +~~~~ +aaa +~~~ +~~~~ . -<p>Foo -bar ---- -baz</p> +<pre><code>aaa +~~~ +</code></pre> ```````````````````````````````` -## 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 preceded by four or more spaces of indentation. 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.) +Unclosed code blocks are closed by the end of the document +(or the enclosing [block quote][block quotes] or [list item][list items]): ```````````````````````````````` example - a simple - indented code block +``` . -<pre><code>a simple - indented code block -</code></pre> +<pre><code></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 +``` +aaa . -<ul> -<li> -<p>foo</p> -<p>bar</p> -</li> -</ul> +<pre><code> +``` +aaa +</code></pre> ```````````````````````````````` ```````````````````````````````` example -1. foo +> ``` +> aaa - - bar +bbb . -<ol> -<li> -<p>foo</p> -<ul> -<li>bar</li> -</ul> -</li> -</ol> +<blockquote> +<pre><code>aaa +</code></pre> +</blockquote> +<p>bbb</p> ```````````````````````````````` - -The contents of a code block are literal text, and do not get parsed -as Markdown: +A code block can have all empty lines as its content: ```````````````````````````````` example - <a/> - *hi* +``` - - one + +``` . -<pre><code>&lt;a/&gt; -*hi* - -- one +<pre><code> + </code></pre> ```````````````````````````````` -Here we have three chunks separated by blank lines: +A code block can be empty: ```````````````````````````````` example - chunk1 - - chunk2 - - - - chunk3 +``` +``` . -<pre><code>chunk1 - -chunk2 +<pre><code></code></pre> +```````````````````````````````` +Fences can be indented. If the opening fence is indented, +content lines will have equivalent opening indentation removed, +if present: -chunk3 +```````````````````````````````` example + ``` + aaa +aaa +``` +. +<pre><code>aaa +aaa </code></pre> ```````````````````````````````` -Any initial spaces or tabs beyond four spaces of indentation will be included in -the content, even in interior blank lines: - ```````````````````````````````` example - chunk1 - - chunk2 + ``` +aaa + aaa +aaa + ``` . -<pre><code>chunk1 - - chunk2 +<pre><code>aaa +aaa +aaa </code></pre> ```````````````````````````````` -An indented code block cannot interrupt a paragraph. (This -allows hanging indents and the like.) - ```````````````````````````````` example -Foo - bar - + ``` + aaa + aaa + aaa + ``` . -<p>Foo -bar</p> +<pre><code>aaa + aaa +aaa +</code></pre> ```````````````````````````````` -However, any non-blank line with fewer than four spaces of indentation ends -the code block immediately. So a paragraph may occur immediately -after indented code: +Four spaces indentation produces an indented code block: ```````````````````````````````` example - foo -bar + ``` + aaa + ``` . -<pre><code>foo +<pre><code>``` +aaa +``` </code></pre> -<p>bar</p> ```````````````````````````````` -And indented code can occur immediately before and after other kinds of -blocks: +Closing fences may be indented by 0-3 spaces, and their indentation +need not match that of the opening fence: ```````````````````````````````` example -# Heading - foo -Heading ------- - foo ----- +``` +aaa + ``` . -<h1>Heading</h1> -<pre><code>foo -</code></pre> -<h2>Heading</h2> -<pre><code>foo +<pre><code>aaa </code></pre> -<hr /> ```````````````````````````````` -The first line can be preceded by more than four spaces of indentation: - ```````````````````````````````` 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 - - + ``` +aaa + ``` . -<pre><code>foo +<pre><code>aaa </code></pre> ```````````````````````````````` -Trailing spaces or tabs are included in the code block's content: +This is not a closing fence, because it is indented 4 spaces: ```````````````````````````````` example - foo +``` +aaa + ``` . -<pre><code>foo +<pre><code>aaa + ``` </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, preceded by up to three spaces of indentation. - -The line with the opening code fence may optionally contain some text -following the code fence; this is trimmed of leading and trailing -spaces or tabs 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 -preceded by N spaces of indentation, 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 N spaces or less, all -of the indentation is removed.) - -The closing code fence may be preceded by up to three spaces of indentation, and -may be followed only by spaces or tabs, 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: +Code fences (opening and closing) cannot contain internal spaces: ```````````````````````````````` example -``` -< - > -``` +``` ``` +aaa . -<pre><code>&lt; - &gt; -</code></pre> +<p><code> </code> +aaa</p> ```````````````````````````````` -With tildes: - ```````````````````````````````` example -~~~ -< - > -~~~ +~~~~~~ +aaa +~~~ ~~ . -<pre><code>&lt; - &gt; +<pre><code>aaa +~~~ ~~ </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: +Fenced code blocks can interrupt paragraphs, and can be followed +directly by paragraphs, without a blank line between: ```````````````````````````````` example +foo ``` -aaa -~~~ +bar ``` +baz . -<pre><code>aaa -~~~ +<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 +--- ~~~ -aaa -``` +bar ~~~ +# baz . -<pre><code>aaa -``` +<h2>foo</h2> +<pre><code>bar </code></pre> +<h1>baz</h1> ```````````````````````````````` -The closing code fence must be at least as long as the opening fence: +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 -```` -aaa +```ruby +def foo(x) + return 3 +end ``` -`````` . -<pre><code>aaa -``` +<pre><code class="language-ruby">def foo(x) + return 3 +end </code></pre> ```````````````````````````````` ```````````````````````````````` example -~~~~ -aaa -~~~ -~~~~ +~~~~ ruby startline=3 $%@#$ +def foo(x) + return 3 +end +~~~~~~~ . -<pre><code>aaa -~~~ +<pre><code class="language-ruby">def foo(x) + return 3 +end </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> +<pre><code class="language-;"></code></pre> ```````````````````````````````` -```````````````````````````````` example -````` +[Info strings] for backtick code blocks cannot contain backticks: -``` -aaa +```````````````````````````````` example +``` aa ``` +foo . -<pre><code> -``` -aaa -</code></pre> +<p><code>aa</code> +foo</p> ```````````````````````````````` -```````````````````````````````` example -> ``` -> aaa +[Info strings] for tilde code blocks can contain backticks and tildes: -bbb +```````````````````````````````` example +~~~ aa ``` ~~~ +foo +~~~ . -<blockquote> -<pre><code>aaa +<pre><code class="language-aa">foo </code></pre> -</blockquote> -<p>bbb</p> ```````````````````````````````` -A code block can have all empty lines as its content: +Closing code fences cannot have [info strings]: ```````````````````````````````` example ``` - - +``` aaa ``` . -<pre><code> - +<pre><code>``` aaa </code></pre> ```````````````````````````````` -A code block can be empty: -```````````````````````````````` example -``` -``` -. -<pre><code></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). -Fences can be indented. If the opening fence is indented, -content lines will have equivalent opening indentation removed, -if present: +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. -```````````````````````````````` example - ``` - aaa -aaa -``` -. -<pre><code>aaa -aaa -</code></pre> -```````````````````````````````` +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 `-->`. -```````````````````````````````` example - ``` -aaa - aaa -aaa - ``` -. -<pre><code>aaa -aaa -aaa -</code></pre> -```````````````````````````````` +3. **Start condition:** line begins with the string `<?`.\ +**End condition:** line contains the string `?>`. - -```````````````````````````````` example - ``` - aaa - aaa - aaa - ``` -. -<pre><code>aaa - aaa -aaa -</code></pre> -```````````````````````````````` - - -Four spaces of indentation is too many: - -```````````````````````````````` example - ``` - aaa - ``` -. -<pre><code>``` -aaa -``` -</code></pre> -```````````````````````````````` - - -Closing fences may be preceded by up to three spaces of indentation, 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 or tabs: - -```````````````````````````````` 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 optional spaces of 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 `<pre`, -`<script`, `<style`, or `<textarea` (case-insensitive), followed by a space, -a tab, the string `>`, or the end of the line.\ -**End condition:** line contains an end tag -`</pre>`, `</script>`, `</style>`, or `</textarea>` (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 `>`. +4. **Start condition:** line begins with the string `<!` +followed by an uppercase ASCII letter.\ +**End condition:** line contains the character `>`. 5. **Start condition:** line begins with the string `<![CDATA[`.\ @@ -2408,14 +2079,14 @@ followed by one of the strings (case-insensitive) `address`, `nav`, `noframes`, `ol`, `optgroup`, `option`, `p`, `param`, `section`, `source`, `summary`, `table`, `tbody`, `td`, `tfoot`, `th`, `thead`, `title`, `tr`, `track`, `ul`, followed -by a space, a tab, the end of the line, the string `>`, or +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 `pre`, `script`, -`style`, or `textarea`) or a complete [closing tag], -followed by zero or more spaces and tabs, followed by the end of the line.\ +(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 @@ -2425,7 +2096,7 @@ 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 an HTML block started by `<table>` will not affect +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: @@ -2446,7 +2117,7 @@ _world_. </td></tr></table> ```````````````````````````````` -In this case, the HTML block is terminated by the blank line — the `**Hello**` +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. @@ -2724,7 +2395,7 @@ rather than an [HTML block].) HTML tags designed to contain literal content -(`pre`, `script`, `style`, `textarea`), comments, processing instructions, +(`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. @@ -2770,26 +2441,6 @@ document.getElementById("demo").innerHTML = "Hello JavaScript!"; ```````````````````````````````` -A textarea tag (type 1): - -```````````````````````````````` example -<textarea> - -*foo* - -_bar_ - -</textarea> -. -<textarea> - -*foo* - -_bar_ - -</textarea> -```````````````````````````````` - A style tag (type 1): ```````````````````````````````` example @@ -2968,8 +2619,7 @@ function matchwo(a,b) ```````````````````````````````` -The opening tag can be preceded by up to three spaces of indentation, but not -four: +The opening tag can be indented 1-3 spaces, but not 4: ```````````````````````````````` example <!-- foo --> @@ -3045,7 +2695,7 @@ 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 spaces or tabs. +> block should not be indented with tabs or spaces. In some ways Gruber's rule is more restrictive than the one given here: @@ -3163,15 +2813,14 @@ deleted. The exception is inside `<pre>` tags, but as described ## Link reference definitions A [link reference definition](@) -consists of a [link label], optionally preceded by up to three spaces of -indentation, followed -by a colon (`:`), optional spaces or tabs (including up to one +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 spaces or tabs (including up to one +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 spaces or tabs. -No further character may occur. +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 @@ -3190,9 +2839,9 @@ them. ```````````````````````````````` example - [foo]: - /url - 'the title' + [foo]: + /url + 'the title' [foo] . @@ -3289,7 +2938,7 @@ The link destination may not be omitted: ```````````````````````````````` The title must be separated from the link destination by -spaces or tabs: +whitespace: ```````````````````````````````` example [foo]: <bar>(baz) @@ -3358,11 +3007,8 @@ case-insensitive (see [matches]). ```````````````````````````````` -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: +Here is a link reference definition with no corresponding link. +It contributes nothing to the document. ```````````````````````````````` example [foo]: /url @@ -3383,7 +3029,7 @@ bar This is not a link reference definition, because there are -characters other than spaces or tabs after the title: +[non-whitespace characters] after the title: ```````````````````````````````` example [foo]: /url "title" ok @@ -3515,6 +3161,18 @@ are defined: ```````````````````````````````` +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 @@ -3522,7 +3180,7 @@ 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 -spaces or tabs. +[whitespace]. A simple example with two paragraphs: @@ -3552,7 +3210,7 @@ ddd</p> ```````````````````````````````` -Multiple blank lines between paragraphs have no effect: +Multiple blank lines between paragraph have no effect: ```````````````````````````````` example aaa @@ -3565,7 +3223,7 @@ bbb ```````````````````````````````` -Leading spaces or tabs are skipped: +Leading spaces are skipped: ```````````````````````````````` example aaa @@ -3590,8 +3248,8 @@ ccc</p> ```````````````````````````````` -However, the first line may be preceded by up to three spaces of indentation. -Four spaces of indentation is too many: +However, the first line may be indented at most three spaces, +or an indented code block will be triggered: ```````````````````````````````` example aaa @@ -3612,13 +3270,13 @@ bbb ```````````````````````````````` -Final spaces or tabs are stripped before inline parsing, so a paragraph +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 +aaa +bbb . <p>aaa<br /> bbb</p> @@ -3634,20 +3292,228 @@ 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> ```````````````````````````````` +<div class="extension"> +## Tables (extension) + +GFM enables the `table` extension, where an additional leaf block type is +available. + +A [table](@) is an arrangement of data with rows and columns, consisting of a +single header row, a [delimiter row] separating the header from the data, and +zero or more data rows. + +Each row consists of cells containing arbitrary text, in which [inlines] are +parsed, separated by pipes (`|`). A leading and trailing pipe is also +recommended for clarity of reading, and if there's otherwise parsing ambiguity. +Spaces between pipes and cell content are trimmed. Block-level elements cannot +be inserted in a table. + +The [delimiter row](@) consists of cells whose only content are hyphens (`-`), +and optionally, a leading or trailing colon (`:`), or both, to indicate left, +right, or center alignment respectively. + +```````````````````````````````` example table +| foo | bar | +| --- | --- | +| baz | bim | +. +<table> +<thead> +<tr> +<th>foo</th> +<th>bar</th> +</tr> +</thead> +<tbody> +<tr> +<td>baz</td> +<td>bim</td> +</tr> +</tbody> +</table> +```````````````````````````````` + +Cells in one column don't need to match length, though it's easier to read if +they are. Likewise, use of leading and trailing pipes may be inconsistent: + +```````````````````````````````` example table +| abc | defghi | +:-: | -----------: +bar | baz +. +<table> +<thead> +<tr> +<th align="center">abc</th> +<th align="right">defghi</th> +</tr> +</thead> +<tbody> +<tr> +<td align="center">bar</td> +<td align="right">baz</td> +</tr> +</tbody> +</table> +```````````````````````````````` + +Include a pipe in a cell's content by escaping it, including inside other +inline spans: + +```````````````````````````````` example table +| f\|oo | +| ------ | +| b `\|` az | +| b **\|** im | +. +<table> +<thead> +<tr> +<th>f|oo</th> +</tr> +</thead> +<tbody> +<tr> +<td>b <code>|</code> az</td> +</tr> +<tr> +<td>b <strong>|</strong> im</td> +</tr> +</tbody> +</table> +```````````````````````````````` + +The table is broken at the first empty line, or beginning of another +block-level structure: + +```````````````````````````````` example table +| abc | def | +| --- | --- | +| bar | baz | +> bar +. +<table> +<thead> +<tr> +<th>abc</th> +<th>def</th> +</tr> +</thead> +<tbody> +<tr> +<td>bar</td> +<td>baz</td> +</tr> +</tbody> +</table> +<blockquote> +<p>bar</p> +</blockquote> +```````````````````````````````` + +```````````````````````````````` example table +| abc | def | +| --- | --- | +| bar | baz | +bar + +bar +. +<table> +<thead> +<tr> +<th>abc</th> +<th>def</th> +</tr> +</thead> +<tbody> +<tr> +<td>bar</td> +<td>baz</td> +</tr> +<tr> +<td>bar</td> +<td></td> +</tr> +</tbody> +</table> +<p>bar</p> +```````````````````````````````` + +The header row must match the [delimiter row] in the number of cells. If not, +a table will not be recognized: + +```````````````````````````````` example table +| abc | def | +| --- | +| bar | +. +<p>| abc | def | +| --- | +| bar |</p> +```````````````````````````````` + +The remainder of the table's rows may vary in the number of cells. If there +are a number of cells fewer than the number of cells in the header row, empty +cells are inserted. If there are greater, the excess is ignored: + +```````````````````````````````` example table +| abc | def | +| --- | --- | +| bar | +| bar | baz | boo | +. +<table> +<thead> +<tr> +<th>abc</th> +<th>def</th> +</tr> +</thead> +<tbody> +<tr> +<td>bar</td> +<td></td> +</tr> +<tr> +<td>bar</td> +<td>baz</td> +</tr> +</tbody> +</table> +```````````````````````````````` + +If there are no rows in the body, no `<tbody>` is generated in HTML output: + +```````````````````````````````` example table +| abc | def | +| --- | --- | +. +<table> +<thead> +<tr> +<th>abc</th> +<th>def</th> +</tr> +</thead> +</table> +```````````````````````````````` + +</div> # Container blocks @@ -3671,11 +3537,9 @@ these constructions. (A recipe is provided below in the section entitled ## Block quotes -A [block quote marker](@), -optionally preceded by up to three spaces of indentation, -consists of (a) the character `>` together with a following space of -indentation, or (b) a single character `>` not followed by a space of -indentation. +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]: @@ -3687,8 +3551,8 @@ The following rules define [block quotes]: 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 character other than a space or tab after the - [block quote marker] is [paragraph continuation + 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 @@ -3714,7 +3578,7 @@ baz</p> ```````````````````````````````` -The space or tab after the `>` characters can be omitted: +The spaces after the `>` characters can be omitted: ```````````````````````````````` example ># Foo @@ -3729,7 +3593,7 @@ baz</p> ```````````````````````````````` -The `>` characters can be preceded by up to three spaces of indentation: +The `>` characters can be indented 1-3 spaces: ```````````````````````````````` example > # Foo @@ -3744,7 +3608,7 @@ baz</p> ```````````````````````````````` -Four spaces of indentation is too many: +Four spaces gives us a code block: ```````````````````````````````` example > # Foo @@ -3902,8 +3766,8 @@ A block quote can be empty: ```````````````````````````````` example > -> -> +> +> . <blockquote> </blockquote> @@ -3915,7 +3779,7 @@ A block quote can have initial or final blank lines: ```````````````````````````````` example > > foo -> +> . <blockquote> <p>foo</p> @@ -4079,8 +3943,8 @@ baz</p> When including an indented code block in a block quote, remember that the [block quote marker] includes -both the `>` and a following space of indentation. So *five spaces* are needed -after the `>`: +both the `>` and a following space. So *five spaces* are needed after +the `>`: ```````````````````````````````` example > code @@ -4115,10 +3979,10 @@ 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 character other than a space or tab, and *M* is - a list marker of width *W* followed by 1 ≤ *N* ≤ 4 spaces of indentation, - 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 + 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 @@ -4127,10 +3991,10 @@ The following rules define [list items]: 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. + 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. @@ -4183,8 +4047,8 @@ with two lines.</p> 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 of indentation, and there are three spaces between -the list marker and the next character other than a space or tab, then blocks +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. @@ -4245,10 +4109,10 @@ put under the list item: 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 character other than -a space or tab after the list marker. However, that is not quite right. -The spaces of indentation after the list marker determine how much relative -indentation is needed. Which column this indentation reaches will depend on +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: @@ -4295,7 +4159,7 @@ far enough past the blockquote marker: ```````````````````````````````` -Note that at least one space or tab is needed between the list marker and +Note that at least one space is needed between the list marker and any following content, so these are not list items: ```````````````````````````````` example @@ -4427,16 +4291,16 @@ A start number may not be negative: 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 of indentation, 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. + 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 preceded by four spaces of indentation -beyond the edge of the region where text will be included in the list item. +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 @@ -4472,8 +4336,8 @@ And in this case it is 11 spaces: If the *first* block in the list item is an indented code block, -then by rule #2, the contents must be preceded by *one* space of indentation -after the list marker: +then by rule #2, the contents must be indented *one* space after the +list marker: ```````````````````````````````` example indented code @@ -4509,7 +4373,7 @@ paragraph ```````````````````````````````` -Note that an additional space of indentation is interpreted as space +Note that an additional space indent is interpreted as space inside the code block: ```````````````````````````````` example @@ -4533,10 +4397,10 @@ inside the code block: 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 -character other than a space or tab, and (b) cases in which +[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 -three spaces of indentation, the rules do not allow us to form a list item by +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 @@ -4561,8 +4425,8 @@ bar ```````````````````````````````` -This is not a significant restriction, because when a block is preceded by up to -three spaces of indentation, the indentation can always be removed without +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: @@ -4582,10 +4446,11 @@ the above case: 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*, and *M* is a list marker of width *W*, + 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 - preceding subsequent lines of *Ls* by *W + 1* spaces of indentation, is a - list item with *Bs* as its contents. + 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 @@ -4620,7 +4485,7 @@ 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> @@ -4660,11 +4525,11 @@ Here is an empty bullet list item: ```````````````````````````````` -It does not matter whether there are spaces or tabs following the [list marker]: +It does not matter whether there are spaces following the [list marker]: ```````````````````````````````` example - foo -- +- - bar . <ul> @@ -4717,9 +4582,9 @@ foo 4. **Indentation.** If a sequence of lines *Ls* constitutes a list item - according to rule #1, #2, or #3, then the result of preceding each line - of *Ls* by up to three spaces of indentation (the same for each line) also - constitutes a list item with the same contents and attributes. If a line is + 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: @@ -4818,7 +4683,7 @@ Four spaces indent gives a code block: 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 character other than a space or tab after the indentation is + 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 @@ -4903,7 +4768,7 @@ continued here.</p> The rules for sublists follow from the general rules [above][List items]. A sublist must be indented the same number -of spaces of indentation a paragraph would need to be in order to be included +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: @@ -5136,8 +5001,8 @@ 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 up to three spaces of indentation for -the initial list marker, allows text that is indented *less than* the +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 @@ -5191,7 +5056,7 @@ is not indented as far as the first paragraph `foo`: ``` markdown 10. foo - bar + bar ``` Arguably this text does read like a list item with `bar` as a subparagraph, @@ -5217,6 +5082,63 @@ that in such cases, we require one space indentation from the list marker four-space rule in cases where the list marker plus its initial indentation takes four spaces (a common case), but diverge in other cases. +<div class="extension"> + +## Task list items (extension) + +GFM enables the `tasklist` extension, where an additional processing step is +performed on [list items]. + +A [task list item](@) is a [list item][list items] where the first block in it +is a paragraph which begins with a [task list item marker] and at least one +whitespace character before any other content. + +A [task list item marker](@) consists of an optional number of spaces, a left +bracket (`[`), either a whitespace character or the letter `x` in either +lowercase or uppercase, and then a right bracket (`]`). + +When rendered, the [task list item marker] is replaced with a semantic checkbox element; +in an HTML output, this would be an `<input type="checkbox">` element. + +If the character between the brackets is a whitespace character, the checkbox +is unchecked. Otherwise, the checkbox is checked. + +This spec does not define how the checkbox elements are interacted with: in practice, +implementors are free to render the checkboxes as disabled or inmutable elements, +or they may dynamically handle dynamic interactions (i.e. checking, unchecking) in +the final rendered document. + +```````````````````````````````` example disabled +- [ ] foo +- [x] bar +. +<ul> +<li><input type="checkbox" disabled="" /> foo</li> +<li><input type="checkbox" disabled="" checked="" /> bar</li> +</ul> +```````````````````````````````` + +Task lists can be arbitrarily nested: + +```````````````````````````````` example disabled +- [x] foo + - [ ] bar + - [x] baz +- [ ] bim +. +<ul> +<li><input type="checkbox" disabled="" checked="" /> foo +<ul> +<li><input type="checkbox" disabled="" /> bar</li> +<li><input type="checkbox" disabled="" checked="" /> baz</li> +</ul> +</li> +<li><input type="checkbox" disabled="" /> bim</li> +</ul> +```````````````````````````````` + +</div> + ## Lists A [list](@) is a sequence of one or more @@ -5529,8 +5451,8 @@ item: </ol> ```````````````````````````````` -Note, however, that list items may not be preceded by more than -three spaces of indentation. Here `- e` is treated as a paragraph continuation +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 @@ -5616,7 +5538,7 @@ So is this, with a empty second item: ```````````````````````````````` -These are loose lists, even though there are no blank lines between the items, +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: @@ -5732,138 +5654,477 @@ block quote: ```````````````````````````````` -This list is tight, because the consecutive block elements -are not separated by blank lines: - +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. + + +## 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/multipage/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; +&#987654321; +&#abcdef0; +&ThisIsNotDefined; &hi?; +. +<p>&amp;nbsp &amp;x; &amp;#; &amp;#x; +&amp;#987654321; +&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 -- a - > b - ``` - c - ``` -- d +[foo](/f&ouml;&ouml; "f&ouml;&ouml;") . -<ul> -<li>a -<blockquote> -<p>b</p> -</blockquote> -<pre><code>c -</code></pre> -</li> -<li>d</li> -</ul> +<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p> ```````````````````````````````` -A single-paragraph list is tight: - ```````````````````````````````` example -- a +[foo] + +[foo]: /f&ouml;&ouml; "f&ouml;&ouml;" . -<ul> -<li>a</li> -</ul> +<p><a href="/f%C3%B6%C3%B6" title="föö">foo</a></p> ```````````````````````````````` ```````````````````````````````` example -- a - - b +``` f&ouml;&ouml; +foo +``` . -<ul> -<li>a -<ul> -<li>b</li> -</ul> -</li> -</ul> +<pre><code class="language-föö">foo +</code></pre> ```````````````````````````````` -This list is loose, because of the blank line between the -two block elements in the list item: +Entity and numeric character references are treated as literal +text in code spans and code blocks: ```````````````````````````````` example -1. ``` - foo - ``` +`f&ouml;&ouml;` +. +<p><code>f&amp;ouml;&amp;ouml;</code></p> +```````````````````````````````` - bar + +```````````````````````````````` example + f&ouml;f&ouml; . -<ol> -<li> -<pre><code>foo +<pre><code>f&amp;ouml;f&amp;ouml; </code></pre> -<p>bar</p> -</li> -</ol> ```````````````````````````````` -Here the outer list is loose, the inner list tight: +Entity and numeric character references cannot be used +in place of symbols indicating structure in CommonMark +documents. ```````````````````````````````` example -* foo - * bar - - baz +&#42;foo&#42; +*foo* . -<ul> -<li> -<p>foo</p> -<ul> -<li>bar</li> -</ul> -<p>baz</p> -</li> -</ul> +<p>*foo* +<em>foo</em></p> ```````````````````````````````` - ```````````````````````````````` example -- a - - b - - c +&#42; foo -- d - - e - - f +* foo . +<p>* foo</p> <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> +<li>foo</li> </ul> ```````````````````````````````` +```````````````````````````````` example +foo&#10;&#10;bar +. +<p>foo -# 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 +bar</p> +```````````````````````````````` ```````````````````````````````` example -`hi`lo` +&#9;foo . -<p><code>hi</code>lo`</p> +<p>→foo</p> ```````````````````````````````` -`hi` is parsed as code, leaving the backtick at the end as a literal -backtick. +```````````````````````````````` example +[a](url &quot;tit&quot;) +. +<p>[a](url &quot;tit&quot;)</p> +```````````````````````````````` ## Code spans @@ -5874,7 +6135,7 @@ 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 +the characters between the two backtick strings, normalized in the following ways: - First, [line endings] are converted to [spaces]. @@ -5935,18 +6196,18 @@ Only [spaces], and not [unicode whitespace] in general, are stripped in this way: ```````````````````````````````` example -` b ` +` b ` . -<p><code> b </code></p> +<p><code> b </code></p> ```````````````````````````````` No stripping occurs if the code span contains only spaces: ```````````````````````````````` example -` ` +` ` ` ` . -<p><code> </code> +<p><code> </code> <code> </code></p> ```````````````````````````````` @@ -5956,7 +6217,7 @@ No stripping occurs if the code span contains only spaces: ```````````````````````````````` example `` foo -bar +bar baz `` . @@ -5965,7 +6226,7 @@ baz ```````````````````````````````` example `` -foo +foo `` . <p><code>foo </code></p> @@ -5975,7 +6236,7 @@ foo Interior spaces are not collapsed: ```````````````````````````````` example -`foo bar +`foo bar baz` . <p><code>foo bar baz</code></p> @@ -6153,17 +6414,17 @@ 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 [Unicode punctuation character], or -(2b) followed by a [Unicode punctuation character] and -preceded by [Unicode whitespace] or a [Unicode punctuation character]. +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 [Unicode punctuation character], or -(2b) preceded by a [Unicode punctuation character] and -followed by [Unicode whitespace] or a [Unicode punctuation character]. +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. @@ -6218,7 +6479,7 @@ The following rules define emphasis and strong emphasis: 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 a [Unicode punctuation character]. + preceded by punctuation. 3. A single `*` character [can close emphasis](@) iff it is part of a [right-flanking delimiter run]. @@ -6227,7 +6488,7 @@ The following rules define emphasis and strong emphasis: 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 a [Unicode punctuation character]. + followed by punctuation. 5. A double `**` [can open strong emphasis](@) iff it is part of a [left-flanking delimiter run]. @@ -6236,7 +6497,7 @@ The following rules define emphasis and strong emphasis: 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 a [Unicode punctuation character]. + preceded by punctuation. 7. A double `**` [can close strong emphasis](@) iff it is part of a [right-flanking delimiter run]. @@ -6245,7 +6506,7 @@ The following rules define emphasis and strong emphasis: 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 a [Unicode punctuation character]. + 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 @@ -6340,9 +6601,9 @@ a*"foo"* Unicode nonbreaking spaces count as whitespace, too: ```````````````````````````````` example -* a * +* a * . -<p>* a *</p> +<p>* a *</p> ```````````````````````````````` @@ -6457,7 +6718,7 @@ whitespace: ```````````````````````````````` -A line ending also counts as whitespace: +A newline also counts as whitespace: ```````````````````````````````` example *foo bar @@ -6622,7 +6883,7 @@ __ foo bar__ ```````````````````````````````` -A line ending counts as whitespace: +A newline counts as whitespace: ```````````````````````````````` example __ foo bar__ @@ -6901,7 +7162,7 @@ emphasis sections in this example: The same condition ensures that the following cases are all strong emphasis nested inside -emphasis, even when the interior whitespace is +emphasis, even when the interior spaces are omitted: @@ -7444,6 +7705,34 @@ __a<http://foo.bar/?q=__> ```````````````````````````````` +<div class="extension"> + +## Strikethrough (extension) + +GFM enables the `strikethrough` extension, where an additional emphasis type is +available. + +Strikethrough text is any text wrapped in two tildes (`~`). + +```````````````````````````````` example strikethrough +~~Hi~~ Hello, world! +. +<p><del>Hi</del> Hello, world!</p> +```````````````````````````````` + +As with regular emphasis delimiters, a new paragraph will cause strikethrough +parsing to cease: + +```````````````````````````````` example strikethrough +This ~~has a + +new paragraph~~. +. +<p>This ~~has a</p> +<p>new paragraph~~.</p> +```````````````````````````````` + +</div> ## Links @@ -7478,14 +7767,13 @@ following rules apply: A [link destination](@) consists of either - a sequence of zero or more characters between an opening `<` and a - closing `>` that contains no line endings or unescaped + 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 [space] character, and includes parentheses only if (a) they are - backslash-escaped or (b) they are part of a balanced pair of - unescaped parentheses. +- a nonempty sequence of characters that does not start with + `<`, does not include ASCII space or control characters, 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.) @@ -7508,14 +7796,10 @@ 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 `(`, an optional [link destination], an optional -[link title], and a right parenthesis `)`. -These four components may be separated by spaces, tabs, and up to one line -ending. -If both [link destination] and [link title] are present, they *must* be -separated by spaces, tabs, and up to one line ending. - -The link's text consists of the inlines contained +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 @@ -7532,8 +7816,7 @@ Here is a simple inline link: ```````````````````````````````` -The title, the link text and even -the destination may be omitted: +The title may be omitted: ```````````````````````````````` example [link](/uri) @@ -7541,12 +7824,8 @@ the destination may be omitted: <p><a href="/uri">link</a></p> ```````````````````````````````` -```````````````````````````````` example -[](./target.md) -. -<p><a href="./target.md"></a></p> -```````````````````````````````` +Both the title and the destination may be omitted: ```````````````````````````````` example [link]() @@ -7561,13 +7840,6 @@ the destination may be omitted: <p><a href="">link</a></p> ```````````````````````````````` - -```````````````````````````````` example -[]() -. -<p><a href=""></a></p> -```````````````````````````````` - The destination can only contain spaces if it is enclosed in pointy brackets: @@ -7583,7 +7855,7 @@ enclosed in pointy brackets: <p><a href="/my%20uri">link</a></p> ```````````````````````````````` -The destination cannot contain line endings, +The destination cannot contain line breaks, even if enclosed in pointy brackets: ```````````````````````````````` example @@ -7652,13 +7924,6 @@ balanced: 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\)) . @@ -7758,12 +8023,11 @@ may be used in titles: ```````````````````````````````` -Titles must be separated from the link using spaces, tabs, and up to one line -ending. +Titles must be separated from the link using a [whitespace]. Other [Unicode whitespace] like non-breaking space doesn't work. ```````````````````````````````` example -[link](/url "title") +[link](/url "title") . <p><a href="/url%C2%A0%22title%22">link</a></p> ```````````````````````````````` @@ -7802,8 +8066,7 @@ 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.) -Spaces, tabs, and up to one line ending is allowed around the destination and -title: +[Whitespace] is allowed around the destination and title: ```````````````````````````````` example [link]( /uri @@ -7954,8 +8217,7 @@ 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 character that is not a space, -tab, or line ending. +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 @@ -7965,13 +8227,14 @@ 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 -spaces, tabs, and line endings, and collapse consecutive internal -spaces, tabs, and line endings to a single space. If there are multiple +[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]. +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]. Here is a simple example: @@ -8064,11 +8327,11 @@ emphasis grouping: ```````````````````````````````` example -[foo *bar][ref]* +[foo *bar][ref] [ref]: /uri . -<p><a href="/uri">foo *bar</a>*</p> +<p><a href="/uri">foo *bar</a></p> ```````````````````````````````` @@ -8116,15 +8379,15 @@ Matching is case-insensitive: Unicode case fold is used: ```````````````````````````````` example -[ẞ] +[Толпой][Толпой] is a Russian word. -[SS]: /url +[ТОЛПОЙ]: /url . -<p><a href="/url">ẞ</a></p> +<p><a href="/url">Толпой</a> is a Russian word.</p> ```````````````````````````````` -Consecutive internal spaces, tabs, and line endings are treated as one space for +Consecutive internal [whitespace] is treated as one space for purposes of determining matching: ```````````````````````````````` example @@ -8137,7 +8400,7 @@ purposes of determining matching: ```````````````````````````````` -No spaces, tabs, or line endings are allowed between the [link text] and the +No [whitespace] is allowed between the [link text] and the [link label]: ```````````````````````````````` example @@ -8267,8 +8530,7 @@ Note that in this example `]` is not backslash-escaped: ```````````````````````````````` -A [link label] must contain at least one character that is not a space, tab, or -line ending: +A [link label] must contain at least one [non-whitespace character]: ```````````````````````````````` example [] @@ -8333,11 +8595,11 @@ The link labels are case-insensitive: -As with full reference links, spaces, tabs, or line endings are not +As with full reference links, [whitespace] is not allowed between the two sets of brackets: ```````````````````````````````` example -[foo] +[foo] [] [foo]: /url "title" @@ -8661,11 +8923,11 @@ The labels are case-insensitive: ```````````````````````````````` -As with reference links, spaces, tabs, and line endings, are not allowed +As with reference links, [whitespace] is not allowed between the two sets of brackets: ```````````````````````````````` example -![foo] +![foo] [] [foo]: /url "title" @@ -8754,9 +9016,9 @@ 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], [space], `<`, and `>`. -If the URI includes these characters, they must be percent-encoded +followed by zero or more characters other than ASCII +[whitespace] and control characters, `<`, 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 @@ -8928,6 +9190,175 @@ foo@bar.example.com <p>foo@bar.example.com</p> ```````````````````````````````` +<div class="extension"> + +## Autolinks (extension) + +GFM enables the `autolink` extension, where autolinks will be recognised in a +greater number of conditions. + +[Autolink]s can also be constructed without requiring the use of `<` and to `>` +to delimit them, although they will be recognized under a smaller set of +circumstances. All such recognized autolinks can only come at the beginning of +a line, after whitespace, or any of the delimiting characters `*`, `_`, `~`, +and `(`. + +An [extended www autolink](@) will be recognized +when the text `www.` is found followed by a [valid domain]. +A [valid domain](@) consists of segments +of alphanumeric characters, underscores (`_`) and hyphens (`-`) +separated by periods (`.`). +There must be at least one period, +and no underscores may be present in the last two segments of the domain. + +The scheme `http` will be inserted automatically: + +```````````````````````````````` example autolink +www.commonmark.org +. +<p><a href="http://www.commonmark.org">www.commonmark.org</a></p> +```````````````````````````````` + +After a [valid domain], zero or more non-space non-`<` characters may follow: + +```````````````````````````````` example autolink +Visit www.commonmark.org/help for more information. +. +<p>Visit <a href="http://www.commonmark.org/help">www.commonmark.org/help</a> for more information.</p> +```````````````````````````````` + +We then apply [extended autolink path validation](@) as follows: + +Trailing punctuation (specifically, `?`, `!`, `.`, `,`, `:`, `*`, `_`, and `~`) +will not be considered part of the autolink, though they may be included in the +interior of the link: + +```````````````````````````````` example autolink +Visit www.commonmark.org. + +Visit www.commonmark.org/a.b. +. +<p>Visit <a href="http://www.commonmark.org">www.commonmark.org</a>.</p> +<p>Visit <a href="http://www.commonmark.org/a.b">www.commonmark.org/a.b</a>.</p> +```````````````````````````````` + +When an autolink ends in `)`, we scan the entire autolink for the total number +of parentheses. If there is a greater number of closing parentheses than +opening ones, we don't consider the unmatched trailing parentheses part of the +autolink, in order to facilitate including an autolink inside a parenthesis: + +```````````````````````````````` example autolink +www.google.com/search?q=Markup+(business) + +www.google.com/search?q=Markup+(business))) + +(www.google.com/search?q=Markup+(business)) + +(www.google.com/search?q=Markup+(business) +. +<p><a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a></p> +<p><a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a>))</p> +<p>(<a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a>)</p> +<p>(<a href="http://www.google.com/search?q=Markup+(business)">www.google.com/search?q=Markup+(business)</a></p> +```````````````````````````````` + +This check is only done when the link ends in a closing parentheses `)`, so if +the only parentheses are in the interior of the autolink, no special rules are +applied: + +```````````````````````````````` example autolink +www.google.com/search?q=(business))+ok +. +<p><a href="http://www.google.com/search?q=(business))+ok">www.google.com/search?q=(business))+ok</a></p> +```````````````````````````````` + +If an autolink ends in a semicolon (`;`), we check to see if it appears to +resemble an [entity reference][entity references]; if the preceding text is `&` +followed by one or more alphanumeric characters. If so, it is excluded from +the autolink: + +```````````````````````````````` example autolink +www.google.com/search?q=commonmark&hl=en + +www.google.com/search?q=commonmark&hl; +. +<p><a href="http://www.google.com/search?q=commonmark&amp;hl=en">www.google.com/search?q=commonmark&amp;hl=en</a></p> +<p><a href="http://www.google.com/search?q=commonmark">www.google.com/search?q=commonmark</a>&amp;hl;</p> +```````````````````````````````` + +`<` immediately ends an autolink. + +```````````````````````````````` example autolink +www.commonmark.org/he<lp +. +<p><a href="http://www.commonmark.org/he">www.commonmark.org/he</a>&lt;lp</p> +```````````````````````````````` + +An [extended url autolink](@) will be recognised when one of the schemes +`http://`, `https://`, or `ftp://`, followed by a [valid domain], then zero or +more non-space non-`<` characters according to +[extended autolink path validation]: + +```````````````````````````````` example autolink +http://commonmark.org + +(Visit https://encrypted.google.com/search?q=Markup+(business)) + +Anonymous FTP is available at ftp://foo.bar.baz. +. +<p><a href="http://commonmark.org">http://commonmark.org</a></p> +<p>(Visit <a href="https://encrypted.google.com/search?q=Markup+(business)">https://encrypted.google.com/search?q=Markup+(business)</a>)</p> +<p>Anonymous FTP is available at <a href="ftp://foo.bar.baz">ftp://foo.bar.baz</a>.</p> +```````````````````````````````` + + +An [extended email autolink](@) will be recognised when an email address is +recognised within any text node. Email addresses are recognised according to +the following rules: + +* One ore more characters which are alphanumeric, or `.`, `-`, `_`, or `+`. +* An `@` symbol. +* One or more characters which are alphanumeric, or `-` or `_`, + separated by periods (`.`). + There must be at least one period. + The last character must not be one of `-` or `_`. + +The scheme `mailto:` will automatically be added to the generated link: + +```````````````````````````````` example autolink +foo@bar.baz +. +<p><a href="mailto:foo@bar.baz">foo@bar.baz</a></p> +```````````````````````````````` + +`+` can occur before the `@`, but not after. + +```````````````````````````````` example autolink +hello@mail+xyz.example isn't valid, but hello+xyz@mail.example is. +. +<p>hello@mail+xyz.example isn't valid, but <a href="mailto:hello+xyz@mail.example">hello+xyz@mail.example</a> is.</p> +```````````````````````````````` + +`.`, `-`, and `_` can occur on both sides of the `@`, but only `.` may occur at +the end of the email address, in which case it will not be considered part of +the address: + +```````````````````````````````` example autolink +a.b-c_d@a.b + +a.b-c_d@a.b. + +a.b-c_d@a.b- + +a.b-c_d@a.b_ +. +<p><a href="mailto:a.b-c_d@a.b">a.b-c_d@a.b</a></p> +<p><a href="mailto:a.b-c_d@a.b">a.b-c_d@a.b</a>.</p> +<p>a.b-c_d@a.b-</p> +<p>a.b-c_d@a.b_</p> +```````````````````````````````` + +</div> ## Raw HTML @@ -8942,7 +9373,7 @@ A [tag name](@) consists of an ASCII letter followed by zero or more ASCII letters, digits, or hyphens (`-`). -An [attribute](@) consists of spaces, tabs, and up to one line ending, +An [attribute](@) consists of [whitespace], an [attribute name], and an optional [attribute value specification]. @@ -8952,9 +9383,9 @@ letters, digits, `_`, `.`, `:`, or `-`. (Note: This is the XML specification restricted to ASCII. HTML5 is laxer.) An [attribute value specification](@) -consists of optional spaces, tabs, and up to one line ending, -a `=` character, optional spaces, tabs, and up to one line ending, -and an [attribute value]. +consists of optional [whitespace], +a `=` character, optional [whitespace], and an [attribute +value]. An [attribute value](@) consists of an [unquoted attribute value], @@ -8962,7 +9393,7 @@ a [single-quoted attribute value], or a [double-quoted attribute value]. An [unquoted attribute value](@) is a nonempty string of characters not -including spaces, tabs, line endings, `"`, `'`, `=`, `<`, `>`, or `` ` ``. +including [whitespace], `"`, `'`, `=`, `<`, `>`, or `` ` ``. A [single-quoted attribute value](@) consists of `'`, zero or more @@ -8973,12 +9404,11 @@ 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 spaces, tabs, and up to one line ending, -an optional `/` character, and a `>` character. +zero or more [attributes], optional [whitespace], an optional `/` +character, and a `>` character. A [closing tag](@) consists of the string `</`, a -[tag name], optional spaces, tabs, and up to one line ending, and the character -`>`. +[tag name], optional [whitespace], and the character `>`. An [HTML comment](@) consists of `<!--` + *text* + `-->`, where *text* does not start with `>` or `->`, does not end with `-`, @@ -8990,8 +9420,10 @@ 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 [declaration](@) consists of the +string `<!`, a name consisting of one or more uppercase ASCII letters, +[whitespace], a string of characters not including the +character `>`, and the character `>`. A [CDATA section](@) consists of the string `<![CDATA[`, a string of characters not including the string @@ -9019,7 +9451,7 @@ Empty elements: ```````````````````````````````` -Whitespace is allowed: +[Whitespace] is allowed: ```````````````````````````````` example <a /><b2 @@ -9077,7 +9509,7 @@ Illegal attribute values: ```````````````````````````````` -Illegal whitespace: +Illegal [whitespace]: ```````````````````````````````` example < a>< @@ -9092,7 +9524,7 @@ bim!bop /&gt;</p> ```````````````````````````````` -Missing whitespace: +Missing [whitespace]: ```````````````````````````````` example <a href='bar'title=title> @@ -9202,15 +9634,54 @@ foo <a href="\*"> ```````````````````````````````` +<div class="extension"> + +## Disallowed Raw HTML (extension) + +GFM enables the `tagfilter` extension, where the following HTML tags will be +filtered when rendering HTML output: + +* `<title>` +* `<textarea>` +* `<style>` +* `<xmp>` +* `<iframe>` +* `<noembed>` +* `<noframes>` +* `<script>` +* `<plaintext>` + +Filtering is done by replacing the leading `<` with the entity `&lt;`. These +tags are chosen in particular as they change how HTML is interpreted in a way +unique to them (i.e. nested HTML is interpreted differently), and this is +usually undesireable in the context of other rendered Markdown content. + +All other HTML tags are left untouched. + +```````````````````````````````` example tagfilter +<strong> <title> <style> <em> + +<blockquote> + <xmp> is disallowed. <XMP> is also disallowed. +</blockquote> +. +<p><strong> &lt;title> &lt;style> <em></p> +<blockquote> + &lt;xmp> is disallowed. &lt;XMP> is also disallowed. +</blockquote> +```````````````````````````````` + +</div> + ## Hard line breaks -A line ending (not in a code span or HTML tag) that is preceded +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 +foo baz . <p>foo<br /> @@ -9219,7 +9690,7 @@ baz</p> For a more visible alternative, a backslash before the -[line ending] may be used instead of two or more spaces: +[line ending] may be used instead of two spaces: ```````````````````````````````` example foo\ @@ -9233,7 +9704,7 @@ baz</p> More than two spaces can be used: ```````````````````````````````` example -foo +foo baz . <p>foo<br /> @@ -9244,7 +9715,7 @@ baz</p> Leading spaces at the beginning of the next line are ignored: ```````````````````````````````` example -foo +foo bar . <p>foo<br /> @@ -9261,11 +9732,11 @@ bar</p> ```````````````````````````````` -Hard line breaks can occur inside emphasis, links, and other constructs +Line breaks can occur inside emphasis, links, and other constructs that allow inline content: ```````````````````````````````` example -*foo +*foo bar* . <p><em>foo<br /> @@ -9282,10 +9753,10 @@ bar</em></p> ```````````````````````````````` -Hard line breaks do not occur inside code spans +Line breaks do not occur inside code spans ```````````````````````````````` example -`code +`code span` . <p><code>code span</code></p> @@ -9303,10 +9774,10 @@ span` or HTML tags: ```````````````````````````````` example -<a href="foo +<a href="foo bar"> . -<p><a href="foo +<p><a href="foo bar"></p> ```````````````````````````````` @@ -9332,7 +9803,7 @@ foo\ ```````````````````````````````` example -foo +foo . <p>foo</p> ```````````````````````````````` @@ -9346,7 +9817,7 @@ foo ```````````````````````````````` example -### foo +### foo . <h3>foo</h3> ```````````````````````````````` @@ -9354,9 +9825,9 @@ foo ## Soft line breaks -A regular line ending (not in a code span or HTML tag) that is not +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 soft line break may be rendered in HTML either 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.) @@ -9373,7 +9844,7 @@ Spaces at the end of the line and beginning of the next line are removed: ```````````````````````````````` example -foo +foo baz . <p>foo @@ -9382,7 +9853,7 @@ baz</p> A conforming parser may render a soft line break in HTML either as a -line ending or as a space. +line break or as a space. A renderer may also provide an option to render soft line breaks as hard line breaks. @@ -9490,7 +9961,7 @@ blocks. But we cannot close unmatched blocks yet, because we may have a 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. +matched block. 3. Finally, we look at the remainder of the line (after block markers like `>`, list markers, and indentation have been consumed). @@ -9706,9 +10177,8 @@ just above `stack_bottom` (or the first element if `stack_bottom` is NULL). We keep track of the `openers_bottom` for each delimiter -type (`*`, `_`), indexed to the length of the closing delimiter run -(modulo 3) and to whether the closing delimiter can also be an -opener. Initialize this to `stack_bottom`. +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: diff --git a/test/test_basics.rb b/test/test_basics.rb index 3c138906..5ac12a31 100644 --- a/test/test_basics.rb +++ b/test/test_basics.rb @@ -12,7 +12,7 @@ def test_to_html def test_to_html_accept_default_options text = "Hello **world** -- how are _you_ today? I'm ~~fine~~, ~yourself~?" - html = Commonmarker.to_html(text, options: Commonmarker::Config::OPTS) - assert_equal("<p>Hello <strong>world</strong> -- how are <em>you</em> today? I’m <del>fine</del>, ~yourself~?</p>\n", html) + html = Commonmarker.to_html(text, options: Commonmarker::Config::OPTS).rstrip + assert_equal("<p>Hello <strong>world</strong> -- how are <em>you</em> today? I'm <del>fine</del>, <del>yourself</del>?</p>", html) end end diff --git a/test/test_commands.rb b/test/test_commands.rb deleted file mode 100644 index f26fe89f..00000000 --- a/test/test_commands.rb +++ /dev/null @@ -1,72 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestCommands < Minitest::Test - def test_basic - out = make_bin("strong.md") - assert_equal("<p>I am <strong>strong</strong></p>", out) - end - - def test_does_not_have_extensions - out = make_bin("table.md") - assert_includes(out, "| a") - refute_includes(out, "<p><del>hi</del>") - refute_includes(out, "<table> <tr> <th> a </th> <td> c </td>") - end - - def test_understands_extensions - out = make_bin("table.md", "--extension=table") - refute_includes(out, "| a") - refute_includes(out, "<p><del>hi</del>") - ["<table>", "<tr>", "<th>", "a", "</th>", "<td>", "c", "</td>"].each { |html| assert_includes(out, html) } - end - - def test_understands_multiple_extensions - out = make_bin("table.md", "--extension=table,strikethrough") - refute_includes(out, "| a") - assert_includes(out, "<p><del>hi</del>") - ["<table>", "<tr>", "<th>", "a", "</th>", "<td>", "c", "</td>"].each { |html| assert_includes(out, html) } - end - - def test_understands_html_format_with_renderer_and_extensions - out = make_bin("table.md", "--to=html --extension=table,strikethrough --html-renderer") - refute_includes(out, "| a") - assert_includes(out, "<p><del>hi</del>") - ["<table>", "<tr>", "<th>", "a", "</th>", "<td>", "c", "</td>"].each { |html| assert_includes(out, html) } - end - - def test_understands_xml_format - out = make_bin("strong.md", "--to=xml") - assert_includes(out, '<?xml version="1.0" encoding="UTF-8"?>') - assert_includes(out, '<text xml:space="preserve">strong</text>') - end - - def test_understands_commonmark_format - out = make_bin("strong.md", "--to=commonmark") - assert_equal("I am **strong**", out) - end - - def test_understands_plaintext_format - out = make_bin("strong.md", "--to=plaintext") - assert_equal("I am strong", out) - end - - def test_aborts_invalid_format - _out, err = capture_subprocess_io do - make_bin("strong.md", "--to=unknown") - end - - assert_match("format 'unknown' not found", err) - end - - def test_aborts_format_and_html_renderer_combinations - (CommonMarker::Config::OPTS[:format] - [:html]).each do |format| - _out, err = capture_subprocess_io do - make_bin("strong.md", "--to=#{format} --html-renderer") - end - - assert_match("format '#{format}' does not support using the HtmlRenderer renderer", err) - end - end -end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index 33c78f76..d3c8685d 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -6,14 +6,14 @@ class TestEncoding < Minitest::Test # see http://git.io/vq4FR def test_encoding contents = fixtures_file("curly.md") - render = Commonmarker.to_html(contents, :SMART) + render = Commonmarker.to_html(contents, options: { parse: { smart: true } }) assert_equal("<p>This curly quote “makes commonmarker throw an exception”.</p>", render.rstrip) end def test_string_content_is_utf8 html = Commonmarker.to_html("Hi *there*") - assert_equal("<p>Hi <strong>there</strong>", html) + assert_equal("<p>Hi <em>there</em></p>", html.rstrip) assert_equal("UTF-8", html.encoding.name) end end diff --git a/test/test_extensions.rb b/test/test_extensions.rb index 09549c04..758cf8dd 100644 --- a/test/test_extensions.rb +++ b/test/test_extensions.rb @@ -8,106 +8,32 @@ def setup end def test_uses_specified_extensions - Commonmarker.to_html(@markdown, :DEFAULT, []).tap do |out| + Commonmarker.to_html(@markdown, options: { extension: {} }).tap do |out| assert_includes(out, "| a") assert_includes(out, "| <strong>x</strong>") assert_includes(out, "~~hi~~") end - Commonmarker.to_html(@markdown, :DEFAULT, [:table]).tap do |out| + Commonmarker.to_html(@markdown, options: { extension: { table: true } }).tap do |out| refute_includes(out, "| a") ["<table>", "<tr>", "<th>", "a", "</th>", "<td>", "c", "</td>", "<strong>x</strong>"].each { |html| assert_includes(out, html) } assert_includes(out, "~~hi~~") end - Commonmarker.to_html(@markdown, :DEFAULT, [:strikethrough]).tap do |out| + Commonmarker.to_html(@markdown, options: { extension: { strikethrough: true } }).tap do |out| assert_includes(out, "| a") refute_includes(out, "~~hi~~") assert_includes(out, "<del>hi</del>") end - - html = Commonmarker.to_html("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) - assert_equal("<p>~a~ <del>b</del> ~~~c~~~</p>\n", html) - - Commonmarker.to_html(@markdown, :DEFAULT, [:table, :strikethrough]).tap do |out| - refute_includes(out, "| a") - refute_includes(out, "| <strong>x</strong>") - refute_includes(out, "~~hi~~") - end - end - - def test_extensions_with_renderers - doc = Commonmarker.to_html(@markdown, :DEFAULT, [:table]) - - doc.to_html.tap do |out| - refute_includes(out, "| a") - ["<table>", "<tr>", "<th>", "a", "</th>", "<td>", "c", "</td>", "<strong>x</strong>"].each { |html| assert_includes(out, html) } - assert_includes(out, "~~hi~~") - end - - HtmlRenderer.new.render(doc).tap do |out| - refute_includes(out, "| a") - ["<table>", "<tr>", "<th>", "a", "</th>", "<td>", "c", "</td>", "<strong>x</strong>"].each { |html| assert_includes(out, html) } - assert_includes(out, "~~hi~~") - end - - doc = Commonmarker.to_html("~a~ ~~b~~ ~~~c~~~", :STRIKETHROUGH_DOUBLE_TILDE, [:strikethrough]) - assert_equal("<p>~a~ <del>b</del> ~~~c~~~</p>\n", HtmlRenderer.new.render(doc)) end def test_bad_extension_specifications - assert_raises(TypeError) { Commonmarker.to_html(@markdown, :DEFAULT, "nope") } - assert_raises(TypeError) { Commonmarker.to_html(@markdown, :DEFAULT, ["table"]) } - assert_raises(ArgumentError) { Commonmarker.to_html(@markdown, :DEFAULT, [:table, :bad]) } + assert_raises(TypeError) { Commonmarker.to_html(@markdown, options: "nope") } end def test_comments_are_kept_as_expected + options = { render: { unsafe_: true }, extension: { tagfilter: true } } assert_equal("<!--hello--> <blah> &lt;xmp>\n", - Commonmarker.to_html("<!--hello--> <blah> <xmp>\n", :UNSAFE, [:tagfilter])) - end - - def test_table_prefer_style_attributes - assert_equal(<<~HTML, Commonmarker.to_html(<<~MD, :TABLE_PREFER_STYLE_ATTRIBUTES, [:table])) - <table> - <thead> - <tr> - <th style="text-align: left">aaa</th> - <th>bbb</th> - <th style="text-align: center">ccc</th> - <th>ddd</th> - <th style="text-align: right">eee</th> - </tr> - </thead> - <tbody> - <tr> - <td style="text-align: left">fff</td> - <td>ggg</td> - <td style="text-align: center">hhh</td> - <td>iii</td> - <td style="text-align: right">jjj</td> - </tr> - </tbody> - </table> - HTML - aaa | bbb | ccc | ddd | eee - :-- | --- | :-: | --- | --: - fff | ggg | hhh | iii | jjj - MD - end - - def test_plaintext - assert_equal(<<~HTML, Commonmarker.to_html(<<~MD, :DEFAULT, [:table, :strikethrough]).to_plaintext) - Hello ~there~. - - | a | - | --- | - | b | - HTML - Hello ~~there~~. - - | a | - | - | - | b | - MD + Commonmarker.to_html("<!--hello--> <blah> <xmp>\n", options: options)) end end diff --git a/test/test_footnotes.rb b/test/test_footnotes.rb index 35013029..ed664168 100644 --- a/test/test_footnotes.rb +++ b/test/test_footnotes.rb @@ -12,15 +12,16 @@ def test_to_html MARKDOWN expected = <<~HTML <h1>footnotes</h1> - <p>Let's render some footnotes<sup class="footnote-ref"><a href="#fn-1" id="fnref-1" data-footnote-ref>1</a></sup></p> - <section class="footnotes" data-footnotes> + <p>Let's render some footnotes<sup class="footnote-ref"><a href="#fn1" id="fnref1">1</a></sup></p> + <section class="footnotes"> <ol> - <li id="fn-1"> - <p>This is a footnote <a href="#fnref-1" class="footnote-backref" data-footnote-backref aria-label="Back to content">↩</a></p> + <li id="fn1"> + <p>This is a footnote <a href="#fnref1" class="footnote-backref">↩</a></p> </li> </ol> </section> HTML - assert_equal(expected, Commonmarker.to_html(md, :FOOTNOTES)) + + assert_equal(expected, Commonmarker.to_html(md, options: { extension: { footnotes: true } })) end end diff --git a/test/test_format_commonmark.rb b/test/test_format_commonmark.rb new file mode 100644 index 00000000..e69de29b diff --git a/test/test_helper.rb b/test/test_helper.rb index 9485f8f7..fad6492e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -5,6 +5,8 @@ require "minitest/pride" require "minitest/focus" +require "nokogiri" + include Commonmarker FIXTURES_DIR = File.join(File.dirname(__FILE__), "fixtures") diff --git a/test/test_linebreaks.rb b/test/test_linebreaks.rb index b8c8d977..0b5523f8 100644 --- a/test/test_linebreaks.rb +++ b/test/test_linebreaks.rb @@ -3,13 +3,17 @@ require "test_helper" class TestLinebreaks < Minitest::Test + def setup + @options = { parse: { hardbreaks: true } } + end + def test_hardbreak_no_spaces - doc = Commonmarker.to_html("foo\nbaz") - assert_equal("<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)) + html = Commonmarker.to_html("foo\nbaz", options: @options) + assert_equal("<p>foo<br />\nbaz</p>\n", html) end def test_hardbreak_with_spaces - doc = Commonmarker.to_html("foo \nbaz") - assert_equal("<p>foo<br />\nbaz</p>\n", doc.to_html(:HARDBREAKS)) + html = Commonmarker.to_html("foo \nbaz", options: @options) + assert_equal("<p>foo<br />\nbaz</p>\n", html) end end diff --git a/test/test_maliciousness.rb b/test/test_maliciousness.rb index a842eece..0a9f4bdb 100644 --- a/test/test_maliciousness.rb +++ b/test/test_maliciousness.rb @@ -40,25 +40,13 @@ def test_rendering_with_bad_type assert_raises(TypeError) do Commonmarker.to_html("foo \n baz", options: [:SMART, "totes_fake"]) end - end def test_bad_options_value err = assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: { parse: { smart: 111 }}) - end - assert_equal("smart must be a FalseClass got a Number", err.message) - end - - def test_bad_fence_info_set - assert_raises(NodeError) do - @doc.fence_info = "ruby" - end - - fence = Commonmarker.to_html("``` ruby\nputs 'wow'\n```").first_child - assert_raises(TypeError) do - fence.fence_info = 123 + Commonmarker.to_html("foo \n baz", options: { parse: { smart: 111 } }) end + assert_equal("parse_options[:smart] must be a Boolean; got Integer", err.message) end end end diff --git a/test/test_options.rb b/test/test_options.rb deleted file mode 100644 index e7557d98..00000000 --- a/test/test_options.rb +++ /dev/null @@ -1,37 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestExtensions < Minitest::Test - def test_full_info_string - md = <<~MD - ```ruby - module Foo - ``` - MD - - Commonmarker.to_html(md, :FULL_INFO_STRING).tap do |out| - assert_includes(out, '<pre><code class="language-ruby">') - end - - md = <<~MD - ```ruby my info string - module Foo - ``` - MD - - Commonmarker.to_html(md, :FULL_INFO_STRING).tap do |out| - assert_includes(out, '<pre><code class="language-ruby" data-meta="my info string">') - end - - md = <<~MD - ```ruby my \x00 string - module Foo - ``` - MD - - Commonmarker.to_html(md, :FULL_INFO_STRING).tap do |out| - assert_includes(out, %(<pre><code class="language-ruby" data-meta="my � string">)) - end - end -end diff --git a/test/test_pathological_inputs.rb b/test/test_pathological_inputs.rb index 7f247784..ed159238 100644 --- a/test/test_pathological_inputs.rb +++ b/test/test_pathological_inputs.rb @@ -7,88 +7,86 @@ def markdown(str) Commonmarker.to_html(str).to_html end -# list of pairs consisting of input and a regex that must match the output. -pathological = { - "nested strong emph" => - ["#{"*a **a " * 65_000}b#{" a** a*" * 65_000}", - Regexp.compile("(<em>a <strong>a ){65_000}b( a</strong> a</em>){65_000}"),], - "many emph closers with no openers" => - [("a_ " * 65_000), - Regexp.compile("(a[_] ){64999}a_"),], - "many emph openers with no closers" => - [("_a " * 65_000), - Regexp.compile("(_a ){64999}_a"),], - "many link closers with no openers" => - [("a]" * 65_000), - Regexp.compile('(a\]){65_000}'),], - "many link openers with no closers" => - [("[a" * 65_000), - Regexp.compile('(\[a){65_000}'),], - "mismatched openers and closers" => - [("*a_ " * 50_000), - Regexp.compile("([*]a[_] ){49999}[*]a_"),], - "link openers and emph closers" => - [("[ a_" * 50_000), - Regexp.compile('(\[ a_){50000}'),], - "hard link/emph case" => - ["**x [a*b**c*](d)", - Regexp.compile('\\*\\*x <a href=\'d\'>a<em>b</em><em>c</em></a>'),], - "nested brackets" => - ["#{"[" * 50_000}a#{"]" * 50_000}", - Regexp.compile('\[{50000}a\]{50000}'),], - "nested block quotes" => - ["#{"> " * 50_000}a", - Regexp.compile('(<blockquote>\n){50000}'),], - "U+0000 in input" => - ['abc\u0000de\u0000', - Regexp.compile('abc\ufffd?de\ufffd?'),], -} +class PathologicalInputsPerformanceTest < Minitest::Benchmark + # list of pairs consisting of input and a regex that must match the output. + pathological = { + "nested strong emph" => + ["#{"*a **a " * 65_000}b#{" a** a*" * 65_000}", + Regexp.compile("(<em>a <strong>a ){65_000}b( a</strong> a</em>){65_000}"),], + "many emph closers with no openers" => + [("a_ " * 65_000), + Regexp.compile("(a[_] ){64999}a_"),], + "many emph openers with no closers" => + [("_a " * 65_000), + Regexp.compile("(_a ){64999}_a"),], + "many link closers with no openers" => + [("a]" * 65_000), + Regexp.compile('(a\]){65_000}'),], + "many link openers with no closers" => + [("[a" * 65_000), + Regexp.compile('(\[a){65_000}'),], + "mismatched openers and closers" => + [("*a_ " * 50_000), + Regexp.compile("([*]a[_] ){49999}[*]a_"),], + "link openers and emph closers" => + [("[ a_" * 50_000), + Regexp.compile('(\[ a_){50000}'),], + "hard link/emph case" => + ["**x [a*b**c*](d)", + Regexp.compile('\\*\\*x <a href=\'d\'>a<em>b</em><em>c</em></a>'),], + "nested brackets" => + ["#{"[" * 50_000}a#{"]" * 50_000}", + Regexp.compile('\[{50000}a\]{50000}'),], + "nested block quotes" => + ["#{"> " * 50_000}a", + Regexp.compile('(<blockquote>\n){50000}'),], + "U+0000 in input" => + ['abc\u0000de\u0000', + Regexp.compile('abc\ufffd?de\ufffd?'),], + } -if ENV["BENCH"] - class PathologicalInputsPerformanceTest < Minitest::Benchmark - pathological.each_pair do |name, description| - define_method("test_#{name}") do - input, = description - assert markdown(input) - end + pathological.each_pair do |name, description| + define_method("test_#{name}") do + input, = description + assert markdown(input) end + end - def test_bench_pathological_one - assert_performance_linear(0.99) do |n| - star = "*" * (n * 10) - markdown("#{star}#{star}hi#{star}#{star}") - end + def test_bench_pathological_one + assert_performance_linear(0.99) do |n| + star = "*" * (n * 10) + markdown("#{star}#{star}hi#{star}#{star}") end + end - def test_bench_pathological_two - assert_performance_linear(0.99) do |n| - c = "`t`t`t`t`t`t" * (n * 10) - markdown(c) - end + def test_bench_pathological_two + assert_performance_linear(0.99) do |n| + c = "`t`t`t`t`t`t" * (n * 10) + markdown(c) end + end - def test_bench_pathological_three - assert_performance_linear(0.99) do |n| - markdown(" [a]: #{"A" * n}\n\n#{"[a][]" * n}\n") - end + def test_bench_pathological_three + assert_performance_linear(0.99) do |n| + markdown(" [a]: #{"A" * n}\n\n#{"[a][]" * n}\n") end + end - def test_bench_pathological_four - assert_performance_linear(0.5) do |n| - markdown("#{"[" * n}a#{"]" * n}") - end + def test_bench_pathological_four + assert_performance_linear(0.5) do |n| + markdown("#{"[" * n}a#{"]" * n}") end + end - def test_bench_pathological_five - assert_performance_linear(0.99) do |n| - markdown("#{"**a *a " * n}#{"a* a**" * n}") - end + def test_bench_pathological_five + assert_performance_linear(0.99) do |n| + markdown("#{"**a *a " * n}#{"a* a**" * n}") end + end - def test_bench_unbound_recursion - assert_performance_linear(0.99) do |n| - markdown("#{"[" * n}foo#{"](bar)" * n}") - end + def test_bench_unbound_recursion + assert_performance_linear(0.99) do |n| + markdown("#{"[" * n}foo#{"](bar)" * n}") end end -end +end if ENV["BENCH"] diff --git a/test/test_plaintext.rb b/test/test_plaintext.rb deleted file mode 100644 index 377da65c..00000000 --- a/test/test_plaintext.rb +++ /dev/null @@ -1,46 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestPlaintext < Minitest::Test - def setup - @markdown = <<~MD - Hi *there*! - - 1. I am a numeric list. - 2. I continue the list. - * Suddenly, an unordered list! - * What fun! - - Okay, _enough_. - - | a | b | - | --- | --- | - | c | d | - MD - end - - def render_doc(doc) - Commonmarker.to_html(doc, :DEFAULT, [:table]) - end - - def test_to_commonmark - compare = render_doc(@markdown).to_plaintext - - assert_equal(<<~PLAINTEXT, compare) - Hi there! - - 1. I am a numeric list. - 2. I continue the list. - - - Suddenly, an unordered list! - - What fun! - - Okay, enough. - - | a | b | - | --- | --- | - | c | d | - PLAINTEXT - end -end diff --git a/test/test_renderer.rb b/test/test_renderer.rb deleted file mode 100644 index e2f69f45..00000000 --- a/test/test_renderer.rb +++ /dev/null @@ -1,20 +0,0 @@ -# frozen_string_literal: true - -require "test_helper" - -class TestRenderer < Minitest::Test - def test_multiple_tables - content = <<~DOC - | Input | Expected | Actual | - | ----------- | ---------------- | --------- | - | One | Two | Three | - - | Header | Row | Example | - | :------: | ---: | :------ | - | Foo | Bar | Baz | - DOC - doc = Commonmarker.to_html(content, [:autolink, :table, :tagfilter]) - results = CommonMarker::HtmlRenderer.new.render(doc) - assert_equal(2, results.scan(/<tbody>/).size) - end -end diff --git a/test/test_smartpunct.rb b/test/test_smartpunct.rb index b523c873..68f8e2b8 100644 --- a/test/test_smartpunct.rb +++ b/test/test_smartpunct.rb @@ -10,10 +10,13 @@ class SmartPunctTest < Minitest::Test parse: { smart: true, }, + render: { + hardbreaks: false, + }, } define_method("test_smart_punct_example_#{testcase[:example]}") do - html = Commonmarker.to_html(testcase[:markdown], opts).strip + html = Commonmarker.to_html(testcase[:markdown], options: opts).strip assert_equal testcase[:html], html, testcase[:markdown] end @@ -30,7 +33,7 @@ def test_smart_hardbreak_no_spaces_render_doc hardbreaks: true, }, } - html = Commonmarker.commonmark_to_html(markdown, opts) + html = Commonmarker.to_html(markdown, options: opts) assert_equal(result, html) end end diff --git a/test/test_spec.rb b/test/test_spec.rb index f983ca68..cb7d41c0 100644 --- a/test/test_spec.rb +++ b/test/test_spec.rb @@ -7,8 +7,6 @@ class TestSpec < Minitest::Test spec = load_spec_file("spec.txt") spec.each do |testcase| - html = Commonmarker.to_html(testcase[:markdown]) - focus define_method("test_to_html_example_#{testcase[:example]}") do opts = { render: { @@ -16,14 +14,14 @@ class TestSpec < Minitest::Test }, extension: testcase[:extensions].each_with_object({}) do |ext, hash| hash[ext] = true - end + end, } options = Commonmarker::Config.merged_with_defaults(opts) options[:extension].delete(:header_ids) # this interefers with the spec.txt extension-less capability - actual = Commonmarker.to_html(testcase[:markdown].strip, options: options).rstrip - # debugger if actual != testcase[:html] - Commonmarker.to_html(testcase[:markdown].strip, options: options).rstrip + options[:extension][:tasklist] = true + actual = Commonmarker.to_html(testcase[:markdown], options: options).rstrip + assert_equal testcase[:html], actual, testcase[:markdown] end end diff --git a/test/test_tasklists.rb b/test/test_tasklists.rb index c4202329..bd64011b 100644 --- a/test/test_tasklists.rb +++ b/test/test_tasklists.rb @@ -3,38 +3,19 @@ require "test_helper" class TestTasklists < Minitest::Test - def setup + def test_to_html text = <<-MD - [x] Add task list - [ ] Define task list MD - @html = Commonmarker.to_html(text, :DEFAULT, [:tasklist]) - @expected = <<~HTML + html = Commonmarker.to_html(text, options: { extension: { tasklist: true } }) + expected = <<~HTML <ul> - <li><input type="checkbox" checked="" disabled="" /> Add task list</li> + <li><input type="checkbox" disabled="" checked="" /> Add task list</li> <li><input type="checkbox" disabled="" /> Define task list</li> </ul> HTML - @doc = Nokogiri::HTML(@html) - end - - def test_to_html - assert_equal(@expected, @html) - end - - def test_tasklist_state - list = @doc.first_child - assert_equal("checked", list.first_child.tasklist_state) - assert_predicate(list.first_child, :tasklist_item_checked?) - assert_equal("unchecked", list.first_child.next.tasklist_state) - refute_predicate(list.first_child.next, :tasklist_item_checked?) - end - def test_set_tasklist_state - list = @doc.first_child - list.first_child.tasklist_item_checked = false - refute_predicate(list.first_child, :tasklist_item_checked?) - list.first_child.next.tasklist_item_checked = true - assert_predicate(list.first_child.next, :tasklist_item_checked?) + assert_equal(expected, html) end end From 89f48e6d34f1e160b04160cca9f08e2c8673342e Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:19:53 -0400 Subject: [PATCH 05/14] typo --- test/test_maliciousness.rb | 68 ++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/test/test_maliciousness.rb b/test/test_maliciousness.rb index 0a9f4bdb..4185d826 100644 --- a/test/test_maliciousness.rb +++ b/test/test_maliciousness.rb @@ -2,51 +2,49 @@ require "test_helper" -module CommonMarker - class TestMaliciousness < Minitest::Test - def test_rendering_with_bad_type - assert_raises(TypeError) do - Commonmarker.to_html(nil) - end +class TestMaliciousness < Minitest::Test + def test_rendering_with_bad_type + assert_raises(TypeError) do + Commonmarker.to_html(nil) + end - assert_raises(TypeError) do - Commonmarker.to_html(123) - end + assert_raises(TypeError) do + Commonmarker.to_html(123) + end - assert_raises(TypeError) do - Commonmarker.to_html([123]) - end + assert_raises(TypeError) do + Commonmarker.to_html([123]) + end - assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: 123) - end + assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: 123) + end - assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: :totes_fake) - end + assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: :totes_fake) + end - assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: []) - end + assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: []) + end - assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: [23]) - end + assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: [23]) + end - assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: nil) - end + assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: nil) + end - assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: [:SMART, "totes_fake"]) - end + assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: [:SMART, "totes_fake"]) end + end - def test_bad_options_value - err = assert_raises(TypeError) do - Commonmarker.to_html("foo \n baz", options: { parse: { smart: 111 } }) - end - assert_equal("parse_options[:smart] must be a Boolean; got Integer", err.message) + def test_bad_options_value + err = assert_raises(TypeError) do + Commonmarker.to_html("foo \n baz", options: { parse: { smart: 111 } }) end + assert_equal("parse_options[:smart] must be a Boolean; got Integer", err.message) end end From f4ff7469fac9cf2f308b0dbc61ad54ed68c5f1f0 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:22:11 -0400 Subject: [PATCH 06/14] drop older ruby support --- .github/workflows/test.yml | 4 ++-- commonmarker.gemspec | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5a5c1bfb..38b0a6c2 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,7 @@ on: types: [opened, synchronize, reopened] push: branches: - - production + - main jobs: test: @@ -16,7 +16,7 @@ jobs: - ubuntu-latest - macos-latest - windows-latest - ruby-version: [3.1, 3.0.0, 2.7.2, 2.6.6] + ruby-version: [3.1, 3.0] runs-on: ${{ matrix.os }} diff --git a/commonmarker.gemspec b/commonmarker.gemspec index 8c026317..98e19a6b 100644 --- a/commonmarker.gemspec +++ b/commonmarker.gemspec @@ -19,7 +19,7 @@ Gem::Specification.new do |spec| spec.extensions = ["ext/commonmarker/extconf.rb"] spec.require_paths = ["lib", "ext"] - spec.required_ruby_version = [">= 2.7", "< 4.0"] + spec.required_ruby_version = [">= 3.0", "< 4.0"] spec.metadata["rubygems_mfa_required"] = "true" From 838998f7f2cc317ea387ef9493424bbddd1e6f73 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:22:45 -0400 Subject: [PATCH 07/14] funding --- commonmarker.gemspec | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/commonmarker.gemspec b/commonmarker.gemspec index 98e19a6b..2c2b443a 100644 --- a/commonmarker.gemspec +++ b/commonmarker.gemspec @@ -21,7 +21,10 @@ Gem::Specification.new do |spec| spec.require_paths = ["lib", "ext"] spec.required_ruby_version = [">= 3.0", "< 4.0"] - spec.metadata["rubygems_mfa_required"] = "true" + spec.metadata = { + "funding_uri" => "https://github.com/sponsors/gjtorikian/", + "rubygems_mfa_required" => "true", + } spec.add_development_dependency("awesome_print") spec.add_development_dependency("debug") if "#{RbConfig::CONFIG["MAJOR"]}.#{RbConfig::CONFIG["MINOR"]}".to_f >= 3.1 From 1dd97e543eb7f588d855ecefa54b91976b07c7b2 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:37:29 -0400 Subject: [PATCH 08/14] show me what you got --- ext/commonmarker/extconf.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index db3939df..5ecb3d73 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -1,8 +1,18 @@ require "mkmf" require "mini_portile2" -PACKAGE_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")) -EXT_DIR = File.join(PACKAGE_ROOT_DIR, "ext", "commonmarker") + +windows = RUBY_PLATFORM =~ /mingw|mswin/ +windows_ucrt = RUBY_PLATFORM =~ /(mingw|mswin).*ucrt/ +bsd = RUBY_PLATFORM =~ /bsd/ +darwin = RUBY_PLATFORM =~ /darwin/ +linux = RUBY_PLATFORM =~ /linux/ +cross_compiling = ENV['RCD_HOST_RUBY_VERSION'] # set by rake-compiler-dock in build containers +# TruffleRuby uses the Sulong LLVM runtime, which is different from Apple's. +apple_toolchain = darwin && RUBY_ENGINE != 'truffleruby' + +GEM_ROOT_DIR = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")) +EXT_DIR = File.join(GEM_ROOT_DIR, "ext", "commonmarker") CROSS_BUILD_P = enable_config("cross-build") RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] @@ -22,7 +32,7 @@ def darwin? TARBALL_URL = "https://github.com/#{USER}/comrak/archive/refs/heads/#{COMRAK_VERSION}.tar.gz" MiniPortile.new("comrak", COMRAK_VERSION).tap do |recipe| - recipe.target = File.join(PACKAGE_ROOT_DIR, "ports") + recipe.target = File.join(GEM_ROOT_DIR, "ports") recipe.files = [{ url: TARBALL_URL, # sha256: "055fa44ef002a1a07853d3a4dd2a8c553a1dc58ff3809b4fa530ed35694d8571", @@ -50,7 +60,8 @@ def darwin? end # Why is this so long? - tarball_extract_path = File.join(PACKAGE_ROOT_DIR, "tmp", host, "commonmarker", RUBY_VERSION, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") + tarball_extract_path = File.join(GEM_ROOT_DIR, "tmp", host, "commonmarker", RUBY_VERSION, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") + puts `ls -LR` Dir.chdir(tarball_extract_path) do puts `cargo build --manifest-path=./c-api/Cargo.toml --release` end From 1764782a3b87536a58c65074be8a14d7f63f6559 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Mon, 1 Aug 2022 18:45:08 -0400 Subject: [PATCH 09/14] not sure what is up with `tarball_extract_path` --- ext/commonmarker/extconf.rb | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index 5ecb3d73..06f9d52a 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -1,7 +1,6 @@ require "mkmf" require "mini_portile2" - windows = RUBY_PLATFORM =~ /mingw|mswin/ windows_ucrt = RUBY_PLATFORM =~ /(mingw|mswin).*ucrt/ bsd = RUBY_PLATFORM =~ /bsd/ @@ -52,16 +51,15 @@ def darwin? recipe.download unless recipe.downloaded? recipe.extract - host = if darwin? + tarball_extract_path = if darwin? recipe.host =~ /arm64-apple-darwin(\d+)\.\d+\.0/ - "arm64-darwin#{$1}" + host = "arm64-darwin#{$1}" + File.join(GEM_ROOT_DIR, "tmp", host, "commonmarker", RUBY_VERSION, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") else - recipe.host + File.join(GEM_ROOT_DIR, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") end # Why is this so long? - tarball_extract_path = File.join(GEM_ROOT_DIR, "tmp", host, "commonmarker", RUBY_VERSION, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") - puts `ls -LR` Dir.chdir(tarball_extract_path) do puts `cargo build --manifest-path=./c-api/Cargo.toml --release` end From a76379a2e5108bb88e4a7f0048e6b4a59264dc34 Mon Sep 17 00:00:00 2001 From: Asherah Connor <asherah@hrzn.ee> Date: Fri, 5 Aug 2022 10:37:27 +1000 Subject: [PATCH 10/14] Makefile: remove Was only used to assist in bringing upstream cmark sources in. --- Makefile | 26 -------------------------- 1 file changed, 26 deletions(-) delete mode 100644 Makefile diff --git a/Makefile b/Makefile deleted file mode 100644 index b92c1c11..00000000 --- a/Makefile +++ /dev/null @@ -1,26 +0,0 @@ -C_SOURCES = $(wildcard ext/commonmarker/*.[ch]) - -update-c-sources: build-upstream $(C_SOURCES) - -.PHONY: build-upstream - -build-upstream: - cd ext/commonmarker/cmark-upstream && make - -ext/commonmarker/%: ext/commonmarker/cmark-upstream/src/% - cp $< $@ - -ext/commonmarker/%: ext/commonmarker/cmark-upstream/extensions/% - cp $< $@ - -ext/commonmarker/config.h: ext/commonmarker/cmark-upstream/build/src/config.h - cp $< $@ - -ext/commonmarker/cmark-gfm_export.h: ext/commonmarker/cmark-upstream/build/src/cmark-gfm_export.h - cp $< $@ - -ext/commonmarker/cmark-gfm_version.h: ext/commonmarker/cmark-upstream/build/src/cmark-gfm_version.h - cp $< $@ - -ext/commonmarker/cmark-gfm-extensions_export.h: ext/commonmarker/cmark-upstream/build/extensions/cmark-gfm-extensions_export.h - cp $< $@ From aa4afdece00bcd9bea4f8968368cb9ac7679d992 Mon Sep 17 00:00:00 2001 From: Asherah Connor <asherah@hrzn.ee> Date: Fri, 5 Aug 2022 10:38:06 +1000 Subject: [PATCH 11/14] ext: avoid warnings in rb_hash_foreach calls --- ext/commonmarker/commonmarker.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c index 71509159..111399ed 100644 --- a/ext/commonmarker/commonmarker.c +++ b/ext/commonmarker/commonmarker.c @@ -4,7 +4,9 @@ #include "comrak_ffi.h" -int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { +int iterate_extension_options(VALUE key, VALUE val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + if (key == ID2SYM(rb_intern("strikethrough"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_extension_option_strikethrough(config, val); @@ -50,7 +52,9 @@ int iterate_extension_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_render_options(VALUE key, VALUE val, comrak_options_t *config) { +int iterate_render_options(VALUE key, VALUE val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + if (key == ID2SYM(rb_intern("hardbreaks"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_render_option_hardbreaks(config, val); @@ -77,7 +81,9 @@ int iterate_render_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { +int iterate_parse_options(VALUE key, VALUE val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + if (key == ID2SYM(rb_intern("smart"))) { if (TYPE(val) == T_TRUE || TYPE(val) == T_FALSE) { comrak_set_parse_option_smart(config, val); @@ -92,22 +98,24 @@ int iterate_parse_options(VALUE key, VALUE val, comrak_options_t *config) { return ST_CONTINUE; } -int iterate_options_hash(VALUE rb_option_key, VALUE rb_option_val, comrak_options_t *config) { +int iterate_options_hash(VALUE rb_option_key, VALUE rb_option_val, VALUE arg) { + comrak_options_t *config = (comrak_options_t *)arg; + Check_Type(rb_option_key, T_SYMBOL); // which options are we dealing with? if (rb_option_key == ID2SYM(rb_intern("parse"))) { Check_Type(rb_option_val, T_HASH); - rb_hash_foreach(rb_option_val, iterate_parse_options, config); + rb_hash_foreach(rb_option_val, iterate_parse_options, (VALUE)config); } else if (rb_option_key == ID2SYM(rb_intern("render"))) { Check_Type(rb_option_val, T_HASH); - rb_hash_foreach(rb_option_val, iterate_render_options, config); + rb_hash_foreach(rb_option_val, iterate_render_options, (VALUE)config); } else if (rb_option_key == ID2SYM(rb_intern("extension"))) { Check_Type(rb_option_val, T_HASH); if (rb_hash_aref(rb_option_val, ID2SYM(rb_intern("header_ids"))) == Qnil) { comrak_set_extension_option_header_ids(config, NULL, 0); } - rb_hash_foreach(rb_option_val, iterate_extension_options, config); + rb_hash_foreach(rb_option_val, iterate_extension_options, (VALUE)config); } @@ -121,7 +129,7 @@ VALUE commonmark_to_html(VALUE self, VALUE rb_commonmark, VALUE rb_options) { char *commonmark = StringValueCStr(rb_commonmark); comrak_options_t *options = comrak_options_new(); - rb_hash_foreach(rb_options, iterate_options_hash, options); + rb_hash_foreach(rb_options, iterate_options_hash, (VALUE)options); comrak_str_t html = comrak_commonmark_to_html(commonmark, options); From 9962914e889a61aa72369d85659bacd8114f08c0 Mon Sep 17 00:00:00 2001 From: Asherah Connor <asherah@hrzn.ee> Date: Fri, 5 Aug 2022 10:48:02 +1000 Subject: [PATCH 12/14] get all CI working --- .github/workflows/test.yml | 5 +++++ ext/commonmarker/extconf.rb | 17 +++-------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 38b0a6c2..7036bdda 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,6 +31,11 @@ jobs: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true # 'bundle install' and cache + - name: Set Cargo triple + if: runner.os == 'Windows' + shell: bash + run: rustup default stable-x86_64-pc-windows-gnu + - name: Run ${{ matrix.os }} tests shell: bash run: script/cibuild diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index 06f9d52a..8d9eb289 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -17,10 +17,6 @@ RbConfig::CONFIG["CC"] = RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"] ENV["CC"] = RbConfig::CONFIG["CC"] -def darwin? - RbConfig::CONFIG["target_os"].include?("darwin") -end - # what follows is pretty much an abuse of miniportile2, but it works for now # i just need something to download files and run a cargo build; one day this should # be replaced with actual prepacked binaries. @@ -51,17 +47,9 @@ def darwin? recipe.download unless recipe.downloaded? recipe.extract - tarball_extract_path = if darwin? - recipe.host =~ /arm64-apple-darwin(\d+)\.\d+\.0/ - host = "arm64-darwin#{$1}" - File.join(GEM_ROOT_DIR, "tmp", host, "commonmarker", RUBY_VERSION, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") - else - File.join(GEM_ROOT_DIR, "tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") - end - - # Why is this so long? + tarball_extract_path = File.join("tmp", recipe.host, "ports", recipe.name, recipe.version, "#{recipe.name}-#{recipe.version}") Dir.chdir(tarball_extract_path) do - puts `cargo build --manifest-path=./c-api/Cargo.toml --release` + system "cargo build --manifest-path=./c-api/Cargo.toml --release" end lib_header_path = File.join(tarball_extract_path, "c-api", "include") lib_build_path = File.join(tarball_extract_path, "c-api", "target", "release") @@ -75,6 +63,7 @@ def darwin? recipe.activate $LIBS << ' -lcomrak_ffi' + $LIBS << ' -lbcrypt' if windows end unless find_header("comrak_ffi.h") From 3f677f56bbf1becb47981278ed36b5c79eb30c27 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Fri, 5 Aug 2022 14:13:09 -0400 Subject: [PATCH 13/14] cleanup --- Gemfile | 1 + README.md | 26 +++++++++++++++----------- lib/commonmarker/config.rb | 1 + rakelib/benchmark.rake | 2 +- rakelib/compile.rake | 2 +- script/cibuild | 3 +-- test/benchmark.rb | 9 +++------ 7 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Gemfile b/Gemfile index 36ca595a..2ec41838 100644 --- a/Gemfile +++ b/Gemfile @@ -7,5 +7,6 @@ gemspec group :benchmark do gem "benchmark-ips" gem "kramdown" + gem "kramdown-parser-gfm" gem "redcarpet" end diff --git a/README.md b/README.md index de15bbed..82ed9dbf 100644 --- a/README.md +++ b/README.md @@ -109,22 +109,26 @@ If there were no errors, you're done! Otherwise, make sure to follow the comrak ## Benchmarks -See [BENCHMARKS.md](BENCHMARKS.md) Some rough benchmarks: ``` $ bundle exec rake benchmark -input size = 11063727 bytes +input size = 11064832 bytes -redcarpet - 0.070000 0.020000 0.090000 ( 0.079641) -github-markdown - 0.070000 0.010000 0.080000 ( 0.083535) +Warming up -------------------------------------- + redcarpet 2.000 i/100ms commonmarker with to_html - 0.100000 0.010000 0.110000 ( 0.111947) -commonmarker with ruby HtmlRenderer - 1.830000 0.030000 1.860000 ( 1.866203) -kramdown - 4.610000 0.070000 4.680000 ( 4.678398) + 1.000 i/100ms + kramdown 1.000 i/100ms +Calculating ------------------------------------- + redcarpet 22.634 (± 4.4%) i/s - 114.000 in 5.054490s +commonmarker with to_html + 7.340 (± 0.0%) i/s - 37.000 in 5.058352s + kramdown 0.343 (± 0.0%) i/s - 2.000 in 5.834208s + +Comparison: + redcarpet: 22.6 i/s +commonmarker with to_html: 7.3 i/s - 3.08x (± 0.00) slower + kramdown: 0.3 i/s - 66.02x (± 0.00) slower ``` diff --git a/lib/commonmarker/config.rb b/lib/commonmarker/config.rb index 7ec8c3e0..9611eb90 100644 --- a/lib/commonmarker/config.rb +++ b/lib/commonmarker/config.rb @@ -52,6 +52,7 @@ def self.process_options(options) next end + # option explicitly not included, remove it next if options[key].nil? value_klass = value.class diff --git a/rakelib/benchmark.rake b/rakelib/benchmark.rake index 322776b4..ed561b76 100644 --- a/rakelib/benchmark.rake +++ b/rakelib/benchmark.rake @@ -2,7 +2,7 @@ desc "Run benchmarks" task :benchmark do - if ENV["FETCH_PROGIT"] + unless File.exist?("test/progit") %x(rm -rf test/progit) %x(git clone https://github.com/progit/progit.git test/progit) langs = ["ar", "az", "be", "ca", "cs", "de", "en", "eo", "es", "es-ni", "fa", "fi", "fr", "hi", "hu", "id", "it", "ja", "ko", "mk", "nl", "no-nb", "pl", "pt-br", "ro", "ru", "sr", "th", "tr", "uk", "vi", "zh", "zh-tw"] diff --git a/rakelib/compile.rake b/rakelib/compile.rake index 4742623d..ab6dd252 100644 --- a/rakelib/compile.rake +++ b/rakelib/compile.rake @@ -3,7 +3,7 @@ require "rake/clean" require "rake/extensiontask" -CROSS_RUBIES = ["3.1.0", "3.0.0", "2.7.0"] +CROSS_RUBIES = ["3.1.0", "3.0.0"] CROSS_PLATFORMS = [ "x64-mingw32", "x64-mingw-ucrt", diff --git a/script/cibuild b/script/cibuild index 5c23ddf0..cad63ece 100755 --- a/script/cibuild +++ b/script/cibuild @@ -3,5 +3,4 @@ set -e bundle -bundle exec rake clean -bundle exec rake test +bundle exec rake clean compile test diff --git a/test/benchmark.rb b/test/benchmark.rb index 3b9ea977..e839fd24 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -4,6 +4,7 @@ require "commonmarker" require "redcarpet" require "kramdown" +require 'kramdown-parser-gfm' require "benchmark" benchinput = File.read("test/benchinput.md").freeze @@ -12,19 +13,15 @@ Benchmark.ips do |x| x.report("redcarpet") do - Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: false, tables: false).render(benchinput) + Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true, strikethrough: true, footnotes: true).render(benchinput) end x.report("commonmarker with to_html") do - Commonmarker.render_html(benchinput) - end - - x.report("commonmarker with to_xml") do Commonmarker.to_html(benchinput) end x.report("kramdown") do - Kramdown::Document.new(benchinput).to_html(benchinput) + Kramdown::Document.new(benchinput, input: 'GFM').to_html end x.compare! From be3071b1ae64a25446ccc0f6bf79746a209e70d4 Mon Sep 17 00:00:00 2001 From: "Garen J. Torikian" <gjtorikian@users.noreply.github.com> Date: Fri, 5 Aug 2022 14:15:03 -0400 Subject: [PATCH 14/14] lint --- ext/commonmarker/commonmarker.c | 1 - test/benchmark.rb | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c index 111399ed..20b3f491 100644 --- a/ext/commonmarker/commonmarker.c +++ b/ext/commonmarker/commonmarker.c @@ -116,7 +116,6 @@ int iterate_options_hash(VALUE rb_option_key, VALUE rb_option_val, VALUE arg) { comrak_set_extension_option_header_ids(config, NULL, 0); } rb_hash_foreach(rb_option_val, iterate_extension_options, (VALUE)config); - } return ST_CONTINUE; diff --git a/test/benchmark.rb b/test/benchmark.rb index e839fd24..c6c1d564 100644 --- a/test/benchmark.rb +++ b/test/benchmark.rb @@ -4,7 +4,7 @@ require "commonmarker" require "redcarpet" require "kramdown" -require 'kramdown-parser-gfm' +require "kramdown-parser-gfm" require "benchmark" benchinput = File.read("test/benchinput.md").freeze @@ -21,7 +21,7 @@ end x.report("kramdown") do - Kramdown::Document.new(benchinput, input: 'GFM').to_html + Kramdown::Document.new(benchinput, input: "GFM").to_html end x.compare!
", "a", "", "c", "