12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970 |
- package richtext
- type Block struct {
- ClassList [] string `kmd:"class-list"`
- Lines [] Line `kmd:"lines"`
- Children [] Block `kmd:"children"`
- }
- func (b *Block) AddClass(classes ...string) {
- b.ClassList = append(b.ClassList, classes...)
- }
- func (b *Block) WriteLine(content string, tags ...string) {
- b.Lines = append(b.Lines, Line { [] Span { {
- Content: content,
- Tags: tags,
- } } })
- }
- func (b *Block) WriteSpan(content string, tags ...string) {
- var span = Span {
- Content: content,
- Tags: tags,
- }
- if len(b.Lines) > 0 {
- var last = &(b.Lines[len(b.Lines) - 1])
- last.Spans = append(last.Spans, span)
- } else {
- b.Lines = append(b.Lines, Line { Spans: [] Span { span } })
- }
- }
- func (b *Block) WriteLineFeed() {
- b.Lines = append(b.Lines, Line { Spans: [] Span {} })
- }
- func (b *Block) Append(another Block) {
- b.Children = append(b.Children, another)
- }
- type Line struct {
- Spans [] Span `kmd:"spans"`
- }
- type Span struct {
- Content string `kmd:"content"`
- Tags [] string `kmd:"tags"`
- Link MaybeLink `kmd:"link"` // for doc links
- }
- const (
- TAG_DOC = "doc"
- TAG_EM = "em"
- TAG_SRC_NORMAL = "source"
- TAG_SRC_KEYWORD = "keyword"
- TAG_SRC_NAME = "name"
- TAG_SRC_TYPE = "type"
- TAG_SRC_FUNCTION = "function"
- TAG_SRC_CONST = "const"
- TAG_SRC_COMMENT = "comment"
- TAG_HIGHLIGHT = "highlight"
- TAG_ERR_NORMAL = "error"
- TAG_ERR_NOTE = "note"
- TAG_ERR_INLINE = "inline"
- )
- type MaybeLink interface { Maybe(Link, MaybeLink) }
- func (Link) Maybe(Link, MaybeLink) {}
- type Link struct {
- Page string `kmd:"page"`
- Anchor string `kmd:"anchor"`
- }
|