mdspan

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Overview

Package mdspan finds the inline spans of a markdown line that are not running prose: code spans and links.

It lives here because two readers need the same answer and neither may import the other: the extractor masks code spans so an example in code is not a directive, and the sentence binder must not end a sentence at a full stop inside a code span or a link's text. A second copy of the backtick rule is how the two would drift.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Link struct {
	All, Text, Dest Span
	Image           bool
}

Link is one inline link or image, `[text](destination)`, as byte ranges of its line. Dest excludes the angle brackets of a `<…>` destination.

func InlineLinks(line string) []Link

InlineLinks returns every inline link or image in line, in order.

The destination follows CommonMark: either `<…>`, which may hold spaces, or a run with no whitespace in which parentheses must balance, so `count(*)` stays inside the destination rather than ending it. Every reader of directive links -- the extractor, render, the sentence binder -- uses this one function. They each had a regular expression that stopped at the first `)` or space, so a query holding `count(*)` was cut short and one holding a space was not a link at all, and the directive vanished without a word (bug 51).

type Span

type Span struct{ Start, End int }

Span is a half-open byte range [Start, End) of a line.

func CodeSpans

func CodeSpans(line string) []Span

CodeSpans returns every inline code span in line, backticks included. A span opens at a run of backticks and closes at the next run of exactly the same length; a run with no closer is literal text, as CommonMark reads it. A span continuing onto the next line is not seen.

func Links(line string) []Span

Links returns every inline link or image in line, brackets included.

Jump to

Keyboard shortcuts

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