md_to_bbcode 1.1.0 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b852d6b172b3fb90659c9b2d73d0c439015e2f7eaae67bbe4b4dd054b3294d28
4
- data.tar.gz: 2b1604824090ba1b3e2f9e3d8dc3ca33114ba3dd009ef93ac60f7b9bd21d54d7
3
+ metadata.gz: 882bfada1866cb31be09d565ddbdf8b7a4a76570e66c2f0618951ad7815888f7
4
+ data.tar.gz: 70b7c9fb216b71575e56521104e3ccc23cbd807c0cfff63ac2791d3c0dc0d957
5
5
  SHA512:
6
- metadata.gz: d4551e53bace327117ba494f0f08ca6ce79713b703e94a5c055a8e78d1074e7087ac9d29b6ebc5717b9481a600e6f55101a5d165aa8cc5372907c4155a0a7a6e
7
- data.tar.gz: c9d7804233ecdd7760026aeafaed92d19e0ff8200e2a892941827ce75ec892797dbcaa8bff7b2960be82c856d5dea04b6cf7b07682885bc1658caa847581df8c
6
+ metadata.gz: 2aca2c89a8854d459a603d114dadb2fdb9afb3b002a5cb90b1744f352facee7d5a3784276473d09f6eee33753df59210383f66353f4b452162db1a11fd1e413c
7
+ data.tar.gz: 40d70ca3254263bc8a0deb320b1845d1aa8b074a908de38465ae7ee1db28a68accd141d84a5e425c6e5da62f3cb7a5740576a1d160ba48b9f74731f6a1206161
@@ -30,40 +30,50 @@ module MdToBbcode
30
30
  # Don't change anything at the formatting
31
31
  bbcode_lines << "#{line}\n"
32
32
  else
33
- # Images (do this gsub before links and any single tags, like bold, headings...)
34
- line.gsub!(/!\[(.*?)\]\((.*?)\)/, '[img]\2[/img]')
35
- # Links
36
- line.gsub!(/\[(.*?)\]\((.*?)\)/, '[url=\2]\1[/url]')
37
- # Bold (do this before italic)
38
- if in_bold_text
39
- line.gsub!(/\*\*(.*?)\*\*/, '[/b]\1[b]')
40
- else
41
- line.gsub!(/\*\*(.*?)\*\*/, '[b]\1[/b]')
42
- end
43
- if line =~ /.*\*\*.*/
44
- if in_bold_text
45
- line.gsub!(/(.*)\*\*(.*)/, '\1[/b]\2')
46
- in_bold_text = false
47
- else
48
- line.gsub!(/(.*)\*\*(.*)/, '\1[b]\2')
49
- in_bold_text = true
50
- end
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
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]'}"
62
38
  else
63
- line.gsub!(/(.*)\*(\S.*)/, '\1[i]\2')
64
- in_italic_text = true
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 field =~ /.*\*.*/
66
+ if in_italic_text
67
+ field.gsub!(/(.*\S)\*(.*)/, '\1[/i]\2')
68
+ in_italic_text = false
69
+ else
70
+ field.gsub!(/(.*)\*(\S.*)/, '\1[i]\2')
71
+ in_italic_text = true
72
+ end
73
+ end
74
+ field
65
75
  end
66
- end
76
+ end.join
67
77
  # Heading 1
68
78
  line.gsub!(/^# (.*?)$/, '[size=6][b]\1[/b][/size]')
69
79
  # Heading 2
@@ -72,8 +82,6 @@ module MdToBbcode
72
82
  line.gsub!(/^### (.*?)$/, '[size=5][b]\1[/b][/size]')
73
83
  # Heading 4
74
84
  line.gsub!(/^#### (.*?)$/, '[size=5]\1[/size]')
75
- # In-line code
76
- line.gsub!(/`(.*?)`/, '[b][font=Courier New]\1[/font][/b]')
77
85
  # Bullets
78
86
  if line =~ /^\* (.+)$/
79
87
  # Single bullet line
@@ -1,5 +1,5 @@
1
1
  module MdToBbcode
2
2
 
3
- VERSION = '1.1.0'
3
+ VERSION = '1.1.1'
4
4
 
5
5
  end
@@ -36,6 +36,48 @@ describe MdToBbcode do
36
36
  expect('`in-line code`'.md_to_bbcode).to eq '[b][font=Courier New]in-line code[/font][/b]'
37
37
  end
38
38
 
39
+ it 'converts inline code in bold text' do
40
+ expect('**Bold `in-line code` to display**'.md_to_bbcode).to eq '[b]Bold [font=Courier New]in-line code[/font] to display[/b]'
41
+ end
42
+
43
+ it 'converts inline code in italic text' do
44
+ 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]'
45
+ end
46
+
47
+ it 'converts inline code in a multi-line bold text' do
48
+ md = <<~EOS
49
+ **Bold
50
+ `in-line code`
51
+ on
52
+ multi-line**
53
+ EOS
54
+ expect(md.md_to_bbcode).to eq(<<~EOS)
55
+ [b]Bold
56
+ [font=Courier New]in-line code[/font]
57
+ on
58
+ multi-line[/b]
59
+ EOS
60
+ end
61
+
62
+ it 'converts inline code in a multi-line italic text' do
63
+ md = <<~EOS
64
+ *Italic
65
+ `in-line code`
66
+ on
67
+ multi-line*
68
+ EOS
69
+ expect(md.md_to_bbcode).to eq(<<~EOS)
70
+ [i]Italic
71
+ [b][font=Courier New]in-line code[/font][/b]
72
+ on
73
+ multi-line[/i]
74
+ EOS
75
+ end
76
+
77
+ it 'does not convert other formatting in inline code' do
78
+ 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]'
79
+ end
80
+
39
81
  it 'converts images' do
40
82
  expect('![Image text](https://my.domain.com/image.jpg)'.md_to_bbcode).to eq '[img]https://my.domain.com/image.jpg[/img]'
41
83
  end
@@ -278,6 +320,7 @@ describe MdToBbcode do
278
320
  Here is a link to [Google](https://www.google.com/) in a middle of a line.
279
321
 
280
322
  An inline code block `this is code` to be inserted.
323
+ And **another one in bold: `this is *code* that **is preformatted**` but written** in bold.
281
324
 
282
325
  ### Heading h3
283
326
 
@@ -350,6 +393,7 @@ describe MdToBbcode do
350
393
  Here is a link to [url=https://www.google.com/]Google[/url] in a middle of a line.
351
394
 
352
395
  An inline code block [b][font=Courier New]this is code[/font][/b] to be inserted.
396
+ And [b]another one in bold: [font=Courier New]this is *code* that **is preformatted**[/font] but written[/b] in bold.
353
397
 
354
398
  [size=5][b]Heading h3[/b][/size]
355
399
 
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: md_to_bbcode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
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-12-01 00:00:00.000000000 Z
11
+ date: 2020-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '3.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '3.10'
27
27
  description: Provides an API and an executable to convert Markdown text to BBCode
28
28
  format
29
29
  email: