From 2bd0073b6e7db911e74bb6829d0b3f31b6f1f4e0 Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 11 Oct 2016 14:22:53 -0700 Subject: [PATCH 01/11] Revert "cmark extensions" --- .gitmodules | 2 +- Rakefile | 3 - appveyor.yml | 16 ---- bin/commonmarker | 22 +---- ext/commonmarker/cmark | 2 +- ext/commonmarker/commonmarker.c | 147 ++++---------------------------- ext/commonmarker/commonmarker.h | 4 - ext/commonmarker/extconf.rb | 17 ++-- lib/commonmarker.rb | 14 ++- lib/commonmarker/node.rb | 15 +--- lib/commonmarker/renderer.rb | 2 +- script/update_submodules | 4 +- test/test_commonmark.rb | 34 -------- test/test_encoding.rb | 3 +- test/test_extensions.rb | 50 ----------- test/test_helper.rb | 3 +- 16 files changed, 38 insertions(+), 300 deletions(-) delete mode 100644 appveyor.yml delete mode 100644 test/test_commonmark.rb delete mode 100644 test/test_extensions.rb diff --git a/.gitmodules b/.gitmodules index d61964e6..a8c4fb06 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "ext/commonmarker/cmark"] path = ext/commonmarker/cmark - url = https://github.com/kivikakk/cmark.git + url = https://github.com/jgm/cmark.git ignore = dirty diff --git a/Rakefile b/Rakefile index 0b6b2f26..43f350eb 100644 --- a/Rakefile +++ b/Rakefile @@ -3,9 +3,6 @@ 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 diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index fbd8f8a1..00000000 --- a/appveyor.yml +++ /dev/null @@ -1,16 +0,0 @@ -# appveyor.yml -install: - - set PATH=C:\Ruby22\bin;%PATH% - - git submodule init - - git submodule update - - bundle install - -build: off - -before_test: - - ruby -v - - gem -v - - bundle -v - -test_script: - - bundle exec rake diff --git a/bin/commonmarker b/bin/commonmarker index 71cf8a02..094db054 100755 --- a/bin/commonmarker +++ b/bin/commonmarker @@ -1,11 +1,9 @@ #!/usr/bin/env ruby -# Usage: commonmarker [--html-renderer] [--list-extensions] [--extension=EXTENSION] [FILE..] +# Usage: commonmarker [--html-renderer] [FILE..] # Convert one or more CommonMark files to HTML and write to standard output. # If no FILE argument is provided, text will be read from STDIN. # With --html-renderer, use the HtmlRenderer renderer rather than the native C # renderer. -# With --extension=EXTENSION, EXTENSION will be used for parsing, and HTML -# output unless --html-renderer is specified. if ARGV.include?('--help') or ARGV.include?('-h') File.read(__FILE__).split("\n").grep(/^# /).each do |line| puts line[2..-1] @@ -24,34 +22,20 @@ end root = File.expand_path('../../', __FILE__) $:.unshift File.expand_path('lib', root) -extensions = CommonMarker.extensions -active_extensions = [] - renderer = nil ARGV.delete_if do |arg| if arg =~ /^--html-renderer$/ renderer = CommonMarker::HtmlRenderer.new true - elsif arg =~ /^--list-extensions$/ - puts extensions - exit 0 - elsif arg =~ /^--extension=(.+)$/ - if extensions.include?($1) - active_extensions << $1 - else - STDERR.puts "extension #$1 not found" - exit 1 - end - true else false end end -doc = CommonMarker.render_doc(ARGF.read, :default, active_extensions) +doc = CommonMarker.render_doc(ARGF.read) if renderer STDOUT.write(renderer.render(doc)) else - STDOUT.write(doc.to_html(:default, active_extensions)) + STDOUT.write(doc.to_html) end diff --git a/ext/commonmarker/cmark b/ext/commonmarker/cmark index 90bde9f9..e91dc121 160000 --- a/ext/commonmarker/cmark +++ b/ext/commonmarker/cmark @@ -1 +1 @@ -Subproject commit 90bde9f9cf5df589f03ceb8a5cf8802f97a26999 +Subproject commit e91dc12128b156f1b355e88b3d4f46ad162f1dc5 diff --git a/ext/commonmarker/commonmarker.c b/ext/commonmarker/commonmarker.c index 073d5962..bed02218 100644 --- a/ext/commonmarker/commonmarker.c +++ b/ext/commonmarker/commonmarker.c @@ -2,10 +2,6 @@ #include "cmark.h" #include "houdini.h" #include "node.h" -#include "registry.h" -#include "parser.h" -#include "syntax_extension.h" -#include "core-extensions.h" static VALUE rb_mNodeError; static VALUE rb_mNode; @@ -95,69 +91,24 @@ 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; - int extensions_len; - VALUE rb_ext_name; - int i; - - Check_Type(rb_options, T_FIXNUM); - Check_Type(rb_extensions, T_ARRAY); - - options = FIX2INT(rb_options); - extensions_len = RARRAY_LEN(rb_extensions); - - cmark_parser *parser = cmark_parser_new(options); - for (i = 0; i < extensions_len; ++i) { - rb_ext_name = RARRAY_PTR(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 *str, *html; - int len; - cmark_parser *parser; - cmark_node *doc; +static VALUE rb_markdown_to_html(VALUE self, VALUE rb_text, VALUE rb_options) { + char *str; + int len, options; + Check_Type(rb_text, T_STRING); Check_Type(rb_options, T_FIXNUM); - parser = prepare_parser(rb_options, rb_extensions); - str = (char *)RSTRING_PTR(rb_text); len = RSTRING_LEN(rb_text); + options = FIX2INT(rb_options); - cmark_parser_feed(parser, str, len); - doc = cmark_parser_finish(parser); - if (doc == NULL) { - rb_raise(rb_mNodeError, "error parsing document"); - } - - html = cmark_render_html(doc, FIX2INT(rb_options), parser->syntax_extensions); - cmark_parser_free(parser); - cmark_node_free(doc); - + char *html = cmark_markdown_to_html(str, len, options); VALUE ruby_html = rb_str_new2(html); + free(html); return ruby_html; @@ -245,27 +196,22 @@ static VALUE rb_node_new(VALUE self, VALUE type) { * */ static VALUE rb_parse_document(VALUE self, VALUE rb_text, VALUE rb_len, - VALUE rb_options, VALUE rb_extensions) { + VALUE rb_options) { char *text; int len, options; - 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); options = FIX2INT(rb_options); - cmark_parser_feed(parser, text, len); - doc = cmark_parser_finish(parser); + doc = cmark_parse_document(text, len, options); if (doc == NULL) { rb_raise(rb_mNodeError, "error parsing document"); } - cmark_parser_free(parser); return rb_node_to_value(doc); } @@ -493,67 +439,23 @@ static VALUE rb_node_insert_before(VALUE self, VALUE sibling) { * * Returns a {String}. */ -static VALUE rb_render_html(VALUE n, VALUE rb_options, VALUE rb_extensions) { - int options, extensions_len; - VALUE rb_ext_name; - int i; +static VALUE rb_render_html(VALUE n, VALUE rb_options) { + int options; cmark_node *node; - cmark_llist *extensions = NULL; 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(n, 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(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(extensions); - rb_raise(rb_eArgError, "extension %s not found\n", rb_id2name(SYM2ID(rb_ext_name))); - } - - extensions = cmark_llist_append(extensions, syntax_extension); - } - - char *html = cmark_render_html(node, options, extensions); + char *html = cmark_render_html(node, options); VALUE ruby_html = rb_str_new2(html); - cmark_llist_free(extensions); free(html); return ruby_html; } -/* Internal: Convert the node to a CommonMark string. - * - * Returns a {String}. - */ -static VALUE rb_render_commonmark(VALUE n, VALUE rb_options) { - int options; - cmark_node *node; - Check_Type(rb_options, T_FIXNUM); - - options = FIX2INT(rb_options); - Data_Get_Struct(n, cmark_node, node); - - char *cmark = cmark_render_commonmark(node, options, 120); - VALUE ruby_cmark = rb_str_new2(cmark); - free(cmark); - - return ruby_cmark; -} - /* * Public: Inserts a node as a sibling after the current node. * @@ -1005,21 +907,6 @@ static VALUE rb_html_escape_html(VALUE self, VALUE rb_text) { return rb_text; } -VALUE rb_extensions(VALUE self) { - cmark_llist *exts, *it; - cmark_syntax_extension *ext; - VALUE ary = rb_ary_new(); - - exts = cmark_list_syntax_extensions(); - for (it = exts; it; it = it->next) { - ext = it->data; - rb_ary_push(ary, rb_str_new2(ext->name)); - } - cmark_llist_free(exts); - - return ary; -} - __attribute__((visibility("default"))) void Init_commonmarker() { VALUE module; sym_document = ID2SYM(rb_intern("document")); @@ -1045,13 +932,12 @@ __attribute__((visibility("default"))) void Init_commonmarker() { sym_ordered_list = ID2SYM(rb_intern("ordered_list")); module = rb_define_module("CommonMarker"); - rb_define_singleton_method(module, "extensions", rb_extensions, 0); rb_mNodeError = rb_define_class_under(module, "NodeError", rb_eStandardError); rb_mNode = rb_define_class_under(module, "Node", rb_cObject); rb_define_singleton_method(rb_mNode, "markdown_to_html", rb_markdown_to_html, - 3); + 2); rb_define_singleton_method(rb_mNode, "new", rb_node_new, 1); - rb_define_singleton_method(rb_mNode, "parse_document", rb_parse_document, 4); + rb_define_singleton_method(rb_mNode, "parse_document", rb_parse_document, 3); rb_define_method(rb_mNode, "string_content", rb_node_get_string_content, 0); rb_define_method(rb_mNode, "string_content=", rb_node_set_string_content, 1); rb_define_method(rb_mNode, "type", rb_node_get_type, 0); @@ -1061,8 +947,7 @@ __attribute__((visibility("default"))) void Init_commonmarker() { rb_define_method(rb_mNode, "first_child", rb_node_first_child, 0); rb_define_method(rb_mNode, "next", rb_node_next, 0); rb_define_method(rb_mNode, "insert_before", rb_node_insert_before, 1); - rb_define_method(rb_mNode, "_render_html", rb_render_html, 2); - rb_define_method(rb_mNode, "_render_commonmark", rb_render_commonmark, 1); + rb_define_method(rb_mNode, "_render_html", rb_render_html, 1); rb_define_method(rb_mNode, "insert_after", rb_node_insert_after, 1); rb_define_method(rb_mNode, "prepend_child", rb_node_prepend_child, 1); rb_define_method(rb_mNode, "append_child", rb_node_append_child, 1); @@ -1086,6 +971,4 @@ __attribute__((visibility("default"))) void Init_commonmarker() { rb_define_method(rb_mNode, "html_escape_href", rb_html_escape_href, 1); rb_define_method(rb_mNode, "html_escape_html", rb_html_escape_html, 1); - - cmark_register_plugin(core_extensions_registration); } diff --git a/ext/commonmarker/commonmarker.h b/ext/commonmarker/commonmarker.h index 7ab1128e..a5d59990 100644 --- a/ext/commonmarker/commonmarker.h +++ b/ext/commonmarker/commonmarker.h @@ -1,10 +1,6 @@ #ifndef COMMONMARKER_H #define COMMONMARKER_H -#ifndef __MSXML_LIBRARY_DEFINED__ -#define __MSXML_LIBRARY_DEFINED__ -#endif - #include "cmark.h" #include "ruby.h" diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index 63d2e5fa..3a3521d9 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -23,30 +23,23 @@ FileUtils.mkdir_p(CMARK_BUILD_DIR) Dir.chdir(CMARK_BUILD_DIR) do - if host_os == 'mingw32' - system 'cmake .. -G "MSYS Makefiles"' - else - system 'cmake .. -DCMAKE_C_FLAGS=-fPIC' - end - system "make libcmark_static" or abort "make libcmark_static failed" - system "make libcmarkextensions_static" or abort "make libcmarkextensions_static failed" + system 'cmake .. -DCMAKE_C_FLAGS=-fPIC' + system 'make libcmark_static' # rake-compiler seems to complain about this line, not sure why it's messing with it FileUtils.rm_rf(File.join(CMARK_BUILD_DIR, 'Testing', 'Temporary')) end HEADER_DIRS = [INCLUDEDIR] -LIB_DIRS = [LIBDIR, "#{CMARK_BUILD_DIR}/src", "#{CMARK_BUILD_DIR}/extensions"] +LIB_DIRS = [LIBDIR, "#{CMARK_BUILD_DIR}/src"] dir_config('cmark', HEADER_DIRS, LIB_DIRS) # don't even bother to do this check if using OS X's messed up system Ruby: http://git.io/vsxkn unless sitearch =~ /^universal-darwin/ abort 'libcmark is missing.' unless find_library('cmark', 'cmark_parse_document') - abort 'cmarkextensions is missing.' unless find_library('cmarkextensions', 'core_extensions_registration') end -$LDFLAGS << " -L#{CMARK_BUILD_DIR}/src -L#{CMARK_BUILD_DIR}/extensions -lcmark -lcmarkextensions" -$CFLAGS << " -O2 -I#{CMARK_DIR}/src -I#{CMARK_DIR}/extensions -I#{CMARK_BUILD_DIR}/src" -$CFLAGS << " -DCMARK_STATIC_DEFINE" +$LDFLAGS << " -L#{CMARK_BUILD_DIR}/src -lcmark" +$CFLAGS << " -O2 -I#{CMARK_DIR}/src -I#{CMARK_BUILD_DIR}/src" create_makefile('commonmarker/commonmarker') diff --git a/lib/commonmarker.rb b/lib/commonmarker.rb index 838e6ff0..cd2e2281 100755 --- a/lib/commonmarker.rb +++ b/lib/commonmarker.rb @@ -15,14 +15,13 @@ module CommonMarker # # 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 # # Returns a {String} of converted HTML. - def self.render_html(text, options = :default, extensions = []) - fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) + def self.render_html(text, options = :default) + fail TypeError, 'text must be a string!' unless text.is_a?(String) opts = Config.process_options(options, :render) text = text.encode('UTF-8') - html = Node.markdown_to_html(text, opts, extensions) + html = Node.markdown_to_html(text, opts) html.force_encoding('UTF-8') end @@ -30,13 +29,12 @@ def self.render_html(text, options = :default, extensions = []) # # 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 = []) - fail TypeError, "text must be a String; got a #{text.class}!" unless text.is_a?(String) + def self.render_doc(text, options = :default) + fail TypeError, 'text must be a string!' unless text.is_a?(String) opts = Config.process_options(options, :parse) text = text.encode('UTF-8') - Node.parse_document(text, text.bytesize, opts, extensions) + Node.parse_document(text, text.bytesize, opts) end end diff --git a/lib/commonmarker/node.rb b/lib/commonmarker/node.rb index 3bcc70dc..d86c725d 100644 --- a/lib/commonmarker/node.rb +++ b/lib/commonmarker/node.rb @@ -17,22 +17,11 @@ def walk(&block) # 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 = []) + def to_html(options = :default) opts = Config.process_options(options, :render) - _render_html(opts, extensions).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 - # - # Returns a {String}. - def to_commonmark(options = :default) - opts = Config.process_options(options, :render) - _render_commonmark(opts).force_encoding('utf-8') + _render_html(opts).force_encoding('utf-8') end # Public: Iterate over the children (if any) of the current pointer. diff --git a/lib/commonmarker/renderer.rb b/lib/commonmarker/renderer.rb index 91dea834..87e85f9c 100644 --- a/lib/commonmarker/renderer.rb +++ b/lib/commonmarker/renderer.rb @@ -5,7 +5,7 @@ module CommonMarker class Renderer attr_accessor :in_tight, :warnings, :in_plain def initialize - @stream = StringIO.new("".force_encoding("utf-8")) + @stream = StringIO.new @need_blocksep = false @warnings = Set.new [] @in_tight = false diff --git a/script/update_submodules b/script/update_submodules index 18e194de..ebd8f347 100755 --- a/script/update_submodules +++ b/script/update_submodules @@ -3,7 +3,7 @@ set -e if [ -z "$1" ]; then - BRANCH="extensions" + BRANCH="master" else BRANCH=$1 fi @@ -18,4 +18,4 @@ git checkout $BRANCH && git pull sha=`git rev-parse HEAD` cd ../../.. git add ext/commonmarker/cmark -git commit -m "Update cmark to $(git config submodule.ext/commonmarker/cmark.url | sed s_.git\$__)/commit/${sha}" +git commit -m "Update cmark to https://github.com/jgm/cmark/commit/${sha}" diff --git a/test/test_commonmark.rb b/test/test_commonmark.rb deleted file mode 100644 index f8afd9de..00000000 --- a/test/test_commonmark.rb +++ /dev/null @@ -1,34 +0,0 @@ -require 'test_helper' - -class TestCommonmark < Minitest::Test - HTML_COMMENT = %r[\s?] - - 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, %i[table]) - end - - def test_to_commonmark - compare = render_doc(@markdown).to_commonmark - - assert_equal \ - render_doc(@markdown).to_html.gsub(HTML_COMMENT, ''), - render_doc(compare).to_html.gsub(HTML_COMMENT, '') - end -end diff --git a/test/test_encoding.rb b/test/test_encoding.rb index a3605be4..9fcd8c8c 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -1,10 +1,9 @@ -# coding: utf-8 require 'test_helper' class TestEncoding < Minitest::Test # see http://git.io/vq4FR def test_encoding - contents = File.read(File.join(FIXTURES_DIR, 'curly.md'), encoding: 'utf-8') + contents = File.read(File.join(FIXTURES_DIR, 'curly.md')) doc = CommonMarker.render_doc(contents, :smart) render = doc.to_html assert_equal render.rstrip, '

