Module: Coradoc::AsciiDoc::Parser::Paragraph

Defined in:
lib/coradoc/asciidoc/parser/paragraph.rb

Instance Method Summary collapse

Instance Method Details

#line_not_text?Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
# File 'lib/coradoc/asciidoc/parser/paragraph.rb', line 7

def line_not_text?
  line_start? >>
    (attribute_list >> newline).absent? >>
    block_delimiter.absent? >>
    (str('|===') >> newline).absent? >>
    list.absent? >>
    list_prefix.absent? >>
    list_continuation.absent? >>
    element_id.absent? >>
    section_prefix.absent?
end

#paragraphObject

rubocop:enable Style/OptionalBooleanParameter, Style/NumericPredicate



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/coradoc/asciidoc/parser/paragraph.rb', line 42

def paragraph
  (element_id.maybe >>
    block_title.maybe >>
    (attribute_list >> newline).maybe >>
    ((paragraph_text_line(0).repeat(1, 1) >>
           (newline.repeat(1).as(:line_break) | eof?)) |
      (paragraph_text_line(false).repeat(1) >>
      (paragraph_text_line(true).repeat(1, 1) >>
           (newline.repeat(1).as(:line_break) | eof?)).repeat(0, 1))
    ).as(:lines) >>
    (newline.repeat(0) | eof?)
  ).as(:paragraph)
end

#paragraph_attributesObject



56
57
58
59
60
# File 'lib/coradoc/asciidoc/parser/paragraph.rb', line 56

def paragraph_attributes
  str('[') >>
    keyword.as(:key) >> str('=') >>
    word.as(:value) >> str(']') >> newline
end

#paragraph_text_line(many_breaks = false) ⇒ Object

NOTE: many_breaks parameter has three states for different parsing contexts:

  • 0: Single line with EOF termination (no trailing newline)

  • true: Multiple lines with flexible newline handling

  • false: Single line with strict newline handling

This ternary logic handles different paragraph parsing scenarios in AsciiDoc. rubocop:disable Style/OptionalBooleanParameter, Style/NumericPredicate



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/coradoc/asciidoc/parser/paragraph.rb', line 25

def paragraph_text_line(many_breaks = false)
  tl = line_not_text? >>
       (asciidoc_char_with_id.absent? |
         (element_id_inline >> literal_space?) |
         (line_start? >> line_not_text?)) >>
       text_any.as(:text)
  # Use == 0 instead of .zero? because many_breaks can be false (not a number)
  if many_breaks == 0
    tl >> eof?
  elsif many_breaks
    tl >> (newline.as(:line_break) | eof?)
  else
    tl >> (newline_single.as(:line_break) | eof?)
  end
end