omd2tex.tools#
- class omd2tex.tools.Settings[source]#
Bases:
ConfigBase- class Parse[source]#
Bases:
ConfigBase- merge_elements = True#
- class Export[source]#
Bases:
ConfigBase- search_dir = '~/Obsidian/'#
- search_ignore_dirs = ['.trash', '.obsidian', '.plugins', '.smart-env', '.reference-map']#
- makefile = True#
- export_dir = './test/'#
- branching_project = False#
- class Frontmatter[source]#
Bases:
ConfigBase- parse = True#
- class Beamer[source]#
Bases:
ConfigBase- divide_element = ['splitline', 'headline']#
- class Paragraph[source]#
Bases:
ConfigBase- latinify = True#
- latinify_probability = 0.05#
- latinify_json = ''#
- formulas_json = ''#
- class Preamble[source]#
Bases:
ConfigBase- create_preamble = True#
- settings_json = ''#
- class File[source]#
Bases:
ConfigBase- parse = True#
- max_file_recursion = 5#
- pass_if_not_found = True#
- divide_with_new_page = True#
- class Headline[source]#
Bases:
ConfigBase- parse = True#
- global_level_align = True#
- numeration = True#
- clean_markdown_numeration = False#
- clean_all_highlight = True#
- class Image[source]#
Bases:
ConfigBase- parse = True#
- absolute_path_in_project_export = False#
- copy_to_folder_in_project_export = True#
- wh_aspect_borders = [0.6, 1.8]#
- default_width = '8cm'#
- default_height = '8cm'#
- class Quote[source]#
Bases:
ConfigBase- parse = True#
- max_quote_recursion = 5#
- class List[source]#
Bases:
ConfigBase- itemsep = '0pt'#
- class Codeblock[source]#
Bases:
ConfigBase- parse = True#
- class Fragment[source]#
Bases:
ConfigBase- class Splitline[source]#
Bases:
ConfigBase- parse = True#
- width = '0.5pt'#
- class Caption[source]#
Bases:
ConfigBase- parse = True#
- class omd2tex.tools.Global[source]#
Bases:
ConfigBase- REFERENCE_DICT = {}#
- MIN_HEADLINE_LEVEL = 100#
- CITATION_INITIALIZED = False#
- CREATE_PROJECT = False#
- YAML_DICT = {}#
- DOCUMENT_CLASS = 'article'#
- DOCUMENT_NAME = ''#
- ERROR_CATCHER = True#
- omd2tex.tools.find_file(filename: str, search_path: str | None = None) str | None[source]#
Locate a file by name within a search path honoring ignore rules.
Performs a recursive walk starting from the configured or provided directory, skipping ignored directories, and returns the first path matching the target filename (case-sensitive first, then case-insensitive).
- Parameters:
filename – Target filename; path segments are stripped, and trailing whitespace is trimmed.
search_path – Optional root directory to search; defaults to Settings.Export.search_dir, expanded to user home. Falls back to CWD if None.
- Returns:
Absolute path to the first matching file, or None if not found.
- Raises:
FileNotFoundError – If the search directory does not exist.
- Side Effects:
Prints a not-found message to stdout if no match is located; prints comparison errors if they occur.
- omd2tex.tools.find_file_flexible(filename: str, search_path: str | None = None) str | None[source]#
Search for a file using multiple case variants and Unicode normalization.
Recursively walks the provided directory (or the current working directory by default) and compares several case and normalization variants of the target to discover matches.
- Parameters:
filename – Filename to search for; whitespace is preserved except for trailing and leading characters handled externally.
search_path – Optional root directory; defaults to the current working directory if None. Path is expanded for user home.
- Returns:
Absolute path of the first matched file, or None if no match is found.
- Raises:
FileNotFoundError – If the search directory does not exist.
- Side Effects:
Prints progress and results to stdout during the search.
- omd2tex.tools.list_files_in_directory(search_path: str | None = None) None[source]#
Print directory tree contents for debugging.
Walks the provided directory (or CWD) and prints folders and files with indentation reflecting depth to stdout.
- Parameters:
search_path – Optional directory to list; expanded for user home. Defaults to CWD when None.
- Returns:
None
- Side Effects:
Writes directory listings to stdout.
- omd2tex.tools.get_image_dimensions(file_path: str) Tuple[int, int] | None[source]#
Return width and height of an image file if available.
Attempts to open the file with Pillow and extract its dimensions; returns None if the file is missing or cannot be opened.
- Parameters:
file_path – Absolute or relative path to the image file.
- Returns:
Tuple of (width, height) in pixels when the file is readable, otherwise None.
- Raises:
None explicitly; FileNotFoundError is caught and suppressed. –
- class omd2tex.tools.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.
- class omd2tex.tools.Counter[source]#
Bases:
ConfigBase- Splitline = 0#
- class omd2tex.tools.SettingsPreamble[source]#
Bases:
ConfigBase- class Article[source]#
Bases:
ConfigBase- fontsize = '12pt'#
- linespread = 1.5#
- left = '2cm'#
- right = '2cm'#
- top = '2cm'#
- bottom = '2cm'#
- class Beamer[source]#
Bases:
ConfigBase- fontsize = '12pt'#
- linespread = 1.5#
- left = '0.5cm'#
- right = '0.5cm'#
- top = '0.5cm'#
- bottom = '0.5cm'#
- theme = 'blei'#
- colortheme = 'default'#
- fonttheme = 'professionalfonts'#
- title = ''#
- author = ''#
- institute = ''#
- date = ''#
- documentclass = 'article'#
- class omd2tex.tools.ErrorCompileCatcher(md_object: Document | File | MarkdownParser | List[Any])[source]#
Bases:
object- analyze(batch: int | None = None, total_errors: int = 1, rmdir: bool = True, print_analyzing: bool = True) List[ObjectImage][source]#
Analyze provided objects by compiling them and collecting errors.
- Parameters:
batch – Optional batch size for grouped compilation.
total_errors – Maximum errors to gather before early exit.
rmdir – Whether to delete the temporary export directory afterward.
print_analyzing – Toggle for progress output to stdout.
- Returns:
List of ObjectImage instances that failed compilation; empty list if none.
- Raises:
None explicitly; subprocess errors may propagate. –
- Side Effects:
Alters global error catcher flag, writes temporary files, and prints diagnostics.
- class omd2tex.tools.FrontMatterParser(filename: str | None = None, abs_path: str | None = None, text: List[str] | str = '')[source]#
Bases:
object- static quote_sensitive_yaml_values(yaml_text: str) str[source]#
Safely quote time-like YAML fields to preserve strings.
Wraps values for keys
startTime,endTime, anddatein quotes soyaml.safe_loaddoes not coerce them to numeric or timestamp types.- Parameters:
yaml_text – Raw YAML frontmatter text.
- Returns:
YAML text with targeted values quoted.
- Raises:
None explicitly. –
- update(new_dict: Dict) FrontMatterParser[source]#
Update the stored YAML dictionary with new keys and values.
- Parameters:
new_dict – Mapping of keys to merge into the existing YAML data.
- Returns:
Self instance after update.
- update_file(new_dict: Dict = {}) None[source]#
Persist updated YAML back to the associated file.
Merges new data into the current YAML, reconstructs the file with the updated frontmatter, and writes it to disk.
- Parameters:
new_dict – Optional mapping of additional values to merge before writing.
- Returns:
None
- Raises:
FileNotFoundError – If the target file is missing.
IOError – Propagated on write failures.
- class omd2tex.tools.MdDataBase(search_path: str = None)[source]#
Bases:
object- to_df() pandas.DataFrame[source]#
Collect frontmatter from markdown files into a DataFrame.
Walks the search path, parses frontmatter of each
.mdfile, and aggregates metadata into a pandas DataFrame.- Parameters:
None
- Returns:
pandas.DataFrame containing one row per markdown file with frontmatter fields plus filename and absolute path.
- Side Effects:
Reads files from disk.