coradoc 1.1.4 → 1.1.5
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/lib/coradoc/element/list_item.rb +64 -7
- data/lib/coradoc/util.rb +4 -2
- data/lib/coradoc/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9931a29512bb9c4e3b590dfc1b3e60ae1dc949da9b4c401e1395a14011c55843
|
4
|
+
data.tar.gz: 5990bc988013a86964fd4554f5f094e30a83086b5ae47bada16e83a7a31d596b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a20be2069a6dd16193c6d53c1f08731a3f6732378bd26acac9af98c223c7e801d257c9c0d2055155ed82534d78979fb29fc926d1d896ed07f71d7dffdf002eb7
|
7
|
+
data.tar.gz: c4d5552c3b9862849a995bf77c46b413bf2864569a0d75ef00ee3b071182ec25e3c672105841b9944b85d8f690e19f83efca49a069449954dc727f946fdb4681
|
@@ -15,26 +15,83 @@ module Coradoc
|
|
15
15
|
@line_break = options.fetch(:line_break, "\n")
|
16
16
|
end
|
17
17
|
|
18
|
+
def inline?(elem)
|
19
|
+
case elem
|
20
|
+
when Inline::HardLineBreak
|
21
|
+
:hardbreak
|
22
|
+
when ->(i){ i.class.name.to_s.include? "::Inline::" }
|
23
|
+
true
|
24
|
+
when String, TextElement, Image::InlineImage
|
25
|
+
true
|
26
|
+
else
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
18
31
|
def to_adoc
|
19
32
|
anchor = @anchor.nil? ? "" : " #{@anchor.to_adoc.to_s} "
|
20
33
|
# text = Coradoc::Generator.gen_adoc(@content)
|
21
|
-
content = Array(@content).
|
22
|
-
|
34
|
+
content = Array(@content).flatten.compact
|
35
|
+
out = ""
|
36
|
+
prev_inline = :init
|
37
|
+
|
38
|
+
# Collapse meaningless <DIV>s
|
39
|
+
while content.map(&:class) == [Section] && content.first.safe_to_collapse?
|
40
|
+
content = Array(content.first.contents)
|
41
|
+
end
|
23
42
|
|
43
|
+
content.each_with_index do |subitem, idx|
|
24
44
|
subcontent = Coradoc::Generator.gen_adoc(subitem)
|
45
|
+
|
46
|
+
inline = inline?(subitem)
|
47
|
+
next_inline = idx+1 == content.length ? :end : inline?(content[idx+1])
|
48
|
+
|
25
49
|
# Only try to postprocess elements that are text,
|
26
50
|
# otherwise we could strip markup.
|
27
|
-
if
|
28
|
-
|
51
|
+
if subitem.is_a? Coradoc::Element::TextElement
|
52
|
+
if [:hardbreak, :init, false].include?(prev_inline)
|
53
|
+
subcontent = Coradoc.strip_unicode(subcontent, only: :begin)
|
54
|
+
end
|
55
|
+
if [:hardbreak, :end, false].include?(next_inline)
|
56
|
+
subcontent = Coradoc.strip_unicode(subcontent, only: :end)
|
57
|
+
end
|
29
58
|
end
|
30
|
-
|
31
|
-
|
59
|
+
|
60
|
+
case inline
|
61
|
+
when true
|
62
|
+
if prev_inline == false
|
63
|
+
out += "\n+\n" + subcontent
|
64
|
+
else
|
65
|
+
out += subcontent
|
66
|
+
end
|
67
|
+
when false
|
68
|
+
case prev_inline
|
69
|
+
when :hardbreak
|
70
|
+
out += subcontent.strip
|
71
|
+
when :init
|
72
|
+
out += "{empty}\n+\n" + subcontent.strip
|
73
|
+
else
|
74
|
+
out += "\n+\n" + subcontent.strip
|
75
|
+
end
|
76
|
+
when :hardbreak
|
77
|
+
if %i[hardbreak init].include? prev_inline
|
78
|
+
# can't have two hard breaks in a row; can't start with a hard break
|
79
|
+
else
|
80
|
+
out += "\n+\n"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
prev_inline = inline
|
85
|
+
end
|
86
|
+
out += "{empty}" if prev_inline == :hardbreak
|
87
|
+
out = "{empty}" if out.empty?
|
88
|
+
|
32
89
|
# attach = Coradoc::Generator.gen_adoc(@attached)
|
33
90
|
attach = @attached.map do |elem|
|
34
91
|
"+\n" + Coradoc::Generator.gen_adoc(elem)
|
35
92
|
end.join
|
36
93
|
nest = Coradoc::Generator.gen_adoc(@nested)
|
37
|
-
out = " #{anchor}#{
|
94
|
+
out = " #{anchor}#{out}#{@line_break}"
|
38
95
|
out + attach + nest
|
39
96
|
end
|
40
97
|
end
|
data/lib/coradoc/util.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
module Coradoc
|
2
|
-
def self.strip_unicode(str)
|
3
|
-
str.gsub(/\A[[:space:]]
|
2
|
+
def self.strip_unicode(str, only: nil)
|
3
|
+
str = str.gsub(/\A[[:space:]]+/, "") unless only == :end
|
4
|
+
str = str.gsub(/[[:space:]]+\z/, "") unless only == :begin
|
5
|
+
str
|
4
6
|
end
|
5
7
|
|
6
8
|
def self.a_single?(obj, klass)
|
data/lib/coradoc/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: coradoc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ribose Inc.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2024-12-
|
12
|
+
date: 2024-12-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: marcel
|