module

Asciidoctor::Parser

Inherits Asciidoctor::Logging

Internal: Methods to parse lines of AsciiDoc into an object hierarchy representing the structure of the document. All methods are module methods and should be invoked from the Parser module.

The object hierarchy created by the Parser consists of zero or more Section and Block objects. Section objects may be nested and a Section object contains zero or more Block objects.

Constants

AuthorKeys = Set {"author", "authorinitials", "firstname", "middlename", "lastname", "email"}
BLOCK_CONTEXT_MAP = {"abstract" => :abstract, "admonition" => :admonition, "asciimath" => :asciimath, "audio" => :audio, "colist" => :colist, "comment" => :comment, "dlist" => :dlist, "example" => :example, "fenced_code" => :fenced_code, "floating_title" => :floating_title, "image" => :image, "latexmath" => :latexmath, "listing" => :listing, "literal" => :literal, "olist" => :olist, "open" => :open, "page_break" => :page_break, "paragraph" => :paragraph, "partintro" => :partintro, "pass" => :pass, "preamble" => :preamble, "quote" => :quote, "sidebar" => :sidebar, "source" => :source, "stem" => :stem, "table" => :table, "thematic_break" => :thematic_break, "toc" => :toc, "ulist" => :ulist, "verse" => :verse, "video" => :video}
COMPLIANCE_MARKDOWN_SYNTAX = true
COMPLIANCE_UNDERLINE_STYLE_SECTION_TITLES = true
SETEXT_SECTION_LEVELS = {'=' => 0, '-' => 1, '~' => 2, '^' => 3, '+' => 4}

Setext (two-line) section title levels.

TAB = '\t'
TabIndentRx = /^\t+/
TableCellHorzAlignments = {'<' => "left", '>' => "right", '^' => "center"}

A Hash mapping horizontal alignment abbreviations to alignments

TableCellStyles = {'d' => :none, 's' => :strong, 'e' => :emphasis, 'm' => :monospaced, 'h' => :header, 'l' => :literal, 'a' => :asciidoc}

A Hash mapping style abbreviations to styles for table cells

TableCellVertAlignments = {'<' => "top", '>' => "bottom", '^' => "middle"}

A Hash mapping vertical alignment abbreviations to alignments

Instance methods

adjust_indentation!(lines : Array(String), indent_size : Int32 = 0, tab_size : Int32 = 0) : Nil

Remove the block indentation, replace tabs with spaces, and indent by margin.

Source
atx_section_title?(line : String) : Int32 | Nil

Check whether the line given is an atx section title.

Source
build_block(block_context : Symbol, content_model : ContentModel, terminator : String | Nil, parent : AbstractBlock, reader : Reader, attributes : Hash(String, String)) : Block | Nil

Build a block from delimited content.

Source
catalog_callouts(text : String, document : Document) : Bool

Catalog callout markers found in the text.

Source
catalog_inline_anchor(id : String, reftext : String | Nil, node : AbstractBlock, location : Reader | Cursor, doc : Document | Nil = nil) : Nil

Catalog a matched inline anchor.

Source
catalog_inline_anchors(text : String, block : AbstractBlock, document : Document, reader : Reader) : Nil

