markup

package
v0.13.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package markup parses the body of a KerML textual representation written in a markup language into the content blocks a document plan is built from: paragraphs and lists of inline runs, each with its byte span in the body.

Index

Constants

View Source
const AsciiDocEnv = "OPENSYSML_ASCIIDOCTOR"

AsciiDocEnv names the environment variable that points at the AsciiDoc converter, scripts/asciidoc/asciidoctor-json.js run by node with Asciidoctor.js installed beside it, as scripts/download-doc-pdf-toolchain.sh provisions it.

View Source
const RefScheme = "sysml:"

RefScheme is the URI scheme under which a link destination names a model element rather than a URL.

View Source
const ValuePrefix = "value:"

ValuePrefix follows RefScheme when a destination reads a feature's value rather than referencing the element.

Variables

This section is empty.

Functions

func Languages

func Languages() string

Languages lists the supported languages, comma-separated, for diagnostics.

Types

type AsciiDoc

type AsciiDoc struct{}

AsciiDoc parses AsciiDoc bodies through Asciidoctor.js, run as an external converter that answers the document tree as JSON: paragraphs, admonitions, bullet and numbered lists of single paragraphs, tables of text cells under a header row, stem blocks and block images, with emphasis, strong, monospaced, `stem:[…]`, links, `<<xref>>`, `sysml:ref[…]` and `sysml:value[…]` inline.

func (AsciiDoc) External

func (AsciiDoc) External() bool

External reports that the converter runs outside the process.

func (AsciiDoc) Language

func (AsciiDoc) Language() string

Language implements Parser.

func (AsciiDoc) Parse

func (AsciiDoc) Parse(body string) ([]Block, error)

Parse implements Parser.

type Block

type Block struct {
	Kind BlockKind
	// Runs are a paragraph's inline runs.
	Runs []Run
	// Items are a list's items.
	Items []Item
	// Ordered is true for a numbered list.
	Ordered bool
	// Caption titles a table, formula or image.
	Caption string
	// ColumnLabels head a table's columns and ColumnWidths size them relative
	// to one another (empty for automatic widths).
	ColumnLabels []string
	ColumnWidths []int
	// Rows are a table's body rows, one text cell per column.
	Rows []TableRow
	// Source is a formula's LaTeX.
	Source string
	// Location and Alt are an image's file and alternative text.
	Location string
	Alt      string
	// Level, Title and ID are a heading's level (1 the outermost), plain
	// text and explicit anchor (empty when the markup gives none).
	Level int
	Title string
	ID    string
	Span  Span
}

Block is one content block of a body.

type BlockKind

type BlockKind string

BlockKind classifies a content block.

const (
	// BlockParagraph is a paragraph of inline runs.
	BlockParagraph BlockKind = "paragraph"
	// BlockList is a bullet or numbered list whose items are inline runs.
	BlockList BlockKind = "list"
	// BlockTable is a table of text cells under a header row.
	BlockTable BlockKind = "table"
	// BlockFormula is displayed mathematics: Source is LaTeX.
	BlockFormula BlockKind = "formula"
	// BlockImage is a figure read from a file: Location names it.
	BlockImage BlockKind = "image"
	// BlockHeading opens a section: Level is the markup's heading level and
	// Title its plain text, ID the explicit anchor the markup gave it.
	BlockHeading BlockKind = "heading"
)

type Item

type Item struct {
	Runs []Run
	Span Span
}

Item is one list item: a single paragraph of inline runs.

type Markdown

type Markdown struct{}

Markdown parses CommonMark bodies: paragraphs and tight or loose lists of single paragraphs, with emphasis, strong emphasis, code spans, links, autolinks, `sysml:` references and `$…$` mathematics inline. No GFM extension is enabled, so tables, footnotes, strikethrough and task lists read as the paragraphs CommonMark makes of them.

func (Markdown) External

func (Markdown) External() bool

External reports that Markdown is parsed in this process.

func (Markdown) Language

func (Markdown) Language() string

Language implements Parser.

func (Markdown) Parse

func (Markdown) Parse(body string) ([]Block, error)

Parse implements Parser.

type Parser

type Parser interface {
	// Language is the language string the parser serves, in canonical spelling.
	Language() string
	// Parse maps a body onto content blocks, or fails with an
	// *UnsupportedConstructError for a construct no content block carries.
	Parse(body string) ([]Block, error)
	// External reports whether Parse runs a converter of the host rather than
	// code of this process, so that what it answers is the host's.
	External() bool
}

Parser parses bodies written in one markup language.

func For

func For(language string) (Parser, bool)

For returns the parser for a textual representation's language, matched case-insensitively (KerML 1.0 §8.3.2.3.6); false for a language none serves.

type Run

type Run struct {
	Kind        RunKind
	Style       Style
	Text        string
	Destination string
	Span        Span
}

Run is one inline run of a paragraph or list item.

type RunKind

type RunKind string

RunKind classifies an inline run.

const (
	// RunText is styled prose.
	RunText RunKind = "text"
	// RunLink is a hyperlink: Text labels Destination, a URL.
	RunLink RunKind = "link"
	// RunRef is a model reference: Text labels Destination, the target's
	// notation after the `sysml:` scheme; an empty Text asks for the default label.
	RunRef RunKind = "ref"
	// RunValue is a model value: Destination is the feature's notation after
	// the `sysml:value:` scheme and Text the label the value follows, if any.
	RunValue RunKind = "value"
	// RunMath is inline mathematics: Text is LaTeX source.
	RunMath RunKind = "math"
)

type Span

type Span struct {
	Start int
	Stop  int
}

Span is a half-open byte range within a body.

type Style

type Style string

Style is the typographic style of a text run.

const (
	StylePlain    Style = "plain"
	StyleEmphasis Style = "emphasis"
	StyleStrong   Style = "strong"
	StyleCode     Style = "code"
)

type TableRow

type TableRow struct {
	Cells []string
	Span  Span
}

TableRow is one body row of a table: one plain-text cell per column.

type ToolError

type ToolError struct {
	Tool    string
	EnvVar  string
	Named   bool
	Missing bool
	Detail  string
}

ToolError reports the converter missing or failing: Tool is the converter looked for, Named whether EnvVar named it (else it is the default looked up on PATH), Missing whether it was not found, Detail what else was observed.

func (*ToolError) Error

func (e *ToolError) Error() string

type UnsupportedConstructError

type UnsupportedConstructError struct {
	Construct string
	Line      int
	Span      Span
}

UnsupportedConstructError reports a markup construct no content block carries, with the line of the body it starts on (1-based).

func (*UnsupportedConstructError) Error

func (e *UnsupportedConstructError) Error() string

Directories

Path Synopsis
Package markuptest stands in for the AsciiDoc converter in tests: a recorded converter answers each body it has a recording for, so the mapping is tested without node.
Package markuptest stands in for the AsciiDoc converter in tests: a recorded converter answers each body it has a recording for, so the mapping is tested without node.

Jump to

Keyboard shortcuts

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