omd2tex.tools.markdown_parser module#

class omd2tex.tools.markdown_parser.MarkdownParser(parrentdir: str = '', filename: str = '', filedepth: int = 0, quotedepth=0)[source]#

Bases: BaseClass

re_text_files1 = re.compile('!?\\[\\[([^|\\[\\]]+?(?:\\.(?:md|tex|txt))?)(?:\\|([^\\[\\]]+))?\\]\\]')#
re_text_files2 = re.compile('!?\\[([^\\[\\]]*)\\]\\(([^)]*?)(?:\\.(md|tex|txt))?\\)')#
re_reference = re.compile('\\^([a-zA-Z0-9_-]+)')#
image_extensions_pattern = '\\.(?:png|jpg|jpeg|gif|bmp|svg|webp)(?=\\s*|$|\\|)'#
re_markdown_image = re.compile('!\\[([^\\]]*?)\\]\\(([^\\)]+?)(?:\\s+"([^"]*)")?\\)(?:\\s*\\^([a-zA-Z0-9_-]+))?', re.IGNORECASE)#
re_wiki_image = re.compile('!?\\[\\[([^\\]\\n]+?)\\]\\]?(?:\\s*\\^([a-zA-Z0-9_-]+))?', re.IGNORECASE)#
re_heading = re.compile('^(#{1,6})\\s+(.*)')#
re_footnote = re.compile('^\\s*\\[\\^([^\\]]+)\\]:(.*)')#
enumerate_pattern = '^(\\d+)[.)]\\s+(.+)$'#
check()[source]#

Print parsed elements and their LaTeX representation.

Iterates over collected elements and prints their string representation followed by the rendered LaTeX output. Helpful for debugging parsing results.

Parameters:

None

Returns:

None

Side Effects:

Writes diagnostic information to stdout.

from_file(filename: str) MarkdownParser[source]#

Parse markdown from a file into structured elements.

Resolves the file path via search settings, loads UTF-8 content, and delegates line parsing to the internal parser, preserving recursion metadata.

Parameters:

filename – Name of the markdown file to locate and parse.

Returns:

Self instance for chaining regardless of whether parsing succeeded.

Raises:

FileNotFoundError – Propagated if the search path does not exist.

from_text(text: str | List[str]) MarkdownParser[source]#

Parse raw markdown text supplied as a string or list of lines.

Converts string input to lines when necessary and populates the element list by invoking the internal parser.

Parameters:

text – Markdown content as a single string or list of lines.

Returns:

Self instance for chaining.

from_elements(list: list) MarkdownParser[source]#

Initialize parser state from preconstructed element objects.

Validates elements to avoid unsupported document types and processes them through post-parsing normalization steps.

Parameters:

list – Sequence of element instances to normalize.

Returns:

Self instance with processed elements.

Raises:

TypeError – If disallowed element types (Document or MarkdownParser) are provided.