Class: CodelessCode::Markup::Parser
- Inherits:
-
Object
- Object
- CodelessCode::Markup::Parser
- 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
- LINK_PATTERN =
- [href|title]
-
or [[title]]
/\[\[(?:([^|]+)\|)?([^\]]+)\]\]/.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
-
#doc ⇒ Object
readonly
Returns the value of attribute doc.
Instance Method Summary collapse
-
#call ⇒ Nokogiri::XML::Element
The body of the fable, with non-HTML markup converted into HTML.
-
#initialize(str) ⇒ Parser
constructor
A new instance of Parser.
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
#doc ⇒ Object (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
#call ⇒ Nokogiri::XML::Element
Returns 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 |