Documentation
¶
Overview ¶
Package abbreviations provides a Goldmark extension for handling abbreviations in Markdown documents, similar to PHP Markdown Extra's abbreviation syntax.
This extension allows you to define abbreviations using the syntax:
*[ABBR]: Definition text
And automatically converts abbreviation occurrences in the text to HTML <abbr> tags with appropriate title attributes.
Basic Usage ¶
md := goldmark.New(
goldmark.WithExtensions(
abbreviations.NewAbbreviations(),
),
)
source := `This is HTML.
*[HTML]: HyperText Markup Language`
// Converts to: <p>This is <abbr title="HyperText Markup Language">HTML</abbr>.</p>
For comprehensive documentation, configuration options, and advanced usage examples, see FEATURES.md in the project repository.
Index ¶
- Constants
- Variables
- func NewAbbreviations(opts ...AbbreviationsOption) *abbreviations
- type AbbreviationsEndnotesType
- type AbbreviationsOption
- func WithAdditionalAllowedSymbols(symbols []rune) AbbreviationsOption
- func WithAllowedSymbols(symbols []rune) AbbreviationsOption
- func WithEndnotesGlossary(title ...string) AbbreviationsOption
- func WithEndnotesList(title ...string) AbbreviationsOption
- func WithEndnotesTable(title ...string) AbbreviationsOption
- func WithHeadingAbbr(allow bool) AbbreviationsOption
- func WithHeadingAbbreviations(allow bool) AbbreviationsOption
- func WithMaximumMatches(maximumMatches int) AbbreviationsOption
- func WithShowInvalidNames(show bool) AbbreviationsOption
- func WithoutAllowedSymbols(symbols []rune) AbbreviationsOption
Constants ¶
const ( // EndnotesNone means no endnotes will be generated (default behavior). // Abbreviations will only appear as <abbr> tags in the text. EndnotesNone = config.EndnotesNone // EndnotesList generates abbreviations as a bulleted list at the document end. // Use WithEndnotesList() or WithEndnotesListTitle() to enable this option. EndnotesList = config.EndnotesList // EndnotesTable generates abbreviations as a table at the document end. // Use WithEndnotesTable() or WithEndnotesTableTitle() to enable this option. EndnotesTable = config.EndnotesTable // EndnotesGlossary generates abbreviations as a definition list at the document end. // Use WithEndnotesGlossary() or WithEndnotesGlossaryTitle() to enable this option. EndnotesGlossary = config.EndnotesGlossary )
Variables ¶
var Abbreviations = NewAbbreviations()
Abbreviations is a default instance of the abbreviations extension with default settings. This provides an alternative way to initialize the extension:
goldmark.WithExtensions(abbreviations.Abbreviations)
The preferred method is still using the constructor:
goldmark.WithExtensions(abbreviations.NewAbbreviations())
Functions ¶
func NewAbbreviations ¶
func NewAbbreviations(opts ...AbbreviationsOption) *abbreviations
NewAbbreviations creates a new abbreviations extension with the given options. By default, abbreviations are disabled in headings and no endnotes are generated. For configuration options and usage examples, see FEATURES.md.
Types ¶
type AbbreviationsEndnotesType ¶
type AbbreviationsEndnotesType = config.AbbreviationsEndnotesType
Re-export public types from internal packages
type AbbreviationsOption ¶
type AbbreviationsOption func(*config.Abbreviations)
AbbreviationsOption is a functional option for configuring the abbreviations extension. Options are applied when creating a new extension instance with NewAbbreviations.
func WithAdditionalAllowedSymbols ¶ added in v0.1.1
func WithAdditionalAllowedSymbols(symbols []rune) AbbreviationsOption
WithAdditionalAllowedSymbols adds additional symbols to the default allowed symbols. This extends the default set rather than replacing it. For detailed usage and examples, see FEATURES.md.
func WithAllowedSymbols ¶ added in v0.1.1
func WithAllowedSymbols(symbols []rune) AbbreviationsOption
WithAllowedSymbols sets the allowed symbols for abbreviation names. This replaces the default allowed symbols with the provided list. For detailed usage and examples, see FEATURES.md.
func WithEndnotesGlossary ¶ added in v0.1.1
func WithEndnotesGlossary(title ...string) AbbreviationsOption
WithEndnotesGlossary enables abbreviations to be listed as a definition list at the end of the document. The glossary will be inserted before footnotes if the footnotes extension is also used. If no title is provided, defaults to "Glossary". Only the first title parameter is used. For detailed usage and examples, see FEATURES.md.
func WithEndnotesList ¶ added in v0.1.1
func WithEndnotesList(title ...string) AbbreviationsOption
WithEndnotesList enables abbreviations to be listed as a bulleted list at the end of the document. The list will be inserted before footnotes if the footnotes extension is also used. If no title is provided, defaults to "Abbreviations". Only the first title parameter is used. For detailed usage and examples, see FEATURES.md.
func WithEndnotesTable ¶ added in v0.1.1
func WithEndnotesTable(title ...string) AbbreviationsOption
WithEndnotesTable enables abbreviations to be listed as a table at the end of the document. The table will be inserted before footnotes if the footnotes extension is also used. If no title is provided, defaults to "Abbreviations". Only the first title parameter is used. For detailed usage and examples, see FEATURES.md.
func WithHeadingAbbr ¶
func WithHeadingAbbr(allow bool) AbbreviationsOption
WithHeadingAbbr sets whether abbreviations should be applied in headings. By default, abbreviations are not processed in headings (h1-h6 tags). For detailed usage and examples, see FEATURES.md.
func WithHeadingAbbreviations ¶ added in v0.1.1
func WithHeadingAbbreviations(allow bool) AbbreviationsOption
WithHeadingAbbreviations sets whether abbreviations should be applied in headings. This is an alternative name for WithHeadingAbbr.
func WithMaximumMatches ¶ added in v0.1.1
func WithMaximumMatches(maximumMatches int) AbbreviationsOption
WithMaximumMatches enables limiting the number of times each abbreviation will be matched and converted. By default, abbreviations are unlimited and every occurrence is converted. Setting maximumMatches to 0 disables all abbreviation conversion while still processing definitions. For detailed usage and examples, see FEATURES.md.
func WithShowInvalidNames ¶ added in v0.1.1
func WithShowInvalidNames(show bool) AbbreviationsOption
WithShowInvalidNames sets whether invalid abbreviation names should be rendered as HTML lists. By default, invalid abbreviation names are not displayed (showInvalidNames = false). When enabled, invalid definitions are rendered as bulleted lists with CSS class "abbr-invalid". For detailed usage and examples, see FEATURES.md.
func WithoutAllowedSymbols ¶ added in v0.1.1
func WithoutAllowedSymbols(symbols []rune) AbbreviationsOption
WithoutAllowedSymbols removes specific symbols from the allowed symbols. This allows removing default symbols that you don't want to allow. For detailed usage and examples, see FEATURES.md.