md_to_bbcode 1.0.1 → 1.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 +4 -4
- data/lib/md_to_bbcode.rb +18 -1
- data/lib/md_to_bbcode/version.rb +1 -1
- data/spec/api_spec.rb +57 -26
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b852d6b172b3fb90659c9b2d73d0c439015e2f7eaae67bbe4b4dd054b3294d28
|
4
|
+
data.tar.gz: 2b1604824090ba1b3e2f9e3d8dc3ca33114ba3dd009ef93ac60f7b9bd21d54d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d4551e53bace327117ba494f0f08ca6ce79713b703e94a5c055a8e78d1074e7087ac9d29b6ebc5717b9481a600e6f55101a5d165aa8cc5372907c4155a0a7a6e
|
7
|
+
data.tar.gz: c9d7804233ecdd7760026aeafaed92d19e0ff8200e2a892941827ce75ec892797dbcaa8bff7b2960be82c856d5dea04b6cf7b07682885bc1658caa847581df8c
|
data/lib/md_to_bbcode.rb
CHANGED
@@ -13,6 +13,7 @@ module MdToBbcode
|
|
13
13
|
in_a_list = false
|
14
14
|
in_a_code_block = false
|
15
15
|
in_bold_text = false
|
16
|
+
in_italic_text = false
|
16
17
|
markdown.split("\n").each do |line|
|
17
18
|
unindented_line = in_a_list && line =~ /^ (.*)$/ ? $1 : line
|
18
19
|
if unindented_line =~ /^```(.*)$/
|
@@ -33,7 +34,7 @@ module MdToBbcode
|
|
33
34
|
line.gsub!(/!\[(.*?)\]\((.*?)\)/, '[img]\2[/img]')
|
34
35
|
# Links
|
35
36
|
line.gsub!(/\[(.*?)\]\((.*?)\)/, '[url=\2]\1[/url]')
|
36
|
-
# Bold
|
37
|
+
# Bold (do this before italic)
|
37
38
|
if in_bold_text
|
38
39
|
line.gsub!(/\*\*(.*?)\*\*/, '[/b]\1[b]')
|
39
40
|
else
|
@@ -48,6 +49,21 @@ module MdToBbcode
|
|
48
49
|
in_bold_text = true
|
49
50
|
end
|
50
51
|
end
|
52
|
+
# Italic
|
53
|
+
if in_italic_text
|
54
|
+
line.gsub!(/\*(\S.*?)\*/, '[/i]\1[i]')
|
55
|
+
else
|
56
|
+
line.gsub!(/\*(\S.*?)\*/, '[i]\1[/i]')
|
57
|
+
end
|
58
|
+
if line =~ /.*\*.*/
|
59
|
+
if in_italic_text
|
60
|
+
line.gsub!(/(.*\S)\*(.*)/, '\1[/i]\2')
|
61
|
+
in_italic_text = false
|
62
|
+
else
|
63
|
+
line.gsub!(/(.*)\*(\S.*)/, '\1[i]\2')
|
64
|
+
in_italic_text = true
|
65
|
+
end
|
66
|
+
end
|
51
67
|
# Heading 1
|
52
68
|
line.gsub!(/^# (.*?)$/, '[size=6][b]\1[/b][/size]')
|
53
69
|
# Heading 2
|
@@ -58,6 +74,7 @@ module MdToBbcode
|
|
58
74
|
line.gsub!(/^#### (.*?)$/, '[size=5]\1[/size]')
|
59
75
|
# In-line code
|
60
76
|
line.gsub!(/`(.*?)`/, '[b][font=Courier New]\1[/font][/b]')
|
77
|
+
# Bullets
|
61
78
|
if line =~ /^\* (.+)$/
|
62
79
|
# Single bullet line
|
63
80
|
bbcode_lines << "[list]\n" unless in_a_list
|
data/lib/md_to_bbcode/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -20,6 +20,14 @@ describe MdToBbcode do
|
|
20
20
|
expect('**Bold text**'.md_to_bbcode).to eq '[b]Bold text[/b]'
|
21
21
|
end
|
22
22
|
|
23
|
+
it 'converts italic text' do
|
24
|
+
expect('*Italic text*'.md_to_bbcode).to eq '[i]Italic text[/i]'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'converts italic and bold mixed text' do
|
28
|
+
expect('*Italic and **bold** text* and then **bold and *italic* text**'.md_to_bbcode).to eq '[i]Italic and [b]bold[/b] text[/i] and then [b]bold and [i]italic[/i] text[/b]'
|
29
|
+
end
|
30
|
+
|
23
31
|
it 'converts links' do
|
24
32
|
expect('[Link text](https://my.domain.com/path)'.md_to_bbcode).to eq '[url=https://my.domain.com/path]Link text[/url]'
|
25
33
|
end
|
@@ -34,37 +42,60 @@ describe MdToBbcode do
|
|
34
42
|
|
35
43
|
it 'converts bold text on several lines' do
|
36
44
|
md = <<~EOS
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
45
|
+
**Bold
|
46
|
+
text
|
47
|
+
on
|
48
|
+
multi-line**
|
41
49
|
EOS
|
42
50
|
expect(md.md_to_bbcode).to eq(<<~EOS)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
51
|
+
[b]Bold
|
52
|
+
text
|
53
|
+
on
|
54
|
+
multi-line[/b]
|
47
55
|
EOS
|
48
56
|
end
|
49
57
|
|
50
58
|
it 'converts bold text on several lines mixed with single lines' do
|
51
59
|
md = <<~EOS
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
60
|
+
**Bold text** on **single and
|
61
|
+
on
|
62
|
+
multi-line** but **with** some **new
|
63
|
+
text
|
64
|
+
on** other **lines**
|
65
|
+
all
|
66
|
+
**mixed** up
|
67
|
+
EOS
|
68
|
+
expect(md.md_to_bbcode).to eq(<<~EOS)
|
69
|
+
[b]Bold text[/b] on [b]single and
|
70
|
+
on
|
71
|
+
multi-line[/b] but [b]with[/b] some [b]new
|
72
|
+
text
|
73
|
+
on[/b] other [b]lines[/b]
|
74
|
+
all
|
75
|
+
[b]mixed[/b] up
|
76
|
+
EOS
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'converts bold and italic texts on several lines mixed with single lines' do
|
80
|
+
md = <<~EOS
|
81
|
+
**Bold text** on **single and
|
82
|
+
*on italic
|
83
|
+
words* on
|
84
|
+
multi-line** but **with** some **new
|
85
|
+
text
|
86
|
+
on** other **lines**
|
87
|
+
all *italic **and bold**
|
88
|
+
**mixed*** up
|
59
89
|
EOS
|
60
90
|
expect(md.md_to_bbcode).to eq(<<~EOS)
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
91
|
+
[b]Bold text[/b] on [b]single and
|
92
|
+
[i]on italic
|
93
|
+
words[/i] on
|
94
|
+
multi-line[/b] but [b]with[/b] some [b]new
|
95
|
+
text
|
96
|
+
on[/b] other [b]lines[/b]
|
97
|
+
all [i]italic [b]and bold[/b]
|
98
|
+
[b]mixed[/b][/i] up
|
68
99
|
EOS
|
69
100
|
end
|
70
101
|
|
@@ -235,7 +266,7 @@ describe MdToBbcode do
|
|
235
266
|
followed
|
236
267
|
by** not bold on multi-lines.
|
237
268
|
|
238
|
-
**Bold text including
|
269
|
+
**Bold text including an italic *[link to Google](https://www.google.com)*.**
|
239
270
|
|
240
271
|
This is a bullet list:
|
241
272
|
* Bullet item 1
|
@@ -270,7 +301,7 @@ describe MdToBbcode do
|
|
270
301
|
|
271
302
|
Here is some Ruby:
|
272
303
|
```ruby
|
273
|
-
puts 'Hello'
|
304
|
+
puts 'Hello' * 3 * 5
|
274
305
|
# World
|
275
306
|
puts `echo World`
|
276
307
|
```
|
@@ -305,7 +336,7 @@ describe MdToBbcode do
|
|
305
336
|
followed
|
306
337
|
by[/b] not bold on multi-lines.
|
307
338
|
|
308
|
-
[b]Bold text including
|
339
|
+
[b]Bold text including an italic [i][url=https://www.google.com]link to Google[/url][/i].[/b]
|
309
340
|
|
310
341
|
This is a bullet list:
|
311
342
|
[list]
|
@@ -342,7 +373,7 @@ describe MdToBbcode do
|
|
342
373
|
[/list]
|
343
374
|
|
344
375
|
Here is some Ruby:
|
345
|
-
[code]puts 'Hello'
|
376
|
+
[code]puts 'Hello' * 3 * 5
|
346
377
|
# World
|
347
378
|
puts `echo World`
|
348
379
|
[/code]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md_to_bbcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Muriel Salvan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|