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
.sy
files (SiYuan's JSON note format) in a specifiedinput
directory usingfind_sy_files
For each note file:
Parse the note structure into the
Note
data structureExtract headings to build a table of contents using
extract_toc_items
Generate HTML representation of the note content via
generate_html_for_note
Block Type Identification: The
render_blocks
function processes each block based on itsType
field: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_mark
handles: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_id
locates blocks by their unique identifiersfind_content_by_id
extracts content from referenced blocksNodeBlockQueryEmbed
handles 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_html
prevents HTML injection in user contentremove_zero_width_spaces
cleans up text to improve rendering (SiYuan uses zero-width spaces in certain contexts)get_style_class
translates 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_items
Generates a hierarchical TOC via
generate_toc_html
Adds 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_page
Custom index pages via
generate_custom_index_page
Tag-based index pages via
generate_tag_page
Complete note listing via
generate_all_notes_page
Copy any associated assets (images, CSS, etc.) using
find_and_copy_assets
andcopy_directory
Copy everything into the specified
output
directory and log all events in the terminal output