additional-markdown-filter 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f796edafe0ca71d0b60b6713eb917577dd0547d3
4
+ data.tar.gz: 7612af6d1cf4619380cf1290ba931f83c031243e
5
+ SHA512:
6
+ metadata.gz: 1da5f13f44dd6e6102eec5d29189e0aa60ecaceb92b94c6ba20ea58ed46de201c043fa246a7d796fe972676decf9e4afbf86dc115023276bf35da4d6d24d852c
7
+ data.tar.gz: ad784c1a6acb8e55e4ca8afad1a7c159cc12e1144d5a6cdb513cc3a7693e7cef30c9663b7957814516483b6fa60a88d0455f956c9976e943c494b27cd03d44bf
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Garen Torikian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,30 @@
1
+ additional-markdown-filter
2
+ ====================
3
+
4
+ Additional Markdown filters for the [HTML::Pipeline](https://github.com/jch/html-pipeline).
5
+
6
+ [![Build Status](https://travis-ci.org/gjtorikian/additional-markdown-filter.svg)](https://travis-ci.org/gjtorikian/additional-markdown-filter)
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ gem 'additional-markdown-filter'
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install additional-markdown-filter
21
+
22
+ ## Usage
23
+
24
+ The simplest way to do this is
25
+
26
+ ``` ruby
27
+ require 'additional-markdown-filter'
28
+ ```
29
+
30
+ Then just use the pipeline normally.
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ task :default => [:test]
4
+
5
+ require 'rake/testtask'
6
+ Rake::TestTask.new(:test) do |test|
7
+ test.libs << 'lib' << 'test'
8
+ test.pattern = 'test/**/test_*.rb'
9
+ test.verbose = true
10
+ end
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "additional-markdown-filter"
3
+ spec.version = "0.1.0"
4
+ spec.authors = ["Garen Torikian"]
5
+ spec.email = ["gjtorikian@gmail.com"]
6
+ spec.summary = %q{Add additional markup syntax to the HTML::Pipeline}
7
+ spec.description = %q{This is a custom Markdown processor to be used with GitHub's HTML::Pipeline. }
8
+ spec.homepage = ""
9
+ spec.license = "MIT"
10
+
11
+ spec.files = `git ls-files`.split($/)
12
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
13
+ spec.test_files = spec.files.grep(%r{^(test)/})
14
+ spec.require_paths = ["lib"]
15
+
16
+ spec.add_dependency 'html-pipeline', "~> 1.0"
17
+
18
+ spec.add_development_dependency "bundler", "~> 1.4"
19
+ spec.add_development_dependency "rake"
20
+ spec.add_development_dependency 'minitest', "~> 5.0"
21
+ spec.add_development_dependency 'github-markdown', "~> 0.6.3"
22
+ end
@@ -0,0 +1,69 @@
1
+ require "html/pipeline"
2
+
3
+ class AdditionalMarkdownFilter < HTML::Pipeline::MarkdownFilter
4
+ def initialize(text, context = nil, result = nil)
5
+ # do preprocessing, then call HTML::Pipeline::Markdown
6
+ format_command_line! text
7
+ format_helper! text
8
+
9
+ super text, context, result
10
+ end
11
+
12
+ def call
13
+ # initialize HTML::Pipeline::Markdown, then do post-processing
14
+ html = super
15
+
16
+ format_intro! html
17
+ format_os_blocks! html
18
+ format_admonition! html
19
+
20
+ html
21
+ end
22
+
23
+ def format_command_line!(text)
24
+ text.gsub! /\n?``` command-line(.+?)```/m do |block|
25
+ block.gsub! /^``` command-line/, '<pre class="command-line">'
26
+ block.gsub! /^```$/, "</pre>\n"
27
+ block.gsub!(/^\$ (.+)$/) { %Q|<span class="command">#{$1.rstrip}</span>| }
28
+ block.gsub!(/^(\# .+)$/) { %Q|<span class="comment">#{$1.rstrip}</span>| }
29
+ block.gsub!(/^> (.+)$/) { %Q|<span class="output"><span># </span>#{$1.rstrip}</span>| }
30
+
31
+ block
32
+ end
33
+ end
34
+
35
+ def format_helper!(text)
36
+ text.gsub! /\n?``` helper(.+?)```/m do |block|
37
+ block.gsub! /^``` helper\s*/, ''
38
+ block.gsub! /^```$/, ''
39
+
40
+ header = ''
41
+ block.gsub! /^#### (.+?)$/ do
42
+ header = $1.strip
43
+ ''
44
+ end
45
+
46
+ content = block.strip
47
+ content = "<p>#{content}</p>" unless content =~ /^<p/
48
+ content = "<div class='helper'><h4 class='header'><a href='#'>#{header}</a></h4><div class='content'>#{content}</div></div>"
49
+ end
50
+ end
51
+
52
+ def format_intro!(html)
53
+ html.gsub!(/<p>{{#intro}}<\/p>/, '<div class="intro">')
54
+ html.gsub!(/<p>{{\/intro}}<\/p>/, '</div>')
55
+ end
56
+
57
+ def format_os_blocks!(html)
58
+ html.gsub!(/<p>{{#mac}}<\/p>/, '<div class="platform-mac">')
59
+ html.gsub!(/<p>{{#windows}}<\/p>/, '<div class="platform-windows">')
60
+ html.gsub!(/<p>{{#linux}}<\/p>/, '<div class="platform-linux">')
61
+ html.gsub!(/<p>{{#all}}<\/p>/, '<div class="platform-all">')
62
+ html.gsub!(/<p>{{\/(mac|windows|linux|all)}}<\/p>/, '</div>')
63
+ end
64
+
65
+ def format_admonition!(html)
66
+ html.gsub!(/<p>{{#(tip|warning|error)}}<\/p>/, '<div class="alert \1">')
67
+ html.gsub!(/<p>{{\/(tip|warning|error)}}<\/p>/, '</div>')
68
+ end
69
+ end
@@ -0,0 +1,20 @@
1
+ {{#tip}}
2
+
3
+ Here's a hot tip: **line one**
4
+ Here's a hot tip: line two
5
+
6
+ {{/tip}}
7
+
8
+ {{#warning}}
9
+
10
+ Yo, check this out: line one
11
+ Yo, check this out: line two
12
+
13
+ {{/warning}}
14
+
15
+ {{#error}}
16
+
17
+ Sheeeeit, this is a problem: ~~line one~~
18
+ Sheeeeit, this is a problem: line two
19
+
20
+ {{/error}}
@@ -0,0 +1,5 @@
1
+ ``` command-line
2
+ $ git remote add origin https://github.com/<em>user</em>/<em>repo</em>.git
3
+ # Set a new remote
4
+ > origin https://github.com/user/repo.git
5
+ ```
@@ -0,0 +1,8 @@
1
+
2
+ ``` helper
3
+ #### A note about Sync in GitHub for Mac
4
+
5
+ Those that are already familiar with Git may notice that there are no "Push" or "Pull" buttons in GitHub for Mac.
6
+
7
+ Instead of bringing in new changes from the remote copy with one command and pushing your unpublished commits with another, GitHub for Mac uses a single "Sync" button that quickly completes both operations at the same. Behind the scenes, we do the equivalent of a `git pull --rebase` (but make sure to never rewrite merges).
8
+ ```
@@ -0,0 +1,5 @@
1
+ {{#intro}}
2
+
3
+ [Gists](https://gist.github.com) are a great way to share your work. You can share single files, parts of files, or full applications.
4
+
5
+ {{/intro}}
@@ -0,0 +1,23 @@
1
+ {{#mac}}
2
+
3
+ 1. [Create a new repository](/articles/creating-a-new-repository).
4
+
5
+ {{/mac}}
6
+
7
+ {{#windows}}
8
+
9
+ 1. [Try to create a new repository](/articles/creating-a-new-repository).
10
+
11
+ {{/windows}}
12
+
13
+ {{#linux}}
14
+
15
+ 1. You *already* know what you're doing.
16
+
17
+ {{/linux}}
18
+
19
+ {{#all}}
20
+
21
+ What?
22
+
23
+ {{/all}}
@@ -0,0 +1,70 @@
1
+ require "test_helper"
2
+
3
+ class HTML::Pipeline::AdditionalMarkdownFilterTest < Minitest::Test
4
+ def fixture(name)
5
+ File.open(File.join("#{File.expand_path(File.dirname(__FILE__))}", "fixtures", name)).read
6
+ end
7
+
8
+ def test_command_line
9
+ doc = AdditionalMarkdownFilter.to_document(fixture("command_line.md"), {})
10
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
11
+
12
+ assert_equal 1, doc.css('pre').size
13
+ assert_equal 1, doc.css('span.command').size
14
+ assert_equal 1, doc.css('span.comment').size
15
+ assert_equal 2, doc.css('em').size
16
+ assert_equal 1, doc.css('span.output').size
17
+ end
18
+
19
+ def test_helper
20
+ doc = AdditionalMarkdownFilter.to_document(fixture("helper.md"), {})
21
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
22
+
23
+ assert_equal 1, doc.css('div.helper').size
24
+ assert_equal 1, doc.css('h4.header').size
25
+ assert_equal 1, doc.css('a').size
26
+ assert_equal 1, doc.css('div.content').size
27
+ end
28
+
29
+ def test_intro
30
+ doc = AdditionalMarkdownFilter.to_document(fixture("intro.md"), {})
31
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
32
+
33
+ assert_equal 1, doc.css('div.intro').size
34
+ assert_equal 1, doc.css('a').size # the inner Markdown converted!
35
+ end
36
+
37
+ def test_intro
38
+ doc = AdditionalMarkdownFilter.to_document(fixture("intro.md"), {})
39
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
40
+
41
+ assert_equal 1, doc.css('div.intro').size
42
+ assert_equal 1, doc.css('a').size # the inner Markdown converted!
43
+ end
44
+
45
+ def test_os_blocks
46
+ doc = AdditionalMarkdownFilter.to_document(fixture("os_blocks.md"), {})
47
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
48
+
49
+ assert_equal 1, doc.css('div.platform-mac').size
50
+ assert_equal 1, doc.css('div.platform-windows').size
51
+ assert_equal 1, doc.css('div.platform-linux').size
52
+ assert_equal 1, doc.css('div.platform-all').size
53
+ # the inner Markdown converted!
54
+ assert_equal 3, doc.css('ol').size
55
+ assert_equal 2, doc.css('a').size
56
+ assert_equal 1, doc.css('em').size
57
+ end
58
+
59
+ def test_admonition
60
+ doc = AdditionalMarkdownFilter.to_document(fixture("admonition.md"), {})
61
+ assert doc.kind_of?(HTML::Pipeline::DocumentFragment)
62
+
63
+ assert_equal 1, doc.css('div.tip').size
64
+ assert_equal 1, doc.css('div.warning').size
65
+ assert_equal 1, doc.css('div.error').size
66
+ # the inner Markdown converted!
67
+ assert_equal 1, doc.css('strong').size
68
+ assert_equal 1, doc.css('del').size
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ require "rubygems"
2
+
3
+ require 'minitest/autorun'
4
+
5
+ require "additional_markdown_filter"
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: additional-markdown-filter
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Garen Torikian
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-01 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: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '5.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '5.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: github-markdown
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.6.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.6.3
83
+ description: 'This is a custom Markdown processor to be used with GitHub''s HTML::Pipeline. '
84
+ email:
85
+ - gjtorikian@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - additional-markdown-filter.gemspec
97
+ - lib/additional_markdown_filter.rb
98
+ - test/fixtures/admonition.md
99
+ - test/fixtures/command_line.md
100
+ - test/fixtures/helper.md
101
+ - test/fixtures/intro.md
102
+ - test/fixtures/os_blocks.md
103
+ - test/test_additional_markdown_filter.rb
104
+ - test/test_helper.rb
105
+ homepage: ''
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.2.2
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Add additional markup syntax to the HTML::Pipeline
129
+ test_files:
130
+ - test/fixtures/admonition.md
131
+ - test/fixtures/command_line.md
132
+ - test/fixtures/helper.md
133
+ - test/fixtures/intro.md
134
+ - test/fixtures/os_blocks.md
135
+ - test/test_additional_markdown_filter.rb
136
+ - test/test_helper.rb