Documentation
¶
Overview ¶
Package mdrecord is the Markdown machinery a RECORD BODY is read and written through: which lines are live markdown and which are not, where a section starts and stops, what a top-level bullet is, and where a trailing run of link-reference definitions ends.
It is a leaf for the reason core/grounds and core/issueschema are. Two record families carry the same constructs — the intent record's scope conditions and audit notes, the issue ledger's grounds — and a body reader spelled twice is a reader the two can disagree about, which is how a bullet one writer appends is a bullet the other cannot find. It imports only the standard library: no filesystem, no transport, no record store, and no notion of which family a body belongs to.
What it does NOT own is any heading's meaning. A caller supplies the heading pattern it is looking for; this package only says whether a line matching it is live, and which lines lie under it.
Index ¶
- Constants
- func AnyMasked(mask []uint8, start, end int, flag uint8) bool
- func CodeSpanRanges(ln string) [][2]int
- func CountHeadings(lines []string, mask []uint8, headRe *regexp.Regexp) int
- func InAnyRange(ranges [][2]int, pos int) bool
- func IsHeading(ln string) bool
- func IsTopLevelBullet(ln string) bool
- func Mask(lines []string) []uint8
- func OpensComment(ln string) bool
- func PeelTrailingLinkRefs(section *[]string) []string
- func SectionLineRange(lines []string, headRe *regexp.Regexp) (start, end int, ok bool)
- func SectionLineRangeIn(lines []string, mask []uint8, headRe *regexp.Regexp) (start, end int, ok bool)
- func TrimBulletPrefix(ln string) string
- func Unclosed(lines []string) (line int, flag uint8, ok bool)
- type BulletBlock
Constants ¶
const ( MaskFence uint8 = 1 << iota MaskComment )
Mask flags: why a line is not live markdown. Both are read the same way — the line is neither matched nor written — but they are reported separately, so a refusal names the thing the reader has to go and look at.
Variables ¶
This section is empty.
Functions ¶
func CodeSpanRanges ¶
CodeSpanRanges returns the byte ranges of the inline code spans on one line: a run of backticks closed by a run of the same length (CommonMark).
func CountHeadings ¶
CountHeadings counts the live headings matching headRe.
func InAnyRange ¶
InAnyRange reports whether pos falls inside one of the ranges.
func IsHeading ¶
IsHeading reports whether a line is a markdown ATX heading. It judges the line alone: whether that heading is LIVE is Mask's answer, not this one's.
func IsTopLevelBullet ¶
IsTopLevelBullet reports whether a line opens a column-0 list item.
func Mask ¶
Mask reports, per line, whether that line lies inside a fenced code block or an HTML comment span — the delimiter lines included, since nothing on them is live markdown either. A parser that cannot see either reads an EXAMPLE, or a deliberately PARKED bullet, as an instruction: a fenced or commented `## Scope Conditions` shadows the record's real one, and a bullet inside either is counted as a condition and written into by the stamp. Writing a marker inside a comment is the worst of the three — the marker's own `-->` closes the comment early, so the rest of the parked block starts rendering (iss-2608300235388164, iss-2608300259316871).
Neither construct nests in the other: inside a fence `<!--` is literal text, and inside a comment a fence delimiter is. An unclosed opener of either kind runs to end of file — CommonMark's rule for a fence, and the only safe reading of a comment nobody closed.
func OpensComment ¶
OpensComment reports whether a line leaves an HTML comment open. It walks the line left to right and lets the FIRST construct win, which is CommonMark's own precedence: at a backtick run it skips a matched code span whole (or treats an unmatched run as literal backticks), and at `<!--` it skips to the `-->` that closes it — consuming any backticks in between, because inside a comment they are literal text.
Resolving code spans first, as this did, diverged in both directions: a backtick inside a LIVE comment re-paired the rest of the line, and a comment opener quoted in backticks read as live. One cursor closes both (iss-2608300320418618, iss-2608300335369473). A well-formed identity marker closes on its own line, so it never opens a span; a genuinely unclosed opener masks to end of file.
func PeelTrailingLinkRefs ¶
PeelTrailingLinkRefs removes a trailing run of markdown link-reference definitions (and any blank lines interspersed with them) from *section and returns that run, so an appending writer can re-emit it BELOW the new block. The run must contain at least one real definition — a tail of pure blank lines is not refs and is left to the caller's blank-trimming. Both the newly exposed end of *section and the leading blanks of the returned run are trimmed, so the caller reinstates exactly one separator on each side.
func SectionLineRange ¶
SectionLineRange returns the [start, end) line bounds of the body of the first live section whose heading matches headRe, and whether such a heading exists, which is what separates an absent section from an empty one.
This is the single notion of where a section starts and stops, so every reader and every writer of a record body agrees about which lines belong to which section.
func SectionLineRangeIn ¶
func SectionLineRangeIn(lines []string, mask []uint8, headRe *regexp.Regexp) (start, end int, ok bool)
SectionLineRangeIn is SectionLineRange over a mask the caller already computed. A masked line — fenced or commented — is neither the heading that opens a section nor the heading that closes one.
func TrimBulletPrefix ¶
TrimBulletPrefix strips a top-level list marker, leaving the bullet's prose.
func Unclosed ¶
Unclosed reports the line that opened a span nothing closes before the end of the input, and which construct it is (MaskFence or MaskComment).
An unclosed opener is not itself a fault — running it to end of file is CommonMark's rule for a fence and the only safe reading of a comment nobody closed, and Mask does exactly that. What it IS, is the reason every line below it stops being live markdown, so a writer whose appended line lands there can never read it back. That writer has to be able to NAME the line, or its refusal describes the symptom and sends the operator to rewrite whatever it was appending — which is the one part of the record that is innocent (iss-2608301803423101).
Types ¶
type BulletBlock ¶
type BulletBlock struct{ Start, End int }
BulletBlock is one top-level bullet and the continuation lines folded into it, as the half-open line range [Start, End).
func BulletBlocks ¶
func BulletBlocks(lines []string, mask []uint8, start, end int) []BulletBlock
BulletBlocks splits a section body into its top-level bullets. It is the single notion of where an item starts and stops, so a reader and a writer can never disagree about which lines belong to which item. A masked line — fenced or commented — neither opens a bullet nor continues one.