Documentation
¶
Overview ¶
Package obsidian provides github.com/yuin/goldmark markdown parser extensions for Obsidian Flavored Markdown and some 3rd-party Obsidian plugins.
Example ¶
package main import ( "fmt" "os" "github.com/yuin/goldmark" obsidian "github.com/powerman/goldmark-obsidian" ) func main() { source := []byte(` - [ ] Happy New Year 📅 2025-01-01 ^first-task - [x] Happy Old Year 📅 2024-01-01 `) md := goldmark.New( goldmark.WithExtensions( obsidian.NewPlugTasks(), obsidian.NewObsidian(), ), ) err := md.Convert(source, os.Stdout) if err != nil { fmt.Println(err) } }
Output: <ul class="contains-task-list"> <li data-task="" class="task-list-item" id="^first-task"><input disabled="" type="checkbox" class="task-list-item-checkbox"> Happy New Year 📅 2025-01-01</li> <li data-task="x" class="task-list-item is-checked"><input checked="" disabled="" type="checkbox" class="task-list-item-checkbox"> Happy Old Year 📅 2024-01-01</li> </ul>
Index ¶
- Constants
- Variables
- type BlockID
- type BlockIDHTMLRenderer
- type BlockIDParser
- type Obsidian
- func (e Obsidian) Extend(m goldmark.Markdown)
- func (e Obsidian) WithFootnoteOptions(opts ...extension.FootnoteOption) Obsidian
- func (e Obsidian) WithHashtagResolver(resolver hashtag.Resolver) Obsidian
- func (e Obsidian) WithLinkifyOptions(opts ...extension.LinkifyOption) Obsidian
- func (e Obsidian) WithMathJaxOptions(opts ...mathjax.Option) Obsidian
- func (e Obsidian) WithMermaid(m mermaid.Extender) Obsidian
- func (e Obsidian) WithMetaOptions(opts ...meta.Option) Obsidian
- func (e Obsidian) WithTableOptions(opts ...extension.TableOption) Obsidian
- func (e Obsidian) WithWikilinkResolver(resolver wikilink.Resolver) Obsidian
- type PlugTasks
- type PlugTasksHTMLRenderer
- type PlugTasksOption
- func WithPlugTasksCheckboxClass[T []byte | string](class T) PlugTasksOption
- func WithPlugTasksListClass[T []byte | string](class T) PlugTasksOption
- func WithPlugTasksListItemCheckedClass[T []byte | string](class T) PlugTasksOption
- func WithPlugTasksListItemNotCheckedClass[T []byte | string](class T) PlugTasksOption
- func WithPlugTasksListItemStatusAttr[T []byte | string](name T) PlugTasksOption
- func WithPlugTasksStatusType(symbol rune, statusType ast.PlugTasksStatusType) PlugTasksOption
- func WithPlugTasksStatusTypes(statusTypes map[rune]ast.PlugTasksStatusType) PlugTasksOption
- type PlugTasksParser
- type PlugTasksPropParser
Examples ¶
Constants ¶
const ( DefaultPlugTasksListClass = "contains-task-list" DefaultPlugTasksListItemNotCheckedClass = "task-list-item" DefaultPlugTasksListItemCheckedClass = "task-list-item is-checked" DefaultPlugTasksListItemStatusAttr = "data-task" DefaultPlugTasksCheckboxClass = "task-list-item-checkbox" )
Default attributes used by NewPlugTasksParser.
const ( DefaultPlugTasksTODOSymbol = ' ' DefaultPlugTasksInProgressSymbol = '/' DefaultPlugTasksDoneSymbol = 'x' DefaultPlugTasksCancelledSymbol = '-' )
Task status symbols used by NewPlugTasksParser by default. Any other (unknown) symbols will have status TODO.
NOTE: Upper case 'X' is unknown (i.e. has TODO status) in default Tasks configuration.
Variables ¶
var PlugTasksCheckboxAttributeFilter = html.GlobalAttributeFilter //nolint:gochecknoglobals // By design.
PlugTasksCheckboxAttributeFilter defines attribute names which <input type=checkbox> elements can have.
Functions ¶
This section is empty.
Types ¶
type BlockID ¶
type BlockID struct{}
BlockID is an extension that helps to setup Obsidian block id parser and HTML renderer.
type BlockIDHTMLRenderer ¶
type BlockIDHTMLRenderer struct{}
BlockIDHTMLRenderer is an HTML renderer for Obsidian block id.
Current implementation does not render block id at all (like Obsidian's "Reading" mode).
func NewBlockIDHTMLRenderer ¶
func NewBlockIDHTMLRenderer() BlockIDHTMLRenderer
NewBlockIDHTMLRenderer returns a new BlockIDHTMLRenderer.
func (BlockIDHTMLRenderer) RegisterFuncs ¶
func (BlockIDHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
RegisterFuncs implements renderer.NodeRenderer.
type BlockIDParser ¶
type BlockIDParser struct{}
BlockIDParser is an Obsidian block id parser.
func NewBlockIDParser ¶
func NewBlockIDParser() BlockIDParser
NewBlockIDParser returns a new BlockIDParser.
func (BlockIDParser) Parse ¶
Parse implements parser.InlineParser.
func (BlockIDParser) Trigger ¶
func (BlockIDParser) Trigger() []byte
Trigger implements parser.InlineParser.
type Obsidian ¶
type Obsidian struct {
// contains filtered or unexported fields
}
Obsidian is an extension that helps to setup parsers and HTML renderers for Obsidian Flavored Markdown and all other Obsidian features like Footnotes, Diagrams, LaTeX, Tags and Properties.
It's recommended to add other extensions (e.g. Obsidian plugins) before this one to ensure correct parsing priorities. E.g.:
goldmark.WithExtensions( obsidian.NewPlugTasks(), obsidian.NewObsidian(), )
func (Obsidian) Extend ¶
Extend implements goldmark.Extender.
func (Obsidian) WithFootnoteOptions ¶
func (e Obsidian) WithFootnoteOptions(opts ...extension.FootnoteOption) Obsidian
WithFootnoteOptions returns a new extension modified to use given opts.
func (Obsidian) WithHashtagResolver ¶
WithHashtagResolver returns a new extension modified to use given resolver.
func (Obsidian) WithLinkifyOptions ¶
func (e Obsidian) WithLinkifyOptions(opts ...extension.LinkifyOption) Obsidian
WithLinkifyOptions returns a new extension modified to use given opts.
func (Obsidian) WithMathJaxOptions ¶
WithMathJaxOptions returns a new extension modified to use given opts.
func (Obsidian) WithMermaid ¶
WithMermaid returns a new extension modified to use given m.
func (Obsidian) WithMetaOptions ¶
WithMetaOptions returns a new extension modified to use given opts.
func (Obsidian) WithTableOptions ¶
func (e Obsidian) WithTableOptions(opts ...extension.TableOption) Obsidian
WithTableOptions returns a new extension modified to use given opts.
type PlugTasks ¶
type PlugTasks struct {
// contains filtered or unexported fields
}
PlugTasks is an extension that helps to setup Obsidian plugin Tasks parser and HTML renderer.
func NewPlugTasks ¶
func NewPlugTasks(opts ...PlugTasksOption) PlugTasks
NewPlugTasks returns a new PlugTasks extension.
type PlugTasksHTMLRenderer ¶
type PlugTasksHTMLRenderer struct {
html.Config // Embed to implement renderer.SetOptioner and apply global html options.
}
PlugTasksHTMLRenderer is an HTML renderer for Obsidian plugin Tasks's tasks.
It renders task status checkbox and task properties in format similar to produced by saving Obsidian plugin Tasks's modal window with task details (add missing spaces, drop invalid properties, etc.).
func NewPlugTasksHTMLRenderer ¶
func NewPlugTasksHTMLRenderer() *PlugTasksHTMLRenderer
NewPlugTasksHTMLRenderer returns a new PlugTasksHTMLRenderer.
func (*PlugTasksHTMLRenderer) RegisterFuncs ¶
func (r *PlugTasksHTMLRenderer) RegisterFuncs(reg renderer.NodeRendererFuncRegisterer)
RegisterFuncs implements renderer.NodeRenderer.
type PlugTasksOption ¶
type PlugTasksOption func(*plugTasksConfig)
A PlugTasksOption configures a PlugTasksParser.
func WithPlugTasksCheckboxClass ¶
func WithPlugTasksCheckboxClass[T []byte | string](class T) PlugTasksOption
WithPlugTasksCheckboxClass sets a class for an <input type=checkbox>.
func WithPlugTasksListClass ¶
func WithPlugTasksListClass[T []byte | string](class T) PlugTasksOption
WithPlugTasksListClass sets a class for a list containing task(s).
func WithPlugTasksListItemCheckedClass ¶
func WithPlugTasksListItemCheckedClass[T []byte | string](class T) PlugTasksOption
WithPlugTasksListItemCheckedClass sets a class for a list item containing a task with any status symbol (i.e. not a space).
func WithPlugTasksListItemNotCheckedClass ¶
func WithPlugTasksListItemNotCheckedClass[T []byte | string](class T) PlugTasksOption
WithPlugTasksListItemNotCheckedClass sets a class for a list item containing a task without status symbol: [ ].
func WithPlugTasksListItemStatusAttr ¶
func WithPlugTasksListItemStatusAttr[T []byte | string](name T) PlugTasksOption
WithPlugTasksListItemStatusAttr sets a name for a list item attribute which will contain a task status symbol (one within [ ]). Attribute will be set to empty string if status symbol is a space.
func WithPlugTasksStatusType ¶
func WithPlugTasksStatusType(symbol rune, statusType ast.PlugTasksStatusType) PlugTasksOption
WithPlugTasksStatusType sets a statusType for a symbol. If you need to set many symbols then using WithPlugTasksStatusTypes may be more convenient than multiple calls to WithPlugTasksStatusType.
To "disable" one of default symbols set it statusType to ast.PlugTasksStatusTypeTODO, which is used by default for all unknown symbols.
func WithPlugTasksStatusTypes ¶
func WithPlugTasksStatusTypes(statusTypes map[rune]ast.PlugTasksStatusType) PlugTasksOption
WithPlugTasksStatusTypes sets a statusTypes for a symbols.
To "disable" one of default symbols set it statusType to ast.PlugTasksStatusTypeTODO, which is used by default for all unknown symbols.
type PlugTasksParser ¶
type PlugTasksParser struct {
// contains filtered or unexported fields
}
PlugTasksParser is an Obsidian plugin Tasks's task status parser.
This parser must take precedence over the parser.LinkParser.
func NewPlugTasksParser ¶
func NewPlugTasksParser(opts ...PlugTasksOption) *PlugTasksParser
NewPlugTasksParser returns a new PlugTasksParser.
func (*PlugTasksParser) Parse ¶
Parse implements parser.InlineParser.
func (*PlugTasksParser) Trigger ¶
func (*PlugTasksParser) Trigger() []byte
Trigger implements parser.InlineParser.
type PlugTasksPropParser ¶
type PlugTasksPropParser struct{}
PlugTasksPropParser is an Obsidian plugin Tasks's task properties parser.
Current implementation supports only properties defined in emoji style.
This parser must have lowest precedence than all other inline parsers (e.g. 1000).
func NewPlugTasksPropParser ¶
func NewPlugTasksPropParser() PlugTasksPropParser
NewPlugTasksPropParser returns a new PlugTasksPropParser.
func (PlugTasksPropParser) Parse ¶
Parse implements parser.InlineParser.
func (PlugTasksPropParser) Trigger ¶
func (PlugTasksPropParser) Trigger() []byte
Trigger implements parser.InlineParser.