Module: Coradoc::AsciiDoc::Parser::Inline

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

Instance Method Summary collapse

Instance Method Details

#attribute_referenceObject



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

def attribute_reference
  str('{').present? >> str('{') >>
    match('[a-zA-Z0-9_-]').repeat(1).as(:attribute_reference) >>
    str('}')
end

#bold_constrainedObject



13
14
15
16
17
18
19
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 13

def bold_constrained
  (str('*').present? >> str('*') >>
    match('[^*\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('*') >> str('*').absent? >>
     str("\n\n").absent?
  ).as(:bold_constrained)
end

#bold_unconstrainedObject



21
22
23
24
25
26
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 21

def bold_unconstrained
  (str('**').present? >> str('**') >>
    match('[^*\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('**')
  ).as(:bold_unconstrained)
end

#hard_line_breakObject



195
196
197
198
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 195

def hard_line_break
  ((str(' +') >> str("\n")) |
     (str('\\') >> str("\n"))).as(:hard_line_break)
end

#hard_line_break_marker?Boolean

AsciiDoc hard line break: a space followed by ‘+` at end of line, or a backslash at end of line. Both forms render as `
` inside the enclosing paragraph/verse. Recognised ahead of `text_unformatted` so the marker isn’t swallowed as plain text.

Returns:

  • (Boolean)


190
191
192
193
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 190

def hard_line_break_marker?
  (str(' +') >> str("\n")).present? |
    (str('\\') >> str("\n")).present?
end

#highlight_constrainedObject



58
59
60
61
62
63
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 58

def highlight_constrained
  (str('#') >>
    match('[^#\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('#') >> str('#').absent?
  ).as(:highlight_constrained)
end

#highlight_unconstrainedObject



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

def highlight_unconstrained
  (str('##') >>
    match('[^#\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('##')
  ).as(:highlight_unconstrained)
end

#inlineObject



200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 200

def inline
  bold_unconstrained |
    bold_constrained |
    span_unconstrained |
    span_constrained |
    italic_unconstrained |
    italic_constrained |
    highlight_unconstrained |
    highlight_constrained |
    monospace_unconstrained |
    monospace_constrained |
    superscript |
    subscript |
    attribute_reference |
    escaped_xref |
    cross_reference |
    term_inline |
    term_inline2 |
    footnote |
    stem |
    link |
    inline_image |
    inline_passthrough |
    underline |
    small |
    hard_line_break
end

#inline_chars?Boolean

Returns:

  • (Boolean)


171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 171

def inline_chars?
  match('[\[*#_{<^~`]').present? |
    str('http').present? |
    str('https').present? |
    str('link:').present? |
    str('image:').present? |
    str('+++').present? |
    str('pass:').present? |
    term_type.present? |
    str('footnote').present? |
    stem_type.present? |
    str('\\<<').present? |
    hard_line_break_marker?
end

#inline_imageObject



119
120
121
122
123
124
125
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 119

def inline_image
  (str('image:').present? >> str('image:') >>
    str(':').absent? >>
    match('[A-Za-z0-9_.\\-:/&?=+,%#~;]+').repeat(1).as(:path) >>
    attribute_list(:attribute_list).maybe
  ).as(:inline_image)
end

#inline_passthroughObject



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

def inline_passthrough
  inline_passthrough_triple_plus | inline_passthrough_macro
end

#inline_passthrough_macroObject

pass:` macro form. Equivalent semantic to triple-plus: the bracket payload survives all substitutions verbatim. Common use is inside monospace spans to keep characters like `<` from being re-interpreted as xref markers. The optional `subs` segment (`pass:quotes`) is consumed but currently ignored — the payload is always passed through raw.



143
144
145
146
147
148
149
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 143

def inline_passthrough_macro
  (str('pass:').present? >> str('pass:') >>
    match('[a-zA-Z,+]').repeat(0) >>
    str('[') >> (str(']]').absent? >> match('[^\]\n]')).repeat(1).as(:raw) >>
    str(']')
  ).as(:inline_passthrough)
end

#inline_passthrough_triple_plusObject

Triple-plus inline passthrough: ‘+++raw content+++`. The content passes through all substitutions verbatim. Common use is to embed raw HTML in AsciiDoc documents.



130
131
132
133
134
135
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 130

def inline_passthrough_triple_plus
  (str('+++') >>
    (str('+++').absent? >> match('[^\n]')).repeat(1).as(:raw) >>
    str('+++')
  ).as(:inline_passthrough)
end

#italic_constrainedObject



44
45
46
47
48
49
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 44

def italic_constrained
  (str('_') >> str('_').absent? >>
    match('[^_\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('_') >> str('_').absent?
  ).as(:italic_constrained)
end

#italic_unconstrainedObject



51
52
53
54
55
56
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 51

def italic_unconstrained
  (str('__') >>
    match('[^_\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('__')
  ).as(:italic_unconstrained)
end


108
109
110
111
112
113
114
115
116
117
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 108

def link
  ((str('http').present? | str('https').present? | str('ftp').present?) >>
    match('[A-Za-z0-9_.\\-:/&?=+,%#~;]+').repeat(1).as(:path) >>
    (str('[') >> match('[^\\]]').repeat(1).as(:text) >> str(']')).maybe
  ).as(:link) |
    (str('link:').present? >> str('link:') >>
      match('[A-Za-z0-9_.\\-:/&?=+,%#~;]+').repeat(1).as(:path) >>
      (str('[') >> match('[^\\]]').repeat(1).as(:text) >> str(']')).maybe
    ).as(:link)
end

#monospace_constrainedObject



72
73
74
75
76
77
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 72

def monospace_constrained
  (str('`') >>
    match('[^`\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('`') >> str('`').absent?
  ).as(:monospace_constrained)
end

#monospace_unconstrainedObject



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

def monospace_unconstrained
  (str('``') >>
    match('[^`\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('``')
  ).as(:monospace_unconstrained)
end

#smallObject



163
164
165
166
167
168
169
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 163

def small
  (attribute_list >> match('\\[.small\\]').as(:role) >>
    str('#') >>
    match('[^#\n]').repeat(1).as(:text) >>
    str('#')
  ).as(:small)
end

#spanObject



100
101
102
103
104
105
106
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 100

def span
  attribute_list >>
    (str('#') >>
      match('[^#\n]').repeat(1).as(:text) >>
       str('#') >> str('#').absent?
    ).as(:span)
end

#span_constrainedObject



28
29
30
31
32
33
34
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 28

def span_constrained
  (attribute_list >>
    str('#') >>
    match('[^#\n]').repeat(1).as(:text) >>
     str('#') >> str('#').absent?
  ).as(:span_constrained)
end

#span_unconstrainedObject



36
37
38
39
40
41
42
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 36

def span_unconstrained
  (attribute_list >>
    str('##') >>
    match('[^#\n]').repeat(1).as(:text) >>
     str('##')
  ).as(:span_unconstrained)
end

#subscriptObject



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

def subscript
  (str('~') >>
    match('[^~\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('~')
  ).as(:subscript)
end

#superscriptObject



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

def superscript
  (str('^') >>
    match('[^^\n]').repeat(1).as(:text).repeat(1, 1) >>
     str('^')
  ).as(:superscript)
end

#text_anyObject



243
244
245
246
247
248
249
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 243

def text_any
  (text_formatted |
          text_unformatted.as(:text)
  ).repeat(2) |
    text_formatted.repeat(1, 1) |
    text_unformatted
end

#text_formattedObject



239
240
241
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 239

def text_formatted
  (inline_chars? >> inline)
end

#text_unformattedObject



228
229
230
231
232
233
234
235
236
237
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 228

def text_unformatted
  # `str('\\<<').absent?` stops text from consuming the backslash of
  # an escaped xref (`\<<`). Without this guard, the `\` is taken as
  # plain text, the `<<` re-enters cross_reference, and the literal
  # escape is destroyed.
  (str('\\<<').absent? >>
    inline.absent? >>
    match("[^\n]")
  ).repeat(1)
end

#underlineObject



155
156
157
158
159
160
161
# File 'lib/coradoc/asciidoc/parser/inline.rb', line 155

def underline
  (attribute_list >> match('\\[.underline\\]').as(:role) >>
    str('#') >>
    match('[^#\n]').repeat(1).as(:text) >>
    str('#')
  ).as(:underline)
end