Skip to content

Commit 33c0e92

Browse files
committed
extras: Allow superscript to begin with plus, minus, or single quote
Closes gohugoio#30
1 parent ca07402 commit 33c0e92

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

extras/_test/superscript.txt

+21
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,24 @@ text[^1] text[^2]
6060
//- - - - - - - - -//
6161
<p>text[^1] text[^2]</p>
6262
//= = = = = = = = = = = = = = = = = = = = = = = =//
63+
64+
10: Superscript is one of +, -, '
65+
//- - - - - - - - -//
66+
x^+^ x^-^ x^'^
67+
//- - - - - - - - -//
68+
<p>x<sup>+</sup> x<sup>-</sup> x<sup>'</sup></p>
69+
//= = = = = = = = = = = = = = = = = = = = = = = =//
70+
71+
11: Superscript begins with one of +, -, '
72+
//- - - - - - - - -//
73+
x^+2^ x^-2^ x^'2^
74+
//- - - - - - - - -//
75+
<p>x<sup>+2</sup> x<sup>-2</sup> x<sup>'2</sup></p>
76+
//= = = = = = = = = = = = = = = = = = = = = = = =//
77+
78+
12: Superscript ends with one of +, -, '
79+
//- - - - - - - - -//
80+
x^2+^ x^2-^ x^2'^
81+
//- - - - - - - - -//
82+
<p>x<sup>2+</sup> x<sup>2-</sup> x<sup>2'</sup></p>
83+
//= = = = = = = = = = = = = = = = = = = = = = = =//

extras/inline.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package extras
22

33
import (
4+
"slices"
5+
46
"github.com/yuin/goldmark"
57
"github.com/yuin/goldmark/ast"
68
"github.com/yuin/goldmark/parser"
@@ -47,7 +49,17 @@ func (s *inlineTagParser) Trigger() []byte {
4749
func (s *inlineTagParser) Parse(_ ast.Node, block text.Reader, pc parser.Context) ast.Node {
4850
before := block.PrecendingCharacter()
4951
line, segment := block.PeekLine()
50-
node := parser.ScanDelimiter(line, before, s.Number, newInlineTagDelimiterProcessor(s.inlineTag))
52+
53+
// Issue 30
54+
lineClone := slices.Clone(line)
55+
if s.inlineTag.TagKind == kindSuperscript && len(line) > s.Number {
56+
switch line[s.Number] {
57+
case byte('+'), byte('-'), byte('\''):
58+
lineClone[s.Number] = byte('z') // replace symbols with any letter
59+
}
60+
}
61+
62+
node := parser.ScanDelimiter(lineClone, before, s.Number, newInlineTagDelimiterProcessor(s.inlineTag))
5163
if node == nil || node.OriginalLength > 2 || before == rune(s.Char) {
5264
return nil
5365
}

0 commit comments

Comments
 (0)