mdts (Markdown Tree Server)

repository·main·Indexed 42 days ago

https://github.com/unhappychoice/mdts

A zero-config CLI tool and Node.js module for previewing local Markdown files in a tree-based web interface with live reloading. Version 0.20.6 features a File Tree API, Outline API, and Configuration API for managing visual settings like themes and fonts. Supports glob pattern filtering via the --glob flag and can be run without installation using npx.

Tokens
14.5K
Snippets
66
Records
88
Agent score
51%

What's inside mdts

  1. Core features of mdts

    main

    mdts provides several key capabilities for managing markdown-based documentation:

    • Markdown Rendering: Converts markdown files into clean HTML.
    • File Tree Navigation: Provides an intuitive interface to browse files and directories.
    • Outline View: Generates an outline for each file to allow quick section jumping.
    • Live Reload: Automatically updates the view when markdown files are modified.
    • Custom Themes: Supports over 20 application themes and syntax highlighting options.
  2. Navigate the mdts interface layout

    main

    The mdts web interface is organized into three primary panels to facilitate efficient Markdown browsing and reading:

    • File Tree (Left Panel): Used for folder navigation (expand/collapse), file searching by filename, and quick file access. Includes controls to expand or collapse all folders at once.
    • Document Viewer (Center Panel): The main reading area. It renders Markdown (including Mermaid diagrams and syntax-highlighted code), displays breadcrumbs for path navigation, and shows a Frontmatter Panel for document metadata (title, tags, author).
    • Outline Panel (Right Panel): Provides a hierarchical Table of Contents of the current document. Clicking any heading allows for quick jumps to specific sections.

    A Header Bar at the top provides access to the Settings dialog, the project GitHub repository, and version information.

  3. What is Frontmatter and how to use it

    main

    Frontmatter is a block of metadata (typically YAML or JSON) placed at the very top of a Markdown file. It is enclosed by triple-dashed lines (---) and is used to store structured information about the document that can be used by processors, static site generators, or documentation tools.

    To implement frontmatter, place the YAML block at the start of your file before any other content.

    ---
    title: My Awesome Document
    author: Gemini CLI
    date: 2025-07-18
    tags:
      - markdown
      - frontmatter
      - example
    category: Documentation
    published: true
    version: 1.0.0
    ---
    
    This document demonstrates the use of **Frontmatter**.
  4. Understand mdts configuration storage mechanisms

    main

    mdts uses two distinct storage mechanisms depending on the type of setting:

    1. Browser Settings (localStorage): These are specific to each browser and domain. They control UI-specific preferences such as:

      • Theme preferences (light/dark mode)
      • Application color themes
      • Layout mode (compact/full-width)
      • Panel visibility (file tree, outline)
      • File tree expanded state
      • Recent file paths
    2. System Configuration File: A JSON file shared across all browser sessions, located at ~/.config/mdts/config.json. This stores core application settings like fonts and themes.

  5. Security considerations for mdts

    main

    When running mdts, keep the following security aspects in mind:

    Network Access

    • Localhost (Default): Running npx mdts without flags is the most secure method as it limits access to your local machine.
    • Network Accessible: Using --host 0.0.0.0 makes the server accessible over your network. Use this with caution.

    File and Content Security

    • File Access: mdts can only access files within the directory you have mounted. It does not perform any file write operations.
    • Content Security: Inline HTML is processed and rendered. External links are preserved as-is, but mdts does not automatically fetch external content.
  6. Understand how mdts stores settings

    main

    Settings are managed through two layers:

    Browser Settings (localStorage)

    Stored in your browser to manage session-specific UI preferences:

    • Theme settings: Dark/light mode, application color themes, syntax highlighting themes.
    • Layout preferences: Content width (compact/full), panel visibility.
    • File tree state: Expanded/collapsed folder states and recent file paths.

    System Configuration File

    Global preferences are saved to ~/.config/mdts/config.json on your system:

    • Font settings: Font family, size, and monospace preferences.
    • Global theme preferences: Default theme and syntax highlighting settings.
  7. Understand mdts settings persistence

    main

    Settings in mdts are stored in two distinct locations to balance browser flexibility with system-wide consistency:

    1. Browser Storage (localStorage): Stores UI-specific preferences such as theme preferences, layout settings, and the current state of the file tree.
    2. System Configuration: Core preferences and font settings are saved to the local filesystem at ~/.config/mdts/config.json to maintain consistency across different browser sessions.
  8. Watch files for changes using the WebSocket Interface

    main

    The mdts server provides a WebSocket interface for real-time file watching and live reloading.

    Connection URL: ws://localhost:8521

    File Watching

    To start watching a specific file for changes, send a watch-file message via the WebSocket:

    {
      "type": "watch-file",
      "path": "relative/path/to/file.md"
    }

    Live Reload

    When a watched file changes, the server will emit a reload message to the client:

    {
      "type": "reload",
      "path": "path/to/changed/file.md"
    }
  9. Use GitHub Flavored Markdown (GFM) extensions

    main

    Beyond standard CommonMark, mdts supports several GFM extensions:

    • Autolinks: Bare URLs like https://example.com automatically become clickable.
    • Strikethrough: Use ~~text~~ to render text.
    • Tables & Task Lists: (See above).
    • GitHub-Style Alerts: Create admonitions using blockquote syntax with specific identifiers:
      • > [!NOTE]
      • > [!WARNING]
    > [!NOTE]
    > This is a note.
    
    > [!WARNING]
    > This is a warning.
  10. Switch between mdts viewing modes

    main

    The mdts viewer supports several interactive modes to change how you interact with Markdown content:

    • Preview Mode: The default mode providing full Markdown rendering (headings, lists, tables, etc.).
    • Metadata Mode: Specifically designed to view document frontmatter in detail.
    • Raw Mode: Displays the raw Markdown source code.
    • Live Reload: Enables real-time updates; changes made in external editors will appear instantly in the viewer.
  11. Filter files using glob patterns in mdts

    main

    In large projects or monorepos, you can use the --glob (or -g) option to narrow the file tree to a specific subset of Markdown files. This improves startup performance and keeps the UI uncluttered by only showing files that match your pattern.

    To use multiple patterns, provide them as separate arguments following the --glob flag.

    # Show only package READMEs in a monorepo
    npx mdts . -g 'packages/*/README.md'
    
    # Focus on API docs and changelogs
    npx mdts . -g 'docs/api/**/*.md' 'CHANGELOG.md'
  12. Optimize mdts performance

    main

    For large projects, follow these best practices to ensure smooth performance:

    Directory Optimization

    • Target Subdirectories: Point mdts to specific subdirectories rather than large root directories.
    • Exclude Files: Use .gitignore patterns to exclude unnecessary files from being indexed.
    • Avoid Bloat: Avoid pointing mdts at directories containing thousands of files.

    Memory Management

    • Periodic Restarts: Restart mdts periodically during long-running sessions.
    • Monitor Usage: Monitor memory usage if you are processing very large markdown files.
    • File Splitting: Consider splitting very large documents into smaller, more manageable files.