hyperlang 0.1.0
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 +7 -0
- data/.github/workflows/rake.yml +19 -0
- data/.github/workflows/release.yml +28 -0
- data/.gitignore +8 -0
- data/.rspec +3 -0
- data/.rubocop.yml +19 -0
- data/.rubocop_todo.yml +45 -0
- data/Gemfile +15 -0
- data/README.adoc +176 -0
- data/Rakefile +12 -0
- data/hyperlang.gemspec +36 -0
- data/lib/hyperlang/version.rb +5 -0
- data/lib/hyperlang/xhtml/a.rb +44 -0
- data/lib/hyperlang/xhtml/abbr.rb +22 -0
- data/lib/hyperlang/xhtml/acronym.rb +22 -0
- data/lib/hyperlang/xhtml/address.rb +26 -0
- data/lib/hyperlang/xhtml/applet.rb +42 -0
- data/lib/hyperlang/xhtml/area.rb +29 -0
- data/lib/hyperlang/xhtml/b.rb +22 -0
- data/lib/hyperlang/xhtml/base.rb +17 -0
- data/lib/hyperlang/xhtml/basefont.rb +21 -0
- data/lib/hyperlang/xhtml/bdo.rb +22 -0
- data/lib/hyperlang/xhtml/big.rb +22 -0
- data/lib/hyperlang/xhtml/blockquote.rb +44 -0
- data/lib/hyperlang/xhtml/body.rb +54 -0
- data/lib/hyperlang/xhtml/br.rb +12 -0
- data/lib/hyperlang/xhtml/button.rb +42 -0
- data/lib/hyperlang/xhtml/caption.rb +20 -0
- data/lib/hyperlang/xhtml/center.rb +48 -0
- data/lib/hyperlang/xhtml/cite.rb +20 -0
- data/lib/hyperlang/xhtml/code.rb +22 -0
- data/lib/hyperlang/xhtml/col.rb +29 -0
- data/lib/hyperlang/xhtml/colgroup.rb +31 -0
- data/lib/hyperlang/xhtml/dd.rb +40 -0
- data/lib/hyperlang/xhtml/del.rb +38 -0
- data/lib/hyperlang/xhtml/dfn.rb +20 -0
- data/lib/hyperlang/xhtml/dir.rb +21 -0
- data/lib/hyperlang/xhtml/div.rb +64 -0
- data/lib/hyperlang/xhtml/dl.rb +21 -0
- data/lib/hyperlang/xhtml/dt.rb +30 -0
- data/lib/hyperlang/xhtml/em.rb +22 -0
- data/lib/hyperlang/xhtml/fieldset.rb +34 -0
- data/lib/hyperlang/xhtml/font.rb +26 -0
- data/lib/hyperlang/xhtml/form.rb +40 -0
- data/lib/hyperlang/xhtml/frame.rb +31 -0
- data/lib/hyperlang/xhtml/frameset.rb +25 -0
- data/lib/hyperlang/xhtml/h1.rb +34 -0
- data/lib/hyperlang/xhtml/h2.rb +34 -0
- data/lib/hyperlang/xhtml/h3.rb +34 -0
- data/lib/hyperlang/xhtml/h4.rb +34 -0
- data/lib/hyperlang/xhtml/h5.rb +34 -0
- data/lib/hyperlang/xhtml/h6.rb +34 -0
- data/lib/hyperlang/xhtml/head.rb +27 -0
- data/lib/hyperlang/xhtml/hr.rb +17 -0
- data/lib/hyperlang/xhtml/html.rb +17 -0
- data/lib/hyperlang/xhtml/i.rb +22 -0
- data/lib/hyperlang/xhtml/iframe.rb +40 -0
- data/lib/hyperlang/xhtml/img.rb +35 -0
- data/lib/hyperlang/xhtml/input.rb +55 -0
- data/lib/hyperlang/xhtml/ins.rb +38 -0
- data/lib/hyperlang/xhtml/isindex.rb +19 -0
- data/lib/hyperlang/xhtml/kbd.rb +20 -0
- data/lib/hyperlang/xhtml/label.rb +24 -0
- data/lib/hyperlang/xhtml/legend.rb +22 -0
- data/lib/hyperlang/xhtml/li.rb +42 -0
- data/lib/hyperlang/xhtml/link.rb +31 -0
- data/lib/hyperlang/xhtml/map.rb +35 -0
- data/lib/hyperlang/xhtml/menu.rb +21 -0
- data/lib/hyperlang/xhtml/meta.rb +23 -0
- data/lib/hyperlang/xhtml/namespace.rb +10 -0
- data/lib/hyperlang/xhtml/noframes.rb +46 -0
- data/lib/hyperlang/xhtml/noscript.rb +42 -0
- data/lib/hyperlang/xhtml/object.rb +48 -0
- data/lib/hyperlang/xhtml/ol.rb +25 -0
- data/lib/hyperlang/xhtml/optgroup.rb +23 -0
- data/lib/hyperlang/xhtml/option.rb +25 -0
- data/lib/hyperlang/xhtml/p.rb +36 -0
- data/lib/hyperlang/xhtml/param.rb +23 -0
- data/lib/hyperlang/xhtml/pre.rb +32 -0
- data/lib/hyperlang/xhtml/q.rb +22 -0
- data/lib/hyperlang/xhtml/rb.rb +20 -0
- data/lib/hyperlang/xhtml/rbc.rb +19 -0
- data/lib/hyperlang/xhtml/rp.rb +19 -0
- data/lib/hyperlang/xhtml/rt.rb +22 -0
- data/lib/hyperlang/xhtml/rtc.rb +23 -0
- data/lib/hyperlang/xhtml/ruby.rb +27 -0
- data/lib/hyperlang/xhtml/s.rb +20 -0
- data/lib/hyperlang/xhtml/samp.rb +20 -0
- data/lib/hyperlang/xhtml/script.rb +25 -0
- data/lib/hyperlang/xhtml/select.rb +37 -0
- data/lib/hyperlang/xhtml/small.rb +22 -0
- data/lib/hyperlang/xhtml/span.rb +24 -0
- data/lib/hyperlang/xhtml/strike.rb +20 -0
- data/lib/hyperlang/xhtml/strong.rb +22 -0
- data/lib/hyperlang/xhtml/style.rb +23 -0
- data/lib/hyperlang/xhtml/sub.rb +20 -0
- data/lib/hyperlang/xhtml/sup.rb +20 -0
- data/lib/hyperlang/xhtml/table.rb +43 -0
- data/lib/hyperlang/xhtml/tbody.rb +27 -0
- data/lib/hyperlang/xhtml/td.rb +42 -0
- data/lib/hyperlang/xhtml/textarea.rb +41 -0
- data/lib/hyperlang/xhtml/tfoot.rb +27 -0
- data/lib/hyperlang/xhtml/th.rb +42 -0
- data/lib/hyperlang/xhtml/thead.rb +27 -0
- data/lib/hyperlang/xhtml/title.rb +15 -0
- data/lib/hyperlang/xhtml/tr.rb +29 -0
- data/lib/hyperlang/xhtml/tt.rb +20 -0
- data/lib/hyperlang/xhtml/u.rb +20 -0
- data/lib/hyperlang/xhtml/ul.rb +23 -0
- data/lib/hyperlang/xhtml/var.rb +20 -0
- data/lib/hyperlang/xhtml/xhtml.rb +147 -0
- data/lib/hyperlang.rb +16 -0
- data/spec/hyperlang/round_trip_spec.rb +86 -0
- data/spec/hyperlang/xhtml/block_spec.rb +56 -0
- data/spec/hyperlang/xhtml/inline_spec.rb +60 -0
- data/spec/spec_helper.rb +17 -0
- metadata +173 -0
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
|
|
5
|
+
module Hyperlang
|
|
6
|
+
module Xhtml
|
|
7
|
+
# === Structure Module (4) ===
|
|
8
|
+
autoload :Html, "hyperlang/xhtml/html"
|
|
9
|
+
autoload :Head, "hyperlang/xhtml/head"
|
|
10
|
+
autoload :Title, "hyperlang/xhtml/title"
|
|
11
|
+
autoload :Body, "hyperlang/xhtml/body"
|
|
12
|
+
|
|
13
|
+
# === Text Module - Block (10) ===
|
|
14
|
+
autoload :Div, "hyperlang/xhtml/div"
|
|
15
|
+
autoload :P, "hyperlang/xhtml/p"
|
|
16
|
+
autoload :Pre, "hyperlang/xhtml/pre"
|
|
17
|
+
autoload :Address, "hyperlang/xhtml/address"
|
|
18
|
+
autoload :H1, "hyperlang/xhtml/h1"
|
|
19
|
+
autoload :H2, "hyperlang/xhtml/h2"
|
|
20
|
+
autoload :H3, "hyperlang/xhtml/h3"
|
|
21
|
+
autoload :H4, "hyperlang/xhtml/h4"
|
|
22
|
+
autoload :H5, "hyperlang/xhtml/h5"
|
|
23
|
+
autoload :H6, "hyperlang/xhtml/h6"
|
|
24
|
+
|
|
25
|
+
# === Text Module - Inline Phrasal (11) ===
|
|
26
|
+
autoload :Abbr, "hyperlang/xhtml/abbr"
|
|
27
|
+
autoload :Acronym, "hyperlang/xhtml/acronym"
|
|
28
|
+
autoload :Cite, "hyperlang/xhtml/cite"
|
|
29
|
+
autoload :Code, "hyperlang/xhtml/code"
|
|
30
|
+
autoload :Dfn, "hyperlang/xhtml/dfn"
|
|
31
|
+
autoload :Em, "hyperlang/xhtml/em"
|
|
32
|
+
autoload :Kbd, "hyperlang/xhtml/kbd"
|
|
33
|
+
autoload :Q, "hyperlang/xhtml/q"
|
|
34
|
+
autoload :Samp, "hyperlang/xhtml/samp"
|
|
35
|
+
autoload :Strong, "hyperlang/xhtml/strong"
|
|
36
|
+
autoload :Var, "hyperlang/xhtml/var"
|
|
37
|
+
|
|
38
|
+
# === Text Module - Inline Structural (2) ===
|
|
39
|
+
autoload :Span, "hyperlang/xhtml/span"
|
|
40
|
+
autoload :Br, "hyperlang/xhtml/br"
|
|
41
|
+
|
|
42
|
+
# === Hypertext Module (1) ===
|
|
43
|
+
autoload :A, "hyperlang/xhtml/a"
|
|
44
|
+
|
|
45
|
+
# === List Module (6) ===
|
|
46
|
+
autoload :Dl, "hyperlang/xhtml/dl"
|
|
47
|
+
autoload :Dt, "hyperlang/xhtml/dt"
|
|
48
|
+
autoload :Dd, "hyperlang/xhtml/dd"
|
|
49
|
+
autoload :Ol, "hyperlang/xhtml/ol"
|
|
50
|
+
autoload :Ul, "hyperlang/xhtml/ul"
|
|
51
|
+
autoload :Li, "hyperlang/xhtml/li"
|
|
52
|
+
|
|
53
|
+
# === Object Module (2) ===
|
|
54
|
+
autoload :Object, "hyperlang/xhtml/object"
|
|
55
|
+
autoload :Param, "hyperlang/xhtml/param"
|
|
56
|
+
|
|
57
|
+
# === Presentation Module (8) ===
|
|
58
|
+
autoload :B, "hyperlang/xhtml/b"
|
|
59
|
+
autoload :Big, "hyperlang/xhtml/big"
|
|
60
|
+
autoload :I, "hyperlang/xhtml/i"
|
|
61
|
+
autoload :Small, "hyperlang/xhtml/small"
|
|
62
|
+
autoload :Sub, "hyperlang/xhtml/sub"
|
|
63
|
+
autoload :Sup, "hyperlang/xhtml/sup"
|
|
64
|
+
autoload :Tt, "hyperlang/xhtml/tt"
|
|
65
|
+
autoload :Hr, "hyperlang/xhtml/hr"
|
|
66
|
+
|
|
67
|
+
# === Edit Module (2) ===
|
|
68
|
+
autoload :Del, "hyperlang/xhtml/del"
|
|
69
|
+
autoload :Ins, "hyperlang/xhtml/ins"
|
|
70
|
+
|
|
71
|
+
# === BIDI Module (1) ===
|
|
72
|
+
autoload :Bdo, "hyperlang/xhtml/bdo"
|
|
73
|
+
|
|
74
|
+
# === Forms Module (10) ===
|
|
75
|
+
autoload :Form, "hyperlang/xhtml/form"
|
|
76
|
+
autoload :Fieldset, "hyperlang/xhtml/fieldset"
|
|
77
|
+
autoload :Legend, "hyperlang/xhtml/legend"
|
|
78
|
+
autoload :Label, "hyperlang/xhtml/label"
|
|
79
|
+
autoload :Input, "hyperlang/xhtml/input"
|
|
80
|
+
autoload :Select, "hyperlang/xhtml/select"
|
|
81
|
+
autoload :Optgroup, "hyperlang/xhtml/optgroup"
|
|
82
|
+
autoload :Option, "hyperlang/xhtml/option"
|
|
83
|
+
autoload :Textarea, "hyperlang/xhtml/textarea"
|
|
84
|
+
autoload :Button, "hyperlang/xhtml/button"
|
|
85
|
+
|
|
86
|
+
# === Table Module (10) ===
|
|
87
|
+
autoload :Table, "hyperlang/xhtml/table"
|
|
88
|
+
autoload :Caption, "hyperlang/xhtml/caption"
|
|
89
|
+
autoload :Colgroup, "hyperlang/xhtml/colgroup"
|
|
90
|
+
autoload :Col, "hyperlang/xhtml/col"
|
|
91
|
+
autoload :Thead, "hyperlang/xhtml/thead"
|
|
92
|
+
autoload :Tfoot, "hyperlang/xhtml/tfoot"
|
|
93
|
+
autoload :Tbody, "hyperlang/xhtml/tbody"
|
|
94
|
+
autoload :Tr, "hyperlang/xhtml/tr"
|
|
95
|
+
autoload :Th, "hyperlang/xhtml/th"
|
|
96
|
+
autoload :Td, "hyperlang/xhtml/td"
|
|
97
|
+
|
|
98
|
+
# === Image Module (1) ===
|
|
99
|
+
autoload :Img, "hyperlang/xhtml/img"
|
|
100
|
+
|
|
101
|
+
# === Client-side Image Map Module (2) ===
|
|
102
|
+
autoload :Map, "hyperlang/xhtml/map"
|
|
103
|
+
autoload :Area, "hyperlang/xhtml/area"
|
|
104
|
+
|
|
105
|
+
# === Metainformation Module (1) ===
|
|
106
|
+
autoload :Meta, "hyperlang/xhtml/meta"
|
|
107
|
+
|
|
108
|
+
# === Scripting Module (2) ===
|
|
109
|
+
autoload :Script, "hyperlang/xhtml/script"
|
|
110
|
+
autoload :Noscript, "hyperlang/xhtml/noscript"
|
|
111
|
+
|
|
112
|
+
# === Stylesheet Module (1) ===
|
|
113
|
+
autoload :Style, "hyperlang/xhtml/style"
|
|
114
|
+
|
|
115
|
+
# === Link Module (1) ===
|
|
116
|
+
autoload :Link, "hyperlang/xhtml/link"
|
|
117
|
+
|
|
118
|
+
# === Base Module (1) ===
|
|
119
|
+
autoload :Base, "hyperlang/xhtml/base"
|
|
120
|
+
|
|
121
|
+
# === Ruby Module (6) ===
|
|
122
|
+
autoload :Ruby, "hyperlang/xhtml/ruby"
|
|
123
|
+
autoload :Rbc, "hyperlang/xhtml/rbc"
|
|
124
|
+
autoload :Rtc, "hyperlang/xhtml/rtc"
|
|
125
|
+
autoload :Rb, "hyperlang/xhtml/rb"
|
|
126
|
+
autoload :Rt, "hyperlang/xhtml/rt"
|
|
127
|
+
autoload :Rp, "hyperlang/xhtml/rp"
|
|
128
|
+
|
|
129
|
+
# === XHTML 1.0 Transitional-only (11) ===
|
|
130
|
+
autoload :Applet, "hyperlang/xhtml/applet"
|
|
131
|
+
autoload :Basefont, "hyperlang/xhtml/basefont"
|
|
132
|
+
autoload :Center, "hyperlang/xhtml/center"
|
|
133
|
+
autoload :Dir, "hyperlang/xhtml/dir"
|
|
134
|
+
autoload :Font, "hyperlang/xhtml/font"
|
|
135
|
+
autoload :Iframe, "hyperlang/xhtml/iframe"
|
|
136
|
+
autoload :Isindex, "hyperlang/xhtml/isindex"
|
|
137
|
+
autoload :Menu, "hyperlang/xhtml/menu"
|
|
138
|
+
autoload :S, "hyperlang/xhtml/s"
|
|
139
|
+
autoload :Strike, "hyperlang/xhtml/strike"
|
|
140
|
+
autoload :U, "hyperlang/xhtml/u"
|
|
141
|
+
|
|
142
|
+
# === XHTML 1.0 Frameset-only (3) ===
|
|
143
|
+
autoload :Frame, "hyperlang/xhtml/frame"
|
|
144
|
+
autoload :Frameset, "hyperlang/xhtml/frameset"
|
|
145
|
+
autoload :Noframes, "hyperlang/xhtml/noframes"
|
|
146
|
+
end
|
|
147
|
+
end
|
data/lib/hyperlang.rb
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "lutaml/model"
|
|
4
|
+
require "hyperlang/version"
|
|
5
|
+
require "hyperlang/xhtml/namespace"
|
|
6
|
+
|
|
7
|
+
# Topologically sorted load order (computed from dependency analysis).
|
|
8
|
+
%w[
|
|
9
|
+
a abbr acronym applet area b base basefont bdo big br caption cite code col colgroup dfn em font frame hr i iframe img input isindex kbd label legend link meta option optgroup param object q rb rbc rp rt rtc ruby s samp script select small span strike strong dt h1 h2 h3 h4 h5 h6 p address li dir menu ol pre style sub sup td textarea th title head tr tbody tfoot thead table tt u ul dd div blockquote button center del dl fieldset form ins map noscript body html noframes frameset var
|
|
10
|
+
].each do |name|
|
|
11
|
+
require "hyperlang/xhtml/#{name}"
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
module Hyperlang
|
|
15
|
+
# Your code goes here...
|
|
16
|
+
end
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe "XHTML round-trip" do
|
|
6
|
+
def round_trip(xml)
|
|
7
|
+
doc = Hyperlang::Xhtml::Div.from_xml(xml)
|
|
8
|
+
Nokogiri::XML(doc.to_xml, &:noblanks)
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
it "round-trips a div with mixed content" do
|
|
12
|
+
input = <<~XML
|
|
13
|
+
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
14
|
+
<xhtml:p>Paragraph with <xhtml:span style="bold">bold</xhtml:span> text</xhtml:p>
|
|
15
|
+
<xhtml:p>Another paragraph</xhtml:p>
|
|
16
|
+
</xhtml:div>
|
|
17
|
+
XML
|
|
18
|
+
output = round_trip(input)
|
|
19
|
+
|
|
20
|
+
input_doc = Nokogiri::XML(input, &:noblanks)
|
|
21
|
+
expect(output.root.to_html).to eq(input_doc.root.to_html)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
it "round-trips a table" do
|
|
25
|
+
input = <<~XML
|
|
26
|
+
<xhtml:table xmlns:xhtml="http://www.w3.org/1999/xhtml" border="1">
|
|
27
|
+
<xhtml:tr>
|
|
28
|
+
<xhtml:td>A</xhtml:td>
|
|
29
|
+
<xhtml:td>B</xhtml:td>
|
|
30
|
+
</xhtml:tr>
|
|
31
|
+
</xhtml:table>
|
|
32
|
+
XML
|
|
33
|
+
table = Hyperlang::Xhtml::Table.from_xml(input)
|
|
34
|
+
output = Nokogiri::XML(table.to_xml, &:noblanks)
|
|
35
|
+
input_doc = Nokogiri::XML(input, &:noblanks)
|
|
36
|
+
|
|
37
|
+
expect(output.root.to_html).to eq(input_doc.root.to_html)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
it "round-trips a list" do
|
|
41
|
+
input = <<~XML
|
|
42
|
+
<xhtml:ul xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
43
|
+
<xhtml:li>First item</xhtml:li>
|
|
44
|
+
<xhtml:li>Second item</xhtml:li>
|
|
45
|
+
<xhtml:li>Third item</xhtml:li>
|
|
46
|
+
</xhtml:ul>
|
|
47
|
+
XML
|
|
48
|
+
ul = Hyperlang::Xhtml::Ul.from_xml(input)
|
|
49
|
+
output = Nokogiri::XML(ul.to_xml, &:noblanks)
|
|
50
|
+
input_doc = Nokogiri::XML(input, &:noblanks)
|
|
51
|
+
|
|
52
|
+
expect(output.root.to_html).to eq(input_doc.root.to_html)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
it "round-trips a div with spans" do
|
|
56
|
+
input = <<~XML
|
|
57
|
+
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
58
|
+
<xhtml:span>First</xhtml:span>
|
|
59
|
+
<xhtml:span>Second</xhtml:span>
|
|
60
|
+
</xhtml:div>
|
|
61
|
+
XML
|
|
62
|
+
output = round_trip(input)
|
|
63
|
+
input_doc = Nokogiri::XML(input, &:noblanks)
|
|
64
|
+
|
|
65
|
+
expect(output.root.to_html).to eq(input_doc.root.to_html)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
it "round-trips an html document" do
|
|
69
|
+
input = <<~XML
|
|
70
|
+
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
71
|
+
<xhtml:head>
|
|
72
|
+
<xhtml:title>Test Page</xhtml:title>
|
|
73
|
+
</xhtml:head>
|
|
74
|
+
<xhtml:body>
|
|
75
|
+
<xhtml:h1>Heading</xhtml:h1>
|
|
76
|
+
<xhtml:p>Content</xhtml:p>
|
|
77
|
+
</xhtml:body>
|
|
78
|
+
</xhtml:html>
|
|
79
|
+
XML
|
|
80
|
+
html = Hyperlang::Xhtml::Html.from_xml(input)
|
|
81
|
+
output = Nokogiri::XML(html.to_xml, &:noblanks)
|
|
82
|
+
input_doc = Nokogiri::XML(input, &:noblanks)
|
|
83
|
+
|
|
84
|
+
expect(output.root.to_html).to eq(input_doc.root.to_html)
|
|
85
|
+
end
|
|
86
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Hyperlang::Xhtml::Ul do
|
|
6
|
+
it "parses an unordered list" do
|
|
7
|
+
xml = <<~XML
|
|
8
|
+
<xhtml:ul xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
9
|
+
<xhtml:li>Item 1</xhtml:li>
|
|
10
|
+
<xhtml:li>Item 2</xhtml:li>
|
|
11
|
+
</xhtml:ul>
|
|
12
|
+
XML
|
|
13
|
+
ul = described_class.from_xml(xml)
|
|
14
|
+
expect(ul.li.length).to eq(2)
|
|
15
|
+
expect(ul.li.first.content).to eq("Item 1")
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
RSpec.describe Hyperlang::Xhtml::Table do
|
|
20
|
+
it "parses a table with rows and cells" do
|
|
21
|
+
xml = <<~XML
|
|
22
|
+
<xhtml:table xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
23
|
+
<xhtml:tr>
|
|
24
|
+
<xhtml:td>Cell 1</xhtml:td>
|
|
25
|
+
<xhtml:td>Cell 2</xhtml:td>
|
|
26
|
+
</xhtml:tr>
|
|
27
|
+
</xhtml:table>
|
|
28
|
+
XML
|
|
29
|
+
table = described_class.from_xml(xml)
|
|
30
|
+
expect(table.tr.length).to eq(1)
|
|
31
|
+
expect(table.tr.first.td.length).to eq(2)
|
|
32
|
+
expect(table.tr.first.td.first.content).to eq("Cell 1")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
it "parses a table with thead and tbody" do
|
|
36
|
+
xml = <<~XML
|
|
37
|
+
<xhtml:table xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
38
|
+
<xhtml:thead>
|
|
39
|
+
<xhtml:tr>
|
|
40
|
+
<xhtml:th>Header</xhtml:th>
|
|
41
|
+
</xhtml:tr>
|
|
42
|
+
</xhtml:thead>
|
|
43
|
+
<xhtml:tbody>
|
|
44
|
+
<xhtml:tr>
|
|
45
|
+
<xhtml:td>Data</xhtml:td>
|
|
46
|
+
</xhtml:tr>
|
|
47
|
+
</xhtml:tbody>
|
|
48
|
+
</xhtml:table>
|
|
49
|
+
XML
|
|
50
|
+
table = described_class.from_xml(xml)
|
|
51
|
+
expect(table.thead).not_to be_nil
|
|
52
|
+
expect(table.thead.tr.first.th.first.content).to eq("Header")
|
|
53
|
+
expect(table.tbody.length).to eq(1)
|
|
54
|
+
expect(table.tbody.first.tr.first.td.first.content).to eq("Data")
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "spec_helper"
|
|
4
|
+
|
|
5
|
+
RSpec.describe Hyperlang::Xhtml::Span do
|
|
6
|
+
it "parses a span with text content" do
|
|
7
|
+
xml = '<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml">Hello</xhtml:span>'
|
|
8
|
+
span = described_class.from_xml(xml)
|
|
9
|
+
expect(span.content).to eq("Hello")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "round-trips a span with style attribute" do
|
|
13
|
+
xml = '<xhtml:span xmlns:xhtml="http://www.w3.org/1999/xhtml" style="font-weight: bold">text</xhtml:span>'
|
|
14
|
+
span = described_class.from_xml(xml)
|
|
15
|
+
expect(span.style).to eq("font-weight: bold")
|
|
16
|
+
expect(span.to_xml).to include('style="font-weight: bold"')
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
RSpec.describe Hyperlang::Xhtml::P do
|
|
21
|
+
it "parses a paragraph with text content" do
|
|
22
|
+
xml = '<xhtml:p xmlns:xhtml="http://www.w3.org/1999/xhtml">Hello world</xhtml:p>'
|
|
23
|
+
p = described_class.from_xml(xml)
|
|
24
|
+
expect(p.content).to eq("Hello world")
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "parses a paragraph with nested spans" do
|
|
28
|
+
xml = <<~XML
|
|
29
|
+
<xhtml:p xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
30
|
+
Hello <xhtml:span style="bold">world</xhtml:span>
|
|
31
|
+
</xhtml:p>
|
|
32
|
+
XML
|
|
33
|
+
p = described_class.from_xml(xml)
|
|
34
|
+
expect(p.span.length).to eq(1)
|
|
35
|
+
expect(p.span.first.content).to eq("world")
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it "round-trips a paragraph with class attribute" do
|
|
39
|
+
xml = '<xhtml:p xmlns:xhtml="http://www.w3.org/1999/xhtml" class="note">text</xhtml:p>'
|
|
40
|
+
p = described_class.from_xml(xml)
|
|
41
|
+
expect(p.klass).to eq("note")
|
|
42
|
+
regenerated = p.to_xml
|
|
43
|
+
expect(regenerated).to include("note")
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
RSpec.describe Hyperlang::Xhtml::Div do
|
|
48
|
+
it "parses a div with nested paragraphs" do
|
|
49
|
+
xml = <<~XML
|
|
50
|
+
<xhtml:div xmlns:xhtml="http://www.w3.org/1999/xhtml">
|
|
51
|
+
<xhtml:p>First</xhtml:p>
|
|
52
|
+
<xhtml:p>Second</xhtml:p>
|
|
53
|
+
</xhtml:div>
|
|
54
|
+
XML
|
|
55
|
+
div = described_class.from_xml(xml)
|
|
56
|
+
expect(div.p.length).to eq(2)
|
|
57
|
+
expect(div.p.first.content).to eq("First")
|
|
58
|
+
expect(div.p.last.content).to eq("Second")
|
|
59
|
+
end
|
|
60
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "hyperlang"
|
|
4
|
+
require "nokogiri"
|
|
5
|
+
|
|
6
|
+
RSpec.configure do |config|
|
|
7
|
+
config.example_status_persistence_file_path = ".rspec_status"
|
|
8
|
+
config.disable_monkey_patching!
|
|
9
|
+
config.expect_with :rspec do |c|
|
|
10
|
+
c.syntax = :expect
|
|
11
|
+
end
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
require "lutaml/model"
|
|
15
|
+
Lutaml::Model::Config.configure do |config|
|
|
16
|
+
config.xml_adapter_type = :nokogiri
|
|
17
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: hyperlang
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Ribose Inc.
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: lutaml-model
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: 0.8.0
|
|
19
|
+
type: :runtime
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: 0.8.0
|
|
26
|
+
description: XHTML 1.1 Strict, Transitional, and Frameset element models for Lutaml
|
|
27
|
+
email:
|
|
28
|
+
- open.source@ribose.com
|
|
29
|
+
executables: []
|
|
30
|
+
extensions: []
|
|
31
|
+
extra_rdoc_files: []
|
|
32
|
+
files:
|
|
33
|
+
- ".github/workflows/rake.yml"
|
|
34
|
+
- ".github/workflows/release.yml"
|
|
35
|
+
- ".gitignore"
|
|
36
|
+
- ".rspec"
|
|
37
|
+
- ".rubocop.yml"
|
|
38
|
+
- ".rubocop_todo.yml"
|
|
39
|
+
- Gemfile
|
|
40
|
+
- README.adoc
|
|
41
|
+
- Rakefile
|
|
42
|
+
- hyperlang.gemspec
|
|
43
|
+
- lib/hyperlang.rb
|
|
44
|
+
- lib/hyperlang/version.rb
|
|
45
|
+
- lib/hyperlang/xhtml/a.rb
|
|
46
|
+
- lib/hyperlang/xhtml/abbr.rb
|
|
47
|
+
- lib/hyperlang/xhtml/acronym.rb
|
|
48
|
+
- lib/hyperlang/xhtml/address.rb
|
|
49
|
+
- lib/hyperlang/xhtml/applet.rb
|
|
50
|
+
- lib/hyperlang/xhtml/area.rb
|
|
51
|
+
- lib/hyperlang/xhtml/b.rb
|
|
52
|
+
- lib/hyperlang/xhtml/base.rb
|
|
53
|
+
- lib/hyperlang/xhtml/basefont.rb
|
|
54
|
+
- lib/hyperlang/xhtml/bdo.rb
|
|
55
|
+
- lib/hyperlang/xhtml/big.rb
|
|
56
|
+
- lib/hyperlang/xhtml/blockquote.rb
|
|
57
|
+
- lib/hyperlang/xhtml/body.rb
|
|
58
|
+
- lib/hyperlang/xhtml/br.rb
|
|
59
|
+
- lib/hyperlang/xhtml/button.rb
|
|
60
|
+
- lib/hyperlang/xhtml/caption.rb
|
|
61
|
+
- lib/hyperlang/xhtml/center.rb
|
|
62
|
+
- lib/hyperlang/xhtml/cite.rb
|
|
63
|
+
- lib/hyperlang/xhtml/code.rb
|
|
64
|
+
- lib/hyperlang/xhtml/col.rb
|
|
65
|
+
- lib/hyperlang/xhtml/colgroup.rb
|
|
66
|
+
- lib/hyperlang/xhtml/dd.rb
|
|
67
|
+
- lib/hyperlang/xhtml/del.rb
|
|
68
|
+
- lib/hyperlang/xhtml/dfn.rb
|
|
69
|
+
- lib/hyperlang/xhtml/dir.rb
|
|
70
|
+
- lib/hyperlang/xhtml/div.rb
|
|
71
|
+
- lib/hyperlang/xhtml/dl.rb
|
|
72
|
+
- lib/hyperlang/xhtml/dt.rb
|
|
73
|
+
- lib/hyperlang/xhtml/em.rb
|
|
74
|
+
- lib/hyperlang/xhtml/fieldset.rb
|
|
75
|
+
- lib/hyperlang/xhtml/font.rb
|
|
76
|
+
- lib/hyperlang/xhtml/form.rb
|
|
77
|
+
- lib/hyperlang/xhtml/frame.rb
|
|
78
|
+
- lib/hyperlang/xhtml/frameset.rb
|
|
79
|
+
- lib/hyperlang/xhtml/h1.rb
|
|
80
|
+
- lib/hyperlang/xhtml/h2.rb
|
|
81
|
+
- lib/hyperlang/xhtml/h3.rb
|
|
82
|
+
- lib/hyperlang/xhtml/h4.rb
|
|
83
|
+
- lib/hyperlang/xhtml/h5.rb
|
|
84
|
+
- lib/hyperlang/xhtml/h6.rb
|
|
85
|
+
- lib/hyperlang/xhtml/head.rb
|
|
86
|
+
- lib/hyperlang/xhtml/hr.rb
|
|
87
|
+
- lib/hyperlang/xhtml/html.rb
|
|
88
|
+
- lib/hyperlang/xhtml/i.rb
|
|
89
|
+
- lib/hyperlang/xhtml/iframe.rb
|
|
90
|
+
- lib/hyperlang/xhtml/img.rb
|
|
91
|
+
- lib/hyperlang/xhtml/input.rb
|
|
92
|
+
- lib/hyperlang/xhtml/ins.rb
|
|
93
|
+
- lib/hyperlang/xhtml/isindex.rb
|
|
94
|
+
- lib/hyperlang/xhtml/kbd.rb
|
|
95
|
+
- lib/hyperlang/xhtml/label.rb
|
|
96
|
+
- lib/hyperlang/xhtml/legend.rb
|
|
97
|
+
- lib/hyperlang/xhtml/li.rb
|
|
98
|
+
- lib/hyperlang/xhtml/link.rb
|
|
99
|
+
- lib/hyperlang/xhtml/map.rb
|
|
100
|
+
- lib/hyperlang/xhtml/menu.rb
|
|
101
|
+
- lib/hyperlang/xhtml/meta.rb
|
|
102
|
+
- lib/hyperlang/xhtml/namespace.rb
|
|
103
|
+
- lib/hyperlang/xhtml/noframes.rb
|
|
104
|
+
- lib/hyperlang/xhtml/noscript.rb
|
|
105
|
+
- lib/hyperlang/xhtml/object.rb
|
|
106
|
+
- lib/hyperlang/xhtml/ol.rb
|
|
107
|
+
- lib/hyperlang/xhtml/optgroup.rb
|
|
108
|
+
- lib/hyperlang/xhtml/option.rb
|
|
109
|
+
- lib/hyperlang/xhtml/p.rb
|
|
110
|
+
- lib/hyperlang/xhtml/param.rb
|
|
111
|
+
- lib/hyperlang/xhtml/pre.rb
|
|
112
|
+
- lib/hyperlang/xhtml/q.rb
|
|
113
|
+
- lib/hyperlang/xhtml/rb.rb
|
|
114
|
+
- lib/hyperlang/xhtml/rbc.rb
|
|
115
|
+
- lib/hyperlang/xhtml/rp.rb
|
|
116
|
+
- lib/hyperlang/xhtml/rt.rb
|
|
117
|
+
- lib/hyperlang/xhtml/rtc.rb
|
|
118
|
+
- lib/hyperlang/xhtml/ruby.rb
|
|
119
|
+
- lib/hyperlang/xhtml/s.rb
|
|
120
|
+
- lib/hyperlang/xhtml/samp.rb
|
|
121
|
+
- lib/hyperlang/xhtml/script.rb
|
|
122
|
+
- lib/hyperlang/xhtml/select.rb
|
|
123
|
+
- lib/hyperlang/xhtml/small.rb
|
|
124
|
+
- lib/hyperlang/xhtml/span.rb
|
|
125
|
+
- lib/hyperlang/xhtml/strike.rb
|
|
126
|
+
- lib/hyperlang/xhtml/strong.rb
|
|
127
|
+
- lib/hyperlang/xhtml/style.rb
|
|
128
|
+
- lib/hyperlang/xhtml/sub.rb
|
|
129
|
+
- lib/hyperlang/xhtml/sup.rb
|
|
130
|
+
- lib/hyperlang/xhtml/table.rb
|
|
131
|
+
- lib/hyperlang/xhtml/tbody.rb
|
|
132
|
+
- lib/hyperlang/xhtml/td.rb
|
|
133
|
+
- lib/hyperlang/xhtml/textarea.rb
|
|
134
|
+
- lib/hyperlang/xhtml/tfoot.rb
|
|
135
|
+
- lib/hyperlang/xhtml/th.rb
|
|
136
|
+
- lib/hyperlang/xhtml/thead.rb
|
|
137
|
+
- lib/hyperlang/xhtml/title.rb
|
|
138
|
+
- lib/hyperlang/xhtml/tr.rb
|
|
139
|
+
- lib/hyperlang/xhtml/tt.rb
|
|
140
|
+
- lib/hyperlang/xhtml/u.rb
|
|
141
|
+
- lib/hyperlang/xhtml/ul.rb
|
|
142
|
+
- lib/hyperlang/xhtml/var.rb
|
|
143
|
+
- lib/hyperlang/xhtml/xhtml.rb
|
|
144
|
+
- spec/hyperlang/round_trip_spec.rb
|
|
145
|
+
- spec/hyperlang/xhtml/block_spec.rb
|
|
146
|
+
- spec/hyperlang/xhtml/inline_spec.rb
|
|
147
|
+
- spec/spec_helper.rb
|
|
148
|
+
homepage: https://github.com/lutaml/hyperlang
|
|
149
|
+
licenses:
|
|
150
|
+
- MIT
|
|
151
|
+
metadata:
|
|
152
|
+
homepage_uri: https://github.com/lutaml/hyperlang
|
|
153
|
+
source_code_uri: https://github.com/lutaml/hyperlang
|
|
154
|
+
changelog_uri: https://github.com/lutaml/hyperlang/releases
|
|
155
|
+
rubygems_mfa_required: 'true'
|
|
156
|
+
rdoc_options: []
|
|
157
|
+
require_paths:
|
|
158
|
+
- lib
|
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
160
|
+
requirements:
|
|
161
|
+
- - ">="
|
|
162
|
+
- !ruby/object:Gem::Version
|
|
163
|
+
version: 3.0.0
|
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
165
|
+
requirements:
|
|
166
|
+
- - ">="
|
|
167
|
+
- !ruby/object:Gem::Version
|
|
168
|
+
version: '0'
|
|
169
|
+
requirements: []
|
|
170
|
+
rubygems_version: 3.6.9
|
|
171
|
+
specification_version: 4
|
|
172
|
+
summary: Complete XHTML model library for Lutaml
|
|
173
|
+
test_files: []
|