markascend 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/readme ADDED
@@ -0,0 +1,4 @@
1
+ Markascend is an extensible markdown-like, macro-powered html document syntax and processor.
2
+ Can be used as blog-generator, post-formatter or for literate programing.
3
+
4
+ More on website: http://luikore.github.io/markascend
@@ -0,0 +1,73 @@
1
+ require_relative "test_helper"
2
+
3
+ class BuiltinMacrosTest < BaseTest
4
+ def test_del_underline_sub_sup
5
+ %w[del underline sub sup].each do |x|
6
+ assert_equal "<#{x}>#{x}</#{x}>", parse("\\#{x}(#{x})")
7
+ end
8
+ end
9
+
10
+ def test_img
11
+ assert_equal %Q{<img src="src" alt="alt"/>}, parse("\\img(src alt='alt')")
12
+ assert_equal %Q{<a href="href"><img src="src" alt="alt"/></a>}, parse("\\img(src alt='alt' href='href')")
13
+ end
14
+
15
+ def test_html
16
+ html = %Q{<a href="href">a</a>&nbsp;}
17
+ assert_equal html, parse("\\html{#{html}}")
18
+ end
19
+
20
+ def test_slim
21
+ html = %Q{<a href="href">a</a>}
22
+ assert_equal html, parse("\\slim(a href='href' a)")
23
+ end
24
+
25
+ def test_csv
26
+ res = Markascend.compile <<-MA
27
+ \\csv
28
+ name,type
29
+ "Ahri",Mage
30
+ "Miss Fortune",DPS
31
+ \\headless_csv
32
+ "Fizz",DPS
33
+ Sejuani,Tank
34
+ MA
35
+ table1 = "<thead><tr><th>name</th><th>type</th></tr></thead>" +
36
+ "<tbody><tr><td>Ahri</td><td>Mage</td></tr><tr><td>Miss Fortune</td><td>DPS</td></tr></tbody>"
37
+ table2 = "<tbody><tr><td>Fizz</td><td>DPS</td></tr><tr><td>Sejuani</td><td>Tank</td></tr></tbody>"
38
+ assert res.index table1
39
+ assert res.index table2
40
+ end
41
+
42
+ def test_latex
43
+ assert_equal %Q{<code class="latex">\\frac{y}{x}</code>}, parse("\\latex{\\frac{y}{x}}")
44
+ end
45
+
46
+ def test_dot
47
+ res = parse("\\dot(digraph G{main -> parse;})").strip
48
+ src = Nokogiri::XML(res).xpath('//@src').text[/(?<=,).+$/]
49
+ f = Tempfile.new('img')
50
+ f << Base64.decode64(src)
51
+ path = f.path
52
+ f.close
53
+ output = `file #{path}`
54
+ assert output.index('PNG image data'), %Q|generated data should be png: but got #{output.inspect}|
55
+ end
56
+
57
+ def test_options
58
+ parse("\\options(a: [1, 2])")
59
+ assert_equal({"a" => [1, 2]}, @env.options)
60
+ end
61
+
62
+ def test_hi
63
+ parse("\\hi(none)")
64
+ assert_equal nil, @env.hi
65
+ parse("\\hi(c)\\hi(ruby)")
66
+ assert_equal 'ruby', @env.hi
67
+ end
68
+
69
+ def parse src
70
+ l = LineUnit.new @env, src, nil
71
+ l.parse
72
+ end
73
+ end
@@ -0,0 +1,40 @@
1
+ require_relative "test_helper"
2
+
3
+ class LineUnitTest < BaseTest
4
+ def test_nested_italic_and_bold
5
+ assert_equal 'outside<b><i>i</i>b</b>', parse('outside***i*b**').join
6
+ end
7
+
8
+ def test_code
9
+ assert_equal '<code class="highlight">\\\\code</code>', parse('`\\\\code`').join
10
+ assert_equal '<code class="highlight">c`ode</code>', parse('``c`ode``').join
11
+ assert_equal '<code class="highlight"> </code>`', parse('`` ```').join
12
+ end
13
+
14
+ def test_math
15
+ assert_equal '<code class="math">\\\\math\$ </code>', parse('$\\\\math\$ $').join
16
+ end
17
+
18
+ def test_link
19
+ assert_equal '<a href="href">a</a>', parse('[a](href)').join
20
+ end
21
+
22
+ def test_footnote
23
+ assert_equal '<a href="#footnote-1">1</a>', parse('[.](first note)').join
24
+ assert_equal '<a href="#footnote-2">two</a>', parse('[.two](second note)').join
25
+ assert_equal [:footnote_id_ref, 1], parse('[:1]').first
26
+ assert_equal [:footnote_id_ref, 22], parse('[:22]').first
27
+ assert_equal [:footnote_acronym_ref, "two"], parse('[:two]').first
28
+ end
29
+
30
+ def test_sandbox_footnote
31
+ make_sandbox_env
32
+ first_note = '[.](first note)'
33
+ assert_equal first_note, parse('[.](first note)').join
34
+ end
35
+
36
+ def parse src
37
+ l = LineUnit.new @env, src, nil
38
+ l.parse []
39
+ end
40
+ end
@@ -0,0 +1,19 @@
1
+ require_relative "test_helper"
2
+
3
+ class MarkascendTest < BaseTest
4
+ def test_strip_tags
5
+ assert_equal '', Markascend.strip_tags('<script fraud-prop="></script>"></script>')
6
+ assert_equal 'Bold', Markascend.strip_tags('<b>Bold</b>')
7
+ end
8
+
9
+ def test_toc
10
+ res = Markascend.compile <<-MA, toc: true
11
+ h1 h1
12
+ h5 h5
13
+ h3 h3
14
+ MA
15
+ dom = Nokogiri::HTML(res).xpath('//div[@id="toc"]/ol').first
16
+ assert_equal ['li', 'ol'], dom.children.map(&:name)
17
+ assert_equal ['ol', 'li'], dom.children[1].children.map(&:name)
18
+ end
19
+ end
@@ -0,0 +1,93 @@
1
+ require_relative "test_helper"
2
+
3
+ class ParserTest < BaseTest
4
+ def test_hx
5
+ b = Parser.new @env, "h1#cen-tered lovely day!"
6
+ assert_equal "<h1 id=\"cen-tered\">lovely day!</h1>", b.parse
7
+ end
8
+
9
+ def test_sandbox_hx
10
+ make_sandbox_env
11
+ b = Parser.new @env, "h1#cen-tered lovely day!"
12
+ assert_equal "<h1>lovely day!</h1>", b.parse
13
+ end
14
+
15
+ def test_blocked_hx
16
+ b = Parser.new @env, "h3 followed by \\nop a block\n content of block"
17
+ assert_equal "<h3>followed by \\nop a block</h3>", b.parse
18
+ end
19
+
20
+ def test_rec_block
21
+ b = Parser.new @env, <<-MA
22
+ - ul1
23
+ - ul2
24
+ + ol1
25
+ + ol2
26
+ - > quote1
27
+ quote2
28
+ MA
29
+ ol = "<ol><li>ol1</li>" + "<li>ol2</li></ol>"
30
+ quote = "<quote>quote1<br>quote2</quote>"
31
+ ul = "<ul><li>ul1</li>" + "<li>ul2#{ol}</li>" + "<li>#{quote}</li></ul>"
32
+ assert_equal ul, b.parse.strip
33
+ end
34
+
35
+ def test_warning_line
36
+ # should generate warning for missing macro contents
37
+ b = Parser.new @env, <<-MA
38
+ - ul1
39
+ + ol1
40
+ - ul2
41
+ + ol2 \\img()
42
+ MA
43
+ b.parse
44
+ assert b.warnings[4]
45
+ end
46
+
47
+ def test_code_block
48
+ code_text = proc do |b|
49
+ t = Nokogiri::HTML(b.parse.strip).xpath('//pre/code').text
50
+ CGI.unescape_html(t).strip
51
+ end
52
+
53
+ b = Parser.new @env, <<-MA
54
+ |ruby
55
+ puts 'hello world'
56
+ MA
57
+ assert_equal "puts 'hello world'", code_text[b]
58
+
59
+ b = Parser.new @env, <<-MA
60
+ |
61
+ puts 'hello world'
62
+ MA
63
+ assert_equal "puts 'hello world'", code_text[b]
64
+ end
65
+
66
+ def test_inline_macro_fallback_but_block_macro_not
67
+ invalid = "\\invalid{ <content> }"
68
+ expected = "<p>#{CGI.escape_html invalid}</p>"
69
+ assert_equal expected, Parser.new(@env, invalid).parse
70
+
71
+ invalid = "\\invalid\n <content>"
72
+ assert_equal "<p>\\invalid</p>", Parser.new(@env, invalid).parse
73
+ end
74
+
75
+ def test_sandbox_macro
76
+ make_sandbox_env
77
+ src = '\options(a.png)'
78
+ expected = "<p>#{CGI.escape_html src}</p>"
79
+ assert_equal expected, Parser.new(@env, src).parse
80
+ end
81
+
82
+ def test_validate_default_macro_list
83
+ assert_equal Macro.instance_methods.grep(/parse_/).map(&:to_s).sort, Markascend::DEFAULT_MACROS.values.sort
84
+ end
85
+
86
+ def test_validate_default_line_unit_parser_list
87
+ assert_equal LineUnit.instance_methods.grep(/parse_/).map(&:to_s).sort, Markascend::DEFAULT_LINE_UNITS.sort
88
+ end
89
+
90
+ def test_footnote_validation
91
+
92
+ end
93
+ end
@@ -0,0 +1,42 @@
1
+ require_relative "test_helper"
2
+
3
+ class PopularCompanyMacrosTest < BaseTest
4
+ def test_twitter
5
+ assert_equal %Q{<a href="https://twitter.com/dhh">@dhh</a>}, parse("\\twitter(@dhh)")
6
+ end
7
+
8
+ def test_weibo
9
+ assert_equal %Q{<a href="https://weibo.com/dhh">@dhh</a>}, parse("\\weibo(@dhh)")
10
+ end
11
+
12
+ def test_wiki
13
+ assert_equal %Q|<a href="http://en.wikipedia.org/wiki/ruby(programing_language)">ruby(programing_language)</a>|, parse("\\wiki{ruby(programing_language)}")
14
+ end
15
+
16
+ def test_gist
17
+ res = %Q{<script src="https://gist.github.com/luikore/737238.js"></script>}
18
+ assert_equal res, parse("\\gist(luikore/737238)")
19
+ assert_equal res, parse("\\gist(luikore/737238.git)")
20
+ assert_equal res, parse("\\gist(gist.github.com/luikore/737238.git)")
21
+ assert_equal res, parse("\\gist(https://gist.github.com/luikore/737238)")
22
+ end
23
+
24
+ def test_video
25
+ youtube = parse("\\video(400x200 youtu.be/watch?v=TGPvtlnwH6E)")
26
+ assert youtube.start_with? '<iframe width="400" height="200"'
27
+ assert youtube.index('/embed/TGPvtlnwH6E'), youtube.inspect
28
+
29
+ vimeo = parse("\\video(400x200 vimeo.com/36820781)")
30
+ assert vimeo.start_with?('<iframe width="400" height="200"'), vimeo.inspect
31
+ assert vimeo.index('/video/36820781'), vimeo.inspect
32
+
33
+ nico = parse("\\video(400x200 sm32768)")
34
+ assert nico.start_with?('<script '), nico.inspect
35
+ assert nico.index('/thumb_watch/sm32768'), nico.inspect
36
+ end
37
+
38
+ def parse src
39
+ l = LineUnit.new @env, src, nil
40
+ l.parse
41
+ end
42
+ end
@@ -0,0 +1,21 @@
1
+ require "test/unit"
2
+ require_relative "../lib/markascend"
3
+ begin
4
+ require "pry"
5
+ rescue LoadError
6
+ end
7
+
8
+ require "slim"
9
+ require "nokogiri" # for parsing the result
10
+ require "tempfile"
11
+
12
+ class BaseTest < Test::Unit::TestCase
13
+ include Markascend
14
+ def setup
15
+ @env = Env.new({})
16
+ end
17
+
18
+ def make_sandbox_env
19
+ @env = Env.new sandbox: true
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,64 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: markascend
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Zete Lui
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-08 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Extensible markdown-like, macro-powered html document syntax and processor
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - readme
20
+ - copying
21
+ - lib/markascend/builtin_macros.rb
22
+ - lib/markascend/env.rb
23
+ - lib/markascend/line_unit.rb
24
+ - lib/markascend/macro.rb
25
+ - lib/markascend/parser.rb
26
+ - lib/markascend/popular_company_macros.rb
27
+ - lib/markascend.rb
28
+ - test/builtin_macros_test.rb
29
+ - test/line_unit_test.rb
30
+ - test/markascend_test.rb
31
+ - test/parser_test.rb
32
+ - test/popular_company_macros_test.rb
33
+ - test/test_helper.rb
34
+ - Gemfile
35
+ - rakefile
36
+ - doc/api.ma
37
+ - doc/index.ma
38
+ - doc/syntax.ma
39
+ homepage: https://github.com/luikore/markascend
40
+ licenses:
41
+ - BSD
42
+ metadata: {}
43
+ post_install_message:
44
+ rdoc_options: []
45
+ require_paths:
46
+ - lib
47
+ required_ruby_version: !ruby/object:Gem::Requirement
48
+ requirements:
49
+ - - '>='
50
+ - !ruby/object:Gem::Version
51
+ version: 2.0.0
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - '>='
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ requirements: []
58
+ rubyforge_project:
59
+ rubygems_version: 2.0.3
60
+ signing_key:
61
+ specification_version: 4
62
+ summary: Extensible markdown-like, macro-powered html document syntax and processor
63
+ test_files: []
64
+ has_rdoc: false