Class: Coradoc::Mirror::Node

Inherits:
Lutaml::Model::Serializable
  • Object
show all
Defined in:
lib/coradoc/mirror/node.rb,
lib/coradoc/mirror/node.rb,
lib/coradoc/mirror/node.rb

Overview

ProseMirror-compatible document node.

Wire format:

{ "type": "paragraph", "attrs": {...}, "content": [...], "marks": [...] }

All built-in Node subclasses live below in this file so the TYPE_TO_CLASS registry can see every PM_TYPE at load time. Adding a new node type = adding one subclass (+ optional Attrs sub-model) and letting the registry walker pick it up (OCP).

The TYPE_TO_CLASS and POLYMORPHIC constants are declared up-front (empty) because subclass ‘key_value` blocks reference them at class load time. The table is populated and frozen after every subclass is defined at the bottom of this file.

Defined Under Namespace

Classes: Admonition, Bibliography, BibliographyEntry, Blockquote, BulletList, Caption, CodeBlock, DefinitionDescription, DefinitionList, DefinitionTerm, Document, Example, Figure, FootnoteEntry, FootnoteMarker, Footnotes, Frontmatter, FrontmatterEntry, FrontmatterValue, GenericBlock, Header, HorizontalRule, Image, ListItem, OpenBlock, OrderedList, Paragraph, Preamble, Section, Sections, Sidebar, SoftBreak, Table, TableBody, TableCell, TableHead, TableRow, Text, ThematicBreak, Toc, TocEntry, Verse

Constant Summary collapse

PM_TYPE =
'node'
TYPE_TO_CLASS =
{}
POLYMORPHIC =
{ attribute: 'type', class_map: TYPE_TO_CLASS }.freeze

Instance Method Summary collapse

Instance Method Details

#text_contentObject



39
40
41
42
43
# File 'lib/coradoc/mirror/node.rb', line 39

def text_content
  return '' unless content

  content.select { |c| c.is_a?(Node) }.map(&:text_content).join
end