SyMark is simply complexly fascinating software. It runs as a single main.rs file with very few dependencies and is designed to be straightforward and customizable.
Flow of Execution
The program starts by finding all
.syfiles (SiYuan's JSON note format) in a specifiedinputdirectory usingfind_sy_filesFor each note file:
Parse the note structure into the
Notedata structureExtract headings to build a table of contents using
extract_toc_itemsGenerate HTML representation of the note content via
generate_html_for_noteBlock Type Identification: The
render_blocksfunction processes each block based on itsTypefield:Paragraphs
Headings (with levels 1-6)
Lists (ordered, unordered, and task lists)
Code blocks (with syntax highlighting support)
Tables
Blockquotes
HTML blocks
And more specialized types
Text Formatting: Within text blocks,
render_text_markhandles:Basic formatting (bold, italic, underline, strikethrough)
Links (external URLs and internal references)
Code spans
Superscript and subscript
Highlighting
Block references (linking to other blocks by ID)
Inline memos
Cross-References: The system supports references between notes:
find_block_by_idlocates blocks by their unique identifiersfind_content_by_idextracts content from referenced blocksNodeBlockQueryEmbedhandles transclusions within other notesThis enables a wiki-like navigation experience between notes
HTML Safety and SiYuan Compatibility: Several safeguards ensure the generated HTML is safe and valid:
escape_htmlprevents HTML injection in user contentremove_zero_width_spacescleans up text to improve rendering (SiYuan uses zero-width spaces in certain contexts)get_style_classtranslates SiYuan's custom styling variables into appropriate HTML/CSS classesCareful handling of nested structures (lists within lists, etc.)
Navigation Generation: For each note, the system:
Extracts headings to build a table of contents via
extract_toc_itemsGenerates a hierarchical TOC via
generate_toc_htmlAdds a back navigation link (defined in
BACK_NAVIGATION_HTML)Creates links to related notes based on tags
Create navigation elements (table of contents, links to related notes)
Apply styling and formatting based on note properties
Generate index pages:
Main index page via
generate_index_pageCustom index pages via
generate_custom_index_pageTag-based index pages via
generate_tag_pageComplete note listing via
generate_all_notes_page
Copy any associated assets (images, CSS, etc.) using
find_and_copy_assetsandcopy_directoryCopy everything into the specified
outputdirectory and log all events in the terminal output