booklab-sml 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/booklab/sml/base.rb +1 -1
- data/lib/booklab/sml/renderer.rb +26 -2
- data/lib/booklab/sml/rules/base.rb +4 -0
- data/lib/booklab/sml/rules/span_with_mark.rb +5 -1
- data/lib/booklab/sml/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: 1767629aeac09e97ae18ce1b056dc415ef31099c1affb9e4229c1ce77c66af98
|
4
|
+
data.tar.gz: 434420cf3da51edf14548330bf6d9ebc9d0a03139ced8f71aa5967e155f0c039
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 44fe7eb237c13ed61305bcbb7023d2f5b04c2e37cb7bf02c86c198720332965500c9cfd8148e5e06568f774c1f1b652c7e9d9b4789d582b74557e8ccc4967c81
|
7
|
+
data.tar.gz: 1f060f38cb2d7fd70c4d142204297ef62c867fe8b6cf619c1d23b4b3cebb27edf50646e9b8e56667674d1dc2701c44edb473e76ff8c457a3199ddede7acd87f2
|
data/README.md
CHANGED
@@ -16,8 +16,11 @@ and then run `bundle install`
|
|
16
16
|
|
17
17
|
```rb
|
18
18
|
$ sml = %(["p", { align: "center", indent: 1 }, "Hello world"])
|
19
|
-
$ BookLab::SML.parse(sml)
|
19
|
+
$ renderer = BookLab::SML.parse(sml)
|
20
|
+
$ renderer.to_html
|
20
21
|
=> <p style="text-align: center; text-indent: 32px;">Hello world</p>
|
22
|
+
$ renderer.to_text
|
23
|
+
=> "Hello world"
|
21
24
|
```
|
22
25
|
|
23
26
|
## License
|
data/lib/booklab/sml/base.rb
CHANGED
data/lib/booklab/sml/renderer.rb
CHANGED
@@ -6,7 +6,7 @@ module BookLab::SML
|
|
6
6
|
class Renderer
|
7
7
|
include BookLab::SML::Utils
|
8
8
|
|
9
|
-
attr_accessor :sml, :config
|
9
|
+
attr_accessor :sml, :value, :config
|
10
10
|
|
11
11
|
# For table, list for temp mark in block
|
12
12
|
attr_accessor :in_block
|
@@ -16,10 +16,15 @@ module BookLab::SML
|
|
16
16
|
@config = Config.new
|
17
17
|
@config.plantuml_service_host = options[:plantuml_service_host]
|
18
18
|
@config.mathjax_service_host = options[:mathjax_service_host]
|
19
|
+
@value = YAML.load(sml)
|
19
20
|
end
|
20
21
|
|
21
22
|
def to_html
|
22
|
-
node_to_html(
|
23
|
+
node_to_html(self.value)
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
to_html
|
23
28
|
end
|
24
29
|
|
25
30
|
def node_to_html(node, opts = {})
|
@@ -40,5 +45,24 @@ module BookLab::SML
|
|
40
45
|
node_to_html(child, prev: prev_node, next: next_node)
|
41
46
|
end.join("")
|
42
47
|
end
|
48
|
+
|
49
|
+
def to_text
|
50
|
+
node_to_text(self.value)
|
51
|
+
end
|
52
|
+
|
53
|
+
def node_to_text(node, opts = {})
|
54
|
+
opts[:renderer] = self
|
55
|
+
rule = BookLab::SML::Rules::find_by_node(node)
|
56
|
+
rule.to_text(node, opts)&.strip
|
57
|
+
end
|
58
|
+
|
59
|
+
def children_to_text(node)
|
60
|
+
return node if node.is_a?(String)
|
61
|
+
children = self.class.get_children(node)
|
62
|
+
children.each_with_index.map do |child, idx|
|
63
|
+
text = node_to_text(child, {})
|
64
|
+
text.blank? ? nil : text
|
65
|
+
end.compact.join(" ")
|
66
|
+
end
|
43
67
|
end
|
44
68
|
end
|
@@ -23,7 +23,11 @@ module BookLab::SML::Rules
|
|
23
23
|
def self.to_html(node, opts = {})
|
24
24
|
attrs = attributes(node)
|
25
25
|
renderer = opts[:renderer]
|
26
|
-
|
26
|
+
if attrs[:cd] == 1
|
27
|
+
children = renderer.children_to_text(node)
|
28
|
+
else
|
29
|
+
children = renderer.children_to_html(node)
|
30
|
+
end
|
27
31
|
|
28
32
|
case attrs[:va]
|
29
33
|
when "superscript" then attrs[:sup] = 1
|
data/lib/booklab/sml/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: booklab-sml
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Lee
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-01-
|
11
|
+
date: 2019-01-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|