Documentation
¶
Overview ¶
Package rdoc is a pure-Go (CGO=0), MRI-faithful port of the core of Ruby's RDoc documentation tool (the "rdoc" gem): the markup parser, the inline attribute manager, the document model and the HTML formatter, plus a focused reader of Ruby source comments into the RDoc code-object model.
The implementation mirrors RDoc::Markup::Parser, RDoc::Markup::AttributeManager, RDoc::Markup::Document and RDoc::Markup::ToHtml from rdoc 7.x. The goal is byte-for-byte parity with the gem on the markup -> HTML path for the markup constructs the gem supports.
The file-system walking and on-disk "darkfish" HTML-site template generation of the real gem are deliberately out of scope: they are a thin host seam. Everything here is pure, deterministic, in-memory computation.
Index ¶
- func HighlightRuby(code string) (string, bool)
- func ToHTML(markup string) string
- func ToMarkdownString(markup string) string
- func ToRdocString(markup string) string
- type Alias
- type AnyMethod
- type Attr
- type BlankLine
- type BlockQuote
- type ClassModule
- type Constant
- type Document
- type Element
- type Formatter
- type HTMLOptions
- type Heading
- type List
- type ListItem
- type ListType
- type Paragraph
- type Raw
- type Rule
- type ToHtml
- type ToMarkdown
- type ToRdoc
- type TopLevel
- type Verbatim
- type Visibility
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func HighlightRuby ¶
HighlightRuby highlights Ruby source the way RDoc does, returning the HTML and true on success. For constructs this focused highlighter does not model faithfully it returns ("", false) so the caller falls back to a plain block.
func ToHTML ¶
ToHTML is a convenience: parse markup text and render to HTML with default options, equivalent to the gem's markup -> ToHtml round trip.
func ToMarkdownString ¶
ToMarkdownString converts markup text directly to Markdown.
func ToRdocString ¶
ToRdocString converts markup text through the model and back to RDoc markup (a normalisation round-trip).
Types ¶
type AnyMethod ¶
type AnyMethod struct {
Name string
Params string // parameter list including parentheses, e.g. "(a, b)"
Singleton bool // true for "def self.x" / "def Klass.x"
Visibility Visibility
Comment string
// CallSeq is the contents of a "call-seq:" directive in the comment, if any.
CallSeq string
}
AnyMethod is a method declaration. Mirrors RDoc::AnyMethod.
type Attr ¶
type Attr struct {
Name string
RW string // "R", "W" or "RW"
Visibility Visibility
Comment string
}
Attr is an attr_reader/writer/accessor declaration. Mirrors RDoc::Attr.
type BlankLine ¶
type BlankLine struct{}
BlankLine marks a blank line between blocks. Mirrors RDoc::Markup::BlankLine.
type BlockQuote ¶
type BlockQuote struct {
Parts []Element
}
BlockQuote groups indented quoted blocks. Mirrors RDoc::Markup::BlockQuote.
type ClassModule ¶
type ClassModule struct {
// IsModule distinguishes `module` from `class`.
IsModule bool
// Name is the simple (last-segment) name as written, e.g. "Bar" in
// "class Foo::Bar".
Name string
// FullName is the qualified name including the lexical nesting.
FullName string
// Superclass is the parent class name for "class X < Y" (empty otherwise).
Superclass string
// Comment is the attached documentation comment (RDoc markup source).
Comment string
Methods []*AnyMethod
Constants []*Constant
Attrs []*Attr
Aliases []*Alias
// Nested holds classes and modules declared inside this one. Qualified
// declarations like "class A::B" synthesize the intermediate module A and
// nest B inside it, mirroring RDoc's namespace expansion.
Nested []*ClassModule
}
ClassModule is a class or module declaration with its members. Mirrors RDoc::ClassModule (NormalClass / NormalModule).
type Document ¶
type Document struct {
Parts []Element
}
Document is the root of the markup model, a sequence of block-level elements. It mirrors RDoc::Markup::Document.
type Element ¶
type Element interface {
// contains filtered or unexported methods
}
Element is the interface implemented by every node in the markup document model. accept dispatches to the visitor (a Formatter).
type Formatter ¶
type Formatter interface {
// contains filtered or unexported methods
}
Formatter is the public interface implemented by the output visitors (ToHtml, etc.). Document.Accept drives it.
type HTMLOptions ¶
type HTMLOptions struct {
// OutputDecoration controls whether headings get id/anchor decoration
// (RDoc::Options#output_decoration, default true).
OutputDecoration bool
// Pipe mirrors RDoc::Options#pipe (markdown-pipe mode): headings/verbatim
// are emitted without anchors / highlighting.
Pipe bool
// Highlighter, if set, syntax-highlights a verbatim block that looks like
// Ruby, returning (html, true). When nil or returning ok=false, verbatim is
// emitted as a plain escaped <pre>. HighlightRuby is the built-in
// implementation; the deterministic default leaves this nil so output is
// a plain <pre> without needing a Ruby toolchain.
Highlighter func(code string) (string, bool)
// Parseable reports whether a verbatim block is valid Ruby and should be
// highlighted. RDoc::Markup::ToHtml#parseable? evaluates the block with the
// real Ruby parser, which cannot be reproduced without a Ruby toolchain, so
// this is a host seam. When nil, verbatim blocks are never auto-detected as
// Ruby (only blocks explicitly flagged via Verbatim format are highlighted).
Parseable func(code string) bool
// CrossRef, if set, resolves a bare name to a link target for
// ToHtmlCrossref behaviour.
CrossRef func(name string) (href string, ok bool)
}
HTMLOptions controls HTML rendering, mirroring the subset of RDoc::Options the ToHtml formatter consults.
func DefaultHTMLOptions ¶
func DefaultHTMLOptions() *HTMLOptions
DefaultHTMLOptions returns options matching the rdoc gem defaults.
type Heading ¶
Heading is a section heading of a given Level (1-6 logically, clamped to 6 when rendered). Mirrors RDoc::Markup::Heading.
type ListItem ¶
ListItem is one entry in a List. Label holds the label parts for LABEL/NOTE lists (nil for plain lists). Parts holds the nested block content. Mirrors RDoc::Markup::ListItem.
type ListType ¶
type ListType int
ListType identifies the kind of a List, mirroring RDoc::Markup::Parser's LIST_TOKENS.
const ( // ListBullet is an unordered "* item" / "- item" list (:BULLET). ListBullet ListType = iota // ListLabel is a "[label] text" list (:LABEL). ListLabel // ListLalpha is a lower-alpha "a. item" ordered list (:LALPHA). ListLalpha // ListNote is a "label:: text" list (:NOTE). ListNote // ListNumber is a numeric "1. item" ordered list (:NUMBER). ListNumber // ListUalpha is an upper-alpha "A. item" ordered list (:UALPHA). ListUalpha )
type Paragraph ¶
type Paragraph struct {
Parts []string
}
Paragraph is a run of text. Its Parts are the raw text lines (joined with a space). Mirrors RDoc::Markup::Paragraph.
type Raw ¶
type Raw struct {
Parts []string
}
Raw is verbatim output passed through untouched. Mirrors RDoc::Markup::Raw.
type Rule ¶
type Rule struct {
Weight int
}
Rule is a horizontal rule (---). Weight mirrors the dash-count-minus-two stored by RDoc::Markup::Rule.
type ToHtml ¶
type ToHtml struct {
// contains filtered or unexported fields
}
ToHtml renders an RDoc markup document model to HTML. It mirrors RDoc::Markup::ToHtml.
func NewToHtml ¶
func NewToHtml(opts *HTMLOptions) *ToHtml
NewToHtml builds an HTML formatter with the given options (nil = defaults).
type ToMarkdown ¶
type ToMarkdown struct {
// contains filtered or unexported fields
}
ToMarkdown is a Markdown output formatter.
type ToRdoc ¶
type ToRdoc struct {
// contains filtered or unexported fields
}
ToRdoc is an RDoc-markup output formatter.
type TopLevel ¶
type TopLevel struct {
Name string
ClassesAndModule []*ClassModule
}
TopLevel is the root code object for one source file. Mirrors RDoc::TopLevel.
type Verbatim ¶
type Verbatim struct {
Parts []string
// contains filtered or unexported fields
}
Verbatim is an indented literal/code block. Parts are the lines, each ending in a newline. Mirrors RDoc::Markup::Verbatim.
type Visibility ¶
type Visibility string
Visibility mirrors RDoc method/attribute visibility.
const ( // Public visibility (the default). Public Visibility = "public" // Private visibility (after a bare `private`). Private Visibility = "private" // Protected visibility (after a bare `protected`). Protected Visibility = "protected" )
