mdcompose

package
v0.17.0-alpha.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package mdcompose composes Markdown fragments into one coherent document. An embedded fragment — an entry body, a generated section — is demoted beneath the headings of the structure serving it, so no embedded heading outranks its container (d-cpt-5wv).

Headings are recognized in ATX form (`#` … `######`) outside fenced code blocks. Setext underlining is left untouched: graph entry bodies and served fragments are authored ATX throughout, and rewriting an underline would mean rewriting two lines on a guess about which one is prose.

Index

Constants

View Source
const MaxHeadingLevel = 6

MaxHeadingLevel is Markdown's deepest ATX heading. Demotion clamps here: a seventh `#` stops being a heading at all, so a fragment pushed past the floor collapses its deepest levels rather than degrading into paragraph text.

Variables

This section is empty.

Functions

func DemoteTo

func DemoteTo(fragment string, level int) string

DemoteTo shifts every heading in fragment by one constant amount, so that its shallowest heading lands at level and the relative hierarchy is preserved. A fragment whose headings already sit at or below level is returned unchanged — the rule demotes into place, it never promotes a fragment toward the surface.

func SplitLeadingHeading

func SplitLeadingHeading(fragment string) (title, rest string)

SplitLeadingHeading splits a leading heading off fragment: when its first non-blank line is a heading, that heading's text is returned separately from the remaining body, so a composer can lift it into the container's own structure instead of nesting a title under a title. Otherwise title is empty and rest is fragment unchanged.

func TopHeadingLevel

func TopHeadingLevel(fragment string) int

TopHeadingLevel reports the shallowest heading level in fragment, or 0 when it carries no heading. Callers composing their own structure use it to work out how deep an embedded fragment already sits.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL