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, #date, #digit, #digits, #email, #empty_line, #endline, #keyword, #line_ending, #newline, #rich_text, #rich_texts, #space, #space?, #special_character, #text, #word, #words

Instance Method Details

#asciidoc_charObject



119
120
121
# File 'lib/coradoc/parser/asciidoc/content.rb', line 119

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

#asciidoc_char_with_idObject



123
124
125
# File 'lib/coradoc/parser/asciidoc/content.rb', line 123

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

#blockObject



33
34
35
# File 'lib/coradoc/parser/asciidoc/content.rb', line 33

def block
  sidebar_block | example_block | source_block | quote_block
end

#block_style(delimiter = "*", repeater = 4) ⇒ Object



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

def block_style(delimiter="*", repeater = 4)
  block_title.maybe >>
  newline.maybe >>
  block_type.maybe >>
  str(delimiter).repeat(repeater).as(:delimiter) >> newline >>
  text_line.repeat(1).as(:lines) >>
  str(delimiter).repeat(repeater) >> newline
end

#block_titleObject



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

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

#block_typeObject



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

def block_type
  str("[") >> keyword.as(:type) >> str("]") >> newline
end

#cell_contentObject



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

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

#contentsObject



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

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

#definition_listObject



151
152
153
# File 'lib/coradoc/parser/asciidoc/content.rb', line 151

def definition_list
  dlist_item.repeat(1)
end

#dlist_itemObject



163
164
165
# File 'lib/coradoc/parser/asciidoc/content.rb', line 163

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

#empty_cell_contentObject



92
93
94
# File 'lib/coradoc/parser/asciidoc/content.rb', line 92

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

#example_blockObject



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

def example_block
  block_style("=")
end

#glossariesObject



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

def glossaries
  glossary.repeat(1)
end

#glossaryObject



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

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

#highlightObject



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

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

#highlight_textObject



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

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

#listObject

List



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

def list
  unordered_list.as(:unordered) |
    definition_list.as(:definition) | ordered_list.as(:ordered)
end

#literal_spaceObject



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

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

#literal_space?Boolean

Override

Returns:

  • (Boolean)


105
106
107
# File 'lib/coradoc/parser/asciidoc/content.rb', line 105

def literal_space?
  literal_space.maybe
end

#olist_itemObject



155
156
157
# File 'lib/coradoc/parser/asciidoc/content.rb', line 155

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

#ordered_listObject



143
144
145
# File 'lib/coradoc/parser/asciidoc/content.rb', line 143

def ordered_list
  olist_item.repeat(1)
end

#paragraphObject



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

def paragraph
  paragraph_meta.as(:meta).maybe >>
    text_line.repeat(1).as(:lines)
end

#paragraph_metaObject



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

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

#quote_blockObject



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

def quote_block
  block_style("_")
end


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

def sidebar_block
  block_style("*")
end

#source_blockObject



37
38
39
# File 'lib/coradoc/parser/asciidoc/content.rb', line 37

def source_block
  block_style("-", 2)
end

#tableObject

Table



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

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

#table_rowObject



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

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

#text_idObject



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

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

#text_lineObject

Text



114
115
116
117
# File 'lib/coradoc/parser/asciidoc/content.rb', line 114

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

#ulist_itemObject



159
160
161
# File 'lib/coradoc/parser/asciidoc/content.rb', line 159

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

#underlineObject



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

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

#unordered_listObject



147
148
149
# File 'lib/coradoc/parser/asciidoc/content.rb', line 147

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