Can the associated block parser can start at the current line in parser?

Return a new MdBlockStart if the block parser can start. Return null otherwise.

Property definitions

markdown2 $ MdBlockParserFactory :: try_start
	# Can the associated block parser can start at the current line in `parser`?
	#
	# Return a new `MdBlockStart` if the block parser can start.
	# Return null otherwise.
	fun try_start(parser: MdParser, matched_block_parser: MdBlockParser):
		nullable MdBlockStart is abstract
lib/markdown2/markdown_block_parsing.nit:558,2--563,35

markdown2 $ MdHeadingParserFactory :: try_start
	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
lib/markdown2/markdown_block_parsing.nit:664,2--717,4

markdown2 $ MdBlockQuoteParserFactory :: try_start
	redef fun try_start(state, matched_block_parser) do
		var next_non_space = state.next_non_space_index
		var indent = state.indent
		var line = state.line_string

		if indent >= 4 then return null
		if next_non_space >= line.length then return null
		if line.chars[next_non_space] != '>' then return null

		var new_column = state.column + state.indent + 1
		# optional following space or tab
		if state.line_string.is_space_or_tab(next_non_space + 1) then
			new_column += 1
		end
		return (new MdBlockStart(
			[new MdBlockQuoteParser(
				state.line,
				state.column + 1,
				new_column)])
			).at_column(new_column)
	end
lib/markdown2/markdown_block_parsing.nit:757,2--777,4

markdown2 $ MdIndentedCodeBlockParserFactory :: try_start
	redef fun try_start(state, matched_block_parser) do
		if state.indent < 4 then return null
		if state.is_blank then return null
		if state.active_block_parser.block isa MdParagraph then return null

		var use_tabs = state.line_string.has_prefix("\t")
		return (new MdBlockStart(
			[new MdIndentedCodeBlockParser(
				state.line,
				state.column + 1,
				state.column,
				use_tabs)])
			).at_column(state.column + 4)
	end
lib/markdown2/markdown_block_parsing.nit:827,2--840,4

markdown2 $ MdHtmlBlockParserFactory :: try_start
	redef fun try_start(state, matched_block_parser) do
		var next_non_space = state.next_non_space_index
		var line = state.line_string

		if state.indent >= 4 or line.chars[next_non_space] != '<' then return null

		for block_type in [0..6] do
			# type 7 can not interrupt a paragraph
			if block_type == 6 and matched_block_parser.block isa MdParagraph then continue
			var opener = re_html_blocks[block_type].first
			var closer = re_html_blocks[block_type].last
			if line.substring(next_non_space, line.length - next_non_space).has(opener.as(not null)) then
				return (new MdBlockStart(
					[new MdHtmlBlockParser(
						state.line,
						state.column + 1,
						next_non_space,
						closer)])
					).at_index(state.index)
			end
		end
		return null
	end
lib/markdown2/markdown_block_parsing.nit:1338,2--1360,4

markdown2 $ MdFencedCodeBlockParserFactory :: try_start
	redef fun try_start(state, matched_block_parser) do
		var next_non_space = state.next_non_space_index
		var line = state.line_string

		if state.indent >= 4 then return null

		var match = line.substring(next_non_space, line.length - next_non_space).search(re_opening_fence)
		if match == null then return null

		var fence_length
		var fence_char
		var sub0 = match.subs[0]
		if sub0 != null then
			fence_length = sub0.length
			fence_char = sub0.to_s.chars.first
		else
			fence_length = match.subs[2].as(not null).length
			fence_char = match.subs[2].as(not null).to_s.chars.first
		end
		if fence_char == '`' and match.to_s.has("[^`]+`".to_re) then
			return null
		else if match.to_s.has("[^~]+~".to_re) then
			return null
		end
		return (new MdBlockStart(
			[new MdFencedCodeBlockParser(
				state.line,
				state.column + 1,
				state.column,
				fence_char,
				fence_length,
				state.indent)]
			)).at_index(next_non_space + fence_length)
	end
lib/markdown2/markdown_block_parsing.nit:923,2--956,4

markdown2 $ MdListBlockParserFactory :: try_start
	redef fun try_start(state, matched_block_parser) do
		if state.indent >= 4 and not matched_block_parser isa MdListBlockParser then return null

		var marker_index = state.next_non_space_index
		var marker_column = state.column + state.indent

		var in_paragraph = matched_block_parser isa MdParagraphParser and matched_block_parser.content != null
		var list_data = parse_list_marker(state, state.line_string, marker_index, marker_column, in_paragraph)
		if list_data == null then return null


		var new_column = list_data.content_column
		var list_item_parser = new MdListItemParser(
			state.line,
			state.column + 1,
			new_column,
			new_column - state.column)

		# prepend the list block if needed
		if not matched_block_parser isa MdListBlockParser or not lists_match(matched_block_parser.block, list_data) then
			var list_block_parser = new MdListBlockParser(state.line, state.column + 1, new_column - state.column, list_data.is_ordered, list_data.bullet, list_data.digit, list_data.delim)
			list_block_parser.block.is_tight = true

			return (new MdBlockStart([list_block_parser, list_item_parser: MdBlockParser])).at_column(new_column)
		end
		return (new MdBlockStart([list_item_parser])).at_column(new_column)
	end
lib/markdown2/markdown_block_parsing.nit:1024,2--1050,4

markdown2 $ MdThematicBreakParserFactory :: try_start
	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 tbreak  = line.substring(next_non_space, line.length - next_non_space).search(re_thematic_break)
		if tbreak != null then
			return (new MdBlockStart(
				[new MdThematicBreakParser(
					state.line,
					state.column + 1,
					next_non_space,
					tbreak.to_s)]
				)).at_index(line.length)
		end
		return null
	end
lib/markdown2/markdown_block_parsing.nit:1201,2--1217,4