marksplice

package module
v0.1.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

README

Marksplice

Go Reference CI

Structured GitHub Flavored Markdown creation and source-preserving manipulation for Go.

Marksplice is an open-source Pure-Go library for understanding, creating, and structurally editing GitHub Flavored Markdown (GFM). New documents may be generated from reviewed structured intent, while edits to existing documents preserve untouched source bytes whenever the requested operation does not semantically require broader changes.

Status

Marksplice is currently beta software under active development. The first public beta version is v0.1.0-beta.1; until v1, public APIs and behavior may change incompatibly between releases.

The repository has a green retrospective M0 bootstrap record and completed engineering milestones M1–M91. The current model has two deliberately separate paths:

  • parsed Document snapshots expose reviewed source-mapped read/edit capabilities and prepare minimal source-bound changes that reject stale input;
  • DocumentBuilder creates new deterministic GFM and validates generated structure through the same parser/source-model boundary before returning bytes.

The current public surface covers reviewed paragraphs/headings/sections, supported list and task hierarchies, fenced code, GFM tables with public table/row/cell ownership and conservative row/alignment/column structural edits, simple inline spans/links/images/reference definitions/autolinks, source-proven top-level thematic breaks and simple one-line existing-source blockquotes, unique simple YAML/TOML front-matter fields with canonical new-document envelope construction, simple HTML comments/anchors, typed inline construction for semantic text/code/emphasis/strong/strikethrough/links/images/autolinks including conservative canonical link/image titles, bounded reviewed emphasis-family nesting, and full reference-link/reference-image construction against an already-present exact reference definition, canonical single-paragraph blockquote construction at depth 1 or explicit nesting depth 2–64, and construction-only multi-block blockquotes composed from reviewed builder children including recursively nested blockquotes with total depth bounded at 64.

The public API remains intentionally narrower than everything the semantic parser can recognize. Unsupported or ambiguous shapes are preserved or kept internal until exact source ownership and caller-facing semantics are proven.

See docs/README.md for the documentation map and repository layout, docs/capabilities.md for the authoritative current read/edit/create matrix and roadmap, and docs/milestones/ for detailed milestone contracts and historical verification evidence.

Design principles

  • follow the published GitHub Flavored Markdown 0.29 specification as the single normative Markdown syntax profile;
  • create new GFM through deterministic reviewed construction rules and parser/model proof;
  • parse existing GFM for semantic understanding without implying whole-document normalization;
  • preserve untouched author choices such as heading/list/fence styles, whitespace, delimiters, numbering, and line endings during existing-document edits;
  • bind prepared edits to exact source snapshots and reject stale application;
  • promote public capabilities only after operation-oriented source ownership is proven;
  • keep Goldmark behind an internal adapter and expose only Marksplice-owned types;
  • keep filesystem, network, command-execution, and host authorization concerns outside the core library.

Installation

Marksplice requires Go 1.26 or newer. After the first public beta tag is published, install it explicitly because Go does not prefer pre-release versions by default:

go get github.com/zoster81/marksplice@v0.1.0-beta.1

A consuming go.mod may instead contain:

require github.com/zoster81/marksplice v0.1.0-beta.1

The module path remains github.com/zoster81/marksplice throughout v0 and v1.

Quick start

builder := marksplice.NewDocumentBuilder()
_ = builder.AppendHeadingContent(1, marksplice.TextInline("Marksplice"))
_ = builder.AppendParagraphContent(marksplice.TextInline("Source preserving GFM"))
source, err := builder.Markdown()

Executable examples for construction, parsing, and source-preserving heading mutation live in example_test.go and are published by pkg.go.dev.

Construction and editing

DocumentBuilder writes canonical LF GFM for reviewed new-document families such as headings, parser-proven paragraphs, lists/tasks including homogeneous nesting, fenced code, reference definitions, tables with optional alignment, thematic breaks, and blockquotes. AppendBlockquote owns one paragraph at depth 1, AppendNestedBlockquote accepts one paragraph at explicit depths 2–64, and AppendBlockquoteBlocks snapshots another builder's reviewed body blocks and quotes that sequence at depth 1–64. Multi-block composition accepts every reviewed body-block construction family, including recursive blockquote children when total structural depth stays at most 64; front matter remains excluded because it is a document envelope. It can also own one document-leading canonical YAML or TOML front-matter envelope with conservative double-quoted string fields. Typed-inline entrypoints provide a semantic-text alternative to the historical raw-GFM block APIs, including AppendNestedBlockquoteContent; LinkInlineWithTitle and ImageInlineWithTitle add conservative canonical double-quoted titles. M88 allows bounded nesting of CodeInline, EmphasisInline, StrongInline, and StrikethroughInline inside emphasis/strong/strikethrough wrappers, while ambiguous GFM delimiter combinations fail closed. M89 adds ReferenceLinkInline and ReferenceImageInline for canonical full-reference forms whose exact label must match exactly one top-level reference definition already present in the same builder; collapsed/shortcut forms and forward definitions remain outside this slice. Existing parsed-source editing contracts remain unchanged.

Parsed Document values instead retain exact immutable source. Mutations target operation-specific ranges and validate the candidate source when surrounding Markdown interpretation could change. Structural operations never use the construction writer to reformat an existing document.

Documentation

Development

The module path is:

github.com/zoster81/marksplice

The go 1.26 directive is the current minimum compatibility floor. Public CI exercises Go 1.26 and Go 1.27 on Linux, Windows, and macOS.

The public marksplice package intentionally lives at the module root so consumers import exactly github.com/zoster81/marksplice. Root source files are grouped into api* and builder* families; black-box consumer-style API tests live under internal/publictest/, and longer-form project documentation lives under docs/. A top-level src/ package is intentionally avoided because it would change the natural Go import path or require an artificial forwarding facade.

At minimum, normal development uses:

go test ./...
go test -race ./...
go vet ./...

Additional static, complexity, vulnerability, secret-scanning, conformance, and hygiene checks are documented in CONTRIBUTING.md.

Author

Marksplice was created by Giovanni Riccobene (zoster81).

License

Licensed under the Apache License, Version 2.0. See LICENSE and NOTICE.

Goldmark is an MIT-licensed third-party dependency. Exact dependency versions are recorded in go.mod and go.sum.

Documentation

Overview

Package marksplice provides structured GitHub Flavored Markdown creation and source-preserving manipulation.

Marksplice is currently pre-v1 beta software under active development. Public APIs may change incompatibly between v0 releases until a stable v1 contract is explicitly published.

Marksplice exposes reviewed new-document construction, snapshot-scoped structural views, copied bounded source reads, and named source-preserving mutations while keeping Goldmark and lossless source-mapping implementation details internal.

Index

Examples

Constants

This section is empty.

Variables

View Source
var (
	// ErrNodeNotFound reports that a snapshot-local node ID does not exist.
	ErrNodeNotFound = errors.New("node not found")
	// ErrInvalidReplacement reports a requested mutation that cannot preserve the required structure.
	ErrInvalidReplacement = errors.New("invalid replacement")
	// ErrInvalidTargetKind reports that an operation does not support the targeted node kind.
	ErrInvalidTargetKind = errors.New("invalid target kind")
	// ErrSourceConflict reports that a prepared change was applied to a different source snapshot.
	ErrSourceConflict = errors.New("source snapshot conflict")
	// ErrInvalidConstruction reports new-document content that cannot be proven to produce the requested GFM structure.
	ErrInvalidConstruction = errors.New("invalid construction")
)

