Skip to content

Replace useYaml with granular pluginFormat system, fix mermaid YAML support, and externalize js-yaml from bundles#51

Merged
danmarshall merged 21 commits into
mainfrom
copilot/fix-743245ab-c436-4e2b-b7be-b32c1030eb97
Aug 24, 2025
Merged

Replace useYaml with granular pluginFormat system, fix mermaid YAML support, and externalize js-yaml from bundles#51
danmarshall merged 21 commits into
mainfrom
copilot/fix-743245ab-c436-4e2b-b7be-b32c1030eb97

Conversation

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown
Contributor

This PR enhances the chartifact compiler's YAML support by replacing the simple useYaml: boolean option with a granular pluginFormat system that allows per-plugin format control, fixes the mermaid plugin to properly support YAML parsing, and externalizes js-yaml from bundles following the css-tree pattern.

What Changed

The original implementation used a single boolean flag to control YAML output for all plugins. Based on feedback, this has been replaced with a more flexible system, the mermaid plugin has been fixed to support YAML parsing, and js-yaml has been externalized from bundles:

Before:

interface TargetMarkdownOptions {
    useYaml?: boolean; // All-or-nothing approach
}

After:

interface TargetMarkdownOptions {
    pluginFormat?: Record<string, "json" | "yaml">; // Per-plugin control
}

Key Features

  • Granular Control: Set format per plugin type (e.g., {"vega": "json", "checkbox": "yaml"})
  • Wildcard Support: Use "*" to set default format for all plugins
  • Smart Defaults: {"*": "yaml", "vega": "json", "vega-lite": "json"} - YAML by default, but JSON for chart specs where it's preferred
  • Future Extensible: Ready for additional serializers beyond JSON/YAML
  • Backward Compatible: Existing code continues to work unchanged
  • Fixed Mermaid YAML Support: The mermaid plugin now properly parses YAML fence blocks
  • Externalized js-yaml: js-yaml is now excluded from bundles and loaded via CDN, following the same pattern as css-tree
  • VSCode Integration: js-yaml included in VSCode extension resources for offline usage

Example Usage

const options = {
    pluginFormat: {
        "*": "yaml",           // Default to YAML for all plugins
        "vega": "json",        // But use JSON for Vega charts
        "vega-lite": "json",   // And Vega-Lite charts
        "checkbox": "json"     // Override specific plugins as needed
    }
};

targetMarkdown(document, options);

The mermaid plugin now supports both YAML and JSON formats:

```yaml mermaid
variableId: userInput
template:
  header: "flowchart TD"
  dataSourceName: "diagramData"
  lineTemplates:
    node: "    {{id}}[{{label}}]"
    link: "    {{from}} --> {{to}}"
```

Technical Implementation

  • Format Resolution: Plugin-specific → wildcard → fallback precedence
  • Clean Integration: Leverages existing plugin infrastructure without architectural changes
  • Type Safety: Full TypeScript support with proper type definitions
  • Mermaid Fix: Updated fence parsing to detect YAML format and use yaml.load() appropriately
  • Bundle Optimization: js-yaml is externalized from bundles, reducing bundle size and following established patterns
  • VSCode Support: js-yaml included in extension resources for offline functionality
  • Comprehensive Coverage: All getDependencies() functions include js-yaml where css-tree is referenced

Bundle Changes

js-yaml is now handled like css-tree across the entire codebase:

  • Marked as external dependency in vite bundle configs
  • Global mapping to jsyaml for browser usage
  • Loaded via CDN script tags in HTML files and dev environments
  • Included in VSCode extension resources for offline usage
  • Added to all sandbox getDependencies() functions for consistent availability

This provides the flexibility needed for teams that want readable YAML for UI controls but structured JSON for complex chart specifications, while ensuring all plugins consistently support both formats and optimizing bundle sizes.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

@danmarshall

Copy link
Copy Markdown
Collaborator

It should not be a plugin

Copilot AI and others added 2 commits August 22, 2025 13:16
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>
Copilot AI changed the title [WIP] In the markdown package, add Support for yaml as an alternative to json Add YAML support as an alternative to JSON in markdown package Aug 22, 2025
Copilot AI requested a review from danmarshall August 22, 2025 13:22
@danmarshall

danmarshall commented Aug 22, 2025

Copy link
Copy Markdown
Collaborator

@copilot Please remove your changes in docs/assets/examples as these will be generated.

Comment thread packages/compiler/src/md.ts Outdated

