asciidoctor_cjk_breaks 0.0.1 → 0.0.2

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: 9c02afe8dd442f8c710ba0d7378e7725aac105a6f50531c380611d318860376e
4
- data.tar.gz: d3ba448088b097772c1e0e04be5075ae89b3e2072d9ceb08a056f2a3f54fe777
3
+ metadata.gz: 03ca0087d1fa376ff0798af72d2af93a9ff65de401f3ec9cf9f87f881ff34055
4
+ data.tar.gz: af10c813c19a1d60eae229d7426256e76c4e7c4e6418362c5b69e66796984d18
5
5
  SHA512:
6
- metadata.gz: ad97861be354b68c41f5c640667c7ce54ece7be6686287cb73d54a0ae614ebb3acf67f2e8b6b1590101a6b471eb3a1489b9ef96a29d1d25f238502f18d3b0614
7
- data.tar.gz: 3962921d6e1500c0b825e49bee236ae3cfd0edb828ca8b480694265116fdccfcc8871ce53ceb22021b5ee3018ac6b8ce3d050a808161d6ea587b37131deb1c90
6
+ metadata.gz: d98b69981d5d936478b2e5c89f6de7c8b820248c1e6529e1f81d74c88281360e036a952e03199bc3bbd35018cec2defd4d3e38d1ad08f876701ce3749cf143d8
7
+ data.tar.gz: 2e7d4cf825dab40200cf75da3d19072abbf5189d1d739d2ff692bce8aaa43ae0d148c37478b74b95c10e9afa090cb55a8764ca40f58b865d202371947404665c
@@ -15,7 +15,7 @@ This extension finds and removes newlines that cannot be converted to space, alg
15
15
 
16
16
  This is a Ruby port of https://github.com/markdown-it/markdown-it-cjk-breaks[markdown-it-cjk-breaks].
17
17
 
18
- Status: https://github.com/markdown-it/markdown-it-cjk-breaks/commit/15c7a4144e0e6f94fada671a6eb2c7b63e2358f0[15c7a41]
18
+ Status: https://github.com/markdown-it/markdown-it-cjk-breaks/commit/26744838965b07ed5853031461600890b57238f7[2674483]
19
19
 
20
20
  == Install
21
21
 
@@ -23,8 +23,19 @@ Status: https://github.com/markdown-it/markdown-it-cjk-breaks/commit/15c7a4144e0
23
23
 
24
24
  == Usage
25
25
 
26
+ In command line:
27
+
26
28
  $ asciidoctor -r asciidoctor_cjk_breaks example.adoc
27
29
 
30
+ In Ruby:
31
+
32
+ [source, ruby]
33
+ --------------
34
+ require 'asciidoctor_cjk_breaks'
35
+
36
+ Asciidoctor.convert_file filepath
37
+ --------------
38
+
28
39
  == Test
29
40
 
30
41
  $ ruby test/test_cjk_breaks.rb
@@ -3,57 +3,68 @@ require 'east_asian_width'
3
3
 
4
4
  class CjkBreaksTreeprocessor < Asciidoctor::Extensions::Treeprocessor
5
5
  def process(document)
6
- return unless document.blocks?
7
-
8
- remove_cjk_breaks document
6
+ process_interal document
9
7
  nil
10
8
  end
11
9
 
12
- def remove_cjk_breaks(node)
13
- node.blocks.each_with_index do |block, index|
14
- if block.context == :paragraph
15
- content_changed = false
16
- # Processing after raw_source -> block.lines -> block.content in asciidoctor.
17
- # It may be better to make this process while the process from raw_source -> block.lines
18
- # whose code flow is:
19
- # -> `Asciidoctor::Block.initialize`
20
- # -> `Asciidoctor::Helpers.normalize_lines_from_string`.
21
- lines = block.content.lines
22
- lines.each_with_index do |line, line_index|
23
- last_char_idx = line.rindex(/[^\r|\n]/)
24
- last_char = line[last_char_idx]
25
- next_line = lines[line_index + 1]
26
- next_char = next_line[0] if next_line
10
+ def process_interal(block)
11
+ case block.context
12
+ when :paragraph
13
+ remove_cjk_breaks block
14
+ when :dlist
15
+ block
16
+ when :table
17
+ block
18
+ else
19
+ block.blocks.map! do |b|
20
+ process_interal b
21
+ end
22
+ block
23
+ end
24
+ end
27
25
 
28
- next unless last_char && next_char
26
+ def remove_cjk_breaks(block)
27
+ content_changed = false
28
+ # Processing after raw_source -> block.lines -> block.content in asciidoctor.
29
+ # It may be better to make this process while the process from raw_source -> block.lines
30
+ # whose code flow is:
31
+ # -> `Asciidoctor::Block.initialize`
32
+ # -> `Asciidoctor::Helpers.normalize_lines_from_string`.
33
+ lines = block.content.lines
34
+ lines.each_with_index do |line, line_index|
35
+ last_char_idx = line.rindex(/[^\r|\n]/)
36
+ last_char = line[last_char_idx]
37
+ next_line = lines[line_index + 1]
38
+ next_char = next_line[0] if next_line
29
39
 
30
- remove_break = false
40
+ next unless last_char && next_char
31
41
 