Functions

This section is empty.

Types

type AutoLink struct {
	// contains filtered or unexported fields
}

AutoLink is immutable typed detail for one promoted single-line GFM autolink.

func (AutoLink) ID

func (a AutoLink) ID() NodeID

ID returns the autolink's snapshot-scoped node identity.

func (AutoLink) Range

func (a AutoLink) Range() Range

Range returns the exact autolink token content replaced by PrepareReplaceAutoLink. Angle brackets, when present, and surrounding source are outside this range.

type Blockquote

type Blockquote struct {
	// contains filtered or unexported fields
}

Blockquote is immutable typed detail for one promoted simple top-level blockquote.

func (Blockquote) ContentRange

func (b Blockquote) ContentRange() Range

ContentRange returns the exact inner single-paragraph source span. Leading indentation, the '>' marker, its optional following space, and the line terminator are outside this range.

func (Blockquote) ID

func (b Blockquote) ID() NodeID

ID returns the blockquote's snapshot-scoped node identity.

func (Blockquote) Range

func (b Blockquote) Range() Range

Range returns the exact complete physical blockquote line owned by structural operations. When present, the line terminator is included.

type ChangeSet

type ChangeSet struct {
	// contains filtered or unexported fields
}

ChangeSet is an opaque prepared change bound to one exact source snapshot. Its zero value is unbound and Apply reports ErrSourceConflict.

func (ChangeSet) Apply

func (c ChangeSet) Apply(source []byte) ([]byte, error)

Apply applies the prepared change only when source matches its original snapshot.

type CodeSpan

type CodeSpan struct {
	// contains filtered or unexported fields
}

CodeSpan is immutable typed detail for one promoted simple single-line code span.

func (CodeSpan) ID

func (c CodeSpan) ID() NodeID

ID returns the code span's snapshot-scoped node identity.

func (CodeSpan) Range

func (c CodeSpan) Range() Range

Range returns the exact code-span content span replaced by PrepareReplaceCodeSpan.

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document is an immutable parsed Markdown source snapshot.

func Parse

func Parse(source []byte) (*Document, error)

Parse copies and parses source into an immutable document snapshot.

Example
package main

import (
	"fmt"

	"github.com/zoster81/marksplice"
)

func main() {
	source := []byte("# Title\n\nBody.\n")
	document, err := marksplice.Parse(source)
	if err != nil {
		panic(err)
	}

	for _, node := range document.Nodes() {
		if node.Kind() != marksplice.KindHeading {
			continue
		}
		heading, ok := document.Heading(node.ID())
		if !ok {
			continue
		}
		content, ok := document.SourceRange(heading.Range())
		if !ok {
			panic("heading range is not readable")
		}
		fmt.Printf("level=%d text=%s\n", heading.Level(), content)
	}

}
Output:
level=1 text=Title
func (d *Document) AutoLink(id NodeID) (AutoLink, bool)

AutoLink returns typed detail for one promoted single-line GFM autolink.

func (*Document) Blockquote

func (d *Document) Blockquote(id NodeID) (Blockquote, bool)

Blockquote returns typed detail for one promoted simple top-level blockquote.

func (*Document) CodeSpan

func (d *Document) CodeSpan(id NodeID) (CodeSpan, bool)

CodeSpan returns typed detail for one promoted simple single-line code span.

func (*Document) Emphasis

func (d *Document) Emphasis(id NodeID) (Emphasis, bool)

Emphasis returns typed detail for one promoted simple emphasis span.

func (*Document) FencedCode

func (d *Document) FencedCode(id NodeID) (FencedCode, bool)

FencedCode returns typed detail for one promoted supported fenced code block.

func (*Document) FrontMatterField

func (d *Document) FrontMatterField(id NodeID) (FrontMatterField, bool)

FrontMatterField returns typed detail for one promoted simple leading YAML/TOML scalar field.

func (*Document) HTMLAnchor

func (d *Document) HTMLAnchor(id NodeID) (HTMLAnchor, bool)

HTMLAnchor returns typed detail for one promoted simple quoted id/name attribute on an <a> tag.

func (*Document) HTMLComment

func (d *Document) HTMLComment(id NodeID) (HTMLComment, bool)

HTMLComment returns typed detail for one promoted single-line HTML comment.

func (*Document) Heading

func (d *Document) Heading(id NodeID) (Heading, bool)

Heading returns typed detail for one promoted top-level heading.

func (*Document) Image

func (d *Document) Image(id NodeID) (Image, bool)

Image returns typed detail for one promoted simple inline image.

func (d *Document) InlineLink(id NodeID) (InlineLink, bool)

InlineLink returns typed detail for one promoted simple inline link.

func (*Document) ListItem

func (d *Document) ListItem(id NodeID) (ListItem, bool)

ListItem returns typed detail for one promoted single-line list item.

func (*Document) Node

func (d *Document) Node(id NodeID) (Node, bool)

Node returns one node summary by snapshot-local ID.

func (*Document) Nodes

func (d *Document) Nodes() []Node

Nodes returns summaries for node kinds promoted into the public API.

func (*Document) Paragraph

func (d *Document) Paragraph(id NodeID) (Paragraph, bool)

func (*Document) PrepareAppendListItemChild

func (d *Document) PrepareAppendListItemChild(parentID NodeID, fragment []byte) (ChangeSet, error)

PrepareAppendListItemChild prepares appending one complete direct-child subtree to a fully supported list-item subtree.

func (*Document) PrepareAppendSectionChild

func (d *Document) PrepareAppendSectionChild(parentHeadingID NodeID, fragment []byte) (ChangeSet, error)

PrepareAppendSectionChild prepares appending one direct child section subtree to a promoted parent section.

func (*Document) PrepareAppendTableRow

func (d *Document) PrepareAppendTableRow(id NodeID, fragment []byte) (ChangeSet, error)

PrepareAppendTableRow prepares appending one caller-owned compatible body row to a promoted GFM table.

func (*Document) PrepareInsertListItemAfter

func (d *Document) PrepareInsertListItemAfter(anchorID NodeID, fragment []byte) (ChangeSet, error)

PrepareInsertListItemAfter prepares insertion of one complete same-shape supported list-item subtree immediately after a complete supported anchor subtree.

func (*Document) PrepareInsertListItemBefore

func (d *Document) PrepareInsertListItemBefore(anchorID NodeID, fragment []byte) (ChangeSet, error)

PrepareInsertListItemBefore prepares insertion of one complete same-shape supported list-item subtree immediately before a complete supported anchor subtree.

func (*Document) PrepareInsertSectionAfter

func (d *Document) PrepareInsertSectionAfter(headingID NodeID, fragment []byte) (ChangeSet, error)

PrepareInsertSectionAfter prepares insertion of one sibling section subtree immediately after the target section subtree.

func (*Document) PrepareInsertSectionBefore

func (d *Document) PrepareInsertSectionBefore(headingID NodeID, fragment []byte) (ChangeSet, error)

PrepareInsertSectionBefore prepares insertion of one sibling section subtree immediately before the target section.

func (*Document) PrepareInsertTableColumn

func (d *Document) PrepareInsertTableColumn(id NodeID, column int, header []byte, alignment TableAlignment, body [][]byte) (ChangeSet, error)

