MiaoYan Documentation

repository·main·Indexed 27 days ago

https://github.com/tw93/miaoyan

A lightweight, local-first Markdown note-taking application for macOS featuring a Swift-native engine, split editor/preview modes, and cloud-drive sync integration. Documentation covers installation via Mac App Store, Homebrew, or GitHub; usage of the MiaoYan CLI; PPT mode; slash commands for mind maps and diagrams; and developer guidelines regarding the AppEnvironment facade, Storyboard UI bindings, and the editing/preview pipelines.

Tokens
7.5K
Snippets
23
Records
66
Agent score
92%

What's inside MiaoYan

  1. Understand the Editing and Preview Pipelines

    main

    Editing Pipeline (Hot Path)

    Keystrokes flow through EditTextView (a NSTextView subclass with CustomTextStorage) to NSTextStorage.processEditing. Performance is managed by NotesTextProcessor.checkPerformanceLevel:

    • Short text: Full Markdown highlighting via MarkdownRuleHighlighter.
    • Long/Large text (> 1 MB total OR > 64 KB per paragraph OR > 5000 lines): Simplified highlighting (skips code block regex).
    • Medium text (> 2000 lines): Simplified, but code highlighting remains active.

    Preview Pipeline

    Content flows from Note.content through swift-cmark-gfm to generate an HTML string. Post-render transforms (like math <br> cleanup and GitHub Alerts rewrites) are applied in renderMarkdownHTML. The MPreviewView (WKWebView) loads Resources/DownView.bundle/index.html. Subsequent edits use incremental DOM mutation rather than full reloads.

  2. Maintain Storyboard UI Bindings

    main

    MiaoYan uses Main.storyboard for its macOS UI. Certain bindings are strictly tied to specific class selectors and identifiers. Moving or renaming these will break the UI at runtime without compile-time errors:

    • ViewController.swift: Must remain the viewController scene; all @IBOutlet and @IBAction declarations must reside here.
    • SidebarProjectView: Loaded as an outline view subclass; use awakeFromNib for construction, not init.
    • NotesTableView: Cell views must use the identifier NSUserInterfaceItemIdentifier("NoteCellView").
    • SidebarProjectView cells: Must use the identifier "DataCell".
    • Action Chain: @IBAction methods in ViewController+Action.swift must maintain their exact ObjC selectors.
  3. Install MiaoYan Agent Skill

    main

    You can teach AI agents how to use MiaoYan's specific syntax, attachments, PPT patterns, and CLI workflows by installing the official skill.

    npx skills add tw93/MiaoYan/skills/miaoyan -g
  4. Update bundled frontend assets

    main

    Frontend assets used for WKWebView previews are located in Resources/DownView.bundle/. These are vendored manually rather than through SPM. To update an asset:

    1. Replace the existing file in Resources/DownView.bundle/.
    2. Regenerate the manifest hash using shasum -a 256 <path_to_file.min.js>.
    3. Update the entry in Resources/DownView.bundle/js/vendor/MANIFEST.json with the new version and hash.
    4. Commit the changes.
  5. Control element animations and fragments

    main

    To make items appear in a specific sequence (step-by-step), use the .element: directive with class="fragment" and data-fragment-index="n".

    Visual Effects for fragments:

    • fade-in / fade-out / fade-in-then-out
    • highlight-red / highlight-green
    • fade-up (slide up while fading in)
    • grow / shrink
    <!-- .element: class="fragment" data-fragment-index="1" -->
  6. Customize slide backgrounds

    main

    Use the .slide: directive in an HTML comment to apply custom backgrounds to specific slides. You can use colors, gradients, images, or even interactive iframes.

    • Color/Hex: <!-- .slide: data-background="#F8CB9E" -->
    • Iframe/Website: <!-- .slide: data-background-iframe="https://miaoyan.app/" -->
    • Interactive Background: <!-- .slide: data-background-interactive -->
    <!-- .slide: data-background="#F8CB9E" -->
  7. Build and Release Workflow

    main

    macOS Builds

    • App Store: Signed and uploaded by maintainers. Sparkle is excluded via #if !APPSTORE.
    • Direct Downloads: Run bash scripts/build.sh to produce a zipped .app.
    • Appcast Updates: The Sparkle appcast.xml is updated using scripts/release-ci/update_appcast.sh (requires Sparkle EdDSA private key).

    Versioning Requirement

    The following three version identifiers must remain aligned, or CI will reject the push:

    1. Git tag (e.g., Vx.y.z)
    2. MARKETING_VERSION
    3. CURRENT_PROJECT_VERSION