Documentation
¶
Index ¶
- func ExtractText(n ast.Node, source []byte, buf *bytes.Buffer)
- func HeadingLine(heading *ast.Heading, f *lint.File) int
- func HeadingText(heading *ast.Heading, source []byte) string
- func IsTable(para *ast.Paragraph, f *lint.File) bool
- func ParagraphLine(para *ast.Paragraph, f *lint.File) int
- func SectionBody(paragraphs []SectionParagraph, start, end int) string
- func SectionEnd(headings []SectionHeading, i, totalLines int) int
- type SectionHeading
- type SectionParagraph
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ExtractText ¶
ExtractText recursively writes the text content of n and its descendants into buf.
func HeadingLine ¶
HeadingLine returns the 1-based source line of a heading node. Setext headings expose their line via Lines(); ATX headings are found by walking inline descendants until the first text segment. Returns 1 as a safe fallback.
func HeadingText ¶
HeadingText returns the plain-text content of a heading by recursively extracting all text segments from its children.
func IsTable ¶
IsTable reports whether a paragraph node is actually a GFM table (goldmark parses tables as paragraphs when the table extension is absent). It checks whether the first line starts with "|".
func ParagraphLine ¶
ParagraphLine returns the 1-based source line of a paragraph node.
func SectionBody ¶ added in v0.16.0
func SectionBody(paragraphs []SectionParagraph, start, end int) string
SectionBody concatenates paragraph plain text for paragraphs whose start line falls in [start, end). Joins with a space so adjacent paragraphs do not appear glued together to a substring/regex matcher.
func SectionEnd ¶ added in v0.16.0
func SectionEnd(headings []SectionHeading, i, totalLines int) int
SectionEnd returns the exclusive end line of the section starting at headings[i]. The section ends at the first heading at the same or shallower level after headings[i], or at totalLines+1 when no such heading exists. Nested sub-sections stay inside.
Types ¶
type SectionHeading ¶ added in v0.16.0
SectionHeading is a heading discovered by CollectSectionHeadings, carrying the level and source line needed to compute a section's body range.
func CollectSectionHeadings ¶ added in v0.16.0
func CollectSectionHeadings(f *lint.File) []SectionHeading
CollectSectionHeadings returns every heading in the document ordered by source line. Used by content rules (MDS057, MDS058) that need to walk heading-bounded sections.
type SectionParagraph ¶ added in v0.16.0
SectionParagraph is a non-table paragraph discovered by CollectSectionParagraphs, carrying its 1-based source line and the plain text used for section-wide body matches.
func CollectSectionParagraphs ¶ added in v0.16.0
func CollectSectionParagraphs(f *lint.File) []SectionParagraph
CollectSectionParagraphs returns every non-table paragraph with its 1-based source line and plain text. Goldmark parses pipe-delimited tables as paragraphs when the table extension is absent; those are filtered so cell text does not pollute section bodies.
Memoized per File via lint.File.MemoFile (the *File-passing variant of Memo): this walks the whole AST and runs ExtractPlainText on every paragraph. On prose-heavy input the two hot default rules (MDS024 paragraph-structure and paragraph-readability) plus the required-* rules each called it, so the walk and per-paragraph extraction ran several times per file. The result is a pure function of the immutable AST and Source; the memo lives on the per-Check File, so nothing is cached across files or runs. Callers treat the slice as read-only.
The MemoFile variant lets buildSectionParagraphs be a package- level function instead of a closure, so the build itself adds no per-call allocation beyond what the function body does.