sixarm_ruby_markdown 2.0.0 → 2.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/sixarm_ruby_markdown.rb +1 -0
- data/lib/sixarm_ruby_markdown/sixarm/markdown/headline.rb +47 -3
- data/test/sixarm_ruby_markdown_test/sixarm/markdown/headline_test.rb +118 -14
- metadata +23 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af9a2722358657600dc9b1f3ef85dc514c107e2db3a2bb181c8ab72c5f402fe6
|
4
|
+
data.tar.gz: 91b2d23b0ceb68cff8547b08013c36c9e1babbe30e72ee37af3d2a54e913b54c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: '08c993859e8ca51116cb0e1d39821e7b19adaa637972a32b951083ef9d301b82318236cd2cf6c11b534865c8890646589479ebf8a49b6742c65d1b506aa9dbd9'
|
7
|
+
data.tar.gz: 6efc020cfea100b66bfc95df589ed9c0246f189f370c12484256dc31e03025ffb770cb19757fb86c1214ca0367c7a8b7db4f0a8722de1baeefaaf50a1ec99c15
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/sixarm_ruby_markdown.rb
CHANGED
@@ -4,13 +4,57 @@
|
|
4
4
|
|
5
5
|
module SixArm; module Markdown; end; end
|
6
6
|
|
7
|
-
class SixArm::Markdown::Headline
|
7
|
+
class SixArm::Markdown::Headline
|
8
|
+
include EqualInstanceVariables
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
attr_accessor \
|
11
|
+
:text,
|
12
|
+
:anchor,
|
13
|
+
:level,
|
14
|
+
:link
|
15
|
+
|
16
|
+
def initialize(
|
17
|
+
text: nil,
|
18
|
+
anchor: nil,
|
19
|
+
level: nil,
|
20
|
+
link: nil
|
21
|
+
)
|
22
|
+
raise ArgumentError if !text.kind_of?(String)
|
23
|
+
@text = text
|
24
|
+
@anchor = anchor || self.class.text_to_anchor(text)
|
25
|
+
@level = level
|
26
|
+
@link = link
|
11
27
|
end
|
12
28
|
|
13
29
|
def anchor
|
30
|
+
@anchor || self.class.text_to_anchor(text)
|
31
|
+
end
|
32
|
+
|
33
|
+
def level
|
34
|
+
@level || 1
|
35
|
+
end
|
36
|
+
|
37
|
+
def link
|
38
|
+
@link || "[#{text}](##{anchor})"
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.parse_line(line)
|
42
|
+
level = parse_line_level(line)
|
43
|
+
text = trim_line(line)
|
44
|
+
# TODO Add parser for anchor
|
45
|
+
# TODO Add parser for Unicode normalization
|
46
|
+
return SixArm::Markdown::Headline.new(text: text, level: level)
|
47
|
+
end
|
48
|
+
|
49
|
+
def self.parse_line_level(line)
|
50
|
+
return line =~/^\s*([#=]+)/ ? $1.length : nil
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.trim_line(line)
|
54
|
+
line.sub(/^\s*[#=]+\s+/, '').sub(/\s+[#=]+\s*$/, '')
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.text_to_anchor(text)
|
14
58
|
text.downcase.gsub(/\W+/,'-')
|
15
59
|
end
|
16
60
|
|
@@ -3,38 +3,142 @@ require "sixarm_ruby_markdown_test"
|
|
3
3
|
|
4
4
|
describe SixArm::Markdown::Headline do
|
5
5
|
|
6
|
-
let(:
|
7
|
-
let(:
|
8
|
-
let(:
|
6
|
+
let(:text){ "Foo Goo Hoo" }
|
7
|
+
let(:anchor_default) { "foo-goo-hoo"}
|
8
|
+
let(:anchor_custom) { "bar-car-dar"}
|
9
|
+
let(:level_default){ 1 }
|
10
|
+
let(:level_custom){ 3 }
|
11
|
+
let(:link_default){ "[Foo Goo Hoo](#foo-goo-hoo)" }
|
12
|
+
let(:link_custom){ "[My Link Text](#my-link-anchor)" }
|
13
|
+
let(:headline){ SixArm::Markdown::Headline.new(text: text) }
|
9
14
|
|
10
|
-
describe "#
|
15
|
+
describe "#text" do
|
11
16
|
|
12
|
-
it "return
|
13
|
-
expect(headline.
|
17
|
+
it "return text" do
|
18
|
+
expect(headline.text).must_equal text
|
14
19
|
end
|
15
20
|
|
16
21
|
end
|
17
22
|
|
18
|
-
describe "#
|
23
|
+
describe "#anchor" do
|
24
|
+
|
25
|
+
describe "with default, which is no anchor, thus uses autogeneration" do
|
26
|
+
|
27
|
+
it "return default anchor" do
|
28
|
+
headline = SixArm::Markdown::Headline.new(text: text)
|
29
|
+
expect(headline.anchor).must_equal anchor_default
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "with custom anchor" do
|
35
|
+
|
36
|
+
it "return custom anchor" do
|
37
|
+
headline = SixArm::Markdown::Headline.new(text: text, anchor: anchor_custom)
|
38
|
+
expect(headline.anchor).must_equal anchor_custom
|
39
|
+
end
|
19
40
|
|
20
|
-
it "return text" do
|
21
|
-
expect(headline.text).must_equal text
|
22
41
|
end
|
23
42
|
|
24
43
|
end
|
25
44
|
|
26
|
-
describe "#
|
45
|
+
describe "#level" do
|
46
|
+
|
47
|
+
describe "with default, which is no level, thus uses default level which is 1" do
|
48
|
+
|
49
|
+
it "return default level, which is 1 i.e. suitable for HTML H1" do
|
50
|
+
headline = SixArm::Markdown::Headline.new(text: text)
|
51
|
+
expect(headline.level).must_equal level_default
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "with custom level" do
|
57
|
+
|
58
|
+
it "return custom level" do
|
59
|
+
headline = SixArm::Markdown::Headline.new(text: text, level: level_custom)
|
60
|
+
expect(headline.level).must_equal level_custom
|
61
|
+
end
|
27
62
|
|
28
|
-
it "return anchor, which is the text as lowercase, and replacing every run of non-word characters with a dash" do
|
29
|
-
expect(headline.anchor).must_equal "hello-world"
|
30
63
|
end
|
31
64
|
|
32
65
|
end
|
33
66
|
|
34
67
|
describe "#link" do
|
35
68
|
|
36
|
-
|
37
|
-
|
69
|
+
describe "with default, which is no link, thus uses autogeneration" do
|
70
|
+
|
71
|
+
it "return default link, which is the Markdown formatting of the text and anchor" do
|
72
|
+
expect(headline.link).must_equal link_default
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
describe "with custom link" do
|
78
|
+
|
79
|
+
it "return custom link" do
|
80
|
+
headline = SixArm::Markdown::Headline.new(text: text, link: link_custom)
|
81
|
+
expect(headline.link).must_equal link_custom
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
describe ".parse_line" do
|
89
|
+
|
90
|
+
it "parse a headline that starts with hash characters" do
|
91
|
+
line = "### Hello"
|
92
|
+
headline = SixArm::Markdown::Headline::parse_line(line)
|
93
|
+
expect(headline.text).must_equal "Hello"
|
94
|
+
expect(headline.level).must_equal 3
|
95
|
+
end
|
96
|
+
|
97
|
+
it "parse a headline that starts with equal characters" do
|
98
|
+
line = "=== Hello"
|
99
|
+
headline = SixArm::Markdown::Headline::parse_line(line)
|
100
|
+
expect(headline.text).must_equal "Hello"
|
101
|
+
expect(headline.level).must_equal 3
|
102
|
+
end
|
103
|
+
|
104
|
+
it "trim extraneous characters i.e. leading/trailing whitespace and leading/trailing hashes" do
|
105
|
+
line = " ### Hello ### \n"
|
106
|
+
headline = SixArm::Markdown::Headline::parse_line(line)
|
107
|
+
expect(headline.text).must_equal "Hello"
|
108
|
+
expect(headline.level).must_equal 3
|
109
|
+
end
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
describe ".parse_line_level" do
|
114
|
+
|
115
|
+
it "return level" do
|
116
|
+
line = "### Hello"
|
117
|
+
expect = 3
|
118
|
+
actual = SixArm::Markdown::Headline::parse_line_level(line)
|
119
|
+
expect(actual).must_equal expect
|
120
|
+
end
|
121
|
+
|
122
|
+
end
|
123
|
+
|
124
|
+
describe ".trim_line" do
|
125
|
+
|
126
|
+
it "trim extraneous characters i.e. leading/trailing spaces and leading/trailing hashes" do
|
127
|
+
line = " ### Hello ### "
|
128
|
+
expect = "Hello"
|
129
|
+
actual = SixArm::Markdown::Headline::trim_line(line)
|
130
|
+
expect(actual).must_equal actual
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
134
|
+
|
135
|
+
describe ".text_to_anchor" do
|
136
|
+
|
137
|
+
it "return anchor, which is the text as lowercase, and replacing every run of non-word characters with a dash" do
|
138
|
+
text = "Foo ! Goo ! Hoo"
|
139
|
+
expect = "foo-goo-hoo"
|
140
|
+
actual = SixArm::Markdown::Headline::text_to_anchor(text)
|
141
|
+
expect(actual).must_equal expect
|
38
142
|
end
|
39
143
|
|
40
144
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sixarm_ruby_markdown
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- SixArm
|
@@ -39,8 +39,28 @@ cert_chain:
|
|
39
39
|
tzpk/VnZXj7Ek/earx+N/Z+Wtnl2xENm5IF8SFPeI1HFa9NH47pqtxF1YKpNIEVc
|
40
40
|
2xa2BNHSePe7tys/2hbmZuyMu8X5ERmovsabSXB3a+YwtJh5c2jhA21wF7986s0q
|
41
41
|
-----END CERTIFICATE-----
|
42
|
-
date: 2018-02-
|
42
|
+
date: 2018-02-16 00:00:00.000000000 Z
|
43
43
|
dependencies:
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: sixarm_ruby_equal_instance_variables
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1'
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '1'
|
61
|
+
- - "<"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '2'
|
44
64
|
- !ruby/object:Gem::Dependency
|
45
65
|
name: sixarm_ruby_file_rewrite
|
46
66
|
requirement: !ruby/object:Gem::Requirement
|
@@ -183,6 +203,7 @@ licenses:
|
|
183
203
|
- BSD-3-Clause
|
184
204
|
- CC-BY-NC-SA-4.0
|
185
205
|
- AGPL-3.0
|
206
|
+
- EPL-1.0
|
186
207
|
- GPL-2.0
|
187
208
|
- GPL-3.0
|
188
209
|
- LGPL-3.0
|
metadata.gz.sig
CHANGED
Binary file
|