PrepareInsertTableColumn prepares source-preserving insertion of one complete promoted GFM table column.

func (*Document) PrepareInsertTableRowAfter

func (d *Document) PrepareInsertTableRowAfter(anchorID NodeID, fragment []byte) (ChangeSet, error)

PrepareInsertTableRowAfter prepares insertion of one complete compatible body row after a promoted row.

func (*Document) PrepareInsertTableRowBefore

func (d *Document) PrepareInsertTableRowBefore(anchorID NodeID, fragment []byte) (ChangeSet, error)

PrepareInsertTableRowBefore prepares insertion of one complete compatible body row before a promoted row.

func (*Document) PrepareMoveListItemAfter

func (d *Document) PrepareMoveListItemAfter(id, anchorID NodeID) (ChangeSet, error)

PrepareMoveListItemAfter prepares moving one complete supported list-item subtree immediately after a complete same-shape anchor subtree.

func (*Document) PrepareMoveListItemBefore

func (d *Document) PrepareMoveListItemBefore(id, anchorID NodeID) (ChangeSet, error)

PrepareMoveListItemBefore prepares moving one complete supported list-item subtree immediately before a complete same-shape anchor subtree.

func (*Document) PrepareMoveSectionAfter

func (d *Document) PrepareMoveSectionAfter(headingID, anchorHeadingID NodeID) (ChangeSet, error)

PrepareMoveSectionAfter prepares moving one complete promoted section subtree immediately after a same-level anchor subtree.

func (*Document) PrepareMoveSectionBefore

func (d *Document) PrepareMoveSectionBefore(headingID, anchorHeadingID NodeID) (ChangeSet, error)

PrepareMoveSectionBefore prepares moving one complete promoted section subtree immediately before a same-level anchor section.

func (*Document) PrepareMoveTableColumn

func (d *Document) PrepareMoveTableColumn(id NodeID, from, to int) (ChangeSet, error)

PrepareMoveTableColumn prepares moving one complete promoted GFM table column to a new zero-based position.

func (*Document) PrepareMoveTableRowAfter

func (d *Document) PrepareMoveTableRowAfter(id, anchorID NodeID) (ChangeSet, error)

PrepareMoveTableRowAfter prepares moving one complete body row after another promoted row in the same table.

func (*Document) PrepareMoveTableRowBefore

func (d *Document) PrepareMoveTableRowBefore(id, anchorID NodeID) (ChangeSet, error)

PrepareMoveTableRowBefore prepares moving one complete body row before another promoted row in the same table.

func (*Document) PrepareRemoveBlockquote

func (d *Document) PrepareRemoveBlockquote(id NodeID) (ChangeSet, error)

PrepareRemoveBlockquote prepares source-preserving removal of one complete promoted simple top-level blockquote line.

func (*Document) PrepareRemoveListItem

func (d *Document) PrepareRemoveListItem(id NodeID) (ChangeSet, error)

PrepareRemoveListItem prepares removal of one complete supported list-item subtree.

func (*Document) PrepareRemoveSection

func (d *Document) PrepareRemoveSection(headingID NodeID) (ChangeSet, error)

PrepareRemoveSection prepares source-preserving removal of one complete promoted section subtree.

func (*Document) PrepareRemoveTableColumn

func (d *Document) PrepareRemoveTableColumn(id NodeID, column int) (ChangeSet, error)

PrepareRemoveTableColumn prepares source-preserving removal of one complete promoted GFM table column.

func (*Document) PrepareRemoveTableRow

func (d *Document) PrepareRemoveTableRow(id NodeID) (ChangeSet, error)

PrepareRemoveTableRow prepares source-preserving removal of one promoted GFM table body row.

func (*Document) PrepareRemoveThematicBreak

func (d *Document) PrepareRemoveThematicBreak(id NodeID) (ChangeSet, error)

PrepareRemoveThematicBreak prepares source-preserving removal of one complete promoted top-level thematic-break line.

func (*Document) PrepareRenameHeading

func (d *Document) PrepareRenameHeading(id NodeID, replacement []byte) (ChangeSet, error)

PrepareRenameHeading prepares a source-preserving rename of promoted heading content.

Example
package main

import (
	"fmt"

	"github.com/zoster81/marksplice"
)

func main() {
	source := []byte("##  Old title  ##\n\nBody.\n")
	document, err := marksplice.Parse(source)
	if err != nil {
		panic(err)
	}

	var heading marksplice.Heading
	for _, node := range document.Nodes() {
		if node.Kind() != marksplice.KindHeading {
			continue
		}
		var ok bool
		heading, ok = document.Heading(node.ID())
		if ok {
			break
		}
	}

	change, err := document.PrepareRenameHeading(heading.ID(), []byte("New title"))
	if err != nil {
		panic(err)
	}
	updated, err := change.Apply(source)
	if err != nil {
		panic(err)
	}
	fmt.Print(string(updated))

}
Output:
##  New title  ##

