Add basic support for statistic tokens (e.g. [100%] [1/1])
Org mode does not care where those tokens are when it comes to the export (afaict). We'll do the same. (They should only be in the first line of a list item or a headline)
This commit is contained in:
parent
dce67eaddf
commit
a60f844e38
6 changed files with 59 additions and 6 deletions
|
@ -15,6 +15,8 @@ type Text struct {
|
|||
type LineBreak struct{ Count int }
|
||||
type ExplicitLineBreak struct{}
|
||||
|
||||
type StatisticToken struct{ Content string }
|
||||
|
||||
type Emphasis struct {
|
||||
Kind string
|
||||
Content []Node
|
||||
|
@ -39,6 +41,7 @@ var videoExtensionRegexp = regexp.MustCompile(`^[.](webm|mp4)$`)
|
|||
|
||||
var subScriptSuperScriptRegexp = regexp.MustCompile(`([_^])\{(.*?)\}`)
|
||||
var footnoteRegexp = regexp.MustCompile(`\[fn:([\w-]+?)(:(.*?))?\]`)
|
||||
var statisticsTokenRegexp = regexp.MustCompile(`\[(\d+/\d+|\d+%)\]`)
|
||||
|
||||
func (d *Document) parseInline(input string) (nodes []Node) {
|
||||
previous, current := 0, 0
|
||||
|
@ -54,7 +57,7 @@ func (d *Document) parseInline(input string) (nodes []Node) {
|
|||
case '=', '~':
|
||||
consumed, node = d.parseEmphasis(input, current, true)
|
||||
case '[':
|
||||
consumed, node = d.parseRegularLinkOrFootnoteReference(input, current)
|
||||
consumed, node = d.parseOpeningBracket(input, current)
|
||||
case '\\':
|
||||
consumed, node = d.parseExplicitLineBreak(input, current)
|
||||
case '\n':
|
||||
|
@ -140,11 +143,13 @@ func (d *Document) parseSubScriptOrEmphasis(input string, start int) (int, Node)
|
|||
return d.parseEmphasis(input, start, false)
|
||||
}
|
||||
|
||||
func (d *Document) parseRegularLinkOrFootnoteReference(input string, start int) (int, Node) {
|
||||
func (d *Document) parseOpeningBracket(input string, start int) (int, Node) {
|
||||
if len(input[start:]) >= 2 && input[start] == '[' && input[start+1] == '[' {
|
||||
return d.parseRegularLink(input, start)
|
||||
} else if len(input[start:]) >= 1 && input[start] == '[' {
|
||||
} else if footnoteRegexp.MatchString(input[start:]) {
|
||||
return d.parseFootnoteReference(input, start)
|
||||
} else if statisticsTokenRegexp.MatchString(input[start:]) {
|
||||
return d.parseStatisticToken(input, start)
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
@ -162,6 +167,13 @@ func (d *Document) parseFootnoteReference(input string, start int) (int, Node) {
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
func (d *Document) parseStatisticToken(input string, start int) (int, Node) {
|
||||
if m := statisticsTokenRegexp.FindStringSubmatch(input[start:]); m != nil {
|
||||
return len(m[1]) + 2, StatisticToken{m[1]}
|
||||
}
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
func (d *Document) parseAutoLink(input string, start int) (int, int, Node) {
|
||||
if !d.AutoLink || len(input[start:]) < 3 || input[start+1] != '/' || input[start+2] != '/' {
|
||||
return 0, 0, nil
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue