Guidedog 手册 0.2.0
语言
本页内容
Guidedog / 文档 0.2.0

readers/rst/inline

Package rst_inline parses reStructuredText inline markup and resolves references. The block reader in lib/readers/rst owns lines, directives, and document structure; it calls parse_inline for every inline context and resolve once parsing ends.

Types

inline.Inline_State :: struct

Inline_State is shared, long-lived reader state for inline parsing.

ctx: ^gd.Read_Context
source: gd.Source_Id

the source the current lines come from.

roles: []Role

custom roles; storage owned by the block reader.

roles_used: int
default_role: string

“” means title-reference.

hook: Role_Hook

a dialect’s roles, consulted first; see extension.odin.

options: Options

settings of the block reader; see options.odin.

inline.Line :: gd.Line_View

Line is a view of one line of text. offset is the source byte offset of text[0]; for a line copied during tab expansion it is the offset of the original line start.

inline.Options :: struct

Options are the settings of the block reader (rst.Settings) that inline parsing and resolution need.

pep_references: bool
rfc_references: bool
pep_base_url: string
rfc_base_url: string
trim_footnote_reference_space: bool
smart_quotes: Smart_Quotes
smart_quotes_locales: string
language: string
docinfo: bool
sectsubtitle: bool
character_level: bool
tab_width: int

tab stops of the main source; 0 means 8.

default_substitution: Substitution_Hook
inline.Role :: struct

Role is a role defined by the role directive, or a standard role.

name: string

normalized (lowercase) role name.

base: Role_Base
classes: string

space-separated, from :class:.

format: string

raw roles: the output format, e.g. “html”.

language: string

code-derived roles.

inline.Role_Base :: enum u8
Emphasis
Strong
Literal
Code
Math
Subscript
Superscript
Title_Reference
Pep_Reference
Rfc_Reference
Abbreviation
Acronym
Raw
Custom

a Role node carrying the role name and classes.

inline.Role_Call :: struct

Role_Call describes one interpreted text for an extension’s role handler. The strings live in scratch and are valid only during the call.

state: ^Inline_State
b: ^gd.Builder
name: string

the role name as written, or the default role’s name.

marked: string

the content with every escaping backslash as NUL; breaks as “\n”.

text: string

the content with escapes processed; line breaks become spaces.

span: gd.Source_Span

the whole interpreted text, role included.

content: gd.Source_Span

the content between the backquotes.

inline.Role_Hook :: struct

Role_Hook lets a dialect handle interpreted text before the document’s and the standard roles are consulted. The procedure returns false for a role it does not know, and the standard lookup continues.

procedure: proc(user: rawptr, call: ^Role_Call) -> bool
user: rawptr
inline.Smart_Quotes :: enum u8

Smart_Quotes selects typographic quotation marks, apostrophes, dashes, and ellipses.

Off
On

the language’s primary quotation marks outside, secondary inside.

Alt

the language’s alternative marks, where it has them.

inline.Substitution_Hook :: struct

Substitution_Hook supplies substitutions a dialect defines by default, such as Sphinx’s |version|, |release|, and |today|. Resolution offers it every reference whose name no definition in the document has exactly (the case-insensitive match comes after it); a procedure returning true replaces the reference with that text.

procedure: proc(user: rawptr, name: string) -> (text: string, ok: bool)
user: rawptr

Procedures

inline.apply_host_role :: proc(s: ^Inline_State, name: string, lines: []Line, q, j: int) -> gd.Status

apply_host_role runs the role called name on interpreted text written in another markup, such as MyST’s {name}`content`, as the dialect’s hook and the standard roles would for reStructuredText. lines hold the whole construct; the content is the joined text’s range [q, j) (lines joined by “\n”) and is taken literally: a backslash is an ordinary character. An unknown role is reported, and the construct stays as text.

inline.footnote_symbol :: proc(n: int, out: ^gd.Buffer)

footnote_symbol writes the label of symbol footnote n (1-based) into out; nothing for n < 1. A label that does not fit sets out’s overflow, as every Buffer write does.

inline.parse_inline :: proc(s: ^Inline_State, lines: []Line) -> gd.Status

parse_inline emits inline nodes for the lines as children of the builder’s currently open node. Markup may span lines; a line break outside inline literals and roles becomes a Soft_Break node, as in CommonMark. Markup that cannot be completed is kept as text with a warning; unknown or misused roles are errors. It borrows s and lines for the call; its working memory is scratch it releases. Problems go to the reports; the result is the builder’s status, which a full table or spent work budget sets.

inline.python_space :: proc(r: rune) -> bool

python_space reports whether r is white space as Python’s str.isspace and the \s of Python’s regular expressions define it, for readers that follow Python patterns.

inline.resolve :: proc(ctx: ^gd.Read_Context, options := Options{docinfo = true}) -> gd.Status

resolve links references to targets, numbers footnotes, checks substitutions, and promotes the document title when ctx.options.promote_title is set. It edits the builder’s nodes in place, with scratch it releases; problems go to ctx.reports; the result is the builder’s status.

inline.unescape :: proc(out: ^gd.Buffer, marked: string)

unescape writes marked text (escapes as NUL, see Role_Call.marked) with escapes processed: an escaped space or line break disappears, any other escaped character stays, and an unescaped line break becomes a space.