This curly quote “makes commonmarker throw an exception”.

' diff --git a/test/test_extensions.rb b/test/test_extensions.rb deleted file mode 100644 index 41974ee7..00000000 --- a/test/test_extensions.rb +++ /dev/null @@ -1,50 +0,0 @@ -require 'test_helper' - -class TestExtensions < Minitest::Test - def setup - @markdown = <<-MD -One extension: - -| a | b | -| --- | --- | -| c | d | -| **x** | | - -Another extension: - -~~hi~~ - MD - end - - def test_uses_specified_extensions - CommonMarker.render_html(@markdown, :default, %i[]).tap do |out| - assert out.include?("| a") - assert out.include?("| x") - assert out.include?("~~hi~~") - end - - CommonMarker.render_html(@markdown, :default, %i[table]).tap do |out| - refute out.include?("| a") - %w(x).each {|html| assert out.include?(html) } - assert out.include?("~~hi~~") - end - - CommonMarker.render_html(@markdown, :default, %i[strikethrough]).tap do |out| - assert out.include?("| a") - refute out.include?("~~hi~~") - assert out.include?("hi") - end - - CommonMarker.render_html(@markdown, :default, %i[table strikethrough]).tap do |out| - refute out.include?("| a") - refute out.include?("| x") - refute out.include?("~~hi~~") - end - 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, %i[table bad]) } - end -end diff --git a/test/test_helper.rb b/test/test_helper.rb index f7f7bd40..d3158ff7 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,4 +1,3 @@ -# coding: utf-8 require 'commonmarker' require 'minitest/autorun' require 'minitest/pride' @@ -21,7 +20,7 @@ def open_spec_file(filename) header_re = Regexp.new('#+ ') filepath = File.join('ext', 'commonmarker', 'cmark', 'test', filename) - File.readlines(filepath, encoding: "utf-8").each do |line| + File.readlines(filepath).each do |line| line_number += 1 l = line.strip From 5c96aa8c50dd22d69f664d2bd2e98d667ce6457f Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 11 Oct 2016 14:26:43 -0700 Subject: [PATCH 02/11] Update cmark to https://github.com/jgm/cmark/commit/ --- ext/commonmarker/cmark | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/commonmarker/cmark b/ext/commonmarker/cmark index e91dc121..636d6018 160000 --- a/ext/commonmarker/cmark +++ b/ext/commonmarker/cmark @@ -1 +1 @@ -Subproject commit e91dc12128b156f1b355e88b3d4f46ad162f1dc5 +Subproject commit 636d6018ea6bc6697b6491e0e47c4ae1ccad32fe From f57f96cb2bed2acfc094778fb86d6333a58f2094 Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 18:13:12 +1000 Subject: [PATCH 03/11] Windows build changes --- Rakefile | 4 +++- ext/commonmarker/extconf.rb | 10 ++++++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Rakefile b/Rakefile index 43f350eb..4883134f 100644 --- a/Rakefile +++ b/Rakefile @@ -16,7 +16,9 @@ end Rake::Task['clean'].enhance do ext_dir = File.join(File.dirname(__FILE__), 'ext', 'commonmarker', 'cmark') Dir.chdir(ext_dir) do - `make clean` + host_os = RbConfig::CONFIG['host_os'] + make = (host_os == 'mingw32') ? 'nmake.bat' : 'make' + `#{make} clean` end end diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index 3a3521d9..de4ba6e6 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -23,8 +23,14 @@ FileUtils.mkdir_p(CMARK_BUILD_DIR) Dir.chdir(CMARK_BUILD_DIR) do - system 'cmake .. -DCMAKE_C_FLAGS=-fPIC' - system 'make libcmark_static' + if host_os == 'mingw32' + make = 'nmake' + system 'cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE= -D CMAKE_INSTALL_PREFIX=windows .."' + else + make = 'make' + system 'cmake .. -DCMAKE_C_FLAGS=-fPIC' + end + system "#{make} libcmark_static" or abort "make libcmark_static failed" # rake-compiler seems to complain about this line, not sure why it's messing with it FileUtils.rm_rf(File.join(CMARK_BUILD_DIR, 'Testing', 'Temporary')) end From b0c51c16b724fc0eeea7e6719e265c614d5c086b Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 19:11:44 +1000 Subject: [PATCH 04/11] Don't ask, don't tell We get conflicts in msxml.h if we don't do this. It looks like the CMARK_ prefix on our enum is getting ignored by the compiler somehow ...?! --- ext/commonmarker/commonmarker.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ext/commonmarker/commonmarker.h b/ext/commonmarker/commonmarker.h index a5d59990..7ab1128e 100644 --- a/ext/commonmarker/commonmarker.h +++ b/ext/commonmarker/commonmarker.h @@ -1,6 +1,10 @@ #ifndef COMMONMARKER_H #define COMMONMARKER_H +#ifndef __MSXML_LIBRARY_DEFINED__ +#define __MSXML_LIBRARY_DEFINED__ +#endif + #include "cmark.h" #include "ruby.h" From 23bec5e97265f92f2ca5eae8a6afed77a1c07cec Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 19:13:12 +1000 Subject: [PATCH 05/11] Use MSYS Makefiles generator in mingw32 This at least has it compiling with RubyInstaller + DevKit. --- Rakefile | 7 ++++--- ext/commonmarker/extconf.rb | 7 +++---- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/Rakefile b/Rakefile index 4883134f..0b6b2f26 100644 --- a/Rakefile +++ b/Rakefile @@ -3,6 +3,9 @@ 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 @@ -16,9 +19,7 @@ end Rake::Task['clean'].enhance do ext_dir = File.join(File.dirname(__FILE__), 'ext', 'commonmarker', 'cmark') Dir.chdir(ext_dir) do - host_os = RbConfig::CONFIG['host_os'] - make = (host_os == 'mingw32') ? 'nmake.bat' : 'make' - `#{make} clean` + `make clean` end end diff --git a/ext/commonmarker/extconf.rb b/ext/commonmarker/extconf.rb index de4ba6e6..8c9081ed 100644 --- a/ext/commonmarker/extconf.rb +++ b/ext/commonmarker/extconf.rb @@ -24,13 +24,11 @@ Dir.chdir(CMARK_BUILD_DIR) do if host_os == 'mingw32' - make = 'nmake' - system 'cmake -G "NMake Makefiles" -D CMAKE_BUILD_TYPE= -D CMAKE_INSTALL_PREFIX=windows .."' + system 'cmake .. -G "MSYS Makefiles"' else - make = 'make' system 'cmake .. -DCMAKE_C_FLAGS=-fPIC' end - system "#{make} libcmark_static" or abort "make libcmark_static failed" + system "make libcmark_static" or abort "make libcmark_static failed" # rake-compiler seems to complain about this line, not sure why it's messing with it FileUtils.rm_rf(File.join(CMARK_BUILD_DIR, 'Testing', 'Temporary')) end @@ -47,5 +45,6 @@ $LDFLAGS << " -L#{CMARK_BUILD_DIR}/src -lcmark" $CFLAGS << " -O2 -I#{CMARK_DIR}/src -I#{CMARK_BUILD_DIR}/src" +$CFLAGS << " -DCMARK_STATIC_DEFINE" create_makefile('commonmarker/commonmarker') From c71e282035be4da35d7fcb2a0d0e230bb5b1b484 Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 19:16:37 +1000 Subject: [PATCH 06/11] Add appveyor.yml --- appveyor.yml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 00000000..9c54a402 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,14 @@ +# appveyor.yml +install: + - set PATH=C:\Ruby22\bin;%PATH% + - bundle install + +build: off + +before_test: + - ruby -v + - gem -v + - bundle -v + +test_script: + - bundle exec rake \ No newline at end of file From 8bd2514449bd7d10abba722e8098bde92ea76111 Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 19:18:18 +1000 Subject: [PATCH 07/11] Grab submodules --- appveyor.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/appveyor.yml b/appveyor.yml index 9c54a402..58206b29 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,6 +1,8 @@ # appveyor.yml install: - set PATH=C:\Ruby22\bin;%PATH% + - git submodule init + - git submodule update - bundle install build: off From 183d3bf859a7476a552c7ebb1ab7308d763c92ca Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 19:32:34 +1000 Subject: [PATCH 08/11] Windows encoding fun. One assertion left. --- lib/commonmarker/renderer.rb | 2 +- test/test_helper.rb | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/commonmarker/renderer.rb b/lib/commonmarker/renderer.rb index 87e85f9c..91dea834 100644 --- a/lib/commonmarker/renderer.rb +++ b/lib/commonmarker/renderer.rb @@ -5,7 +5,7 @@ module CommonMarker class Renderer attr_accessor :in_tight, :warnings, :in_plain def initialize - @stream = StringIO.new + @stream = StringIO.new("".force_encoding("utf-8")) @need_blocksep = false @warnings = Set.new [] @in_tight = false diff --git a/test/test_helper.rb b/test/test_helper.rb index d3158ff7..f7f7bd40 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,3 +1,4 @@ +# coding: utf-8 require 'commonmarker' require 'minitest/autorun' require 'minitest/pride' @@ -20,7 +21,7 @@ def open_spec_file(filename) header_re = Regexp.new('#+ ') filepath = File.join('ext', 'commonmarker', 'cmark', 'test', filename) - File.readlines(filepath).each do |line| + File.readlines(filepath, encoding: "utf-8").each do |line| line_number += 1 l = line.strip From c50d0c690ee41f3b242917387145c2095b56c0cb Mon Sep 17 00:00:00 2001 From: Yuki Izumi Date: Thu, 15 Sep 2016 19:33:16 +1000 Subject: [PATCH 09/11] And done! <3 --- test/test_encoding.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_encoding.rb b/test/test_encoding.rb index 9fcd8c8c..a3605be4 100644 --- a/test/test_encoding.rb +++ b/test/test_encoding.rb @@ -1,9 +1,10 @@ +# coding: utf-8 require 'test_helper' class TestEncoding < Minitest::Test # see http://git.io/vq4FR def test_encoding - contents = File.read(File.join(FIXTURES_DIR, 'curly.md')) + contents = File.read(File.join(FIXTURES_DIR, 'curly.md'), encoding: 'utf-8') doc = CommonMarker.render_doc(contents, :smart) render = doc.to_html assert_equal render.rstrip, '

This curly quote “makes commonmarker throw an exception”.

' From 13c0e7eb283fa9b56356a87d914804a8f4d1b3ac Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 11 Oct 2016 14:32:53 -0700 Subject: [PATCH 10/11] newline --- appveyor.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appveyor.yml b/appveyor.yml index 58206b29..fbd8f8a1 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -13,4 +13,4 @@ before_test: - bundle -v test_script: - - bundle exec rake \ No newline at end of file + - bundle exec rake From f2e3bebfe8b7a3aedf4de9b3515dd2bc6578ce4c Mon Sep 17 00:00:00 2001 From: Garen Torikian Date: Tue, 11 Oct 2016 14:39:01 -0700 Subject: [PATCH 11/11] :gem: bump to 0.12.0 --- lib/commonmarker/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/commonmarker/version.rb b/lib/commonmarker/version.rb index 6a7f32ea..9260dbd1 100644 --- a/lib/commonmarker/version.rb +++ b/lib/commonmarker/version.rb @@ -1,3 +1,3 @@ module CommonMarker - VERSION = '0.11.0'.freeze + VERSION = '0.12.0'.freeze end
a c