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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9ba8590ac0d2bd4b5794190e2c570d45a239ca642f490ef81b20fc5b2f205de6
4
- data.tar.gz: aaf32b72afcfec851c5eb51870207c897dc896e2aef3428e24caa33764d80767
3
+ metadata.gz: af9a2722358657600dc9b1f3ef85dc514c107e2db3a2bb181c8ab72c5f402fe6
4
+ data.tar.gz: 91b2d23b0ceb68cff8547b08013c36c9e1babbe30e72ee37af3d2a54e913b54c
5
5
  SHA512:
6
- metadata.gz: 3fcf8f64f0571e4d4818575944bc407e659f2b138a0bd11dea38fb4bd9e9b1115f62e1c9aede2b1c13928691d56162dc3d8272deb1281d4273d02d094fc9b34b
7
- data.tar.gz: 0b4de1f52e4bfabe4c4a9b8dba29b95caa4c16b8c0056833b483b3864084ec0c35320a63eabd158f9e18da12dd0f94d9b717ac6fc16a914a92da4b0e96fdd7b4
6
+ metadata.gz: '08c993859e8ca51116cb0e1d39821e7b19adaa637972a32b951083ef9d301b82318236cd2cf6c11b534865c8890646589479ebf8a49b6742c65d1b506aa9dbd9'
7
+ data.tar.gz: 6efc020cfea100b66bfc95df589ed9c0246f189f370c12484256dc31e03025ffb770cb19757fb86c1214ca0367c7a8b7db4f0a8722de1baeefaaf50a1ec99c15
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -4,6 +4,7 @@ Please see README
4
4
  =end
5
5
 
6
6
  require "ostruct"
7
+ require "sixarm_ruby_equal_instance_variables"
7
8
  require "sixarm_ruby_file_rewrite"
8
9
 
9
10
  require_relative "sixarm_ruby_markdown/sixarm/markdown/headline"
@@ -4,13 +4,57 @@
4
4
 
5
5
  module SixArm; module Markdown; end; end
6
6
 
7
- class SixArm::Markdown::Headline < OpenStruct
7
+ class SixArm::Markdown::Headline
8
+ include EqualInstanceVariables
8
9
 
9
- def link
10
- "[#{text}](##{anchor})"
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(:level){ 3 }
7
- let(:text){ "Hello World" }
8
- let(:headline){ SixArm::Markdown::Headline.new(level: level, text: text) }
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 "#level" do
15
+ describe "#text" do
11
16
 
12
- it "return level" do
13
- expect(headline.level).must_equal level
17
+ it "return text" do
18
+ expect(headline.text).must_equal text
14
19
  end
15
20
 
16
21
  end
17
22
 
18
- describe "#text" do
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 "#anchor" do
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
- it "return link, which is the Markdown formatting of the text and anchor" do
37
- expect(headline.link).must_equal "[Hello World](#hello-world)"
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.0.0
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-11 00:00:00.000000000 Z
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