32
- if last_char == "\u200b" || next_char == "\u200b"
33
- # remove newline if it's adjacent to ZWSP
34
- remove_break = true
35
- elsif EastAsianWidth.east_asian_width(last_char).match?(/^[FWH]$/) &&
36
- EastAsianWidth.east_asian_width(next_char).match?(/^[FWH]$/)
37
- # remove newline if both characters are fullwidth (F), wide (W) or
38
- # halfwidth (H), but not Hangul
39
- remove_break = true if !hangul?(last_char) && !hangul?(next_char)
40
- end
42
+ remove_break = false
41
43
 
42
- if remove_break
43
- lines[line_index] = line.chomp
44
- content_changed = true
45
- end
46
- end
44
+ if last_char == "\u200b" || next_char == "\u200b"
45
+ # remove newline if it's adjacent to ZWSP
46
+ remove_break = true
47
+ elsif EastAsianWidth.east_asian_width(last_char).match?(/^[FWH]$/) &&
48
+ EastAsianWidth.east_asian_width(next_char).match?(/^[FWH]$/)
49
+ # remove newline if both characters are fullwidth (F), wide (W) or
50
+ # halfwidth (H), but not Hangul
51
+ remove_break = true if !hangul?(last_char) && !hangul?(next_char)
52
+ end
47
53
 
48
- if content_changed
49
- node.blocks[index] = create_paragraph block.document, lines.join(''), block.attributes
50
- end
51
- else
52
- remove_cjk_breaks block
54
+ if remove_break
55
+ lines[line_index] = line.chomp
56
+ content_changed = true
53
57
  end
54
58
  end
59
+
60
+ if content_changed
61
+ create_paragraph block.document, lines.join(''), block.attributes
62
+ else
63
+ block
64
+ end
55
65
  end
56
66
 
67
+
57
68
  REGEXP_HANGUL_CHARS = /
58
69
  [
59
70
  \u1100-\u11FF
@@ -70,3 +70,12 @@ foo🈀
70
70
  .
71
71
  <p>foo🈀🈀foo</p>
72
72
  .
73
+
74
+ Should process EOL correctly
75
+ .
76
+ image:image.png[img]
77
+ text
78
+ .
79
+ <p><img src="image.png" alt="img">
80
+ text</p>
81
+ .
@@ -0,0 +1,14 @@
1
+ hello::
2
+ world
3
+ goodbye::
4
+ cruel world1
5
+
6
+ ***
7
+
8
+ Dairy::
9
+ * Milk
10
+ * Eggs
11
+ Bakery::
12
+ * Bread
13
+ Produce::
14
+ * Bananas
@@ -0,0 +1,20 @@
1
+ |===
2
+
3
+ | Cell in column 1, row 1 | Cell in column 2, row 1
4
+
5
+ | Cell in column 1, row 2 | Cell in column 2, row 2
6
+
7
+ | Cell in column 1, row 3 | Cell in column 2, row 3
8
+
9
+ |===
10
+
11
+ ***
12
+
13
+ [cols="3*"]
14
+ |===
15
+ |Cell in column 1, row 1 |Cell in column 2, row 1
16
+ |Cell in column 3, row 1
17
+
18
+ |Cell in column 1, row 2
19
+ |Cell in column 2, row 2 |Cell in column 3, row 2
20
+ |===
@@ -1,4 +1,5 @@
1
- 滕王阁序 --- 王勃
1
+ = 滕王阁序
2
+ 王勃
2
3
 
3
4
  豫章故郡,洪都新府。
4
5
  星分翼轸,地接衡庐。
@@ -2,3 +2,6 @@ require_relative '../lib/asciidoctor_cjk_breaks'
2
2
 
3
3
  Asciidoctor.convert_file 'test/fixtures/cjk_breaks.txt'
4
4
  Asciidoctor.convert_file 'test/fixtures/tengwanggexu-wangbo.txt'
5
+
6
+ Asciidoctor.convert_file 'test/fixtures/dlist.txt'
7
+ Asciidoctor.convert_file 'test/fixtures/table.txt'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: asciidoctor_cjk_breaks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaizhao Zhang
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: asciidoctor
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.5'
19
+ version: '2'
20
20
  type: :runtime
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: '1.5'
26
+ version: '2'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: east_asian_width
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -49,13 +49,15 @@ files:
49
49
  - lib/asciidoctor/cjk_breaks_treeprocessor.rb
50
50
  - lib/asciidoctor_cjk_breaks.rb
51
51
  - test/fixtures/cjk_breaks.txt
52
+ - test/fixtures/dlist.txt
53
+ - test/fixtures/table.txt
52
54
  - test/fixtures/tengwanggexu-wangbo.txt
53
55
  - test/test_cjk_breaks.rb
54
56
  homepage: https://github.com/zhangkaizhao/asciidoctor_cjk_breaks
55
57
  licenses:
56
58
  - MIT
57
59
  metadata: {}
58
- post_install_message:
60
+ post_install_message:
59
61
  rdoc_options: []
60
62
  require_paths:
61
63
  - lib
@@ -70,9 +72,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
72
  - !ruby/object:Gem::Version
71
73
  version: '0'
72
74
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.7.6
75
- signing_key:
75
+ rubygems_version: 3.1.4
76
+ signing_key:
76
77
  specification_version: 4
77
78
  summary: Suppress line breaks between east asian characters
78
79
  test_files: []