Class: CodelessCode::Markup::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/codeless_code/markup/parser.rb

Overview

Parses the body of a Fable, including HTML, MediaWiki syntax, and custom syntax, and returns it as an HTML DOM.

Constant Summary collapse

/\[\[(?:([^|]+)\|)?([^\]]+)\]\]/.freeze
ITALIC_PATTERN =

/some text/

%r{/([^/]+)/}.freeze
SUP_PATTERN =

{*}

/{{([^}]+)}}/.freeze
HR_PATTERN =
    • -

/^- - -(?: -)*$/.freeze
BR_PATTERN =

end of line //

%r{\s*//\s*(?:\n|$)}m.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(str) ⇒ Parser

Returns a new instance of Parser.



35
36
37
# File 'lib/codeless_code/markup/parser.rb', line 35

def initialize(str)
  @doc = Nokogiri::HTML(format('<main>%s</main>', str))
end

Instance Attribute Details

#docObject (readonly)

Returns the value of attribute doc.



33
34
35
# File 'lib/codeless_code/markup/parser.rb', line 33

def doc
  @doc
end

Instance Method Details

#callNokogiri::XML::Element

Returns The body of the fable, with non-HTML markup converted into HTML.

Returns:

  • (Nokogiri::XML::Element)

    The body of the fable, with non-HTML markup converted into HTML



41
42
43
44
45
46
47
# File 'lib/codeless_code/markup/parser.rb', line 41

def call
  new_elem(:main).tap do |main|
    paragraphs.each do |para|
      main << parse_paragraph(para) unless para.inner_html.empty?
    end
  end
end