asciidoctor_cjk_breaks 0.0.1 → 0.0.3

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: 2ab0bb16cfe28013986b1c52388a04745176560ea3504f49952a9d605395e7c5
4
+ data.tar.gz: bb8faf93ff3508affcc83873ea85ef1161dbfa9a77c0cd3bf5a6be3aa504337c
5
5
  SHA512:
6
- metadata.gz: ad97861be354b68c41f5c640667c7ce54ece7be6686287cb73d54a0ae614ebb3acf67f2e8b6b1590101a6b471eb3a1489b9ef96a29d1d25f238502f18d3b0614
7
- data.tar.gz: 3962921d6e1500c0b825e49bee236ae3cfd0edb828ca8b480694265116fdccfcc8871ce53ceb22021b5ee3018ac6b8ce3d050a808161d6ea587b37131deb1c90
6
+ metadata.gz: 0ac77115546662ea97a1c6a35013f3168861c1376863c69b22b5837ff5bb566a44c7cb7a0275ff84ae8fd926aa6ac5935931bfa7244517b4329306e753ce1648
7
+ data.tar.gz: 2c35b6d8a78928e5db7421a42f522d4c9ececf6cc69f307bd35fcd7d8df86a4085182d96d336b6e5dc9bbdf514e84d24bb873691e96d66f018e99ccc6e6d1303
data/README.adoc CHANGED
@@ -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,65 @@ 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
+ # NOTE: use block.lines instead of block.content to avoid issues of auto-generated content e.g. footnotes.
29
+ # see source code: https://github.com/asciidoctor/asciidoctor/blob/v2.0.23/lib/asciidoctor/block.rb#L98-L129
30
+ lines = block.lines
31
+ lines.each_with_index do |line, line_index|
32
+ last_char_idx = line.rindex(/[^\r|\n]/)
33
+ last_char = line[last_char_idx]
34
+ next_line = lines[line_index + 1]
35
+ next_char = next_line[0] if next_line
29
36
 
30
- remove_break = false
37
+ next unless last_char && next_char
31
38
 
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
39
+ remove_break = false
41
40
 
42
- if remove_break
43
- lines[line_index] = line.chomp
44
- content_changed = true
45
- end
46
- end
41
+ if last_char == "\u200b" || next_char == "\u200b"
42
+ # remove newline if it's adjacent to ZWSP
43
+ remove_break = true
44
+ elsif EastAsianWidth.east_asian_width(last_char).match?(/^[FWH]$/) &&
45
+ EastAsianWidth.east_asian_width(next_char).match?(/^[FWH]$/)
46
+ # remove newline if both characters are fullwidth (F), wide (W) or
47
+ # halfwidth (H), but not Hangul
48
+ remove_break = true if !hangul?(last_char) && !hangul?(next_char)
49
+ end
47
50
 
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
51
+ if remove_break
52
+ lines[line_index] = line.chomp
53
+ content_changed = true
53
54
  end
54
55
  end
56
+
57
+ if content_changed
58
+ create_paragraph block.document, lines.join(''), block.attributes
59
+ else
60
+ block
61
+ end
55
62
  end
56
63
 
64
+
57
65
  REGEXP_HANGUL_CHARS = /
58
66
  [
59
67
  \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,8 @@
1
+ wordfootnote:[nota bene a].
2
+ word{empty}footnote:[nota bene b].
3
+ wordfootnote:[nota bene again].
4
+
5
+ See <<heading>>.
6
+
7
+ [[heading,Heading]]
8
+ == Headingfootnote:[This is a heading with a footnote]
@@ -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,8 @@ 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'
8
+
9
+ Asciidoctor.convert_file 'test/fixtures/footnote.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.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaizhao Zhang
8
- autorequire:
8
+ - Kefu Chai
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-09 00:00:00.000000000 Z
11
+ date: 1980-01-02 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
@@ -40,7 +40,9 @@ dependencies:
40
40
  version: '0'
41
41
  description: An extension for Asciidoctor that suppresses line breaks between east
42
42
  asian characters.
43
- email: zhangkaizhao@gmail.com
43
+ email:
44
+ - zhangkaizhao@gmail.com
45
+ - tchaikov@gmail.com
44
46
  executables: []
45
47
  extensions: []
46
48
  extra_rdoc_files: []
@@ -49,13 +51,15 @@ files:
49
51
  - lib/asciidoctor/cjk_breaks_treeprocessor.rb
50
52
  - lib/asciidoctor_cjk_breaks.rb
51
53
  - test/fixtures/cjk_breaks.txt
54
+ - test/fixtures/dlist.txt
55
+ - test/fixtures/footnote.txt
56
+ - test/fixtures/table.txt
52
57
  - test/fixtures/tengwanggexu-wangbo.txt
53
58
  - test/test_cjk_breaks.rb
54
59
  homepage: https://github.com/zhangkaizhao/asciidoctor_cjk_breaks
55
60
  licenses:
56
61
  - MIT
57
62
  metadata: {}
58
- post_install_message:
59
63
  rdoc_options: []
60
64
  require_paths:
61
65
  - lib
@@ -70,9 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
70
74
  - !ruby/object:Gem::Version
71
75
  version: '0'
72
76
  requirements: []
73
- rubyforge_project:
74
- rubygems_version: 2.7.6
75
- signing_key:
77
+ rubygems_version: 3.6.7
76
78
  specification_version: 4
77
79
  summary: Suppress line breaks between east asian characters
78
80
  test_files: []