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 +4 -4
- data/README.adoc +12 -1
- data/lib/asciidoctor/cjk_breaks_treeprocessor.rb +50 -39
- data/test/fixtures/cjk_breaks.txt +9 -0
- data/test/fixtures/dlist.txt +14 -0
- data/test/fixtures/table.txt +20 -0
- data/test/fixtures/tengwanggexu-wangbo.txt +2 -1
- data/test/test_cjk_breaks.rb +3 -0
- metadata +10 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 03ca0087d1fa376ff0798af72d2af93a9ff65de401f3ec9cf9f87f881ff34055
|
4
|
+
data.tar.gz: af10c813c19a1d60eae229d7426256e76c4e7c4e6418362c5b69e66796984d18
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d98b69981d5d936478b2e5c89f6de7c8b820248c1e6529e1f81d74c88281360e036a952e03199bc3bbd35018cec2defd4d3e38d1ad08f876701ce3749cf143d8
|
7
|
+
data.tar.gz: 2e7d4cf825dab40200cf75da3d19072abbf5189d1d739d2ff692bce8aaa43ae0d148c37478b74b95c10e9afa090cb55a8764ca40f58b865d202371947404665c
|
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/
|
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
|
-
|
7
|
-
|
8
|
-
remove_cjk_breaks document
|
6
|
+
process_interal document
|
9
7
|
nil
|
10
8
|
end
|
11
9
|
|
12
|
-
def
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
-
|
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
|
-
|
40
|
+
next unless last_char && next_char
|
31
41
|
|
32
|
-
|
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
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
@@ -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
|
+
|===
|
data/test/test_cjk_breaks.rb
CHANGED
@@ -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.
|
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:
|
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: '
|
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: '
|
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
|
-
|
74
|
-
|
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: []
|