nanoc-code-classifier 0.0.3 → 0.0.4
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.
@@ -13,16 +13,21 @@ module Nanoc3
|
|
13
13
|
type :text
|
14
14
|
|
15
15
|
def run(content, params = {})
|
16
|
+
params = {
|
17
|
+
:caption => {},
|
18
|
+
:pre => {}
|
19
|
+
}.update(params)
|
20
|
+
|
16
21
|
html = Nokogiri::HTML.fragment(content)
|
17
22
|
|
18
23
|
html.xpath("pre/code").each do |code|
|
19
24
|
pre = code.parent
|
20
25
|
|
21
26
|
# Set the class on the <pre>.
|
22
|
-
append_class(pre, params[:
|
27
|
+
append_class(pre, params[:pre][:class]) if params[:pre][:class]
|
23
28
|
|
24
|
-
process_language_tag(code)
|
25
|
-
process_caption_tag(code)
|
29
|
+
process_language_tag(code, params)
|
30
|
+
process_caption_tag(code, params[:caption])
|
26
31
|
end
|
27
32
|
|
28
33
|
html.to_s
|
@@ -30,14 +35,18 @@ module Nanoc3
|
|
30
35
|
|
31
36
|
private
|
32
37
|
|
33
|
-
def process_language_tag(element)
|
38
|
+
def process_language_tag(element, params)
|
34
39
|
element.content = element.content.sub(/\[\s*@language\s*=\s*"([^"]+)"\s*\]/) do
|
35
40
|
append_class(element, "language-#{$1}")
|
36
41
|
nil
|
37
42
|
end.strip!
|
38
43
|
end
|
39
44
|
|
40
|
-
def process_caption_tag(element)
|
45
|
+
def process_caption_tag(element, params)
|
46
|
+
params = {
|
47
|
+
:position => :top
|
48
|
+
}.update(params)
|
49
|
+
|
41
50
|
element.content = element.content.sub(/\[\s*@caption\s*=\s*"([^"]+)"\s*\]/) do
|
42
51
|
# Wrap in a <figure>.
|
43
52
|
figure = Nokogiri::XML::Node.new("figure", element.document)
|
@@ -47,7 +56,16 @@ module Nanoc3
|
|
47
56
|
# Add a <figcaption>.
|
48
57
|
figcaption = Nokogiri::XML::Node.new("figcaption", element.document)
|
49
58
|
figcaption.content = $1
|
50
|
-
|
59
|
+
|
60
|
+
position = params[:position].to_sym
|
61
|
+
|
62
|
+
if position == :top
|
63
|
+
element.parent.add_previous_sibling(figcaption)
|
64
|
+
elsif position == :bottom
|
65
|
+
element.parent.add_next_sibling(figcaption)
|
66
|
+
else
|
67
|
+
raise "Unknown position: #{position}"
|
68
|
+
end
|
51
69
|
|
52
70
|
nil
|
53
71
|
end.strip!
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nanoc-code-classifier
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 0
|
8
7
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
8
|
+
- 4
|
9
|
+
version: 0.0.4
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Josh Bassett
|
@@ -22,11 +21,9 @@ dependencies:
|
|
22
21
|
name: nokogiri
|
23
22
|
prerelease: false
|
24
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
25
|
- - ~>
|
28
26
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 15
|
30
27
|
segments:
|
31
28
|
- 1
|
32
29
|
- 0
|
@@ -37,11 +34,9 @@ dependencies:
|
|
37
34
|
name: nanoc
|
38
35
|
prerelease: false
|
39
36
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
-
none: false
|
41
37
|
requirements:
|
42
38
|
- - ~>
|
43
39
|
- !ruby/object:Gem::Version
|
44
|
-
hash: 7
|
45
40
|
segments:
|
46
41
|
- 3
|
47
42
|
- 0
|
@@ -72,27 +67,23 @@ rdoc_options: []
|
|
72
67
|
require_paths:
|
73
68
|
- lib
|
74
69
|
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
-
none: false
|
76
70
|
requirements:
|
77
71
|
- - ">="
|
78
72
|
- !ruby/object:Gem::Version
|
79
|
-
hash: 3
|
80
73
|
segments:
|
81
74
|
- 0
|
82
75
|
version: "0"
|
83
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
77
|
requirements:
|
86
78
|
- - ">="
|
87
79
|
- !ruby/object:Gem::Version
|
88
|
-
hash: 3
|
89
80
|
segments:
|
90
81
|
- 0
|
91
82
|
version: "0"
|
92
83
|
requirements: []
|
93
84
|
|
94
85
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.
|
86
|
+
rubygems_version: 1.3.6
|
96
87
|
signing_key:
|
97
88
|
specification_version: 3
|
98
89
|
summary: A nanoc filter which pre-processes a code block for special tags.
|