Skip to content

Multi-Content Markdown files (like YAML's multi-documents) #17

Description

@ek9r

Description

I'd like something similar to what the YAML world calls "multi-documents": being able to keep several independent documents, each with their own frontmatter, inside a single Markdown file.

The motivating case: a file describing several related things (e.g. a handful of small records that reference each other) where splitting into one-file-per-record feels premature for small sets, but a single growing file becomes messy without any internal structure.

Rough idea of how I'd approach it, happy to be told this is a bad fit:

---
type: application
name: storefront
status: up
composed_of: [web-service]
---
The customer-facing storefront application.
Handles browsing, checkout, and order history for end users.

<!-- next: web-1 -->
---
type: host
name: web-1
status: up
---
Primary application server, running in the eu-central region.
Serves all incoming HTTP traffic for the storefront.

<!-- next: web-service -->
---
type: service
name: web-service
runs_on: [web-1]
---
Handles incoming HTTP traffic and renders the storefront pages.
Depends on the primary database service for product and order data.

$chunks = $markdown->parseMany($content);
$chunks[0]->frontmatter['type'];    // application
$chunks[2]->frontmatter['runs_on']; // ['web-1']
  • parseMany() alongside the existing parse(), additive only
  • a <!-- next --> / <!-- next: name --> marker as the document separator, recognized before tokenization (so each document still gets its own frontmatter parsed from position 0)
  • ParsedMarkdown gains an optional $name, defaulting to null

I've got a rough, tested implementation on a branch here, mostly to validate the idea works end-to-end rather than as a finished PR: https://github.com/ek9r/markdown_dev/tree/Multi-Content

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions