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 +4 -4
- data/README.adoc +12 -1
- data/lib/asciidoctor/cjk_breaks_treeprocessor.rb +47 -39
- data/test/fixtures/cjk_breaks.txt +9 -0
- data/test/fixtures/dlist.txt +14 -0
- data/test/fixtures/footnote.txt +8 -0
- data/test/fixtures/table.txt +20 -0
- data/test/fixtures/tengwanggexu-wangbo.txt +2 -1
- data/test/test_cjk_breaks.rb +5 -0
- metadata +12 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ab0bb16cfe28013986b1c52388a04745176560ea3504f49952a9d605395e7c5
|
4
|
+
data.tar.gz: bb8faf93ff3508affcc83873ea85ef1161dbfa9a77c0cd3bf5a6be3aa504337c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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/
|
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
|
-
|
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
|
+
# 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
|
-
|
37
|
+
next unless last_char && next_char
|
31
38
|
|
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
|
39
|
+
remove_break = false
|
41
40
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
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
|
-
|
49
|
-
|
50
|
-
|
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
|
@@ -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,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.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kaizhao Zhang
|
8
|
-
|
8
|
+
- Kefu Chai
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
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: '
|
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
|
@@ -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:
|
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
|
-
|
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: []
|