Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func PlainText ¶
PlainText converts a BibTeX field value to plain Unicode text. Accent commands become precomposed characters where Unicode has one, known symbols are replaced, other commands are dropped while their arguments are kept, braces are removed and whitespace is collapsed. Math between $ signs is kept verbatim.
Types ¶
type Diagnostic ¶
Diagnostic describes a recoverable problem without requiring consumers to parse its message.
type Entry ¶
type Entry struct {
// Type is lowercased, e.g. "article".
Type string `json:"type"`
// Key is the citation key with its original case.
Key string `json:"key"`
Fields []Field `json:"fields"`
Position
// Start and End are byte offsets of the entry in the input, from the @ to
// just after the closing delimiter.
Start int `json:"start"`
End int `json:"end"`
}
Entry is one BibTeX entry such as @article{key, ...}.
type Error ¶
type Error struct {
Diagnostic
Cause error
}
Error wraps a failure that stopped parsing, for errors.Is and errors.As.
type Field ¶
Field is a field or @string definition. Name is lowercased. Value has macros expanded, # concatenation applied, outer delimiters removed and whitespace runs collapsed; TeX markup and inner braces are retained.
type File ¶
type File struct {
Entries []Entry `json:"entries"`
// Strings holds @string definitions in source order, with values expanded.
Strings []Field `json:"strings,omitempty"`
Preambles []string `json:"preambles,omitempty"`
// Encoding is "utf-8", or "windows-1252" when the input was not valid
// UTF-8 and was decoded as Windows-1252.
Encoding string `json:"encoding"`
Diagnostics []Diagnostic `json:"diagnostics,omitempty"`
}
File is the result of parsing a BibTeX database or extracting entries from a document. It owns its strings; the input buffer may be reused after parsing.
func Extract ¶
func Extract(data []byte, opts ParseOptions) (*File, error)
Extract finds BibTeX entries embedded in other text, such as a README. An entry is recognised where a line begins with "@type{key," or "@type(key," after optional indentation. Inside a Markdown fenced code block, an entry cannot extend past the closing fence.
func ParseWithOptions ¶
func ParseWithOptions(data []byte, opts ParseOptions) (*File, error)
ParseWithOptions reads a BibTeX database. Text outside entries is ignored, as BibTeX does. Malformed entries produce diagnostics; an error is returned only for invalid options, unsupported encodings, and exceeded limits.
type Name ¶
type Name struct {
First string `json:"first,omitempty"`
Von string `json:"von,omitempty"`
Last string `json:"last,omitempty"`
Jr string `json:"jr,omitempty"`
// Others marks the "and others" placeholder for omitted names.
Others bool `json:"others,omitempty"`
// Literal marks a name written entirely in braces, which is how BibTeX
// files give organisations.
Literal bool `json:"literal,omitempty"`
}
Name is one person or organisation from a BibTeX name list, split into BibTeX's four parts and converted to plain text. A name written in braces, such as {World Health Organization}, is returned whole in Last.
func ParseNames ¶
ParseNames splits an author or editor value on "and" outside braces and parses each name with BibTeX's rules for the "First von Last", "von Last, First" and "von Last, Jr, First" forms.
Unlike BibTeX, a name with two or more commas whose parts are each at least two words, such as "Jifeng Dai, Yi Li, Kaiming He", is read as a comma-separated list of "First Last" names. READMEs often list authors this way, and BibTeX rejects it.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
examples
|
|
|
read
command
Command read prints the entries of a BibTeX file, or of a README with -extract, as JSON.
|
Command read prints the entries of a BibTeX file, or of a README with -extract, as JSON. |
|
internal
|
|
|
generate
command
Command generate writes compose_generated.go from Unicode 17.0.0 UnicodeData.txt, available at https://www.unicode.org/Public/17.0.0/ucd/UnicodeData.txt.
|
Command generate writes compose_generated.go from Unicode 17.0.0 UnicodeData.txt, available at https://www.unicode.org/Public/17.0.0/ucd/UnicodeData.txt. |