quartz-transformer-mmlabc
A Quartz transformer plugin that displays sheet music and allows click-to-play functionality simply by writing chord progressions in a code block. Supports MML (Music Macro Language) and ABC Notation as well.
Note: Parts of this documentation were generated by AI.
Quick Links
| Item | Link | |ββ|ββ| | π Development Status | generated-docs/development-status |
Status
- Core implementation is complete
- Currently dogfooding
- Subject to breaking changes
- Demo: https://cat2151.github.io/digital-garden/Quartz-%E3%82%B3%E3%83%BC%E3%83%89%E9%80%B2%E8%A1%8C%E3%82%92%E5%9B%95%E7%B7%9A%E8%AD%9C%E3%81%A7%E8%A1%A8%E7%A4%BA%E3%81%97%E3%81%A6%E3%82%AF%E3%83%AA%E3%83%83%E3%82%AF%E3%81%A7%E6%BC%94%E5%A5%8F%E3%81%A7%E3%81%8D%E3%82%8B%E3%82%88%E3%81%86%E3%81%AB%E3%81%97%E3%81%9F
Summary in 3 Lines
- In Obsidian, you can write chord progressions in a code block to display sheet music and play it: https://github.com/cat2151/obsidian-plugin-mmlabc
- To bring this capability to Quartz 4, a new transformer plugin was created
- Just like the Obsidian version, it supports MML (Music Macro Language) and ABC Notation
Features
- π΅ Converts
mmlcode blocks to ABC notation and renders them usingabcjs - πΈ Converts
chordcode blocks to MML, then to ABC notation, and renders them usingabcjs - πΌ Supports
abcnotation code blocks for troubleshooting - π¨ Renders sheet music as SVG
- π§ Click-to-play - Click on the rendered score to play the music
- β¨οΈ Keyboard accessibility support (play with Enter or Space key)
Installation
Run the following command in your Quartz installation directory:
npm install github:cat2151/quartz-transformer-mmlabc
The plugin is installed directly from GitHub (not npm). Pre-built files (in the dist directory) are included in the repository, so you can use it immediately after installation.
Migration Guide for Existing Users
Important: Starting from this version, the dist folder is included in the repository, eliminating the need for manual builds.
Updating GitHub Actions Workflow
If you are already building the plugin in GitHub Actions, please remove the build step.
Before:
- name: Install Dependencies
run: npm ci
- name: Update quartz-transformer-mmlabc to latest
run: npm update quartz-transformer-mmlabc
- name: Build quartz-transformer-mmlabc
run: npm run build
working-directory: node_modules/quartz-transformer-mmlabc
- name: Build Quartz
run: npx quartz build
After:
- name: Install Dependencies
run: npm ci
- name: Update quartz-transformer-mmlabc to latest
run: npm update quartz-transformer-mmlabc
- name: Build Quartz
run: npx quartz build
What changed: Removed the Build quartz-transformer-mmlabc step. This step is no longer necessary as pre-built files are now included in the repository.
How to Update the Plugin (Two Options)
Important: This plugin is currently Work In Progress and may introduce frequent breaking changes (nonstable). You have two options for updating the plugin:
Option 1: Always use the latest version on deployment (Recommended during development)
If you want to use the latest version of the plugin on every deployment, add the following steps to .github/workflows/deploy.yml:
- name: Install Dependencies
run: npm ci
- name: Update quartz-transformer-mmlabc to latest
run: npm update quartz-transformer-mmlabc
Pros:
- Always get the latest features and bug fixes
- Critical bug fixes are applied immediately
Cons:
- Breaking changes may be reflected immediately
- Build time will be slightly longer
Option 2: Rely on Dependabot for weekly updates
If you configure Dependabot, it will automatically create pull requests to update the plugin weekly. This allows you to review updates before merging.
Example .github/dependabot.yml:
version: 2
updates:
- package-ecosystem: "npm"
directory: "/"
schedule:
interval: "weekly"
Pros:
- Review updates before merging
- Operate with a stable version
Cons:
- Plugin updates may be delayed by up to a week
- Critical bug fixes will also wait up to a week
Usage
Usage in Quartz Configuration
Add the transformer to your quartz.config.ts:
import { QuartzConfig } from "./quartz/cfg"
import * as Plugin from "./quartz/plugins"
import { MMLABCTransformer } from "quartz-transformer-mmlabc"
const config: QuartzConfig = {
configuration: {
// ... site configuration
},
plugins: {
transformers: [
Plugin.FrontMatter(),
Plugin.CreatedModifiedDate({ priority: ["frontmatter", "filesystem"] }),
// Add the MMLABC transformer
MMLABCTransformer(),
// ... other transformers
],
filters: [Plugin.RemoveDrafts()],
emitters: [
Plugin.AliasRedirects(),
Plugin.ComponentResources(),
Plugin.ContentPage(),
// ... other emitters
],
},
}
export default config
Important Points:
- Import
QuartzConfigand built-in plugins from Quartzβs internal paths - Import this plugin from its npm package name
- Add it to the
transformersarray alongside other transformers - Order generally does not matter unless there are dependencies between plugins
Usage in Markdown Files
MML Notation
```mml
t120 l4 cdefgab<c
```
Chord Progression Notation
```chord
C Dm7 G7 C
```
ABC Notation (Direct Specification)
```abc
X:1
T:Simple Scale
M:4/4
L:1/4
K:C
C D E F|G A B c|
```
Useful for troubleshooting or when you want to write ABC notation directly.
Options
The plugin accepts configuration options:
MMLABCTransformer({
enableMML: true, // Enable MML block transformation (default: true)
enableChord: true, // Enable chord progression block transformation (default: true)
enableABC: true, // Enable ABC block transformation (default: true)
})
How It Works
- During the Quartz build process, the plugin detects code blocks with
mml,chord, orabclanguage tags. - It replaces these code blocks with HTML
divelements containing the source notation as data attributes. - In the browser:
- Loads
abcjsandmml2abcfrom CDN - For MML blocks: Converts MML to ABC notation using
mml2abc - For chord progression blocks: Converts chord progressions to MML using
chord2mml, then to ABC notation - For ABC blocks: Uses the notation directly without conversion
- Renders the ABC notation as interactive SVG using
abcjs - Initializes an audio synthesizer to support playback
- Adds click event handlers to play music when clicking on the sheet music
- Loads
Quartz v4 SPA Navigation Support
This plugin is fully compatible with Quartz v4βs SPA (Single Page Application) navigation:
- Automatic Re-initialization: Listens to Quartzβs
navevents and automatically re-renders sheet music on page transitions - Memory Leak Prevention: Uses
window.addCleanup()to clean up properly during navigation - Idempotency: Tracks elements using a
WeakSetto prevent processing the same element multiple times - Performance Optimization: Caches CDN modules (
mml2abc,chord2mml) andAudioContextacross navigations
This ensures reliable rendering not only on initial load, but also when navigating from other pages to a page containing sheet music (Fixes Issue #63).
Notes
- Conversion to HTML happens during the Quartz build process
- Actual sheet music conversion and rendering happen within the browser
- CDN library versions are specified based on operational verification with
easychord2mmlby @cat2151 - MML-to-ABC conversion uses
mml2abcloaded from CDN - Chord-to-MML conversion uses
chord2mmlloaded from CDN - Rendering uses
abcjs(latest in version 6 series) loaded from CDN - Libraries are loaded dynamically to avoid bundling issues
Testing
The plugin includes a comprehensive automated test suite:
Running Tests
# Run unit tests once
npm test
# Run integration tests (Playwright)
npm run test:integration
# Run all tests
npm run test:all
# Run tests in watch mode
npm run test:watch
# Run tests with UI
npm run test:ui
Test Coverage
The test suite includes:
- Unit tests for AST transformation logic (Vitest)
- HTML escaping tests (line breaks, tabs, special characters)
- Tests for plugin options and configuration
- Edge case handling
- External resource validation
- Integration tests for browser rendering and interactive features (Playwright)
For manual testing, please use the included demo.html file.
Note: When a Coding Agent runs tests in a Linux runner, CDNs are blocked, preventing the display of sheet music. If you want to verify the sheet music rendering, please test in a local environment (real device).
Dependencies
Runtime (Loaded via CDN)
The following CDN dependencies are based on compatibility with easychord2mml. Please verify functionality before making changes.
- abcjs - JavaScript library for rendering ABC music notation
- CDN:
https://cdn.jsdelivr.net/npm/abcjs@6/dist/abcjs-basic-min.min.js - Specifying
@6always fetches the latest version in the version 6 series (6.x.x)
- CDN:
- mml2abc - Converts Music Macro Language to ABC notation
- CDN:
https://cdn.jsdelivr.net/gh/cat2151/mml2abc/dist/mml2abc.mjs - Loaded via dynamic ES module imports
- CDN:
- chord2mml - Converts chord progression notation to MML
- CDN:
https://cdn.jsdelivr.net/gh/cat2151/chord2mml@latest/dist/chord2mml.js - Loaded in UMD bundle format
- Tracks the latest version served by jsDelivr. Fixed SRI hashes are not used as the fetched file updates accordingly.
- CDN:
Build-time
- unified - Interface for parsing and transforming content
- unist-util-visit - Utility for traversing syntax trees
Development
Build
npm run build
Project Structure
quartz-transformer-mmlabc/
βββ src/
β βββ index.ts # Main plugin implementation
β βββ index.test.ts # Unit tests
βββ test/
β βββ integration.test.ts # Integration tests
βββ dist/ # Compilation output (generated)
β βββ index.js
β βββ index.d.ts
βββ demo.html # Demo file for manual testing
βββ package.json
βββ tsconfig.json
βββ vitest.config.ts # Vitest test configuration
βββ playwright.config.ts # Playwright test configuration
βββ README.md
Why We Adopted the External Package Approach
Instead of building this directly into the Quartz core, this plugin is distributed as an external npm package. This architectural decision was made for the following reasons:
- Reusability
- The same plugin can be used across multiple Quartz projects
- No need to copy code into each individual project
- Independence
- Enables its own release cycle and versioning independent of Quartz
- Can be developed and updated without being affected by updates to the Quartz core
- Shareability
- Easily shareable with the community via GitHub
- Makes it easier for many users to adopt as an open-source project
This approach maximizes the pluginβs value and enables support for a broader user base.
License
MIT License - see the LICENSE file for details
Related Projects
- Quartz - Fast, batteries-included static site generator
- abcjs - JavaScript for rendering ABC music notation
- mml2abc - MML to ABC converter
- chord2mml - Chord progression notation to MML converter
Note: The English README.md is automatically generated from README.ja.md using Gemini translation via GitHub Actions.