Module: Coradoc::Parser::Asciidoc::Content

Includes:
Base
Included in:
Section
Defined in:
lib/coradoc/parser/asciidoc/content.rb

Instance Method Summary collapse

Methods included from Base

#attribute_name, #attribute_value, #digits, #email, #empty_line, #endline, #keyword, #line_ending, #newline, #space, #space?, #special_character, #text, #words

Instance Method Details

#asciidoc_charObject



99
100
101
# File 'lib/coradoc/parser/asciidoc/content.rb', line 99

def asciidoc_char
  match("^[*_:=-]")
end

#asciidoc_char_with_idObject



103
104
105
# File 'lib/coradoc/parser/asciidoc/content.rb', line 103

def asciidoc_char_with_id
  asciidoc_char | str("[#") | str("[[")
end

#block_titleObject



89
90
91
# File 'lib/coradoc/parser/asciidoc/content.rb', line 89

def block_title
  str(".") >> text.as(:title) >> line_ending
end

#cell_contentObject



76
77
78
# File 'lib/coradoc/parser/asciidoc/content.rb', line 76

def cell_content
  str("|").absent? >> literal_space? >> words.as(:text)
end

#contentsObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/coradoc/parser/asciidoc/content.rb', line 21

def contents
  (
    example_block.as(:example) |
    list.as(:list) |
    table.as(:table) |
    highlight.as(:highlight) |
    glossaries.as(:glossaries) |
    paragraph.as(:paragraph) | empty_line
  ).repeat(1)
end

#definition_listObject



125
126
127
# File 'lib/coradoc/parser/asciidoc/content.rb', line 125

def definition_list
  dlist_item.repeat(1)
end

#dlist_itemObject



137
138
139
# File 'lib/coradoc/parser/asciidoc/content.rb', line 137

def dlist_item
  str("term") >> space >> digits >> str("::") >> space >> text_line
end

#empty_cell_contentObject



72
73
74
# File 'lib/coradoc/parser/asciidoc/content.rb', line 72

def empty_cell_content
  str("|").absent? >> literal_space.as(:text)
end

#example_blockObject



32
33
34
35
36
37
38
39
# File 'lib/coradoc/parser/asciidoc/content.rb', line 32

def example_block
  str("[example]") >> newline >>
  str("=").repeat(4).capture(:delimiter) >> newline >>
  dynamic do |source, context|
    (str(context.captures[:delimiter]).absent? >> text.as(:text) >> endline).repeat(1) >>
    str(context.captures[:delimiter]) >> endline
  end
end

#glossariesObject



11
12
13
# File 'lib/coradoc/parser/asciidoc/content.rb', line 11

def glossaries
  glossary.repeat(1)
end

#glossaryObject



112
113
114
115
# File 'lib/coradoc/parser/asciidoc/content.rb', line 112

def glossary
  keyword.as(:key) >> str("::") >> space? >>
  text.as(:value) >> line_ending.as(:break)
end

#highlightObject



41
42
43
44
# File 'lib/coradoc/parser/asciidoc/content.rb', line 41

def highlight
  text_id >> newline >>
  underline >> highlight_text >> newline
end

#highlight_textObject



50
51
52
# File 'lib/coradoc/parser/asciidoc/content.rb', line 50

def highlight_text
  str("#") >> words.as(:text) >> str("#")
end

#listObject

List



16
17
18
19
# File 'lib/coradoc/parser/asciidoc/content.rb', line 16

def list
  unnumbered_list.as(:unnumbered) |
    definition_list.as(:definition) | numbered_list.as(:numbered)
end

#literal_spaceObject



80
81
82
# File 'lib/coradoc/parser/asciidoc/content.rb', line 80

def literal_space
  (match[' '] | match[' \t']).repeat(1)
end

#literal_space?Boolean

Override

Returns:

  • (Boolean)


85
86
87
# File 'lib/coradoc/parser/asciidoc/content.rb', line 85

def literal_space?
  literal_space.maybe
end

#nlist_itemObject



129
130
131
# File 'lib/coradoc/parser/asciidoc/content.rb', line 129

def nlist_item
  match("\.") >> space >> text_line
end

#numbered_listObject



117
118
119
# File 'lib/coradoc/parser/asciidoc/content.rb', line 117

def numbered_list
  nlist_item.repeat(1)
end

#paragraphObject



7
8
9
# File 'lib/coradoc/parser/asciidoc/content.rb', line 7

def paragraph
  text_line.repeat(1)
end

#tableObject

Table



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

def table
  block_title >>
  str("|===") >> line_ending >>
  table_row.repeat(1).as(:rows) >>
  str("|===") >> line_ending
end

#table_rowObject



62
63
64
65
# File 'lib/coradoc/parser/asciidoc/content.rb', line 62

def table_row
  (literal_space? >> str("|") >> (cell_content | empty_cell_content)).
    repeat(1).as(:cols) >> line_ending
end

#text_idObject



107
108
109
110
# File 'lib/coradoc/parser/asciidoc/content.rb', line 107

def text_id
  str("[[") >> keyword.as(:id) >> str("]]") |
    str("[#") >> keyword.as(:id) >> str("]")
end

#text_lineObject

Text



94
95
96
97
# File 'lib/coradoc/parser/asciidoc/content.rb', line 94

def text_line
  (asciidoc_char_with_id.absent? | text_id) >> literal_space? >>
  text.as(:text) >> line_ending.as(:break)
end

#ulist_itemObject



133
134
135
# File 'lib/coradoc/parser/asciidoc/content.rb', line 133

def ulist_item
  match("\\*") >> space >> text_line
end

#underlineObject



46
47
48
# File 'lib/coradoc/parser/asciidoc/content.rb', line 46

def underline
  str("[underline]") | str("[.underline]")
end

#unnumbered_listObject



121
122
123
# File 'lib/coradoc/parser/asciidoc/content.rb', line 121

def unnumbered_list
  (ulist_item >> newline.maybe).repeat(1)
end

#wordObject

Extended



68
69
70
# File 'lib/coradoc/parser/asciidoc/content.rb', line 68

def word
  (match("[a-zA-Z0-9_-]") | str(".") | str("*") | match("@")).repeat(1)
end