Class: Coradoc::Markdown::Transform::ToCoreModel

Inherits:
Object
  • Object
show all
Extended by:
TextExtraction
Defined in:
lib/coradoc/markdown/transform/to_core_model.rb

Overview

Transforms Markdown models to CoreModel equivalents

This transformer converts the format-specific Markdown model to the canonical CoreModel representation.

Class Method Summary collapse

Methods included from TextExtraction

extract_text

Class Method Details

.transform(model) ⇒ Coradoc::CoreModel::Base

Transform a Markdown model to CoreModel

Parameters:

Returns:

  • (Coradoc::CoreModel::Base)

    CoreModel equivalent



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/coradoc/markdown/transform/to_core_model.rb', line 19

def transform(model)
  case model
  when Coradoc::Markdown::Document
    transform_document(model)
  when Coradoc::Markdown::Heading
    transform_heading(model)
  when Coradoc::Markdown::Paragraph
    transform_paragraph(model)
  when Coradoc::Markdown::CodeBlock
    transform_code_block(model)
  when Coradoc::Markdown::Blockquote
    transform_blockquote(model)
  when Coradoc::Markdown::List
    transform_list(model)
  when Coradoc::Markdown::DefinitionList
    transform_definition_list(model)
  when Coradoc::Markdown::Table
    transform_table(model)
  when Coradoc::Markdown::Image
    transform_image(model)
  when Coradoc::Markdown::Link
    transform_link(model)
  when Coradoc::Markdown::Emphasis
    transform_inline(model, 'italic')
  when Coradoc::Markdown::Strong
    transform_inline(model, 'bold')
  when Coradoc::Markdown::Code
    transform_inline(model, 'monospace')
  when Coradoc::Markdown::Highlight
    transform_inline(model, 'highlight')
  when Coradoc::Markdown::Strikethrough
    transform_inline(model, 'strikethrough')
  when Coradoc::Markdown::Footnote
    transform_footnote(model)
  when Coradoc::Markdown::FootnoteReference
    transform_footnote_reference(model)
  when Coradoc::Markdown::Abbreviation
    transform_abbreviation(model)
  when Coradoc::Markdown::HorizontalRule
    transform_horizontal_rule(model)
  when Coradoc::Markdown::Math
    transform_math(model)
  when Coradoc::Markdown::Extension
    transform_extension(model)
  when Coradoc::Markdown::AttributeList
    transform_attribute_list(model)
  when Coradoc::Markdown::Text
    model.content.to_s
  when Array
    model.map { |item| transform(item) }
  else
    model
  end
end