commonmarker-0.23.2/ 0000755 0000041 0000041 00000000000 14126215200 014311 5 ustar www-data www-data commonmarker-0.23.2/test/ 0000755 0000041 0000041 00000000000 14126215200 015270 5 ustar www-data www-data commonmarker-0.23.2/test/test_maliciousness.rb 0000644 0000041 0000041 00000013223 14126215200 021533 0 ustar www-data www-data # frozen_string_literal: true require 'test_helper' 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) end assert_raises TypeError do CommonMarker.render_html("foo \n baz", :totes_fake) end assert_raises TypeError do CommonMarker.render_html("foo \n baz", []) end assert_raises TypeError do CommonMarker.render_html("foo \n baz", [23]) end assert_raises TypeError do CommonMarker.render_html("foo \n baz", nil) end assert_raises TypeError do CommonMarker.render_html("foo \n baz", [:SMART, 'totes_fake']) end assert_raises TypeError do CommonMarker.render_html(123) end assert_raises TypeError do CommonMarker.render_html([123]) end assert_raises TypeError do CommonMarker.render_html(nil) 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('') 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 end end def test_bad_fence_info_set assert_raises NodeError do @doc.fence_info = 'ruby' end fence = CommonMarker.render_doc("``` ruby\nputs 'wow'\n```").first_child assert_raises TypeError do fence.fence_info = 123 end end end end commonmarker-0.23.2/test/test_basics.rb 0000644 0000041 0000041 00000003172 14126215200 020123 0 ustar www-data www-data # frozen_string_literal: true 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_markdown_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 = %i[SOURCEPOS UNSAFE VALIDATE_UTF8 SMART LIBERAL_HTML_TAG FOOTNOTES STRIKETHROUGH_DOUBLE_TILDE] render_opt = parse_opt + %i[HARDBREAKS NOBREAKS GITHUB_PRE_LANG TABLE_PREFER_STYLE_ATTRIBUTES FULL_INFO_STRING] extensions = %i[table tasklist strikethrough autolink tagfilter] assert_equal "Hello world – how are you today? I’m fine, ~yourself~?
Hello world – how are you today? I’m fine, ~yourself~?
Hello world – how are you today? I’m fine, ~yourself~?
Hi there
\n", result end def test_multiple_tables content = <<~DOC | Input | Expected | Actual | | ----------- | ---------------- | --------- | | One | Two | Three | | Header | Row | Example | | :------: | ---: | :------ | | Foo | Bar | Baz | DOC doc = CommonMarker.render_doc(content, :DEFAULT, %i[autolink table tagfilter]) results = CommonMarker::HtmlRenderer.new.render(doc) assert_equal 2, results.scan(//).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 commonmarker-0.23.2/test/fixtures/ 0000755 0000041 0000041 00000000000 14126215200 017141 5 ustar www-data www-data commonmarker-0.23.2/test/fixtures/table.md 0000644 0000041 0000041 00000000142 14126215200 020547 0 ustar www-data www-data One extension: | a | b | | --- | --- | | c | d | | **x** | | Another extension: ~~hi~~ commonmarker-0.23.2/test/fixtures/dingus.md 0000644 0000041 0000041 00000000336 14126215200 020756 0 ustar www-data www-data ## Try CommonMark You can try CommonMark here. This dingus is powered by [commonmark.js](https://github.com/jgm/commonmark.js), the JavaScript reference implementation. 1. item one 2. item two - sublist - sublist commonmarker-0.23.2/test/fixtures/strong.md 0000644 0000041 0000041 00000000020 14126215200 020767 0 ustar www-data www-data I am **strong** commonmarker-0.23.2/test/fixtures/curly.md 0000644 0000041 0000041 00000000076 14126215200 020624 0 ustar www-data www-data This curly quote “makes commonmarker throw an exception”. commonmarker-0.23.2/test/test_smartpunct.rb 0000644 0000041 0000041 00000001512 14126215200 021053 0 ustar www-data www-data # frozen_string_literal: true require 'test_helper' class SmartPunctTest < Minitest::Test smart_punct = open_spec_file('smart_punct.txt') smart_punct.each do |testcase| doc = CommonMarker.render_doc(testcase[:markdown], :SMART) html = CommonMarker.render_html(testcase[:markdown], :SMART) define_method("test_smart_punct_example_#{testcase[:example]}") do doc_rendered = doc.to_html.strip html_rendered = html.strip assert_equal testcase[:html], doc_rendered, testcase[:markdown] assert_equal testcase[:html], html_rendered, testcase[:markdown] end end def test_smart_hardbreak_no_spaces_render_doc markdown = "\"foo\"\nbaz" result = "“foo”
\nbaz
This curly quote “makes commonmarker throw an exception”.
', render.rstrip) render = doc.to_xml assert_includes(render, 'Hello1.
Hey! ↩
Hello1.
Hey! ↩
Let's render some footnotes1
This is a footnote ↩
Hi there, I am mostly text!
\n", @doc.to_html end def test_html_renderer renderer = HtmlRenderer.new result = renderer.render(@doc) assert_equal "Hi there, I am mostly text!
\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 "Hi world, I am mostly text!
\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 "Hi there, I am mostly text!
\n", @doc.to_html end def test_inspect assert_match(/#