Body.
func (d *Document) PrepareReplaceAutoLink(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceAutoLink prepares a source-preserving replacement of a promoted GFM autolink token.

func (*Document) PrepareReplaceCodeSpan

func (d *Document) PrepareReplaceCodeSpan(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceCodeSpan prepares a source-preserving replacement of promoted code-span content.

func (*Document) PrepareReplaceEmphasis

func (d *Document) PrepareReplaceEmphasis(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceEmphasis prepares a source-preserving replacement of promoted emphasis content.

func (*Document) PrepareReplaceFencedCode

func (d *Document) PrepareReplaceFencedCode(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceFencedCode prepares a source-preserving replacement of promoted fenced-code content.

func (*Document) PrepareReplaceFrontMatterValue

func (d *Document) PrepareReplaceFrontMatterValue(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceFrontMatterValue prepares a source-preserving replacement of a promoted simple front-matter scalar value.

func (*Document) PrepareReplaceHTMLAnchor

func (d *Document) PrepareReplaceHTMLAnchor(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceHTMLAnchor prepares a source-preserving replacement of a promoted HTML anchor id/name value.

func (*Document) PrepareReplaceHTMLComment

func (d *Document) PrepareReplaceHTMLComment(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceHTMLComment prepares a source-preserving replacement of a promoted HTML comment payload.

func (*Document) PrepareReplaceImageDestination

func (d *Document) PrepareReplaceImageDestination(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceImageDestination prepares a source-preserving replacement of a promoted image destination.

func (*Document) PrepareReplaceInlineLinkDestination

func (d *Document) PrepareReplaceInlineLinkDestination(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceInlineLinkDestination prepares a source-preserving replacement of a promoted inline-link destination.

func (*Document) PrepareReplaceListItem

func (d *Document) PrepareReplaceListItem(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceListItem prepares a source-preserving replacement of promoted list-item content.

func (*Document) PrepareReplaceListItemSubtree

func (d *Document) PrepareReplaceListItemSubtree(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceListItemSubtree prepares replacement of one complete supported list-item subtree while preserving its external sibling shape and semantic parent.

func (*Document) PrepareReplaceParagraph

func (d *Document) PrepareReplaceParagraph(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceParagraph prepares a source-preserving paragraph replacement.

func (*Document) PrepareReplaceReferenceDefinitionDestination

func (d *Document) PrepareReplaceReferenceDefinitionDestination(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceReferenceDefinitionDestination prepares a source-preserving replacement of a promoted reference-definition destination.

func (*Document) PrepareReplaceSection

func (d *Document) PrepareReplaceSection(headingID NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceSection prepares source-preserving replacement of one complete promoted section subtree.

func (*Document) PrepareReplaceSectionBody

func (d *Document) PrepareReplaceSectionBody(headingID NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceSectionBody prepares source-preserving replacement of one promoted section's direct body.

func (*Document) PrepareReplaceStrikethrough

func (d *Document) PrepareReplaceStrikethrough(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceStrikethrough prepares a source-preserving replacement of promoted strikethrough content.

func (*Document) PrepareReplaceStrong

func (d *Document) PrepareReplaceStrong(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceStrong prepares a source-preserving replacement of promoted strong-emphasis content.

func (*Document) PrepareReplaceTableCell

func (d *Document) PrepareReplaceTableCell(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceTableCell prepares a source-preserving replacement of promoted table-cell content.

func (*Document) PrepareReplaceTableRow

func (d *Document) PrepareReplaceTableRow(id NodeID, replacement []byte) (ChangeSet, error)

PrepareReplaceTableRow prepares source-preserving replacement of one complete promoted GFM table body row.

func (*Document) PrepareSetTableAlignments

func (d *Document) PrepareSetTableAlignments(id NodeID, alignments []TableAlignment) (ChangeSet, error)

PrepareSetTableAlignments prepares one atomic source-preserving alignment update for every promoted GFM table column.

func (*Document) PrepareSetTableColumnAlignment

func (d *Document) PrepareSetTableColumnAlignment(id NodeID, column int, alignment TableAlignment) (ChangeSet, error)

PrepareSetTableColumnAlignment prepares a source-preserving alignment change for one promoted GFM table column.

func (*Document) PrepareSetTaskChecked

func (d *Document) PrepareSetTaskChecked(id NodeID, checked bool) (ChangeSet, error)

PrepareSetTaskChecked prepares a source-preserving GFM task state change.

func (*Document) ReferenceDefinition

func (d *Document) ReferenceDefinition(id NodeID) (ReferenceDefinition, bool)

ReferenceDefinition returns typed detail for one promoted single-line reference definition.

func (*Document) Section

func (d *Document) Section(headingID NodeID) (Section, bool)

Section returns the derived section governed by headingID.

func (*Document) SectionChildHeadingIDs

func (d *Document) SectionChildHeadingIDs(headingID NodeID) ([]NodeID, bool)

SectionChildHeadingIDs returns one section's immediate child heading identities in source order.

func (*Document) Sections

func (d *Document) Sections() []Section

Sections returns all derived document sections in source order.

func (*Document) SourceRange

func (d *Document) SourceRange(range_ Range) ([]byte, bool)

SourceRange returns a copy of one valid byte range from the immutable source snapshot. Caller mutations of the returned bytes do not affect the document.

func (*Document) Strikethrough

func (d *Document) Strikethrough(id NodeID) (Strikethrough, bool)

Strikethrough returns typed detail for one promoted simple GFM strikethrough.

func (*Document) Strong

func (d *Document) Strong(id NodeID) (Strong, bool)

Strong returns typed detail for one promoted simple strong-emphasis span.

func (*Document) Table

func (d *Document) Table(id NodeID) (Table, bool)

Table returns typed detail for one promoted GFM table.

func (*Document) TableAlignments

func (d *Document) TableAlignments(tableID NodeID) ([]TableAlignment, bool)

TableAlignments returns one semantic alignment per source-proven table column. The returned slice is caller-owned.

func (*Document) TableCell

func (d *Document) TableCell(id NodeID) (TableCell, bool)

TableCell returns typed detail for one promoted non-empty GFM table cell.

func (*Document) TableHeaderCellIDs

func (d *Document) TableHeaderCellIDs(tableID NodeID) ([]NodeID, bool)

TableHeaderCellIDs returns the promoted non-empty header-cell identities owned by one promoted table in source order. Empty or otherwise unpromoted header cells are omitted.

func (*Document) TableRow

func (d *Document) TableRow(id NodeID) (TableRow, bool)

TableRow returns typed detail for one promoted GFM table body row.

func (*Document) TableRowAlignments

func (d *Document) TableRowAlignments(rowID NodeID) ([]TableAlignment, bool)

TableRowAlignments returns the semantic column alignments for the table that owns one promoted body row. The returned slice has exactly TableRow.ColumnCount entries and is caller-owned.

func (*Document) TableRowCellIDs

func (d *Document) TableRowCellIDs(rowID NodeID) ([]NodeID, bool)

TableRowCellIDs returns the promoted non-empty cells owned by one promoted body row in source order. Empty cells are omitted because M5 does not assign them public cell identities.

func (*Document) TableRowHeaderCellIDs

func (d *Document) TableRowHeaderCellIDs(rowID NodeID) ([]NodeID, bool)

TableRowHeaderCellIDs returns the promoted non-empty header cells for the table that owns one promoted body row. Empty header cells are omitted because M5 does not assign them public cell identities.

func (*Document) TableRowIDs

func (d *Document) TableRowIDs(tableID NodeID) ([]NodeID, bool)

TableRowIDs returns the promoted body-row identities owned by one promoted table in source order. The returned slice is caller-owned and can be empty even when BodyRowCount is non-zero.

func (*Document) Task

func (d *Document) Task(id NodeID) (Task, bool)

Task returns typed detail for one promoted GFM task marker.

func (*Document) ThematicBreak

func (d *Document) ThematicBreak(id NodeID) (ThematicBreak, bool)

ThematicBreak returns typed detail for one promoted top-level thematic break.

type DocumentBuilder

type DocumentBuilder struct {
	// contains filtered or unexported fields
}

DocumentBuilder constructs a new GFM document independently from parsed source snapshots.

M44-M89 support one optional document-leading YAML/TOML front-matter envelope, top-level ATX headings, parser-proven paragraphs, thematic breaks, parser-proven single-paragraph and reviewed multi-block blockquotes, flat or homogeneous nested unordered/ordered lists and task lists, supported fenced code, simple reference definitions, canonical unaligned/aligned tables, and typed inline construction for semantic text plus conservative code/emphasis/strong, strikethrough, link, image, and angle-autolink content, including bounded reviewed structured inline nesting. Generated documents use LF line endings, one blank line between GFM blocks, one blank line between retained front matter and a non-empty body, and one final line ending.

Example
package main

import (
	"fmt"

	"github.com/zoster81/marksplice"
)

func main() {
	builder := marksplice.NewDocumentBuilder()
	if err := builder.AppendHeadingContent(1, marksplice.TextInline("Marksplice")); err != nil {
		panic(err)
	}
	if err := builder.AppendParagraphContent(marksplice.TextInline("Source preserving GFM")); err != nil {
		panic(err)
	}

	source, err := builder.Markdown()
	if err != nil {
		panic(err)
	}
	fmt.Print(string(source))

}
Output:
# Marksplice

Source preserving GFM

func NewDocumentBuilder

func NewDocumentBuilder() *DocumentBuilder

NewDocumentBuilder returns an empty new-document builder.

func (*DocumentBuilder) AppendBlockquote

func (b *DocumentBuilder) AppendBlockquote(inlineGFM string) error

AppendBlockquote appends one top-level blockquote containing one paragraph.

M56 introduced the canonical single-line '> ' form. M81 extends the same API to non-empty LF-separated paragraph GFM and writes canonical '> ' on every physical line. The block is retained only when construction-only source and semantic proof reproduce exactly one top-level blockquote paragraph; broader existing-source blockquote promotion remains unchanged.

func (*DocumentBuilder) AppendBlockquoteBlocks

func (b *DocumentBuilder) AppendBlockquoteBlocks(depth int, content *DocumentBuilder) error

AppendBlockquoteBlocks appends one blockquote container from an existing child builder.

depth must be between 1 and 64. content is treated as an immutable construction snapshot: its current reviewed body blocks are copied into the new container, while later changes to content do not affect this builder. M83-M86 accept every reviewed body-block construction family, including recursive blockquote children whose total structural depth remains at most 64. Front matter remains a document envelope and is never accepted as a blockquote child.

func (*DocumentBuilder) AppendBlockquoteContent

func (b *DocumentBuilder) AppendBlockquoteContent(content ...Inline) error

AppendBlockquoteContent appends one simple top-level blockquote from typed inline content.

func (*DocumentBuilder) AppendFencedCode

func (b *DocumentBuilder) AppendFencedCode(content, info string) error

AppendFencedCode appends one top-level fenced code block.

M49 introduced the canonical unindented backtick form; M53 extends content to non-empty LF-separated multiline text. The fence is at least three bytes and grows beyond every potentially closing backtick run in the body. info is an optional single-line raw GFM info string and must not contain backticks.

func (*DocumentBuilder) AppendHeading

func (b *DocumentBuilder) AppendHeading(level int, inlineGFM string) error

AppendHeading appends one top-level ATX heading.

inlineGFM must be one non-empty physical line of valid UTF-8 GFM source. The generated source is accepted only when reparsing proves the requested heading level and exact content range.

func (*DocumentBuilder) AppendHeadingContent

func (b *DocumentBuilder) AppendHeadingContent(level int, content ...Inline) error

AppendHeadingContent appends one top-level ATX heading from typed inline content.

func (*DocumentBuilder) AppendNestedBlockquote

func (b *DocumentBuilder) AppendNestedBlockquote(depth int, inlineGFM string) error

AppendNestedBlockquote appends one explicitly nested blockquote containing one paragraph.

depth is structural container depth and must be between 2 and 64. The writer derives the canonical repeated "> " prefix on every physical line; caller content remains raw paragraph GFM and must not introduce container structure that changes the requested nesting hierarchy.

func (*DocumentBuilder) AppendNestedBlockquoteContent

func (b *DocumentBuilder) AppendNestedBlockquoteContent(depth int, content ...Inline) error

AppendNestedBlockquoteContent appends one explicitly nested blockquote from typed inline content.

func (*DocumentBuilder) AppendNestedOrderedList

func (b *DocumentBuilder) AppendNestedOrderedList(items ...ListItemInput) error

AppendNestedOrderedList appends one homogeneous nested ordered list.

M58 uses the same structural depth contract as M57. Decimal numbering starts at 1 in every list container and indentation follows the actual generated parent marker width, including transitions such as '9.' to '10.'.

func (*DocumentBuilder) AppendNestedOrderedTaskList

func (b *DocumentBuilder) AppendNestedOrderedTaskList(items ...TaskListItemInput) error

AppendNestedOrderedTaskList appends one homogeneous nested ordered GFM task list. M60 combines M58 container-local numbering/indentation with M48 task proof.

func (*DocumentBuilder) AppendNestedUnorderedList

func (b *DocumentBuilder) AppendNestedUnorderedList(items ...ListItemInput) error

AppendNestedUnorderedList appends one homogeneous nested unordered list.

M57 accepts source-ordered ListItemInput values whose Depth describes the parent/child hierarchy. The writer uses canonical '-' markers and derives each nested indentation from the generated parent's exact content column.

func (*DocumentBuilder) AppendNestedUnorderedTaskList

func (b *DocumentBuilder) AppendNestedUnorderedTaskList(items ...TaskListItemInput) error

AppendNestedUnorderedTaskList appends one homogeneous nested unordered GFM task list. M59 combines M57 structural depth with the exact M47 task-marker/state proof.

func (*DocumentBuilder) AppendOrderedList

func (b *DocumentBuilder) AppendOrderedList(items ...string) error

AppendOrderedList appends one flat top-level ordered list.

M46 writes canonical sequential decimal markers beginning at 1 with '.' as the delimiter. The generated items must reparse as one ordered list container.

func (*DocumentBuilder) AppendOrderedTaskList

func (b *DocumentBuilder) AppendOrderedTaskList(items ...TaskListItem) error

AppendOrderedTaskList appends one flat top-level ordered GFM task list.

M48 combines canonical sequential '1.', '2.', ... list markers with the same semantic task proof used by unordered task lists.

func (*DocumentBuilder) AppendParagraph

func (b *DocumentBuilder) AppendParagraph(inlineGFM string) error

AppendParagraph appends one top-level paragraph.

M54 accepts non-empty valid UTF-8 GFM source with canonical LF line endings. The complete input must reparse as exactly one top-level paragraph; input that becomes multiple blocks or another block kind fails closed instead of being escaped or normalized implicitly.

func (*DocumentBuilder) AppendParagraphContent

func (b *DocumentBuilder) AppendParagraphContent(content ...Inline) error

AppendParagraphContent appends one top-level single-line paragraph from typed inline content.

func (*DocumentBuilder) AppendReferenceDefinition

func (b *DocumentBuilder) AppendReferenceDefinition(label, destination string) error

AppendReferenceDefinition appends one top-level single-line link reference definition.

M50 writes canonical angle-bracket destination syntax without a title. The generated definition is retained only when reparsing reproduces the exact label, destination, and source mapping.

func (*DocumentBuilder) AppendReferenceDefinitionWithTitle

func (b *DocumentBuilder) AppendReferenceDefinitionWithTitle(label, destination, title string) error

AppendReferenceDefinitionWithTitle appends one top-level single-line link reference definition with a canonical double-quoted title.

M61 keeps the existing M50 angle-bracket destination form and accepts the block only when reparsing reproduces the exact label, destination, title, and source mapping. title must not require escaping in the canonical form.

func (*DocumentBuilder) AppendTable

func (b *DocumentBuilder) AppendTable(header []string, rows ...[]string) error

AppendTable appends one top-level unaligned GFM table.

M51 requires at least one header column and one body row. Every body row must have the same width as header. Cell strings are caller-provided single-line GFM source; empty cells are allowed. The builder writes canonical outer pipes and '---' delimiter cells and retains the table only after exact body-row and semantic table-container proof.

func (*DocumentBuilder) AppendTableWithAlignments

func (b *DocumentBuilder) AppendTableWithAlignments(header []string, alignments []TableAlignment, rows ...[]string) error

AppendTableWithAlignments appends one top-level GFM table with explicit semantic column alignments.

M62 preserves the M51 canonical outer-pipe/padding policy while writing delimiter cells as '---', ':---', '---:', or ':---:' for default, left, right, or center alignment. alignments must have exactly one entry per header column.

func (*DocumentBuilder) AppendThematicBreak

func (b *DocumentBuilder) AppendThematicBreak() error

AppendThematicBreak appends one canonical top-level thematic break.

M55 writes exactly three hyphens and retains the block only when the internal GFM parser observes one top-level thematic break over those exact bytes.

func (*DocumentBuilder) AppendUnorderedList

func (b *DocumentBuilder) AppendUnorderedList(items ...string) error

AppendUnorderedList appends one flat top-level unordered list.

Each item must be one non-empty physical line of valid UTF-8 inline GFM. M45 writes the canonical '-' marker and accepts the block only when reparsing proves that every generated item belongs to the one requested list container.

func (*DocumentBuilder) AppendUnorderedTaskList

func (b *DocumentBuilder) AppendUnorderedTaskList(items ...TaskListItem) error

AppendUnorderedTaskList appends one flat top-level unordered GFM task list.

M47 writes canonical '-' list markers and '[ ]'/'[x]' task markers. The block is retained only when reparsing proves both the requested list container and each requested semantic task marker/state.

func (*DocumentBuilder) Markdown

func (b *DocumentBuilder) Markdown() ([]byte, error)

Markdown returns newly generated canonical GFM source.

The returned bytes are caller-owned. The zero-value builder produces an empty document. A nil builder reports ErrInvalidConstruction.

func (*DocumentBuilder) SetTOMLFrontMatter

func (b *DocumentBuilder) SetTOMLFrontMatter(fields ...FrontMatterFieldInput) error

SetTOMLFrontMatter configures one canonical leading TOML front-matter envelope. A DocumentBuilder can own at most one front-matter envelope.

func (*DocumentBuilder) SetYAMLFrontMatter

func (b *DocumentBuilder) SetYAMLFrontMatter(fields ...FrontMatterFieldInput) error

SetYAMLFrontMatter configures one canonical leading YAML front-matter envelope. A DocumentBuilder can own at most one front-matter envelope.

type Emphasis

type Emphasis struct {
	// contains filtered or unexported fields
}

Emphasis is immutable typed detail for one promoted simple emphasis span.

func (Emphasis) ID

func (e Emphasis) ID() NodeID

ID returns the emphasis span's snapshot-scoped node identity.

func (Emphasis) Range

func (e Emphasis) Range() Range

Range returns the exact emphasis content span replaced by PrepareReplaceEmphasis.

type FencedCode

type FencedCode struct {
	// contains filtered or unexported fields
}

FencedCode is immutable typed detail for one promoted supported fenced code block.

func (FencedCode) ID

func (f FencedCode) ID() NodeID

ID returns the fenced code block's snapshot-scoped node identity.

func (FencedCode) Range

func (f FencedCode) Range() Range

Range returns the exact fenced-code content span replaced by PrepareReplaceFencedCode. Internal body line endings are part of this span. Fence lines, info-string source, and the final line ending immediately before the closing fence are outside it.

type FrontMatterField

type FrontMatterField struct {
	// contains filtered or unexported fields
}

FrontMatterField is immutable typed detail for one promoted simple leading YAML/TOML scalar field.

func (FrontMatterField) Format

Format returns whether the field belongs to a YAML or TOML front-matter envelope.

func (FrontMatterField) ID

func (f FrontMatterField) ID() NodeID

ID returns the field's snapshot-scoped node identity.

func (FrontMatterField) Key

func (f FrontMatterField) Key() string

Key returns the recognized simple scalar field key.

func (FrontMatterField) Range

func (f FrontMatterField) Range() Range

Range returns the exact scalar value span replaced by PrepareReplaceFrontMatterValue. Delimiters, key spelling, separator spacing, quote wrappers, comments, and line endings are outside this range.

type FrontMatterFieldInput

type FrontMatterFieldInput struct {
	Key   string
	Value string
}

FrontMatterFieldInput is construction-only input for one canonical simple YAML/TOML string scalar.

Key uses the existing conservative front-matter key alphabet. Value is written as one double-quoted string and therefore must not require escaping.

type FrontMatterFormat

type FrontMatterFormat uint8

FrontMatterFormat identifies the source envelope format of a promoted front-matter field.

const (
	FrontMatterFormatUnknown FrontMatterFormat = iota
	FrontMatterFormatYAML
	FrontMatterFormatTOML
)

type HTMLAnchor

type HTMLAnchor struct {
	// contains filtered or unexported fields
}

HTMLAnchor is immutable typed detail for one promoted simple quoted id/name attribute on an <a> tag.

func (HTMLAnchor) Attribute

func (a HTMLAnchor) Attribute() HTMLAnchorAttribute

Attribute returns whether the promoted anchor targets an id or name attribute.

func (HTMLAnchor) ID

func (a HTMLAnchor) ID() NodeID

ID returns the HTML anchor's snapshot-scoped node identity.

func (HTMLAnchor) Range

func (a HTMLAnchor) Range() Range

Range returns the exact quoted attribute value span replaced by PrepareReplaceHTMLAnchor. Tag/attribute spelling, spacing, quote wrappers, and other attributes are outside this range.

type HTMLAnchorAttribute

type HTMLAnchorAttribute uint8

HTMLAnchorAttribute identifies the semantic anchor attribute targeted by an HTMLAnchor.

const (
	HTMLAnchorAttributeUnknown HTMLAnchorAttribute = iota
	HTMLAnchorAttributeID
	HTMLAnchorAttributeName
)

type HTMLComment

type HTMLComment struct {
	// contains filtered or unexported fields
}

HTMLComment is immutable typed detail for one promoted single-line HTML comment payload.

func (HTMLComment) ID

func (c HTMLComment) ID() NodeID

ID returns the HTML comment's snapshot-scoped node identity.

func (HTMLComment) Range

func (c HTMLComment) Range() Range

Range returns the exact comment payload span replaced by PrepareReplaceHTMLComment. Comment delimiters and preserved inner horizontal padding are outside this range.

type Heading

type Heading struct {
	// contains filtered or unexported fields
}

Heading is immutable typed detail for one promoted top-level heading.

func (Heading) ID

func (h Heading) ID() NodeID

ID returns the heading's snapshot-scoped node identity.

func (Heading) Level

func (h Heading) Level() int

Level returns the GFM heading level from 1 through 6.

func (Heading) Range

func (h Heading) Range() Range

Range returns the exact heading-content byte span replaced by PrepareRenameHeading. ATX markers, optional closing markers, Setext underlines, and line endings are outside this range.

func (Heading) Style

func (h Heading) Style() HeadingStyle

Style returns whether the heading uses ATX or Setext source syntax.

type HeadingStyle

type HeadingStyle uint8

HeadingStyle identifies the source syntax of a promoted heading.

const (
	HeadingStyleUnknown HeadingStyle = iota
	HeadingStyleATX
	HeadingStyleSetext
)

type Image

type Image struct {
	// contains filtered or unexported fields
}

Image is immutable typed detail for one promoted simple inline image.

func (Image) ID

func (i Image) ID() NodeID

ID returns the image's snapshot-scoped node identity.

func (Image) Range

func (i Image) Range() Range

Range returns the exact destination span replaced by PrepareReplaceImageDestination. The image marker, alt text, parentheses, destination wrappers, title syntax, and surrounding source are outside this range.

type Inline

type Inline struct {
	// contains filtered or unexported fields
}

Inline is a construction-only typed inline value.

Its zero value is invalid. Use the exported Inline construction functions rather than depending on its private representation.

func AutoLinkInline

func AutoLinkInline(value string) Inline

AutoLinkInline returns one canonical angle-autolink construction value. Validation succeeds only when reparsing produces the existing source-proven AutoLink capability.

func CodeInline

func CodeInline(code string) Inline

CodeInline returns one conservative single-line code span construction value.

M76 selects an adaptive backtick delimiter longer than every internal run. Leading/trailing horizontal space and leading/trailing backticks are rejected because supporting those shapes would require semantic whitespace or delimiter normalization beyond the existing source-proven parsed CodeSpan capability.

func EmphasisInline

func EmphasisInline(content ...Inline) Inline

EmphasisInline returns one conservative emphasis construction value. M88 permits bounded nesting of code, emphasis, strong, and strikethrough children while keeping links/images/autolinks outside this wrapper slice.

func ImageInline

func ImageInline(destination string, alt ...Inline) Inline

ImageInline returns one conservative inline-image construction value.

M77 writes the destination in angle brackets and accepts only TextInline alt-text children. M87 adds the separate WithTitle constructor; broader structured alt text remains deferred.

func ImageInlineWithTitle

func ImageInlineWithTitle(destination, title string, alt ...Inline) Inline

ImageInlineWithTitle returns one conservative inline-image construction value with a canonical double-quoted title. M87 applies the same conservative title policy as LinkInlineWithTitle.

func LinkInline

func LinkInline(destination string, label ...Inline) Inline

LinkInline returns one conservative inline-link construction value.

M77 writes the destination in angle brackets and accepts only TextInline label children. M87 adds the separate WithTitle constructor; broader structured labels remain deferred.

func LinkInlineWithTitle

func LinkInlineWithTitle(destination, title string, label ...Inline) Inline

LinkInlineWithTitle returns one conservative inline-link construction value with a canonical double-quoted title. M87 requires a non-empty title that needs no GFM escape or entity interpretation.

func ReferenceImageInline

func ReferenceImageInline(reference string, alt ...Inline) Inline

ReferenceImageInline returns one conservative full reference-image construction value. It follows the same existing exact-definition requirement as ReferenceLinkInline.

func ReferenceLinkInline

func ReferenceLinkInline(reference string, label ...Inline) Inline

ReferenceLinkInline returns one conservative full reference-link construction value. The exact reference label must identify one already-appended top-level reference definition in the destination DocumentBuilder when the value is appended.

func StrikethroughInline

func StrikethroughInline(content ...Inline) Inline

StrikethroughInline returns one conservative GFM strikethrough construction value. M88 permits bounded code/emphasis/strong children but rejects direct strikethrough-in-strikethrough nesting because adjacent tilde runs are ambiguous.

func StrongInline

func StrongInline(content ...Inline) Inline

StrongInline returns one conservative strong-emphasis construction value. M88 applies the same bounded structured-child policy as EmphasisInline.

func TextInline

func TextInline(text string) Inline

TextInline returns semantic plain text for typed inline construction.

M75 encodes ASCII punctuation with canonical GFM backslash escapes so caller text cannot become Markdown syntax implicitly. Validation occurs when the value is appended to a DocumentBuilder.

type InlineLink struct {
	// contains filtered or unexported fields
}

InlineLink is immutable typed detail for one promoted simple inline link.

func (InlineLink) ID

func (l InlineLink) ID() NodeID

ID returns the inline link's snapshot-scoped node identity.

func (InlineLink) Range

func (l InlineLink) Range() Range

Range returns the exact destination span replaced by PrepareReplaceInlineLinkDestination. Label, parentheses, destination wrappers, title syntax, and surrounding source are outside this range.

type Kind

type Kind uint8

Kind identifies a structural Markdown node category.

const (
	KindUnknown Kind = iota
	KindParagraph
	KindHeading
	KindListItem
	KindTask
	KindTableCell
	KindFencedCode
	KindStrikethrough
	KindCodeSpan
	KindEmphasis
	KindStrong
	KindInlineLink
	KindReferenceDefinition
	KindAutoLink
	KindFrontMatterField
	KindHTMLComment
	KindHTMLAnchor
	KindImage
	KindTableRow
	KindTable
	KindThematicBreak
	KindBlockquote
)

type ListItem

type ListItem struct {
	// contains filtered or unexported fields
}

ListItem is immutable typed detail for one promoted single-line list item.

func (ListItem) ChildIDs

func (i ListItem) ChildIDs() []NodeID

ChildIDs returns the immediate supported list-item child identities in source order. Semantic children outside the promoted public subset are omitted.

func (ListItem) HasChildren

func (i ListItem) HasChildren() bool

HasChildren reports whether the supported single-line item owns one or more semantic direct child list items. It can be true even when ChildIDs is empty because unsupported children are not assigned public identities.

func (ListItem) ID

func (i ListItem) ID() NodeID

ID returns the list item's snapshot-scoped node identity.

func (ListItem) Marker

func (i ListItem) Marker() byte

Marker returns the source marker/delimiter byte. Unordered items use '-', '*', or '+'; ordered items use '.' or ')'.

func (ListItem) Ordered

func (i ListItem) Ordered() bool

Ordered reports whether the item belongs to an ordered list.

func (ListItem) ParentID

func (i ListItem) ParentID() (NodeID, bool)

ParentID returns the immediate supported list-item parent's snapshot-scoped identity. The boolean is false for root items and when the semantic parent exists but is not publicly promoted.

func (ListItem) Range

func (i ListItem) Range() Range

Range returns the exact list-item content span replaced by PrepareReplaceListItem. Indentation, list numbering, marker/delimiter bytes, post-marker spacing, and line endings are outside this range.

func (ListItem) SubtreeRange

func (i ListItem) SubtreeRange() (Range, bool)

SubtreeRange returns the exact complete supported subtree source span used by structural list-item operations. The boolean is false when Marksplice cannot prove that every semantic descendant belongs to the supported list-item model.

type ListItemInput

type ListItemInput struct {
	InlineGFM string
	Depth     int
}

ListItemInput is construction-only structured input for one item in a nested list.

Depth is structural depth, not source indentation: zero denotes a top-level item and each child is exactly one level deeper than its parent. DocumentBuilder derives canonical indentation from the generated parent marker width.

type Node

type Node struct {
	// contains filtered or unexported fields
}

Node is an immutable public summary of one promoted structural node.

Syntax-specific details and source ranges are intentionally not part of this common value until their public semantics are reviewed.

func (Node) ID

func (n Node) ID() NodeID

ID returns the snapshot-scoped node identity.

func (Node) Kind

func (n Node) Kind() Kind

Kind returns the structural node category.

type NodeID

type NodeID struct {
	// contains filtered or unexported fields
}

NodeID identifies a node within one parsed source snapshot.

Node IDs are deterministic for a snapshot, but they are not durable identities across arbitrary source changes or reparses. The representation is opaque; String is for diagnostics and does not define a persistence or round-trip format.

func (NodeID) String

func (id NodeID) String() string

String returns a diagnostic representation of the snapshot-scoped ID.

type Paragraph

type Paragraph struct {
	// contains filtered or unexported fields
}

Paragraph is immutable typed detail for one promoted top-level paragraph.

func (Paragraph) ID

func (p Paragraph) ID() NodeID

ID returns the paragraph's snapshot-scoped node identity.

func (Paragraph) Range

func (p Paragraph) Range() Range

Range returns the exact paragraph byte span replaced by PrepareReplaceParagraph. A line ending immediately following the paragraph is outside this range.

type Range

type Range struct {
	Start int
	End   int
}

Range is a half-open byte range [Start, End) in a source snapshot. The accessor returning a Range defines the semantic meaning of that span.

func (Range) Valid

func (r Range) Valid(total int) bool

Valid reports whether r is ordered and contained in a source of total bytes.

type ReferenceDefinition

type ReferenceDefinition struct {
	// contains filtered or unexported fields
}

ReferenceDefinition is immutable typed detail for one promoted single-line reference definition.

func (ReferenceDefinition) ID

func (r ReferenceDefinition) ID() NodeID

ID returns the reference definition's snapshot-scoped node identity.

func (ReferenceDefinition) Range

func (r ReferenceDefinition) Range() Range

Range returns the exact destination span replaced by PrepareReplaceReferenceDefinitionDestination. Label, colon, destination wrappers, title syntax, indentation, trailing spaces, and line endings are outside this range.

type Section

type Section struct {
	// contains filtered or unexported fields
}

Section is an immutable source-bound view governed by one promoted document heading.

func (Section) BodyRange

func (s Section) BodyRange() Range

BodyRange returns the direct body source span after the heading line and before the next heading of any level. Nested subsection headings and their content are outside this range.

func (Section) HeadingID

func (s Section) HeadingID() NodeID

HeadingID returns the snapshot-scoped heading node identity governing this section.

func (Section) Level

func (s Section) Level() int

Level returns the governing GFM heading level from 1 through 6.

func (Section) ParentHeadingID

func (s Section) ParentHeadingID() (NodeID, bool)

ParentHeadingID returns the governing heading ID of the nearest enclosing section.

func (Section) Range

func (s Section) Range() Range

Range returns the complete section subtree source span, including its heading. The range ends immediately before the next heading of equal or higher level, or at end of source.

type Strikethrough

type Strikethrough struct {
	// contains filtered or unexported fields
}

Strikethrough is immutable typed detail for one promoted simple GFM strikethrough.

func (Strikethrough) ID

func (s Strikethrough) ID() NodeID

ID returns the strikethrough's snapshot-scoped node identity.

func (Strikethrough) Range

func (s Strikethrough) Range() Range

Range returns the exact strikethrough content span replaced by PrepareReplaceStrikethrough.

type Strong

type Strong struct {
	// contains filtered or unexported fields
}

Strong is immutable typed detail for one promoted simple strong-emphasis span.

func (Strong) ID

func (s Strong) ID() NodeID

ID returns the strong span's snapshot-scoped node identity.

func (Strong) Range

func (s Strong) Range() Range

Range returns the exact strong content span replaced by PrepareReplaceStrong.

type Table

type Table struct {
	// contains filtered or unexported fields
}

Table is immutable typed detail for one promoted GFM table.

func (Table) BodyRowCount

func (t Table) BodyRowCount() int

BodyRowCount returns the semantic number of body rows, including rows outside the promoted public row subset.

func (Table) ColumnCount

func (t Table) ColumnCount() int

ColumnCount returns the semantic/source-proven number of table columns.

func (Table) ID

func (t Table) ID() NodeID

ID returns the table's snapshot-scoped node identity.

func (Table) Range

func (t Table) Range() Range

Range returns the exact complete table source span. It owns the header row, delimiter row, and every semantic body row; when present, the final owned line terminator is included.

type TableAlignment

type TableAlignment uint8

TableAlignment identifies the semantic alignment of a GFM table column. It is used for new-document construction and read-only parsed table alignment access.

const (
	TableAlignmentDefault TableAlignment = iota
	TableAlignmentLeft
	TableAlignmentRight
	TableAlignmentCenter
)

type TableCell

type TableCell struct {
	// contains filtered or unexported fields
}

TableCell is immutable typed detail for one promoted non-empty GFM table cell.

func (TableCell) Column

func (c TableCell) Column() int

Column returns the zero-based column index within the mapped table row.

func (TableCell) Header

func (c TableCell) Header() bool

Header reports whether the cell belongs to the table header row.

func (TableCell) ID

func (c TableCell) ID() NodeID

ID returns the table cell's snapshot-scoped node identity.

func (TableCell) Range

func (c TableCell) Range() Range

Range returns the exact table-cell content span replaced by PrepareReplaceTableCell. Pipes, cell padding, alignment syntax, neighboring cells, and line endings are outside this range.

func (TableCell) RowID

func (c TableCell) RowID() (NodeID, bool)

RowID returns the promoted GFM body row that owns this cell. The boolean is false for header cells and when no promoted body-row identity is available.

func (TableCell) TableID

func (c TableCell) TableID() (NodeID, bool)

TableID returns the promoted GFM table that owns this cell. The boolean is false when no promoted table identity is available.

type TableRow

type TableRow struct {
	// contains filtered or unexported fields
}

TableRow is immutable typed detail for one promoted GFM table body row.

func (TableRow) ColumnCount

func (r TableRow) ColumnCount() int

ColumnCount returns the semantic/source-proven number of columns in the body row.

func (TableRow) ID

func (r TableRow) ID() NodeID

ID returns the table row's snapshot-scoped node identity.

func (TableRow) NextID

func (r TableRow) NextID() (NodeID, bool)

NextID returns the nearest promoted body row after this row in the same table.

func (TableRow) PreviousID

func (r TableRow) PreviousID() (NodeID, bool)

PreviousID returns the nearest promoted body row before this row in the same table.

func (TableRow) Range

func (r TableRow) Range() Range

Range returns the exact complete physical body-row span used by structural row operations. When present, the row's own line terminator is included; header and delimiter rows are never part of this range.

func (TableRow) TableID

func (r TableRow) TableID() (NodeID, bool)

TableID returns the promoted GFM table that owns this body row. The boolean is false when no promoted table identity is available.

type Task

type Task struct {
	// contains filtered or unexported fields
}

Task is immutable typed detail for one promoted GFM task marker.

func (Task) Checked

func (t Task) Checked() bool

Checked reports the semantic task state.

func (Task) ID

func (t Task) ID() NodeID

ID returns the task's snapshot-scoped node identity.

func (Task) Range

func (t Task) Range() Range

Range returns the exact one-byte task state span changed by PrepareSetTaskChecked. The surrounding brackets and list-item source are outside this range.

type TaskListItem

type TaskListItem struct {
	InlineGFM string
	Checked   bool
}

TaskListItem is structured input for one newly constructed GFM task-list item. InlineGFM is caller-provided inline GFM source; Checked selects the canonical '[x]' or '[ ]' task marker written before that content.

type TaskListItemInput

type TaskListItemInput struct {
	InlineGFM string
	Checked   bool
	Depth     int
}

TaskListItemInput is construction-only structured input for one item in a nested task list. Depth follows the same structural contract as ListItemInput.

type ThematicBreak

type ThematicBreak struct {
	// contains filtered or unexported fields
}

ThematicBreak is immutable typed detail for one promoted top-level thematic break.

func (ThematicBreak) ID

func (t ThematicBreak) ID() NodeID

ID returns the thematic break's snapshot-scoped node identity.

func (ThematicBreak) Range

func (t ThematicBreak) Range() Range

Range returns the exact complete physical line owned by structural thematic-break operations. When present, the line terminator is included.

Directories

Path Synopsis
internal
publictest
Package publictest hosts black-box tests of the public Marksplice API.
Package publictest hosts black-box tests of the public Marksplice API.

Jump to

Keyboard shortcuts

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