Class: MaRuKu::In::Markdown::BlockLevelParser::LineSource
- Inherits:
-
Object
- Object
- MaRuKu::In::Markdown::BlockLevelParser::LineSource
show all
- Includes:
- Strings
- Defined in:
- lib/maruku/input/linesource.rb
Overview
This represents a source of lines that can be consumed.
It is the twin of CharSource.
Constant Summary
Constants included
from Strings
Strings::Abbreviation, Strings::AttributeDefinitionList, Strings::Definition, Strings::EMailAddress, Strings::FootnoteText, Strings::HeaderWithAttributes, Strings::HeaderWithId, Strings::IncompleteLink, Strings::InlineAttributeList, Strings::LinkRegex, Strings::MightBeTableHeader, Strings::Sep, Strings::TabSize, Strings::TableSeparator, Strings::URL
Instance Method Summary
collapse
Methods included from Strings
#add_tabs, #dbg_describe_ary, #force_linebreak?, #line_md_type, #normalize_key_and_value, #num_leading_hashes, #number_of_leading_spaces, #parse_email_headers, #spaces_before_first_char, #split_lines, #strip_hashes, #strip_indent, #unquote
Constructor Details
#initialize(lines, parent = nil, parent_offset = nil) ⇒ LineSource
Returns a new instance of LineSource.
32
33
34
35
36
37
38
|
# File 'lib/maruku/input/linesource.rb', line 32
def initialize(lines, parent=nil, parent_offset=nil)
raise "NIL lines? " if not lines
@lines = lines
@lines_index = 0
@parent = parent
@parent_offset = parent_offset
end
|
Instance Method Details
#cur_index ⇒ Object
87
88
89
|
# File 'lib/maruku/input/linesource.rb', line 87
def cur_index
@lines_index
end
|
40
|
# File 'lib/maruku/input/linesource.rb', line 40
def cur_line() @lines[@lines_index] end
|
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
# File 'lib/maruku/input/linesource.rb', line 55
def describe
s = "At line #{original_line_number(@lines_index)}\n"
context = 3 from = [@lines_index-context, 0].max
to = [@lines_index+context, @lines.size-1].min
for i in from..to
prefix = (i == @lines_index) ? '--> ' : ' ';
l = @lines[i]
s += "%10s %4s|#{l}" %
[@lines[i].md_type.to_s, prefix]
s += "|\n"
end
s
end
|
#ignore_line ⇒ Object
50
51
52
53
|
# File 'lib/maruku/input/linesource.rb', line 50
def ignore_line
raise "Over the rainbow" if @lines_index >= @lines.size
@lines_index += 1
end
|
#next_line ⇒ Object
41
|
# File 'lib/maruku/input/linesource.rb', line 41
def next_line() @lines[@lines_index+1] end
|
#original_line_number(index) ⇒ Object
79
80
81
82
83
84
85
|
# File 'lib/maruku/input/linesource.rb', line 79
def original_line_number(index)
if @parent
return index + @parent.original_line_number(@parent_offset)
else
1 + index
end
end
|
#shift_line ⇒ Object
43
44
45
46
47
48
|
# File 'lib/maruku/input/linesource.rb', line 43
def shift_line()
raise "Over the rainbow" if @lines_index >= @lines.size
l = @lines[@lines_index]
@lines_index += 1
return l
end
|
#tell_me_the_future ⇒ Object
Returns the type of next line as a string breaks at first :definition
93
94
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/maruku/input/linesource.rb', line 93
def tell_me_the_future
s = ""; num_e = 0;
for i in @lines_index..@lines.size-1
c = case @lines[i].md_type
when :text; "t"
when :empty; num_e+=1; "e"
when :definition; "d"
else "o"
end
s += c
break if c == "d" or num_e>1
end
s
end
|