github-markdown-jekyll 0.7.0

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.
@@ -0,0 +1,43 @@
1
+ # encoding: utf-8
2
+ Gem::Specification.new do |s|
3
+ s.name = 'github-markdown-jekyll'
4
+ s.version = '0.7.0'
5
+ s.summary = 'The Markdown parser with support for jekyll yaml frontmatter'
6
+ s.description = 'Self-contained Markdown parser for GitHub, with all our custom extensions'
7
+ s.date = '2013-10-01'
8
+ s.email = 'username@franzoni.eu'
9
+ s.homepage = 'https://github.com/alanfranz/github-markdown-jekyll'
10
+ s.authors = ['GitHub, Inc', 'Alan Franzoni']
11
+ # = MANIFEST =
12
+ s.files = %w[
13
+ Rakefile
14
+ bin/gfm
15
+ ext/markdown/autolink.c
16
+ ext/markdown/autolink.h
17
+ ext/markdown/buffer.c
18
+ ext/markdown/buffer.h
19
+ ext/markdown/extconf.rb
20
+ ext/markdown/gh-markdown.c
21
+ ext/markdown/houdini.h
22
+ ext/markdown/houdini_href_e.c
23
+ ext/markdown/houdini_html_e.c
24
+ ext/markdown/html.c
25
+ ext/markdown/html.h
26
+ ext/markdown/html_blocks.h
27
+ ext/markdown/markdown.c
28
+ ext/markdown/markdown.h
29
+ ext/markdown/plaintext.c
30
+ ext/markdown/plaintext.h
31
+ ext/markdown/stack.c
32
+ ext/markdown/stack.h
33
+ github-markdown-jekyll.gemspec
34
+ lib/github/markdown.rb
35
+ test/gfm_test.rb
36
+ ]
37
+ # = MANIFEST =
38
+ s.test_files = ["test/gfm_test.rb"]
39
+ s.extensions = ["ext/markdown/extconf.rb"]
40
+ s.require_paths = ["lib"]
41
+ s.add_development_dependency 'rake-compiler', '~> 0.9.2'
42
+ s.add_development_dependency 'nokogiri', '~> 1.6.2.1'
43
+ end
@@ -0,0 +1,62 @@
1
+
2
+ # GitHub Markdown Rendering class
3
+ #
4
+ # Provides a Markdown rendering method as a singleton, and two
5
+ # auxiliary functions
6
+ #
7
+ # There are two kinds of Markdown in GitHub.com:
8
+ #
9
+ # - Plain Markdown: used in Wikis, Pages and GitHub::Markup (READMEs).
10
+ # This is standards-compliant Markdown, with some of the PHP-Markdown
11
+ # extensions:
12
+ #
13
+ # - GitHub-flavored Markdown: used in user-input text, such as comments.
14
+ # Same extensions as Plain Markdown, and additionally the following
15
+ # extensions:
16
+ #
17
+ # GitHub::Markdown.render(content)
18
+ # #=> Rendered Markdown as HTML plaintext with the default extensions
19
+ #
20
+ # GitHub::Markdown.render_gfm(content)
21
+ # #=> Rendered GitHub-flavored Markdown as HTML plaintext
22
+ #
23
+ # GitHub::Markdown._to_html(content, mode) { |code, lang| ... }
24
+ # #=> Rendered Markdown with the given mode as HTML plaintext
25
+ module GitHub
26
+ class Markdown
27
+ def self.render(content)
28
+ self.to_html(content, :markdown)
29
+ end
30
+
31
+ def self.render_gfm(content)
32
+ self.to_html(content, :gfm)
33
+ end
34
+ end
35
+ end
36
+
37
+ # Load the actual C extension
38
+ require 'github/markdown.so'
39
+
40
+ module GitHub
41
+ Markdown.class_eval do
42
+ class << self
43
+ alias_method :original_to_html, :to_html
44
+
45
+ def to_html(content, mode)
46
+ pattern = /\A\s*---\s*?\n(?:(.*?)\n|)---\s*?(?:\n(.*))?\z/m
47
+ match = pattern.match(content)
48
+ if match.nil?
49
+ return original_to_html(content, mode)
50
+ end
51
+
52
+ yaml_frontmatter = match[1] || ''
53
+ md_content = match[2] || ''
54
+
55
+ return original_to_html("```yaml\n#{yaml_frontmatter}\n```\n#{md_content}", mode)
56
+
57
+
58
+ end
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,100 @@
1
+ # coding: UTF-8
2
+ rootdir = File.dirname(File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift "#{rootdir}/lib"
4
+
5
+ if defined? Encoding
6
+ Encoding.default_internal = 'UTF-8'
7
+ end
8
+
9
+ require 'test/unit'
10
+ require 'github/markdown'
11
+ require 'nokogiri'
12
+
13
+ def html_equal(html_a, html_b)
14
+ assert_equal Nokogiri::HTML::DocumentFragment.parse(html_a).to_html,
15
+ Nokogiri::HTML::DocumentFragment.parse(html_b).to_html
16
+ end
17
+
18
+ class GFMBasicTest < Test::Unit::TestCase
19
+ Dir['test/fixtures/*.text', 'test/fixtures/Markdown_Redcarpet/**/*.text'].each do |md_file|
20
+ dirname = File.dirname(md_file)
21
+ markup = md_file.split('/').last.gsub(/\.text/, '').gsub(/(\s+)/, "_")
22
+ define_method "test_#{dirname}_#{markup}" do
23
+ source = File.read(md_file)
24
+
25
+ expected_file = "#{dirname}/#{markup}.html"
26
+ expected = File.read(expected_file).rstrip
27
+ actual = GitHub::Markdown.render(source).rstrip
28
+
29
+ if source != expected
30
+ assert(source != actual, "#{markup} did not render anything")
31
+ end
32
+
33
+ diff = IO.popen("diff -u - #{expected_file}", 'r+') do |f|
34
+ f.write actual
35
+ f.close_write
36
+ f.read
37
+ end
38
+
39
+ assert expected == actual, <<message
40
+ #{File.basename expected_file}'s contents don't match command output:
41
+ #{diff}
42
+ message
43
+ end
44
+ end
45
+
46
+ def test_that_render_works
47
+ GitHub::Markdown.to_html("Hello **world**!", :gfm)
48
+ end
49
+
50
+ def test_that_code_blocks_work
51
+ GitHub::Markdown.to_html("~~~~~~~~~~\nhello world!\n~~~~~~~~~\n", :gfm)
52
+ end
53
+
54
+ def test_yaml_is_rendered_in_frontmatter
55
+ html = GitHub::Markdown.render("---\npippo: 123\n---\n**Hello**")
56
+ parsed = Nokogiri::HTML::DocumentFragment.parse(html)
57
+ node = parsed.xpath('.//pre/code')
58
+ assert_equal "pippo: 123", node.text.strip
59
+ end
60
+
61
+ def test_if_no_frontmatter_normal_rendering_happens
62
+ html = GitHub::Markdown.render("**Hello**")
63
+ parsed = Nokogiri::HTML::DocumentFragment.parse(html)
64
+ node = parsed.xpath('.//p/strong')
65
+ assert_equal "Hello", node.text.strip
66
+ end
67
+
68
+ # With GITHUB_MD_NESTING set to 32, we can handle up to 10 levels of list
69
+ # nesting. We do not go to 11.
70
+ def test_nested_list
71
+ items = [
72
+ 'Item 1',
73
+ 'Item 1a',
74
+ 'Item 1a1',
75
+ 'Item 1a1a',
76
+ 'Item 1a1a1',
77
+ 'Item 1a1a1a',
78
+ 'Item 1a1a1a1',
79
+ 'Item 1a1a1a1a',
80
+ 'Item 1a1a1a1a1',
81
+ 'Item 1a1a1a1a1a'
82
+ ]
83
+
84
+ pre = -3
85
+ markdown = items.inject('') do |md, item|
86
+ pre += 3
87
+ md.concat(' '*pre + '+ ' + item + "\n")
88
+ end
89
+
90
+ html = GitHub::Markdown.render(markdown)
91
+ parsed = Nokogiri::HTML::DocumentFragment.parse(html)
92
+
93
+ items.inject(parsed) do |node, expected_item|
94
+ child = node.xpath('.//ul/li')
95
+ child_item = child.children.detect{|e| e.text?}.text.strip
96
+ assert_equal expected_item, child_item
97
+ node = child
98
+ end
99
+ end
100
+ end
metadata ADDED
@@ -0,0 +1,96 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-markdown-jekyll
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
+ platform: ruby
6
+ authors:
7
+ - GitHub, Inc
8
+ - Alan Franzoni
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-10-01 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake-compiler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 0.9.2
21
+ type: :development
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 0.9.2
28
+ - !ruby/object:Gem::Dependency
29
+ name: nokogiri
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.6.2.1
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.6.2.1
42
+ description: Self-contained Markdown parser for GitHub, with all our custom extensions
43
+ email: username@franzoni.eu
44
+ executables: []
45
+ extensions:
46
+ - ext/markdown/extconf.rb
47
+ extra_rdoc_files: []
48
+ files:
49
+ - Rakefile
50
+ - bin/gfm
51
+ - ext/markdown/autolink.c
52
+ - ext/markdown/autolink.h
53
+ - ext/markdown/buffer.c
54
+ - ext/markdown/buffer.h
55
+ - ext/markdown/extconf.rb
56
+ - ext/markdown/gh-markdown.c
57
+ - ext/markdown/houdini.h
58
+ - ext/markdown/houdini_href_e.c
59
+ - ext/markdown/houdini_html_e.c
60
+ - ext/markdown/html.c
61
+ - ext/markdown/html.h
62
+ - ext/markdown/html_blocks.h
63
+ - ext/markdown/markdown.c
64
+ - ext/markdown/markdown.h
65
+ - ext/markdown/plaintext.c
66
+ - ext/markdown/plaintext.h
67
+ - ext/markdown/stack.c
68
+ - ext/markdown/stack.h
69
+ - github-markdown-jekyll.gemspec
70
+ - lib/github/markdown.rb
71
+ - test/gfm_test.rb
72
+ homepage: https://github.com/alanfranz/github-markdown-jekyll
73
+ licenses: []
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '0'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubyforge_project:
91
+ rubygems_version: 2.2.2
92
+ signing_key:
93
+ specification_version: 4
94
+ summary: The Markdown parser with support for jekyll yaml frontmatter
95
+ test_files:
96
+ - test/gfm_test.rb