Catalog any inline anchors found in the text (but don't convert).

Source
catalog_inline_biblio_anchor(id : String, reftext : String | Nil, node : AbstractBlock, reader : Reader) : Nil

Catalog the bibliography inline anchor found in the start of the list item.

Source
extract_manpage_attributes(document : Document) : Nil

Extract manpage-specific attributes from the document title and NAME section. In Ruby Asciidoctor, the manpage doctype extracts manvolnum, manname, mantitle, and manpurpose from the document title (e.g., "command (1)") and the NAME section.

Source
initialize_section(reader : Reader, parent : AbstractBlock, attributes : Hash(String, String) = {} of String => String) : Section

Initialize a new Section from the reader.

Source
is_delimited_block?(line : String, return_match_data : Bool = false) : BlockMatchData | Nil

Determine whether this line is the start of a known delimited block.

Source
is_next_line_doctitle?(reader : Reader, attributes : Hash(String, String), leveloffset : String | Nil) : Bool

Check if the next line on the Reader is the document title.

Source
is_next_line_section?(reader : Reader, attributes : Hash(String, String)) : Int32 | Nil

Check if the next line on the Reader is a section title.

Source
is_section_title?(line1 : String, line2 : String | Nil = nil) : Int32 | Nil

Check whether the lines given are a section title (atx or setext).

Source
is_sibling_list_item?(line : String, list_type : Symbol, sibling_trait : String | Regex) : Bool

Check whether a line is a sibling list item.

Source
next_block(reader : Reader, parent : AbstractBlock, attributes : Hash(String, String) = {} of String => String, parse_metadata : Bool = true, text_only : Bool = false) : AbstractBlock | Nil

Parse and return the next Block at the Reader's current location.

Source
next_section(reader : Reader, parent : AbstractBlock, attributes : Hash(String, String) = {} of String => String) : Tuple(Section | Nil, Hash(String, String))

Return the next section from the Reader.

Source
parse(reader : Reader, document : Document, header_only : Bool = false) : Document

Public: Parses AsciiDoc source read from the Reader into the Document.

Source
parse_block_attribute_list(raw : String, attributes : Hash(String, String), block : AbstractBlock | Nil = nil) : Hash(String, String)

Parse a block attribute list into a Hash.

Source
parse_block_metadata_line(reader : Reader, document : Document, attributes : Hash(String, String), text_only : Bool = false) : Bool

Parse the next line if it contains metadata for the following block.

Source
parse_block_metadata_lines(reader : Reader, document : Document, attributes : Hash(String, String) = {} of String => String) : Hash(String, String)

Parse consecutive lines of block metadata.

Source
parse_blocks(reader : Reader, parent : AbstractBlock, attributes : Hash(String, String) | Nil = nil) : Nil

Parse blocks from this reader until there are no more lines.

Source
parse_callout_list(reader : Reader, match : Regex::MatchData, parent : AbstractBlock, callouts : Callouts) : List

Parse and construct a callout list Block from the current position of the Reader.

Source
parse_cellspec(line : String, pos : Symbol = :end, delimiter : String | Nil = nil) : Tuple(Hash(String, String | Int32) | Nil, String)

Parse a cell spec for a table.

Source
parse_colspecs(records : String) : Array(Hash(String, String | Int32))

Parse column specs for a table.

Source
parse_csv_cells(line : String, sep : String = ",") : Array(String)

Parse a CSV line into cells, handling quoted values with commas and escaped quotes.

Source
parse_description_list(reader : Reader, parent : AbstractBlock, attributes : Hash(String, String) = {} of String => String) : List

Parse a description list.

Source
parse_document_header(reader : Reader, document : Document, header_only : Bool = false) : Hash(String, String)

Parse the document header.

Source
parse_header_metadata(reader : Reader, document : Document) : Nil

Parse the header metadata (author line, revision line, attribute entries).

Source
parse_list(reader : Reader, list_type : Symbol, parent : AbstractBlock, attributes : Hash(String, String) = {} of String => String, start : String | Nil = nil) : List

Parse a list (unordered, ordered, or callout).

Source
parse_list_item(reader : Reader, list_block : List, match : Regex::MatchData, sibling_trait : String | Regex, style : String | Nil = nil) : ListItem

Parse and construct the next ListItem for the specified list Block.

Source
parse_manpage_header(reader : Reader, document : Document, block_attributes : Hash(String, String), header_only : Bool = false) : Nil

Parse the manpage-specific header metadata.

Source
parse_section_title(reader : Reader, document : Document, sect_id : String | Nil = nil) : Tuple(String | Nil, String | Nil, String, Int32, Bool)

Parse the section title from the current position of the reader.

Source
parse_style_attribute(attributes : Hash(String, String)) : String | Nil

Parse the style attribute shorthand (style#id.role%option).

Source
parse_table(table_reader : Reader, parent : AbstractBlock, attributes : Hash(String, String)) : Table

Parse a table from a reader.

Source
process_attribute_entries(reader : Reader, document : Document, attributes : Hash(String, String) | Nil = nil) : Nil

Process consecutive attribute entry lines.

Source
process_attribute_entry(reader : Reader, document : Document, attributes : Hash(String, String) | Nil = nil, match : Regex::MatchData | Nil = nil) : Bool

Process a single attribute entry line.

Source
process_authors(author_line : String, names_only : Bool = false, multiple : Bool = true) : Hash(String, String)

Process authors from an author line.

Source
read_lines_for_list_item(reader : Reader, list_type : Symbol, sibling_trait : String | Regex, has_text : Bool = true) : Array(String)

Collect the lines belonging to the current list item, navigating through all the rules that determine what comprises a list item.

Source
read_paragraph_lines(reader : Reader, break_on_list : Bool = false) : Array(String)

Read paragraph lines until a break condition is met.

Source
resolve_list_marker(list_type : Symbol, marker : String) : String

Resolve the 0-index marker for a list item.

Source
resolve_ordered_list_marker(marker : String, ordinal : Int32 | Nil = nil, validate : Bool = false, reader : Reader | Nil = nil) : Tuple(String, Symbol | Nil)

Resolve the 0-index marker for an ordered list item. When ordinal and validate are provided, validates the marker against the expected value.

Source
resolve_ordered_list_start(marker : String) : Int32

Resolve the start number for an ordered list based on its marker.

Source
sanitize_attribute_name(name : String) : String

Convert a string to a legal attribute name.

Source
setext_section_title?(line1 : String, line2 : String) : Int32 | Nil

Check whether the two lines form a setext-style section title.

Source
store_attribute(name : String, value : String, doc : Document | Nil = nil, attrs : Hash(String, String) | Nil = nil) : Tuple(String, String | Nil)

Store an attribute in the document.

Source
string_to_block_context(name : String) : Symbol | Nil

Convert a string to a block context Symbol.

Source
uniform?(str : String, chr : String, len : Int32) : Bool

Check if a string is uniform (all the same character).

Source
yield_buffered_attribute(attrs : Hash(Symbol, String | Array(String)), name : Symbol | Nil, value : String, reader : Reader | Nil = nil) : Nil

Save the collected attribute (:id, :option, :role, or nil for :style) in the attribute Hash.

Source