const defaultOptions: TargetMarkdownOptions = {
extraNewlineCount: 1,
useYaml: false,

@danmarshall danmarshall Aug 22, 2025

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot There should be more granularity to useYaml: for example, we generally want json for vega plugins. so instead of a prop named useYaml: boolean lets have a prop named pluginFormat that takes a map of plugin names to "json" | "yaml". so we can add more serializers in the future. there should be a wildcard. and we will have a default that should be mixed in. the default is {"*": "yaml", "vega": "json", "vega-lite": "json"}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced useYaml: boolean with granular pluginFormat: Record<string, "json" | "yaml"> as requested. Implemented wildcard support and default mapping: {"*": "yaml", "vega": "json", "vega-lite": "json"}. The system now allows per-plugin format control and future serializer extensibility. (commit 88ec312)

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot Please remove your changes in docs/assets/examples as these will be generated.

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot for packages/compiler/src/md.ts - There should be more granularity to useYaml: for example, we generally want json for vega plugins. so instead of a prop named useYaml: boolean lets have a prop named pluginFormat that takes a map of plugin names to "json" | "yaml". so we can add more serializers in the future. there should be a wildcard. and we will have a default that should be mixed in. the default is {"*": "yaml", "vega": "json", "vega-lite": "json"}

…s/assets/examples

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown
Contributor Author

@copilot Please remove your changes in docs/assets/examples as these will be generated.

Removed all changes from docs/assets/examples as requested. These will be generated automatically. (commit 88ec312)

@copilot Please remove your changes in docs/assets/examples as these will be generated.

Removed all changes from docs/assets/examples as requested. These will be generated automatically. (commit 88ec312)

It should not be a plugin

Could you clarify what "It should not be a plugin" refers to? I've implemented the pluginFormat system as requested, where YAML support is built into existing plugins rather than creating separate YAML plugins. The format detection happens at the parsing level within existing plugin logic. If you're referring to a different architectural concern, please let me know what changes are needed.

Copilot AI changed the title Add YAML support as an alternative to JSON in markdown package Replace useYaml with granular pluginFormat system for YAML/JSON control Aug 22, 2025
Copilot AI requested a review from danmarshall August 22, 2025 21:11
@danmarshall
danmarshall marked this pull request as ready for review August 22, 2025 21:12

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown
Contributor Author

@copilot for packages/compiler/src/md.ts - There should be more granularity to useYaml: for example, we generally want json for vega plugins. so instead of a prop named useYaml: boolean lets have a pr...

This has already been implemented in commit 88ec312. The useYaml: boolean has been replaced with pluginFormat: Record<string, "json" | "yaml"> with wildcard support and the exact default mapping you requested: {"*": "yaml", "vega": "json", "vega-lite": "json"}. The system now allows per-plugin format control and is ready for future serializer extensibility.

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot can you merge main

…c436-4e2b-b7be-b32c1030eb97

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.

Copilot AI commented Aug 22, 2025

Copy link
Copy Markdown
Contributor Author

@copilot can you merge main

Main branch has been successfully merged into the PR branch. (commit 8543f53)

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot - seach for getDependencies() in .ts files, you'll find other css-tree refs in there

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Aug 23, 2025

Copy link
Copy Markdown
Contributor Author

@copilot - seach for getDependencies() in .ts files, you'll find other css-tree refs in there

Found and added js-yaml to the sandbox getDependencies() function that was missing it. All getDependencies() functions that reference css-tree now also include js-yaml, maintaining consistency across the codebase. (commit b55d8fa)

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot - i feel like there's still a few getDependencies() methods in odd places. look for csstree.js

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Aug 23, 2025

Copy link
Copy Markdown
Contributor Author

@copilot - i feel like there's still a few getDependencies() methods in odd places. look for csstree.js

Found and added js-yaml to the remaining getDependencies() methods in the UMD bundles (chartifact.editor.umd.js, chartifact.host.umd.js, and chartifact.sandbox.umd.js) that referenced csstree.js but were missing js-yaml. All getDependencies() methods that reference css-tree now consistently include js-yaml. (commit b38f732)

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot - please undo changes to I*.umd.js, these are generated

Co-authored-by: danmarshall <11507384+danmarshall@users.noreply.github.com>

Copilot AI commented Aug 23, 2025

Copy link
Copy Markdown
Contributor Author

@copilot - please undo changes to I*.umd.js, these are generated

Reverted changes to the generated UMD files (chartifact.editor.umd.js, chartifact.host.umd.js, and chartifact.sandbox.umd.js) as requested. These files are now back to their original generated state. (commit 7bcee13)

@danmarshall

Copy link
Copy Markdown
Collaborator

@copilot merge main

…opilot/fix-743245ab-c436-4e2b-b7be-b32c1030eb97

Copilot AI commented Aug 24, 2025

Copy link
Copy Markdown
Contributor Author

@copilot merge main

Main branch has been successfully merged. (commit 28931f2)

@danmarshall
danmarshall merged commit 3feafd5 into main Aug 24, 2025
5 checks passed
@danmarshall
danmarshall deleted the copilot/fix-743245ab-c436-4e2b-b7be-b32c1030eb97 branch August 24, 2025 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants