Skip to content

Commit

Permalink
extras: Some refactorings
Browse files Browse the repository at this point in the history
* Move ast package one level up
* Unexport most types
* Simplify config
  • Loading branch information
bep committed May 4, 2024
1 parent 5f5e968 commit fbcc3c6
Show file tree
Hide file tree
Showing 4 changed files with 193 additions and 160 deletions.
108 changes: 108 additions & 0 deletions extras/ast.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package extras

import (
"github.com/yuin/goldmark/ast"
)

type inlineTagType int

const (
superscript inlineTagType = iota + 1
subscript
insert
mark
)

type inlineTag struct {
TagType inlineTagType
Char byte
Number int
Html string
WhitespaceAllowed bool
ParsePriority int
RenderPriority int
}

var superscriptTag = inlineTag{
TagType: superscript,
Char: '^',
Number: 1,
Html: "sup",
WhitespaceAllowed: false,
ParsePriority: 600,
RenderPriority: 600,
}

var subscriptTag = inlineTag{
TagType: subscript,
Char: '~',
Number: 1,
Html: "sub",
WhitespaceAllowed: false,
ParsePriority: 602,
RenderPriority: 602,
}

var insertTag = inlineTag{
TagType: insert,
Char: '+',
Number: 2,
Html: "ins",
WhitespaceAllowed: true,
ParsePriority: 501,
RenderPriority: 501,
}

var markTag = inlineTag{
TagType: mark,
Char: '=',
Number: 2,
Html: "mark",
WhitespaceAllowed: true,
ParsePriority: 550,
RenderPriority: 550,
}

type inlineTagNode struct {
ast.BaseInline

inlineTag
}

func newInlineTag(tag inlineTag) *inlineTagNode {
return &inlineTagNode{
BaseInline: ast.BaseInline{},

inlineTag: tag,
}
}

var (
kindSuperscript = ast.NewNodeKind("Superscript")
kindSubscript = ast.NewNodeKind("Subscript")
kindInsert = ast.NewNodeKind("Insert")
kindMark = ast.NewNodeKind("Mark")
)

func newInlineTagNodeKind(tag inlineTagType) ast.NodeKind {
var kind ast.NodeKind
switch tag {
case superscript:
kind = kindSuperscript
case subscript:
kind = kindSubscript
case insert:
kind = kindInsert
case mark:
kind = kindMark
}
return kind
}

func (n *inlineTagNode) Kind() ast.NodeKind {
return newInlineTagNodeKind(n.TagType)
}

func (n *inlineTagNode) Dump(source []byte, level int) {
ast.DumpHelper(n, source, level, nil, nil)
}
106 changes: 0 additions & 106 deletions extras/ast/inline.go

This file was deleted.

Loading

0 comments on commit fbcc3c6

Please sign in to comment.