Complete XHTML 1.1 element model library for Lutaml.
hyperlang provides Ruby object models for every XHTML 1.1 element (Strict, Transitional, and Frameset variants), built on top of lutaml-model. Each element class inherits from Lutaml::Model::Serializable and supports XML round-trip serialization via the xml DSL.
require "hyperlang"html = Hyperlang::Xhtml::Html.from_xml(xhtml_string) puts html.head.title.content puts html.body.div.first.p.first.content
All 99 XHTML element classes live under Hyperlang::Xhtml:::
- Phrasal
-
Abbr,Acronym,Cite,Code,Dfn,Em,Kbd,Q,Samp,Strong,Var - Structural
-
Span,Br
All elements use the XHTML namespace http://www.w3.org/1999/xhtml with prefix xhtml.
Every element follows a consistent pattern:
class Hyperlang::Xhtml::P < Lutaml::Model::Serializable
attribute :content, :string
attribute :span, Hyperlang::Xhtml::Span, collection: true
attribute :klass, :string xml do
element "p"
namespace Hyperlang::Xhtml::Namespace
mixed_content
map_content to: :content
map_element "span", to: :span
map_attribute "class", to: :klass
end
end
Key conventions:
-
mixed_content+map_content to: :contentfor elements allowing text and child elements -
collection: truefor child elements that can appear multiple times -
XML
classattribute mapped to Ruby:klassto avoid collision with Ruby’sClass
Html
+-- Head
| +-- Title
| +-- Meta (collection)
| +-- Link (collection)
| +-- Style (collection)
| +-- Script (collection)
| +-- Base
+-- Body (mixed_content)
+-- Div, P, Span, A, Ul, Ol, Table, H1-H6, Pre, ...The reqif gem uses hyperlang for XHTML content within ReqIF documents. The <XHTML-CONTENT> element in ReqIF can contain any XHTML element, and reqif references hyperlang’s element classes for parsing and serializing rich text content.