markdown2 $ MdHeadingParserFactory :: SELF
Type of this instance, automatically specialized in every classmarkdown2 $ MdHeadingParserFactory :: try_start
Can the associated block parser can start at the current line inparser
?
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Object :: defaultinit
core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: Object :: output_class_name
Display class name on stdout (debug only).markdown2 :: MdBlockParserFactory :: try_start
Can the associated block parser can start at the current line inparser
?
markdown2 :: MdBlockParserFactory
Block parser factory for a block node for determining when a block starts
# Heading parser factory
class MdHeadingParserFactory
super MdBlockParserFactory
redef fun try_start(state, matched_block_parser) do
if state.indent >= 4 then return null
var next_non_space = state.next_non_space_index
var line = state.line_string
var paragraph = null
if matched_block_parser isa MdParagraphParser then
paragraph = matched_block_parser.content
end
var line_content = line.substring(next_non_space, line.length - next_non_space)
var match = line_content.search(re_atx_heading)
if match != null then
# ATX heading
var new_offset = next_non_space + match.subs.first.as(not null).length
var level = match.subs.first.as(not null).to_s.trim.length
# remove trailing ###s
var after_leading = line.substring(new_offset, line.length - new_offset)
var trailing = after_leading.search(re_atx_trailing)
var has_trailing = trailing != null
var trailing_length = if trailing != null then trailing.length else 0
var content = after_leading.replace(re_atx_trailing, "")
return (new MdBlockStart(
[new MdHeadingParser(
state.line,
next_non_space + 1,
new_offset + 1,
state.line,
new_offset + content.length + trailing_length,
level,
content,
has_trailing, false)])
).at_index(line.length)
end
if paragraph == null then return null
match = line_content.search(re_setext_heading)
if match == null then return null
var level = 2
if match.subs.first.as(not null).to_s.chars.first == '=' then level = 1
var content = paragraph.to_s
return (new MdBlockStart(
[new MdHeadingParser(
state.line - 1,
next_non_space + 1,
0,
state.line,
state.column + match.length,
level,
content,
false, true)])
).at_index(line.length).replacing_active_block_parser
end
end
lib/markdown2/markdown_block_parsing.nit:660,1--718,3