module

Crst

Parser for reStructuredText documents

This module contains the core parsing logic for converting RST text into an abstract syntax tree (AST) composed of Node objects.

Constants

VERSION = {{ begin v = (read_file("/tmp/tmp.gmPAGK/src/src/../shard.yml")).lines.find(&.starts_with?("version:")) v ? (v.split(':')).last.strip : "unknown" end }}

Current version of the crst library, extracted from shard.yml at compile time

Class methods

parse(input : String, config : Config = Config.new) : Document

Parses RST text and returns the AST document structure

This is the main entry point for parsing RST content. It returns a Document node containing the complete AST that can be traversed or rendered to various output formats.

input - The RST text to parse config - Optional configuration for parsing behavior

Returns a Document containing all parsed nodes

Example:

doc = Crst.parse("Hello **World**")
doc.children.size # => 1
Source
to_html(input : String, config : Config = Config.new) : String

Converts RST text directly to HTML

This is a convenience method that combines parsing and rendering in a single step. For more control over the rendering process, use parse followed by HTMLRenderer.

input - The RST text to convert config - Optional configuration for parsing and rendering

Returns the HTML string representation

Example:

html = Crst.to_html("**Bold** text")
html # => "<p><strong>Bold</strong> text</p>\n"
Source
to_latex(input : String, config : Config = Config.new) : String

Converts RST text to LaTeX format

input - The RST text to convert config - Optional configuration for parsing and rendering

Returns the LaTeX string representation

Example:

latex = Crst.to_latex("Section\n=======")
latex.includes?("\\section") # => true
Source
to_text(input : String, config : Config = Config.new) : String

Converts RST text to plain text

Strips all markup and returns the text content only. Useful for generating summaries or search indexes.

input - The RST text to convert config - Optional configuration for parsing and rendering

Returns the plain text string

Example:

text = Crst.to_text("**Bold** text")
text # => "Bold text"
Source
to_xml(input : String, config : Config = Config.new) : String

Converts RST text to XML format

The XML output represents the AST structure in a machine-readable format that preserves all document semantics.

input - The RST text to convert config - Optional configuration for parsing and rendering

Returns the XML string representation

Example:

xml = Crst.to_xml("Paragraph")
xml.includes?("<paragraph>") # => true
Source

Nested types