html-pipeline-asciidoc_filter 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af95f8d219ae792a1c9ac10c42cb06e4ea858c15
4
+ data.tar.gz: bf0693e903da2b4d8536858844fb9d0eda32b8f4
5
+ SHA512:
6
+ metadata.gz: e303cd5b06a8c7bf183e8be579e9d8a6bd5aabb18674cf38fbc6f6855a256c2c7a8502a5967194eacbda9be6c6b2f286fbbeac6f0fcd19ae5a12b3725ed84379
7
+ data.tar.gz: ee80dc7c686ac08e5733898674d2e02108c8a5eb4425ae74ee3621932b80091cb26f533ffd8582ae7a4995f5293528fe89179bfbff303e4840a03898351746b9
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (C) 2013 Dan Allen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,90 @@
1
+ = AsciiDoc filter for html-pipeline
2
+ Dan Allen
3
+ ifndef::safe-mode-name[]
4
+
5
+ [float]
6
+ = AsciiDoc filter for html-pipeline
7
+ endif::safe-mode-name[]
8
+
9
+ https://rubygems.org/gems/html-pipeline-asciidoc_filter[html-pipeline-asciidoc_filter] is an AsciiDoc processing filter for https://github.com/jch/html-pipeline[html-pipeline] based on https://asciidoctor.org[Asciidoctor].
10
+
11
+ This filter is used to render AsciiDoc files in GitHub repositories, among other uses.
12
+ Keep in mind that an HTML sanitization filter is run after this filter, so not all elements in the AsciiDoc document render correctly.
13
+ We need to improve the output generated by this filter to get better results.
14
+
15
+ == Example Usage
16
+
17
+ [source,ruby]
18
+ ----
19
+ require 'html/pipeline'
20
+ require 'html/pipeline/asciidoc_filter'
21
+
22
+ filters = [
23
+ HTML::Pipeline::AsciiDocFilter,
24
+ HTML::Pipeline::SanitizationFilter,
25
+ HTML::Pipeline::ImageMaxWidthFilter,
26
+ HTML::Pipeline::EmojiFilter,
27
+ HTML::Pipeline::MentionFilter,
28
+ HTML::Pipeline::AutolinkFilter,
29
+ HTML::Pipeline::TableOfContentsFilter,
30
+ HTML::Pipeline::SyntaxHighlightFilter
31
+ ]
32
+
33
+ context = {
34
+ :asset_root => 'https://github.global.ssl.fastly.net/images/icons/emoji'
35
+ }
36
+
37
+ pipeline = HTML::Pipeline.new filters, context
38
+ pipeline.setup_instrumentation
39
+
40
+ input = <<-EOS
41
+ = Sample Document
42
+ Author Name
43
+
44
+ Preamble paragraph.
45
+
46
+ == Sample Section
47
+
48
+ Section content.
49
+
50
+ .GitHub usernames
51
+ - @jch
52
+ - @rtomayko
53
+ - @mojavelinux
54
+
55
+ [source,ruby]
56
+ --
57
+ require 'asciidoctor'
58
+
59
+ puts Asciidoctor.render('This filter brought to you by http://asciidoctor.org[Asciidoctor].')
60
+ --
61
+
62
+ :shipit:
63
+ EOS
64
+
65
+ puts pipeline.call(input)[:output]
66
+ ----
67
+
68
+ == Note about dependencies
69
+
70
+ You'll need the following two dependencies which aren't declared by +html-pipeline+ or this filter.
71
+
72
+ [source,ruby]
73
+ ----
74
+ gem 'activesupport', '>= 2'
75
+ gem 'github-linguist', '~> 1.2.6'
76
+ ----
77
+
78
+ == TODO
79
+
80
+ * remove `<p>` from text-only list items by defining custom block_paragraph template
81
+ * preserve ToC (likely through subsequent filter)
82
+ * retain checklist items in list (perhaps using text-based checkmarks)
83
+ * enable font-based icons
84
+
85
+ == Copyright and License
86
+
87
+ Copyright (C) 2013 Dan Allen
88
+ Free use of this software is granted under the terms of the MIT License.
89
+
90
+ See the {license}[LICENSE] file for details.
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path '../lib/html/pipeline/asciidoc_filter/version', __FILE__
3
+
4
+ Gem::Specification.new do |gem|
5
+ # named according to http://guides.rubygems.org/name-your-gem
6
+ gem.name = 'html-pipeline-asciidoc_filter'
7
+ gem.version = HTML_Pipeline::AsciiDocFilter::VERSION
8
+ gem.authors = ['Dan Allen']
9
+ gem.email = ['dan.j.allen@gmail.com']
10
+ gem.summary = %(An AsciiDoc filter for html-pipeline based on Asciidoctor)
11
+ gem.description = %(An AsciiDoc filter for html-pipeline based on Asciidoctor)
12
+ gem.homepage = 'https://github.com/asciidoctor/html-pipeline-asciidoc_filter'
13
+ gem.license = 'MIT'
14
+
15
+ gem.files = `git ls-files -z -- */* {README,LICENSE}* *.gemspec`.split("\0")
16
+ gem.executables = gem.files.grep(%r"^bin/") { |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r"^test/")
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'html-pipeline', '~> 0.3'
21
+ gem.add_dependency 'asciidoctor', '= 0.1.4'
22
+
23
+ # activesupport should be a dependency of html-pipeline; cannot it load html-pipeline without it
24
+ gem.add_development_dependency 'activesupport', RUBY_VERSION < '1.9.3' ? ['>= 2', '< 4'] : '>= 2'
25
+
26
+ gem.add_development_dependency 'bundler', '~> 1.3'
27
+ gem.add_development_dependency 'rake'
28
+ gem.add_development_dependency 'github-linguist', '~> 2.6.2'
29
+ end
@@ -0,0 +1,75 @@
1
+ require 'asciidoctor'
2
+ require 'html/pipeline/filter'
3
+ require 'html/pipeline/text_filter'
4
+
5
+ class HTML::Pipeline
6
+
7
+ # HTML Filter that converts AsciiDoc text into HTML.
8
+ #
9
+ # This filter is different from most in that it can take a non-HTML as
10
+ # input. It must be used as the first filter in a pipeline.
11
+ #
12
+ # This filter does not write any additional information to the context hash.
13
+ #
14
+ # Examples
15
+ #
16
+ # require 'html/pipeline'
17
+ # require 'html/pipeline/asciidoc_filter'
18
+ #
19
+ # filters = [
20
+ # HTML::PipelineExt::AsciiDocFilter,
21
+ # HTML::Pipeline::SanitizationFilter,
22
+ # HTML::Pipeline::ImageMaxWidthFilter,
23
+ # HTML::Pipeline::EmojiFilter,
24
+ # HTML::Pipeline::MentionFilter,
25
+ # HTML::Pipeline::AutolinkFilter,
26
+ # HTML::Pipeline::TableOfContentsFilter,
27
+ # HTML::Pipeline::SyntaxHighlightFilter
28
+ # ]
29
+ #
30
+ # context = {
31
+ # :asset_root => 'https://github.global.ssl.fastly.net/images/icons/emoji'
32
+ # }
33
+ #
34
+ # pipeline = HTML::Pipeline.new filters, context
35
+ # pipeline.setup_instrumentation
36
+ #
37
+ # input = <<EOS
38
+ # = Sample Document
39
+ # Author Name
40
+ #
41
+ # Preamble paragraph.
42
+ #
43
+ # == Sample Section
44
+ #
45
+ # Section content.
46
+ #
47
+ # .GitHub usernames
48
+ # - @jch
49
+ # - @jm
50
+ # - @mojavelinux
51
+ #
52
+ # [source,ruby]
53
+ # --
54
+ # require 'asciidoctor'
55
+ # puts Asciidoctor.render('This filter brought to you by http://asciidoctor.org[Asciidoctor].')
56
+ # --
57
+ #
58
+ # :shipit:
59
+ # EOS
60
+ #
61
+ # puts pipeline.call(input)[:output]
62
+ #
63
+ class AsciiDocFilter < TextFilter
64
+ def initialize(text, context = nil, result = nil)
65
+ super text, context, result
66
+ end
67
+
68
+ # Convert AsciiDoc to HTML using Asciidoctor
69
+ def call
70
+ Asciidoctor.render @text, :attributes => 'showtitle idprefix idseparator=- env=github env-github source-highlighter=html-pipeline'
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,7 @@
1
+ # NOTE use HTML_Pipeline since HTML::Pipeline is a class
2
+ # and we don't want to define it here inadvertently
3
+ module HTML_Pipeline
4
+ class AsciiDocFilter
5
+ VERSION = '0.1.4'
6
+ end
7
+ end
@@ -0,0 +1,74 @@
1
+ require 'test_helper'
2
+ require 'html/pipeline/asciidoc_filter'
3
+
4
+ class HTML::Pipeline::AsciiDocFilterTest < Test::Unit::TestCase
5
+
6
+ AsciiDocFilter = HTML::Pipeline::AsciiDocFilter
7
+
8
+ def setup
9
+ @doctitle_example = <<-EOS
10
+ = Sample Document
11
+ Author Name
12
+
13
+ Paragraph in preamble
14
+
15
+ == Sample Section
16
+
17
+ Paragraph in section
18
+ EOS
19
+
20
+ @source_code_example = <<-EOS
21
+ ```ruby
22
+ def hello()
23
+ 'world'
24
+ end
25
+ ```
26
+ EOS
27
+ end
28
+
29
+ def test_for_document_title
30
+ doc = AsciiDocFilter.to_document(@doctitle_example)
31
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
32
+ assert_equal 1, doc.css('h1').size
33
+ assert_equal 1, doc.css('#preamble p').size
34
+ assert_equal 1, doc.css('h2#sample-section').size
35
+ end
36
+
37
+ def test_for_lang_attribute_on_source_code_block
38
+ doc = AsciiDocFilter.to_document(@source_code_example)
39
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
40
+ assert_equal 1, doc.search('pre').size
41
+ assert_equal 'ruby', doc.search('pre').first['lang']
42
+ end
43
+
44
+ AsciiDocPipeline =
45
+ HTML::Pipeline.new [
46
+ HTML::Pipeline::AsciiDocFilter,
47
+ HTML::Pipeline::SanitizationFilter,
48
+ HTML::Pipeline::SyntaxHighlightFilter
49
+ ]
50
+ AsciiDocPipeline.setup_instrumentation
51
+
52
+ def test_syntax_highlighting
53
+ result = {}
54
+ AsciiDocPipeline.call(@source_code_example, {}, result)
55
+ assert_equal_html %(<div>
56
+ <div>
57
+ <div class="highlight highlight-ruby">
58
+ <pre><span class="k">def</span> <span class="nf">hello</span><span class="p">()</span>
59
+ <span class="s1">'world'</span>
60
+ <span class="k">end</span></pre>
61
+ </div>
62
+ </div>
63
+ </div>), result[:output].to_s
64
+ end
65
+
66
+ def test_for_document_structure
67
+ result = {}
68
+ AsciiDocPipeline.call(@doctitle_example, {}, result)
69
+ output = result[:output]
70
+ assert_equal 1, output.css('h1').size
71
+ assert_equal 1, output.css('h2').size
72
+ assert_equal 2, output.css('p').size
73
+ end
74
+ end
@@ -0,0 +1,36 @@
1
+ require 'html/pipeline'
2
+ require 'test/unit'
3
+ require 'active_support/core_ext/object/try'
4
+
5
+ module TestHelpers
6
+ # Asserts that `needle` is not a member of `haystack`, where
7
+ # `haystack` is any object that responds to `include?`.
8
+ def assert_doesnt_include(needle, haystack, message = nil)
9
+ error = '<?> included in <?>'
10
+ message = build_message(message, error, needle.to_s, Array(haystack).map(&:to_s))
11
+
12
+ assert_block message do
13
+ !haystack.include?(needle)
14
+ end
15
+ end
16
+
17
+ # Asserts that `needle` is a member of `haystack`, where
18
+ # `haystack` is any object that responds to `include?`.
19
+ def assert_includes(needle, haystack, message = nil)
20
+ error = '<?> not included in <?>'
21
+ message = build_message(message, error, needle.to_s, Array(haystack).map(&:to_s))
22
+
23
+ assert_block message do
24
+ haystack.include?(needle)
25
+ end
26
+ end
27
+
28
+ # Asserts that two html fragments are equivalent. Attribute order
29
+ # will be ignored.
30
+ def assert_equal_html(expected, actual)
31
+ assert_equal Nokogiri::HTML::DocumentFragment.parse(expected).to_hash,
32
+ Nokogiri::HTML::DocumentFragment.parse(actual).to_hash
33
+ end
34
+ end
35
+
36
+ Test::Unit::TestCase.send(:include, TestHelpers)
metadata ADDED
@@ -0,0 +1,137 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html-pipeline-asciidoc_filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.4
5
+ platform: ruby
6
+ authors:
7
+ - Dan Allen
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-09-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: html-pipeline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '0.3'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '0.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: asciidoctor
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.4
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.4
41
+ - !ruby/object:Gem::Dependency
42
+ name: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '2'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '2'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bundler
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: github-linguist
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: 2.6.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: 2.6.2
97
+ description: An AsciiDoc filter for html-pipeline based on Asciidoctor
98
+ email:
99
+ - dan.j.allen@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - LICENSE
105
+ - README.adoc
106
+ - html-pipeline-asciidoc_filter.gemspec
107
+ - lib/html/pipeline/asciidoc_filter.rb
108
+ - lib/html/pipeline/asciidoc_filter/version.rb
109
+ - test/asciidoc_filter_test.rb
110
+ - test/test_helper.rb
111
+ homepage: https://github.com/asciidoctor/html-pipeline-asciidoc_filter
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - '>='
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.0.3
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: An AsciiDoc filter for html-pipeline based on Asciidoctor
135
+ test_files:
136
+ - test/asciidoc_filter_test.rb
137
+ - test/test_helper.rb