md_to_bbcode 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/md_to_bbcode.rb +13 -93
- data/lib/md_to_bbcode/bbcode_renderer.rb +127 -0
- data/lib/md_to_bbcode/core_extensions/string/md_to_bbcode.rb +0 -0
- data/lib/md_to_bbcode/version.rb +1 -1
- data/spec/api_spec.rb +170 -37
- data/spec/md_to_bbcode_test.rb +0 -0
- data/spec/spec_helper.rb +0 -0
- metadata +32 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e80378d305456770e761ee303fc155f8a645d4532d70381892d88e05e41d4202
|
4
|
+
data.tar.gz: 53c6a99ebd4dedfcb73888c000c8ec78a92eec96f023379b3272af699889bf70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 348e73481b0f2e4f628c9ac5036748d0cdb0d04ada03749da007bf63dcb1df227516dfab72401a36bea5b0d12d1f58de1269ffe61d6090aabd5b6615f6e58e55
|
7
|
+
data.tar.gz: c56f09407124239d60cde3731e90030c3dd98672f0090f1b6dc08b21b2c220551a7501fb2734092bf4f6510949b5110b90f185bc9c0fbd2fcdddd5c7328cd734
|
data/lib/md_to_bbcode.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
require 'md_to_bbcode/bbcode_renderer'
|
1
3
|
require 'md_to_bbcode/core_extensions/string/md_to_bbcode'
|
2
4
|
|
3
5
|
module MdToBbcode
|
@@ -9,100 +11,18 @@ module MdToBbcode
|
|
9
11
|
# Result::
|
10
12
|
# * String: BBCode converted string
|
11
13
|
def self.md_to_bbcode(markdown)
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
markdown.
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
in_a_code_block = false
|
24
|
-
else
|
25
|
-
# We enter a code block
|
26
|
-
bbcode_lines << "#{in_a_list ? ' ' : ''}[code]"
|
27
|
-
in_a_code_block = true
|
28
|
-
end
|
29
|
-
elsif in_a_code_block
|
30
|
-
# Don't change anything at the formatting
|
31
|
-
bbcode_lines << "#{line}\n"
|
32
|
-
else
|
33
|
-
# Handle in-line code markers first
|
34
|
-
line = line.split(/(`.+?`)/).map do |field|
|
35
|
-
if field[0] == '`'
|
36
|
-
# Don't change anything at the formatting
|
37
|
-
"#{in_bold_text ? '' : '[b]'}[font=Courier New]#{field[1..-2]}[/font]#{in_bold_text ? '' : '[/b]'}"
|
38
|
-
else
|
39
|
-
# Apply the formatting except the formatting used for whole lines (headers, bullets, lists...)
|
40
|
-
# Images (do this gsub before links and any single tags, like bold, headings...)
|
41
|
-
field.gsub!(/!\[(.*?)\]\((.*?)\)/, '[img]\2[/img]')
|
42
|
-
# Links
|
43
|
-
field.gsub!(/\[(.*?)\]\((.*?)\)/, '[url=\2]\1[/url]')
|
44
|
-
# Bold (do this before italic)
|
45
|
-
if in_bold_text
|
46
|
-
field.gsub!(/\*\*(.*?)\*\*/, '[/b]\1[b]')
|
47
|
-
else
|
48
|
-
field.gsub!(/\*\*(.*?)\*\*/, '[b]\1[/b]')
|
49
|
-
end
|
50
|
-
if field =~ /.*\*\*.*/
|
51
|
-
if in_bold_text
|
52
|
-
field.gsub!(/(.*)\*\*(.*)/, '\1[/b]\2')
|
53
|
-
in_bold_text = false
|
54
|
-
else
|
55
|
-
field.gsub!(/(.*)\*\*(.*)/, '\1[b]\2')
|
56
|
-
in_bold_text = true
|
57
|
-
end
|
58
|
-
end
|
59
|
-
# Italic
|
60
|
-
if in_italic_text
|
61
|
-
field.gsub!(/\*(\S.*?)\*/, '[/i]\1[i]')
|
62
|
-
else
|
63
|
-
field.gsub!(/\*(\S.*?)\*/, '[i]\1[/i]')
|
64
|
-
end
|
65
|
-
if in_italic_text && field =~ /.*\S\*.*/
|
66
|
-
field.gsub!(/(.*\S)\*(.*)/, '\1[/i]\2')
|
67
|
-
in_italic_text = false
|
68
|
-
elsif !in_italic_text && field =~ /.*\*\S.*/
|
69
|
-
field.gsub!(/(.*)\*(\S.*)/, '\1[i]\2')
|
70
|
-
in_italic_text = true
|
71
|
-
end
|
72
|
-
field
|
73
|
-
end
|
74
|
-
end.join
|
75
|
-
# Heading 1
|
76
|
-
line.gsub!(/^# (.*?)$/, '[size=6][b]\1[/b][/size]')
|
77
|
-
# Heading 2
|
78
|
-
line.gsub!(/^## (.*?)$/, '[size=6]\1[/size]')
|
79
|
-
# Heading 3
|
80
|
-
line.gsub!(/^### (.*?)$/, '[size=5][b]\1[/b][/size]')
|
81
|
-
# Heading 4
|
82
|
-
line.gsub!(/^#### (.*?)$/, '[size=5]\1[/size]')
|
83
|
-
# Bullets
|
84
|
-
if line =~ /^\* (.+)$/
|
85
|
-
# Single bullet line
|
86
|
-
bbcode_lines << "[list]\n" unless in_a_list
|
87
|
-
bbcode_lines << "[*]#{$1}\n"
|
88
|
-
in_a_list = true
|
89
|
-
elsif line =~ /^\d\. (.+)$/
|
90
|
-
# Single numbered line
|
91
|
-
bbcode_lines << "[list=1]\n" unless in_a_list
|
92
|
-
bbcode_lines << "[*]#{$1}\n"
|
93
|
-
in_a_list = true
|
94
|
-
else
|
95
|
-
if in_a_list && !(line =~ /^ (.*)$/)
|
96
|
-
bbcode_lines << "[/list]\n"
|
97
|
-
in_a_list = false
|
98
|
-
end
|
99
|
-
bbcode_lines << "#{line}\n"
|
100
|
-
end
|
101
|
-
end
|
14
|
+
bbcode = Redcarpet::Markdown.new(
|
15
|
+
BbcodeRenderer,
|
16
|
+
fenced_code_blocks: true,
|
17
|
+
lax_spacing: false
|
18
|
+
).render(markdown)
|
19
|
+
if markdown.end_with?("\n")
|
20
|
+
# Sometimes redcarpet removes new lines (after lists), so add them back if needed
|
21
|
+
bbcode.end_with?("\n") ? bbcode : "#{bbcode}\n"
|
22
|
+
else
|
23
|
+
# Sometimes redcarpet adds new lines (after bold markers), so strip them if needed
|
24
|
+
bbcode.end_with?("\n") ? bbcode.strip : bbcode
|
102
25
|
end
|
103
|
-
bbcode_lines << "[/list]\n" if in_a_list
|
104
|
-
bbcode = bbcode_lines.join
|
105
|
-
markdown.end_with?("\n") ? bbcode : bbcode[0..-2]
|
106
26
|
end
|
107
27
|
|
108
28
|
end
|
@@ -0,0 +1,127 @@
|
|
1
|
+
require 'redcarpet/render_strip'
|
2
|
+
|
3
|
+
module MdToBbcode
|
4
|
+
|
5
|
+
class BbcodeRenderer < Redcarpet::Render::StripDown
|
6
|
+
|
7
|
+
MARKER_BOLD = '--MdToBbcode--Bold--'
|
8
|
+
MARKER_ITALIC = '--MdToBbcode--Italic--'
|
9
|
+
|
10
|
+
def preprocess(doc)
|
11
|
+
# Due to Redcarpet bug https://github.com/vmg/redcarpet/issues/396 we have to handle bold and italic conversions before hand
|
12
|
+
# Be careful to mark them uniquely so that we don't convert them if they were in a code block
|
13
|
+
# TODO: Remove this when Redcarpet bug will be fixed
|
14
|
+
doc.
|
15
|
+
gsub('**', MARKER_BOLD).
|
16
|
+
gsub(/\*(\S|$)/, "#{MARKER_ITALIC}\\1").
|
17
|
+
gsub(/(\S)\*/, "\\1#{MARKER_ITALIC}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def postprocess(doc)
|
21
|
+
# Convert bold and italic correctly due to bug https://github.com/vmg/redcarpet/issues/396
|
22
|
+
bbcode_lines = []
|
23
|
+
in_bold_text = false
|
24
|
+
in_italic_text = false
|
25
|
+
# Due to Redcarpet bug https://github.com/vmg/redcarpet/issues/600 we have to change some in-line code to blocks
|
26
|
+
# TODO: Remove when Redcarpet will be fixed
|
27
|
+
doc.split("\n").map do |line|
|
28
|
+
case line
|
29
|
+
when /^(\s*)\[b\]\[font=Courier New\]([^\[]*)$/
|
30
|
+
"#{$1}[code]"
|
31
|
+
when /^(\s*)\[\/font\]\[\/b\]$/
|
32
|
+
"#{$1}[/code]"
|
33
|
+
else
|
34
|
+
# Replace the bold markers with [b] or [/b], and
|
35
|
+
# make sure we remove occurences of bold text ([b] and [/b] already part of the text) when bold is already applied: this can happen as we use bold text for inline code
|
36
|
+
# TODO: Remove this when https://github.com/vmg/redcarpet/issues/396 will be corrected
|
37
|
+
fields = line.split(MARKER_BOLD) + (line.end_with?(MARKER_BOLD) ? [''] : [])
|
38
|
+
line = fields.map.with_index do |field, idx|
|
39
|
+
content = in_bold_text ? field.gsub('[b]', '').gsub('[/b]', '') : field
|
40
|
+
if idx == fields.size - 1
|
41
|
+
content
|
42
|
+
else
|
43
|
+
in_bold_text = !in_bold_text
|
44
|
+
"#{content}[#{in_bold_text ? '' : '/'}b]"
|
45
|
+
end
|
46
|
+
end.join
|
47
|
+
# Italic
|
48
|
+
if in_italic_text
|
49
|
+
line.gsub!(/#{Regexp.escape(MARKER_ITALIC)}(\S.*?)#{Regexp.escape(MARKER_ITALIC)}/, '[/i]\1[i]')
|
50
|
+
else
|
51
|
+
line.gsub!(/#{Regexp.escape(MARKER_ITALIC)}(\S.*?)#{Regexp.escape(MARKER_ITALIC)}/, '[i]\1[/i]')
|
52
|
+
end
|
53
|
+
if in_italic_text && line =~ /.*\S#{Regexp.escape(MARKER_ITALIC)}.*/
|
54
|
+
line.gsub!(/(.*\S)#{Regexp.escape(MARKER_ITALIC)}(.*)/, '\1[/i]\2')
|
55
|
+
in_italic_text = false
|
56
|
+
elsif !in_italic_text && line =~ /.*#{Regexp.escape(MARKER_ITALIC)}\S.*/
|
57
|
+
line.gsub!(/(.*)#{Regexp.escape(MARKER_ITALIC)}(\S.*)/, '\1[i]\2')
|
58
|
+
in_italic_text = true
|
59
|
+
end
|
60
|
+
line
|
61
|
+
end
|
62
|
+
end.join("\n").gsub('<br>', "\n")
|
63
|
+
end
|
64
|
+
|
65
|
+
def emphasis(text)
|
66
|
+
"[i]#{text}[/i]"
|
67
|
+
end
|
68
|
+
|
69
|
+
def double_emphasis(text)
|
70
|
+
# In case the text already contains bold tags (which can be the case as codespan uses them), remove them.
|
71
|
+
"[b]#{text.gsub('[b]', '').gsub('[/b]', '')}[/b]"
|
72
|
+
end
|
73
|
+
|
74
|
+
def link(link, title, content)
|
75
|
+
"[url=#{link}]#{content}[/url]"
|
76
|
+
end
|
77
|
+
|
78
|
+
def header(text, header_level)
|
79
|
+
case header_level
|
80
|
+
when 1
|
81
|
+
"\n[size=6][b]#{text}[/b][/size]\n\n"
|
82
|
+
when 2
|
83
|
+
"\n[size=6]#{text}[/size]\n\n"
|
84
|
+
when 3
|
85
|
+
"\n[size=5][b]#{text}[/b][/size]\n\n"
|
86
|
+
when 4
|
87
|
+
"\n[size=5]#{text}[/size]\n\n"
|
88
|
+
else
|
89
|
+
"\n[size=4][b]#{text}[/b][/size]\n\n"
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def codespan(code)
|
94
|
+
"[b][font=Courier New]#{code.
|
95
|
+
gsub(MARKER_BOLD, '**').
|
96
|
+
gsub(MARKER_ITALIC, '*')
|
97
|
+
}[/font][/b]"
|
98
|
+
end
|
99
|
+
|
100
|
+
def image(link, title, alt_text)
|
101
|
+
"[img]#{link}[/img]"
|
102
|
+
end
|
103
|
+
|
104
|
+
def list(contents, list_type)
|
105
|
+
case list_type
|
106
|
+
when :ordered
|
107
|
+
"[list=1]\n#{contents}[/list]\n"
|
108
|
+
else
|
109
|
+
"[list]\n#{contents}[/list]\n"
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def list_item(text, list_type)
|
114
|
+
# If the item spans multiple lines, prefix each new line with 2 spaces to keep the list running.
|
115
|
+
"[*]#{text.split(/(?<=\n)/).join(" ")}"
|
116
|
+
end
|
117
|
+
|
118
|
+
def block_code(code, language)
|
119
|
+
"[code]#{code.
|
120
|
+
gsub(MARKER_BOLD, '**').
|
121
|
+
gsub(MARKER_ITALIC, '*')
|
122
|
+
}[/code]\n"
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
end
|
File without changes
|
data/lib/md_to_bbcode/version.rb
CHANGED
data/spec/api_spec.rb
CHANGED
@@ -1,19 +1,47 @@
|
|
1
1
|
describe MdToBbcode do
|
2
2
|
|
3
|
+
it 'converts and keeps new lines' do
|
4
|
+
md = <<~EOS
|
5
|
+
Line 1
|
6
|
+
|
7
|
+
Line 2<br>
|
8
|
+
Line 3<br><br>
|
9
|
+
Line 4<br>
|
10
|
+
|
11
|
+
|
12
|
+
Line 5
|
13
|
+
|
14
|
+
|
15
|
+
Line 6
|
16
|
+
EOS
|
17
|
+
expect(md.md_to_bbcode).to eq(<<~EOS)
|
18
|
+
Line 1
|
19
|
+
Line 2
|
20
|
+
|
21
|
+
Line 3
|
22
|
+
|
23
|
+
|
24
|
+
Line 4
|
25
|
+
|
26
|
+
Line 5
|
27
|
+
Line 6
|
28
|
+
EOS
|
29
|
+
end
|
30
|
+
|
3
31
|
it 'converts heading 1' do
|
4
|
-
expect('# Heading 1'.md_to_bbcode).to eq
|
32
|
+
expect('# Heading 1'.md_to_bbcode).to eq "\n[size=6][b]Heading 1[/b][/size]"
|
5
33
|
end
|
6
34
|
|
7
35
|
it 'converts heading 2' do
|
8
|
-
expect('## Heading 2'.md_to_bbcode).to eq
|
36
|
+
expect('## Heading 2'.md_to_bbcode).to eq "\n[size=6]Heading 2[/size]"
|
9
37
|
end
|
10
38
|
|
11
39
|
it 'converts heading 3' do
|
12
|
-
expect('### Heading 3'.md_to_bbcode).to eq
|
40
|
+
expect('### Heading 3'.md_to_bbcode).to eq "\n[size=5][b]Heading 3[/b][/size]"
|
13
41
|
end
|
14
42
|
|
15
43
|
it 'converts heading 4' do
|
16
|
-
expect('#### Heading 4'.md_to_bbcode).to eq
|
44
|
+
expect('#### Heading 4'.md_to_bbcode).to eq "\n[size=5]Heading 4[/size]"
|
17
45
|
end
|
18
46
|
|
19
47
|
it 'converts bold text' do
|
@@ -24,6 +52,10 @@ describe MdToBbcode do
|
|
24
52
|
expect('*Italic text*'.md_to_bbcode).to eq '[i]Italic text[/i]'
|
25
53
|
end
|
26
54
|
|
55
|
+
it 'converts italic text with underscore' do
|
56
|
+
expect('_Italic text_'.md_to_bbcode).to eq '[i]Italic text[/i]'
|
57
|
+
end
|
58
|
+
|
27
59
|
it 'converts italic text after a list' do
|
28
60
|
md = <<~EOS
|
29
61
|
* List item
|
@@ -32,8 +64,8 @@ describe MdToBbcode do
|
|
32
64
|
expect(md.md_to_bbcode).to eq(<<~EOS)
|
33
65
|
[list]
|
34
66
|
[*]List item
|
67
|
+
[i]Italic text[/i]
|
35
68
|
[/list]
|
36
|
-
[i]Italic text[/i]
|
37
69
|
EOS
|
38
70
|
end
|
39
71
|
|
@@ -53,6 +85,19 @@ describe MdToBbcode do
|
|
53
85
|
expect('**Bold `in-line code` to display**'.md_to_bbcode).to eq '[b]Bold [font=Courier New]in-line code[/font] to display[/b]'
|
54
86
|
end
|
55
87
|
|
88
|
+
it 'converts inline code in multi-line bold text' do
|
89
|
+
md = <<~EOS
|
90
|
+
`Before in-line` followed by **bold with `some in-line` and
|
91
|
+
containing a multi-line `in-line code`
|
92
|
+
to display along with `in-line code` again** and `after as-well`.
|
93
|
+
EOS
|
94
|
+
expect(md.md_to_bbcode).to eq(<<~EOS)
|
95
|
+
[b][font=Courier New]Before in-line[/font][/b] followed by [b]bold with [font=Courier New]some in-line[/font] and
|
96
|
+
containing a multi-line [font=Courier New]in-line code[/font]
|
97
|
+
to display along with [font=Courier New]in-line code[/font] again[/b] and [b][font=Courier New]after as-well[/font][/b].
|
98
|
+
EOS
|
99
|
+
end
|
100
|
+
|
56
101
|
it 'converts inline code in italic text' do
|
57
102
|
expect('*Italic `in-line code` to display*'.md_to_bbcode).to eq '[i]Italic [b][font=Courier New]in-line code[/font][/b] to display[/i]'
|
58
103
|
end
|
@@ -87,6 +132,14 @@ describe MdToBbcode do
|
|
87
132
|
EOS
|
88
133
|
end
|
89
134
|
|
135
|
+
it 'converts bold text in links' do
|
136
|
+
expect("This is [a link with **bold** text](http://my.domain.com/path)".md_to_bbcode).to eq 'This is [url=http://my.domain.com/path]a link with [b]bold[/b] text[/url]'
|
137
|
+
end
|
138
|
+
|
139
|
+
it 'converts inline code in links' do
|
140
|
+
expect('This is [a link with `inline` code](http://my.domain.com/path)'.md_to_bbcode).to eq 'This is [url=http://my.domain.com/path]a link with [b][font=Courier New]inline[/font][/b] code[/url]'
|
141
|
+
end
|
142
|
+
|
90
143
|
it 'does not convert other formatting in inline code' do
|
91
144
|
expect('`# in-line *code* that is **not formatted**`'.md_to_bbcode).to eq '[b][font=Courier New]# in-line *code* that is **not formatted**[/font][/b]'
|
92
145
|
end
|
@@ -169,6 +222,35 @@ describe MdToBbcode do
|
|
169
222
|
EOS
|
170
223
|
end
|
171
224
|
|
225
|
+
it 'converts different numbered lists separated with a blank line' do
|
226
|
+
md = <<~EOS
|
227
|
+
1. List item 11
|
228
|
+
2. List item 12
|
229
|
+
3. List item 13
|
230
|
+
In list item
|
231
|
+
|
232
|
+
Not list
|
233
|
+
|
234
|
+
1. List item 21
|
235
|
+
2. List item 22
|
236
|
+
3. List item 23
|
237
|
+
EOS
|
238
|
+
expect(md.md_to_bbcode).to eq(<<~EOS)
|
239
|
+
[list=1]
|
240
|
+
[*]List item 11
|
241
|
+
[*]List item 12
|
242
|
+
[*]List item 13
|
243
|
+
In list item
|
244
|
+
[/list]
|
245
|
+
Not list
|
246
|
+
[list=1]
|
247
|
+
[*]List item 21
|
248
|
+
[*]List item 22
|
249
|
+
[*]List item 23
|
250
|
+
[/list]
|
251
|
+
EOS
|
252
|
+
end
|
253
|
+
|
172
254
|
it 'converts numbered list' do
|
173
255
|
md = <<~EOS
|
174
256
|
1. List item 1
|
@@ -184,25 +266,77 @@ describe MdToBbcode do
|
|
184
266
|
EOS
|
185
267
|
end
|
186
268
|
|
187
|
-
it 'converts multi-line numbered list' do
|
269
|
+
it 'converts multi-line numbered list without indent' do
|
188
270
|
md = <<~EOS
|
189
271
|
1. List item 1
|
272
|
+
And another line 1
|
273
|
+
Again 1
|
274
|
+
2. List item 2
|
275
|
+
And another line 2
|
276
|
+
Again 2
|
277
|
+
3. List item 3
|
278
|
+
And another line 3
|
279
|
+
Again 3
|
280
|
+
EOS
|
281
|
+
expect(md.md_to_bbcode).to eq(<<~EOS)
|
282
|
+
[list=1]
|
283
|
+
[*]List item 1
|
190
284
|
And another line 1
|
191
|
-
|
285
|
+
Again 1
|
286
|
+
[*]List item 2
|
287
|
+
And another line 2
|
288
|
+
Again 2
|
289
|
+
[*]List item 3
|
290
|
+
And another line 3
|
291
|
+
Again 3
|
292
|
+
[/list]
|
293
|
+
EOS
|
294
|
+
end
|
295
|
+
|
296
|
+
it 'converts multi-line numbered list with indent' do
|
297
|
+
md = <<~EOS
|
298
|
+
1. List item 1
|
299
|
+
And another line 1
|
300
|
+
Again 1
|
192
301
|
2. List item 2
|
193
302
|
And another line 2
|
194
|
-
|
303
|
+
Again 2
|
195
304
|
3. List item 3
|
196
305
|
And another line 3
|
306
|
+
Again 3
|
197
307
|
EOS
|
198
308
|
expect(md.md_to_bbcode).to eq(<<~EOS)
|
199
309
|
[list=1]
|
200
310
|
[*]List item 1
|
201
311
|
And another line 1
|
202
|
-
|
312
|
+
Again 1
|
203
313
|
[*]List item 2
|
204
314
|
And another line 2
|
205
|
-
|
315
|
+
Again 2
|
316
|
+
[*]List item 3
|
317
|
+
And another line 3
|
318
|
+
Again 3
|
319
|
+
[/list]
|
320
|
+
EOS
|
321
|
+
end
|
322
|
+
|
323
|
+
it 'converts multi-line numbered list with empty lines' do
|
324
|
+
md = <<~EOS
|
325
|
+
1. List item 1
|
326
|
+
And another line 1<br>
|
327
|
+
2. List item 2
|
328
|
+
And another line 2<br>
|
329
|
+
3. List item 3
|
330
|
+
And another line 3
|
331
|
+
EOS
|
332
|
+
expect(md.md_to_bbcode).to eq(<<~EOS)
|
333
|
+
[list=1]
|
334
|
+
[*]List item 1
|
335
|
+
And another line 1
|
336
|
+
|
337
|
+
[*]List item 2
|
338
|
+
And another line 2
|
339
|
+
|
206
340
|
[*]List item 3
|
207
341
|
And another line 3
|
208
342
|
[/list]
|
@@ -274,13 +408,11 @@ describe MdToBbcode do
|
|
274
408
|
puts 'This is code 1'
|
275
409
|
$stdin.gets
|
276
410
|
```
|
277
|
-
|
278
411
|
2. List item 2
|
279
412
|
```ruby
|
280
413
|
puts 'This is code 2'
|
281
414
|
$stdin.gets
|
282
415
|
```
|
283
|
-
|
284
416
|
3. List item 3
|
285
417
|
```ruby
|
286
418
|
puts 'This is code 3'
|
@@ -290,17 +422,18 @@ describe MdToBbcode do
|
|
290
422
|
expect(md.md_to_bbcode).to eq(<<~EOS)
|
291
423
|
[list=1]
|
292
424
|
[*]List item 1
|
293
|
-
[code]
|
425
|
+
[code]
|
426
|
+
puts 'This is code 1'
|
294
427
|
$stdin.gets
|
295
428
|
[/code]
|
296
|
-
|
297
429
|
[*]List item 2
|
298
|
-
[code]
|
430
|
+
[code]
|
431
|
+
puts 'This is code 2'
|
299
432
|
$stdin.gets
|
300
433
|
[/code]
|
301
|
-
|
302
434
|
[*]List item 3
|
303
|
-
[code]
|
435
|
+
[code]
|
436
|
+
puts 'This is code 3'
|
304
437
|
$stdin.gets
|
305
438
|
[/code]
|
306
439
|
[/list]
|
@@ -312,6 +445,8 @@ describe MdToBbcode do
|
|
312
445
|
# Heading h1
|
313
446
|
|
314
447
|
Normal text
|
448
|
+
And another line<br>
|
449
|
+
with a line break
|
315
450
|
|
316
451
|
**Bold text**
|
317
452
|
|
@@ -324,6 +459,7 @@ describe MdToBbcode do
|
|
324
459
|
**Bold text including an italic *[link to Google](https://www.google.com)*.**
|
325
460
|
|
326
461
|
This is a bullet list:
|
462
|
+
|
327
463
|
* Bullet item 1
|
328
464
|
* Bullet item 2
|
329
465
|
* Bullet item 3
|
@@ -351,11 +487,13 @@ describe MdToBbcode do
|
|
351
487
|
```
|
352
488
|
|
353
489
|
This is a numbered list:
|
490
|
+
|
354
491
|
1. Numbered item 1
|
355
492
|
2. Numbered item 2
|
356
493
|
3. Numbered item 3
|
357
494
|
|
358
495
|
Here is some Ruby:
|
496
|
+
|
359
497
|
```ruby
|
360
498
|
puts 'Hello' * 3 * 5
|
361
499
|
# World
|
@@ -363,9 +501,11 @@ describe MdToBbcode do
|
|
363
501
|
```
|
364
502
|
|
365
503
|
This is a numbered list with 1 item:
|
504
|
+
|
366
505
|
1. Numbered item 1
|
367
506
|
|
368
507
|
This is a numbered list multi-line:
|
508
|
+
|
369
509
|
1. Numbered item 1
|
370
510
|
Additional content 1
|
371
511
|
2. Numbered item 2
|
@@ -380,40 +520,40 @@ describe MdToBbcode do
|
|
380
520
|
And ending text
|
381
521
|
EOS
|
382
522
|
expect(md.md_to_bbcode).to eq(<<~EOS)
|
523
|
+
|
383
524
|
[size=6][b]Heading h1[/b][/size]
|
384
|
-
|
525
|
+
|
385
526
|
Normal text
|
386
|
-
|
527
|
+
And another line
|
528
|
+
|
529
|
+
with a line break
|
387
530
|
[b]Bold text[/b]
|
388
|
-
|
389
531
|
Not bold followed by [b]bold and followed by[/b] not bold.
|
390
|
-
|
391
532
|
Not bold followed by [b]bold and
|
392
533
|
followed
|
393
534
|
by[/b] not bold on multi-lines.
|
394
|
-
|
395
535
|
[b]Bold text including an italic [i][url=https://www.google.com]link to Google[/url][/i].[/b]
|
396
|
-
|
397
536
|
This is a bullet list:
|
398
537
|
[list]
|
399
538
|
[*]Bullet item 1
|
400
539
|
[*]Bullet item 2
|
401
540
|
[*]Bullet item 3
|
402
541
|
[/list]
|
403
|
-
|
542
|
+
|
404
543
|
[size=6]Heading h2[/size]
|
405
|
-
|
544
|
+
|
406
545
|
Here is a link to [url=https://www.google.com/]Google[/url] in a middle of a line.
|
407
|
-
|
408
546
|
An inline code block [b][font=Courier New]this is code[/font][/b] to be inserted.
|
409
547
|
And [b]another one in bold: [font=Courier New]this is *code* that **is preformatted**[/font] but written[/b] in bold.
|
410
|
-
|
548
|
+
|
411
549
|
[size=5][b]Heading h3[/b][/size]
|
412
|
-
|
550
|
+
|
551
|
+
|
413
552
|
[size=5]Heading h4 with [b][font=Courier New]embedded code[/font][/b][/size]
|
414
|
-
|
553
|
+
|
415
554
|
Here is a code block in json:
|
416
|
-
[code]
|
555
|
+
[code]
|
556
|
+
{
|
417
557
|
"my_json": {
|
418
558
|
"is": "super",
|
419
559
|
"great": "and",
|
@@ -421,39 +561,32 @@ describe MdToBbcode do
|
|
421
561
|
}
|
422
562
|
}
|
423
563
|
[/code]
|
424
|
-
|
425
564
|
This is a numbered list:
|
426
565
|
[list=1]
|
427
566
|
[*]Numbered item 1
|
428
567
|
[*]Numbered item 2
|
429
568
|
[*]Numbered item 3
|
430
569
|
[/list]
|
431
|
-
|
432
570
|
Here is some Ruby:
|
433
571
|
[code]puts 'Hello' * 3 * 5
|
434
572
|
# World
|
435
573
|
puts `echo World`
|
436
574
|
[/code]
|
437
|
-
|
438
575
|
This is a numbered list with 1 item:
|
439
576
|
[list=1]
|
440
577
|
[*]Numbered item 1
|
441
578
|
[/list]
|
442
|
-
|
443
579
|
This is a numbered list multi-line:
|
444
580
|
[list=1]
|
445
581
|
[*]Numbered item 1
|
446
582
|
Additional content 1
|
447
583
|
[*]Numbered item 2
|
448
584
|
Additional content 2
|
449
|
-
|
450
585
|
[*]Numbered item 3
|
451
586
|
Additional content 3
|
452
587
|
[/list]
|
453
|
-
|
454
588
|
Here is an inserted image:
|
455
589
|
[img]https://x-aeon.com/muriel.jpg[/img]
|
456
|
-
|
457
590
|
And ending text
|
458
591
|
EOS
|
459
592
|
end
|
data/spec/md_to_bbcode_test.rb
CHANGED
File without changes
|
data/spec/spec_helper.rb
CHANGED
File without changes
|
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: md_to_bbcode
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.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:
|
11
|
+
date: 2021-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: redcarpet
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.5'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.5'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: rspec
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -24,6 +38,20 @@ dependencies:
|
|
24
38
|
- - "~>"
|
25
39
|
- !ruby/object:Gem::Version
|
26
40
|
version: '3.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sem_ver_components
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0.0'
|
27
55
|
description: Provides an API and an executable to convert Markdown text to BBCode
|
28
56
|
format
|
29
57
|
email:
|
@@ -35,6 +63,7 @@ extra_rdoc_files: []
|
|
35
63
|
files:
|
36
64
|
- bin/md_to_bbcode
|
37
65
|
- lib/md_to_bbcode.rb
|
66
|
+
- lib/md_to_bbcode/bbcode_renderer.rb
|
38
67
|
- lib/md_to_bbcode/core_extensions/string/md_to_bbcode.rb
|
39
68
|
- lib/md_to_bbcode/version.rb
|
40
69
|
- spec/api_spec.rb
|
@@ -59,7 +88,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
59
88
|
- !ruby/object:Gem::Version
|
60
89
|
version: '0'
|
61
90
|
requirements: []
|
62
|
-
rubygems_version: 3.
|
91
|
+
rubygems_version: 3.2.3
|
63
92
|
signing_key:
|
64
93
|
specification_version: 4
|
65
94
|
summary: Convert Markdown text to Bbcode
|