html-pipeline-cite 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +68 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +43 -0
- data/LICENSE.md +20 -0
- data/README.md +72 -0
- data/Rakefile +66 -0
- data/html-pipeline-cite.gemspec +42 -0
- data/lib/html/pipeline/cite.rb +6 -0
- data/lib/html/pipeline/cite/cite_filter.rb +123 -0
- data/lib/html/pipeline/cite/version.rb +12 -0
- data/spec/cite_filter_spec.rb +73 -0
- data/spec/data/full_reference.md +3 -0
- data/spec/data/simple_reference.md +1 -0
- data/spec/helpers.rb +26 -0
- metadata +142 -0
data/CHANGELOG.md
ADDED
data/CONTRIBUTING.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Adding new features
|
2
|
+
|
3
|
+
This section includes advice on how to build new features for the project & what kind of process it includes.
|
4
|
+
|
5
|
+
* This is how we like people to add new features:
|
6
|
+
* Add only one feature at a time each on a new branch
|
7
|
+
* Here are some specifics on the coding style we prefer:
|
8
|
+
* Write the code test first
|
9
|
+
* Document the code whether or not it is part of the public API
|
10
|
+
* We use [YARD documentation](http://yardoc.org/)
|
11
|
+
* Documentation comments are in [Markdown](http://daringfireball.net/projects/markdown/) format
|
12
|
+
* This is how you send your pull request:
|
13
|
+
* TBD
|
14
|
+
* You should include the following tests:
|
15
|
+
* Unit tests (including tests for failure cases and testing exception paths) at a bare minimum
|
16
|
+
* If creating a new chunk of code (rather than changing already existing code) include integration tests as well
|
17
|
+
* These are the updates we hope you make to the changelog:
|
18
|
+
* Create a header underneath the current version number with a brief description of the feature
|
19
|
+
* Document any new command-line options
|
20
|
+
|
21
|
+
Don’t get discouraged! We estimate that the response time from the maintainers is around: One week, perhaps longer in December.
|
22
|
+
|
23
|
+
# Bug triage
|
24
|
+
|
25
|
+
This section explains how bug triaging is done for your project. Help beginners by including examples to good bug reports and providing them questions they should look to answer.
|
26
|
+
|
27
|
+
* You can help report bugs by filing them here: [New Issue](https://github.com/lifted-studios/html-pipeline-cite/issues/new)
|
28
|
+
* You can look through the existing bugs here: [Issues List](https://github.com/lifted-studios/html-pipeline-cite/issues)
|
29
|
+
|
30
|
+
* Look at existing bugs and help us understand if
|
31
|
+
* The bug is reproducible? Is it reproducible in other environments (browsers)? What are the steps to reproduce?
|
32
|
+
|
33
|
+
* You can close fixed bugs by testing old tickets to see if they are happening
|
34
|
+
* You can update our change log here
|
35
|
+
* You can remove duplicate bug reports
|
36
|
+
|
37
|
+
# Translations
|
38
|
+
|
39
|
+
This section includes any instructions or translation needs your project has.
|
40
|
+
|
41
|
+
* You can help us translate our project here:
|
42
|
+
|
43
|
+
# Documentation
|
44
|
+
|
45
|
+
This section includes any help you need with the documentation and where it can be found. Code needs explanation, and sometimes those who know the code well have trouble explaining it to someone just getting into it.
|
46
|
+
|
47
|
+
* Help us with documentation here
|
48
|
+
|
49
|
+
# Community
|
50
|
+
This section includes ideas on how non-developers can help with the project. Here's a few examples:
|
51
|
+
|
52
|
+
* You can help us answer questions our users have here:
|
53
|
+
* You can help build and design our website here:
|
54
|
+
* You can help write blog posts about the project by:
|
55
|
+
* You can help with newsletters and internal communications by:
|
56
|
+
|
57
|
+
* Create an example of the project in real world by building something or
|
58
|
+
showing what others have built.
|
59
|
+
* Write about other people’s projects based on this project. Show how
|
60
|
+
it’s used in daily life. Take screenshots and make videos!
|
61
|
+
|
62
|
+
|
63
|
+
# Your first bugfix
|
64
|
+
This section should help a person get started with their very first bug fix and thinking through the problem.
|
65
|
+
|
66
|
+
* If you have further questions, contact:
|
67
|
+
|
68
|
+
This contributing file template is from [contribute.md](http://contribute.md/).
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
html-pipeline-cite (0.0.1)
|
5
|
+
html-pipeline (>= 0.0.8)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
activesupport (3.2.12)
|
11
|
+
i18n (~> 0.6)
|
12
|
+
multi_json (~> 1.0)
|
13
|
+
escape_utils (0.3.1)
|
14
|
+
gemoji (1.4.0)
|
15
|
+
github-markdown (0.5.3)
|
16
|
+
html-pipeline (0.0.8)
|
17
|
+
activesupport (>= 2)
|
18
|
+
escape_utils (~> 0.2)
|
19
|
+
gemoji (~> 1.0)
|
20
|
+
github-markdown (~> 0.5)
|
21
|
+
nokogiri (~> 1.4)
|
22
|
+
rinku (~> 1.7)
|
23
|
+
sanitize (~> 2.0)
|
24
|
+
i18n (0.6.4)
|
25
|
+
minitest (3.5.0)
|
26
|
+
multi_json (1.6.1)
|
27
|
+
nokogiri (1.5.6)
|
28
|
+
rake (10.0.2)
|
29
|
+
redcarpet (2.1.1)
|
30
|
+
rinku (1.7.2)
|
31
|
+
sanitize (2.0.3)
|
32
|
+
nokogiri (>= 1.4.4, < 1.6)
|
33
|
+
yard (0.8.3)
|
34
|
+
|
35
|
+
PLATFORMS
|
36
|
+
ruby
|
37
|
+
|
38
|
+
DEPENDENCIES
|
39
|
+
html-pipeline-cite!
|
40
|
+
minitest (~> 3.0)
|
41
|
+
rake (~> 10.0)
|
42
|
+
redcarpet
|
43
|
+
yard (~> 0.8)
|
data/LICENSE.md
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2012-2013 Lee Dohm, Lifted Studios
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
<!--
|
2
|
+
[![Build Status](NOTE: Use something like Travis CI http://about.travis-ci.org/docs/user/getting-started/)
|
3
|
+
-->
|
4
|
+
|
5
|
+
# HTML::Pipeline Cite Gem
|
6
|
+
|
7
|
+
An [HTML::Pipeline](https://github.com/jch/html-pipeline) filter for WikiMedia-style Cite references.
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'html-pipeline-cite'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
```sh
|
20
|
+
$ bundle
|
21
|
+
```
|
22
|
+
|
23
|
+
Or install it yourself as:
|
24
|
+
|
25
|
+
```sh
|
26
|
+
$ gem install html-pipeline-cite
|
27
|
+
```
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
This gem offers an `HTML::Pipeline` filter that collects references in the text and inserts a table of footnotes where instructed.
|
32
|
+
|
33
|
+
Example:
|
34
|
+
|
35
|
+
<ref>This is a footnote</ref>
|
36
|
+
|
37
|
+
Becomes:
|
38
|
+
|
39
|
+
<sup class="reference" id="wiki-cite_ref-1">[<a href="#wiki-cite_note-1">1</a>]</sup>
|
40
|
+
|
41
|
+
It will show up as a bracketed, superscripted and anchored number at that location in the text. Then when
|
42
|
+
`<references/>` is placed in the text, an ordered list of the references and their text will be placed at that
|
43
|
+
location. The example above would generate a list that looks like this:
|
44
|
+
|
45
|
+
<ol>
|
46
|
+
<li id="wiki-cite_note-1"><b><a href="#wiki-cite_ref-1">^</a></b> This is a footnote.</li>
|
47
|
+
</ol>
|
48
|
+
|
49
|
+
<!--
|
50
|
+
## Troubleshooting
|
51
|
+
-->
|
52
|
+
|
53
|
+
## Development
|
54
|
+
|
55
|
+
To see what has changed in recent versions of the `html-pipeline-cite` gem, see the [CHANGELOG](https://github.com/lifted-studios/html-pipeline-cite/blob/master/CHANGELOG.md).
|
56
|
+
|
57
|
+
## Core Team Members
|
58
|
+
|
59
|
+
* [Lee Dohm](https://github.com/lee-dohm/)
|
60
|
+
|
61
|
+
## Resources
|
62
|
+
|
63
|
+
<!-- ### Other questions
|
64
|
+
|
65
|
+
Feel free to chat with the Lifted Wiki core team (and many other users) on IRC in the [#project](irc://irc.freenode.net/project) channel on Freenode, or via email on the [Project mailing list]().
|
66
|
+
-->
|
67
|
+
|
68
|
+
## Copyright
|
69
|
+
|
70
|
+
Copyright © 2013 Lee Dohm, Lifted Studios. See [LICENSE](https://github.com/lifted-studios/html-pipeline-cite/blob/master/LICENSE.md) for details.
|
71
|
+
|
72
|
+
Project is a member of the [OSS Manifesto](http://ossmanifesto.com/).
|
data/Rakefile
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 by Lifted Studios. All Rights Reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'bundler/gem_tasks'
|
6
|
+
require 'html/pipeline/cite/version'
|
7
|
+
require 'rake/clean'
|
8
|
+
require 'rake/testtask'
|
9
|
+
require 'yard'
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
HTML::Pipeline::Cite::VERSION
|
17
|
+
end
|
18
|
+
|
19
|
+
def gemspec_file
|
20
|
+
"#{name}.gemspec"
|
21
|
+
end
|
22
|
+
|
23
|
+
def gem_file
|
24
|
+
"#{name}-#{version}.gem"
|
25
|
+
end
|
26
|
+
|
27
|
+
CLEAN.include('.yardoc')
|
28
|
+
CLOBBER.include('doc', 'pkg')
|
29
|
+
|
30
|
+
task :default => [:test, :yard]
|
31
|
+
|
32
|
+
desc "Execute all tests"
|
33
|
+
task :test => [:spec]
|
34
|
+
|
35
|
+
Rake::TestTask.new('spec') do |spec|
|
36
|
+
spec.libs << 'spec'
|
37
|
+
spec.test_files = Dir['spec/**/*_spec.rb']
|
38
|
+
# spec.warning = true
|
39
|
+
end
|
40
|
+
|
41
|
+
YARD::Rake::YardocTask.new
|
42
|
+
|
43
|
+
desc 'Build gem'
|
44
|
+
task :build do
|
45
|
+
sh "mkdir -p pkg"
|
46
|
+
sh "gem build #{gemspec_file}"
|
47
|
+
sh "mv #{gem_file} pkg"
|
48
|
+
end
|
49
|
+
|
50
|
+
desc 'Create a release build'
|
51
|
+
task :release => :build do
|
52
|
+
unless `git branch` =~ /^\* master$/
|
53
|
+
puts "You must be on the master branch to release!"
|
54
|
+
exit!
|
55
|
+
end
|
56
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
57
|
+
sh "git pull"
|
58
|
+
sh "git tag v#{version}"
|
59
|
+
sh "git push origin master"
|
60
|
+
sh "git push origin v#{version}"
|
61
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
62
|
+
end
|
63
|
+
|
64
|
+
task :install => [:build] do
|
65
|
+
sh "gem install pkg/#{gem_file}"
|
66
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012-2013 by Lifted Studios. All Rights Reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'date'
|
6
|
+
require File.expand_path('../lib/html/pipeline/cite/version', __FILE__)
|
7
|
+
|
8
|
+
Gem::Specification.new do |s|
|
9
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.rubygems_version = '1.3.5'
|
12
|
+
s.required_ruby_version = ">= 1.9.3"
|
13
|
+
|
14
|
+
s.name = 'html-pipeline-cite'
|
15
|
+
s.version = HTML::Pipeline::Cite::VERSION
|
16
|
+
s.date = Date.today.to_s
|
17
|
+
|
18
|
+
s.summary = "An HTML::Pipeline filter for WikiMedia-style Cite references."
|
19
|
+
s.description = "An HTML::Pipeline filter for WikiMedia-style Cite references."
|
20
|
+
|
21
|
+
s.authors = ["Lee Dohm"]
|
22
|
+
s.email = 'lee@liftedstudios.com'
|
23
|
+
s.homepage = 'https://github.com/lifted-studios/html-pipeline-cite'
|
24
|
+
s.license = 'MIT'
|
25
|
+
|
26
|
+
s.require_paths = ['lib']
|
27
|
+
|
28
|
+
s.add_dependency('html-pipeline', '>= 0.0.8')
|
29
|
+
|
30
|
+
s.add_development_dependency('minitest', '~> 3.0')
|
31
|
+
s.add_development_dependency('rake', '~> 10.0')
|
32
|
+
s.add_development_dependency('redcarpet')
|
33
|
+
s.add_development_dependency('yard', '~> 0.8')
|
34
|
+
|
35
|
+
s.files = `git ls-files`.
|
36
|
+
split("\n").
|
37
|
+
sort.
|
38
|
+
reject { |file| file =~ /^\./ }.
|
39
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }
|
40
|
+
|
41
|
+
s.test_files = s.files.select { |path| path =~ /^spec\/.*_spec\.rb/ }
|
42
|
+
end
|
@@ -0,0 +1,123 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012-2013 by Lifted Studios. All Rights Reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'html/pipeline'
|
6
|
+
require 'nokogiri'
|
7
|
+
|
8
|
+
module HTML
|
9
|
+
class Pipeline
|
10
|
+
# An `HTML::Pipeline` filter that collects references in the text and inserts a table of footnotes where instructed.
|
11
|
+
#
|
12
|
+
# Example:
|
13
|
+
#
|
14
|
+
# <ref>This is a footnote</ref>
|
15
|
+
#
|
16
|
+
# Becomes:
|
17
|
+
#
|
18
|
+
# <sup class="reference" id="wiki-cite_ref-1">[<a href="#wiki-cite_note-1">1</a>]</sup>
|
19
|
+
#
|
20
|
+
# It will show up as a bracketed, superscripted and anchored number at that location in the text. Then when
|
21
|
+
# `<references/>` is placed in the text, an ordered list of the references and their text will be placed at that
|
22
|
+
# location. The example above would generate a list that looks like this:
|
23
|
+
#
|
24
|
+
# <ol>
|
25
|
+
# <li id="wiki-cite_note-1"><b><a href="#wiki-cite_ref-1">^</a></b> This is a footnote.</li>
|
26
|
+
# </ol>
|
27
|
+
#
|
28
|
+
class CiteFilter < Filter
|
29
|
+
# ID of the note
|
30
|
+
NOTE = 'wiki-cite_note'
|
31
|
+
|
32
|
+
# ID of the ref
|
33
|
+
REF = 'wiki-cite_ref'
|
34
|
+
|
35
|
+
# Replaces ref and references tags with the appropriate HTML and returns the result.
|
36
|
+
#
|
37
|
+
# @return [Nokogiri::HTML::DocumentFragment] Updated HTML document fragment.
|
38
|
+
def call
|
39
|
+
refs = replace_refs
|
40
|
+
replace_references(refs)
|
41
|
+
|
42
|
+
doc
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
# Creates the link text for the ref node.
|
48
|
+
#
|
49
|
+
# @param [Integer] index Index of the item.
|
50
|
+
# @return [String] Link text for the ref node replacement.
|
51
|
+
def create_ref_link(index)
|
52
|
+
%Q([<a href="##{NOTE}-#{index}">#{index}</a>])
|
53
|
+
end
|
54
|
+
|
55
|
+
# Creates the HTML to replace the ref node in the document.
|
56
|
+
#
|
57
|
+
# @param [Nokogiri::XML::Node] node Node in the document we are working with.
|
58
|
+
# @param [Integer] index Index of the item.
|
59
|
+
# @return [Nokogiri::XML::Node] Node to replace the `ref` node.
|
60
|
+
def create_ref_node(node, index)
|
61
|
+
ref_node = node.document.create_element('sup', :class => 'reference', :id => "#{REF}-#{index}")
|
62
|
+
ref_node.inner_html = create_ref_link(index)
|
63
|
+
ref_node
|
64
|
+
end
|
65
|
+
|
66
|
+
# Creates the list items text.
|
67
|
+
#
|
68
|
+
# @param [Array] refs Text to place in the list items.
|
69
|
+
# @return [String] List items text.
|
70
|
+
def create_references_list_items(refs)
|
71
|
+
refs.each_with_index.reduce('') do |inner_html, args|
|
72
|
+
note = args.first
|
73
|
+
num = args[1] + 1
|
74
|
+
inner_html << %Q(<li id="#{NOTE}-#{num}"><b><a href="##{REF}-#{num}">^</a></b> #{note}</li>\n)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
# Replaces ref tags with the appropriate HTML and returns the set of reference texts.
|
79
|
+
#
|
80
|
+
# @return [Array] List of texts from the `ref` tags.
|
81
|
+
def replace_refs
|
82
|
+
doc.xpath('.//ref').each_with_index.map do |node, index|
|
83
|
+
text = node.inner_html
|
84
|
+
|
85
|
+
ref_node = create_ref_node(node, index + 1)
|
86
|
+
node.replace(ref_node)
|
87
|
+
|
88
|
+
text
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
# Replaces references tags with the appropriate HTML.
|
93
|
+
#
|
94
|
+
# @param [Array] refs List of reference texts.
|
95
|
+
# @return [nil]
|
96
|
+
def replace_references(refs)
|
97
|
+
set = doc.xpath('.//references')
|
98
|
+
|
99
|
+
if set
|
100
|
+
inner_html = create_references_list_items(refs)
|
101
|
+
replace_references_node(set, inner_html)
|
102
|
+
end
|
103
|
+
|
104
|
+
nil
|
105
|
+
end
|
106
|
+
|
107
|
+
# Replaces the references nodes with the ordered list.
|
108
|
+
#
|
109
|
+
# @param [Nokogiri::XML::NodeSet] set Set of `references` nodes.
|
110
|
+
# @param [String] inner_html Inner HTML to use for the list.
|
111
|
+
# @return [nil]
|
112
|
+
def replace_references_node(set, inner_html)
|
113
|
+
set.each do |references_node|
|
114
|
+
ol_node = references_node.document.create_element "ol"
|
115
|
+
ol_node.inner_html = inner_html
|
116
|
+
references_node.parent.replace(ol_node)
|
117
|
+
end
|
118
|
+
|
119
|
+
nil
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2012-2013 by Lifted Studios. All Rights Reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
gem 'minitest'
|
6
|
+
|
7
|
+
require 'minitest/spec'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
|
10
|
+
require 'helpers'
|
11
|
+
require 'nokogiri'
|
12
|
+
require 'html/pipeline/cite'
|
13
|
+
|
14
|
+
describe HTML::Pipeline::CiteFilter do
|
15
|
+
# Creates a new basic pipeline object.
|
16
|
+
#
|
17
|
+
# @return Basic HTML::Pipeline initialized to convert Markdown into HTML.
|
18
|
+
def new_pipeline
|
19
|
+
HTML::Pipeline.new([ HTML::Pipeline::MarkdownFilter ])
|
20
|
+
end
|
21
|
+
|
22
|
+
# Creates a new filter for testing using the given `fragment`.
|
23
|
+
#
|
24
|
+
# @param fragment Markdown text to convert into HTML and process references.
|
25
|
+
# @return Fully-processed HTML.
|
26
|
+
def new_filter(fragment)
|
27
|
+
if fragment.kind_of? String
|
28
|
+
pipeline = new_pipeline
|
29
|
+
fragment = pipeline.call(fragment)[:output].to_s
|
30
|
+
end
|
31
|
+
|
32
|
+
HTML::Pipeline::CiteFilter.new(fragment)
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can be instantiated' do
|
36
|
+
filter = new_filter('Some fake document text')
|
37
|
+
|
38
|
+
filter.wont_be_nil
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'will pass through a fragment without references unchanged' do
|
42
|
+
filter = new_filter('Some fake document text')
|
43
|
+
|
44
|
+
text = filter.call.to_s
|
45
|
+
|
46
|
+
text.must_equal '<p>Some fake document text</p>'
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'will replace refs with footnote anchors' do
|
50
|
+
filter = new_filter(read_test_file('simple_reference.md'))
|
51
|
+
|
52
|
+
text = filter.call.to_s
|
53
|
+
|
54
|
+
text.node('ref').count.must_equal 0
|
55
|
+
text.node('sup').count.must_equal 1
|
56
|
+
text.node('sup').attribute('class').value.must_equal 'reference'
|
57
|
+
text.node('sup').attribute('id').value.must_equal 'wiki-cite_ref-1'
|
58
|
+
text.node('sup').inner_html.must_equal '[<a href="#wiki-cite_note-1">1</a>]'
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'will replace references with the ordered list of footnotes' do
|
62
|
+
filter = new_filter(read_test_file('full_reference.md'))
|
63
|
+
|
64
|
+
text = filter.call.to_s
|
65
|
+
|
66
|
+
text.node('references').count.must_equal 0
|
67
|
+
text.node('ol').count.must_equal 1
|
68
|
+
text.node('li').count.must_equal 1
|
69
|
+
text.node('li').attribute('id').value.must_equal 'wiki-cite_note-1'
|
70
|
+
text.node('li').inner_html.must_match(/#wiki-cite_ref-1/)
|
71
|
+
text.node('li').inner_html.must_match(/With a footnote\./)
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
First paragraph<ref>With footnote</ref>
|
data/spec/helpers.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (c) 2013 by Lifted Studios. All Rights Reserved.
|
3
|
+
#
|
4
|
+
|
5
|
+
require 'nokogiri'
|
6
|
+
|
7
|
+
class String
|
8
|
+
# Creates an HTML document fragment out of the string's contents and returns the nodes with the matching tags.
|
9
|
+
#
|
10
|
+
# @param [String] tag Tag to search for.
|
11
|
+
# @return Set of nodes that match the given tag.
|
12
|
+
def node(tag)
|
13
|
+
Nokogiri::make("<div>#{self}</div>").xpath(".//#{tag}")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Reads a test data file.
|
18
|
+
#
|
19
|
+
# The path passed to the function is treated as relative to the `spec/data` directory.
|
20
|
+
#
|
21
|
+
# @param path Path to the test file.
|
22
|
+
# @return Text in the file.
|
23
|
+
def read_test_file(path)
|
24
|
+
path = File.join('spec/data', path)
|
25
|
+
IO.read(path)
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: html-pipeline-cite
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Lee Dohm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: html-pipeline
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.0.8
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.8
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: minitest
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '3.0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '3.0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: redcarpet
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: yard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0.8'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0.8'
|
94
|
+
description: An HTML::Pipeline filter for WikiMedia-style Cite references.
|
95
|
+
email: lee@liftedstudios.com
|
96
|
+
executables: []
|
97
|
+
extensions: []
|
98
|
+
extra_rdoc_files: []
|
99
|
+
files:
|
100
|
+
- CHANGELOG.md
|
101
|
+
- CONTRIBUTING.md
|
102
|
+
- Gemfile
|
103
|
+
- Gemfile.lock
|
104
|
+
- LICENSE.md
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
107
|
+
- html-pipeline-cite.gemspec
|
108
|
+
- lib/html/pipeline/cite.rb
|
109
|
+
- lib/html/pipeline/cite/cite_filter.rb
|
110
|
+
- lib/html/pipeline/cite/version.rb
|
111
|
+
- spec/cite_filter_spec.rb
|
112
|
+
- spec/data/full_reference.md
|
113
|
+
- spec/data/simple_reference.md
|
114
|
+
- spec/helpers.rb
|
115
|
+
homepage: https://github.com/lifted-studios/html-pipeline-cite
|
116
|
+
licenses:
|
117
|
+
- MIT
|
118
|
+
post_install_message:
|
119
|
+
rdoc_options: []
|
120
|
+
require_paths:
|
121
|
+
- lib
|
122
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
123
|
+
none: false
|
124
|
+
requirements:
|
125
|
+
- - ! '>='
|
126
|
+
- !ruby/object:Gem::Version
|
127
|
+
version: 1.9.3
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
requirements: []
|
135
|
+
rubyforge_project:
|
136
|
+
rubygems_version: 1.8.24
|
137
|
+
signing_key:
|
138
|
+
specification_version: 2
|
139
|
+
summary: An HTML::Pipeline filter for WikiMedia-style Cite references.
|
140
|
+
test_files:
|
141
|
+
- spec/cite_filter_spec.rb
|
142
|
+
has_rdoc:
|