generated from bep/golibtemplate
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added a working version with **different** NodeKinds
This is a preliminary version. The goal is to create one NodeKind "inlineTag" for all simple inline tags. But I am not sure if it’s going to work out, so I want to leave this on record.
- Loading branch information
1 parent
9dd9d5e
commit 900f6f1
Showing
13 changed files
with
699 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
1 | ||
//- - - - - - - - -// | ||
++Hi++ Hello, world! | ||
//- - - - - - - - -// | ||
<p><ins>Hi</ins> Hello, world!</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
2 | ||
//- - - - - - - - -// | ||
This ++has a | ||
|
||
new paragraph++. | ||
//- - - - - - - - -// | ||
<p>This ++has a</p> | ||
<p>new paragraph++.</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
3 | ||
//- - - - - - - - -// | ||
x ++++foo++ bar++ | ||
//- - - - - - - - -// | ||
<p>x <ins><ins>foo</ins> bar</ins></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
4 | ||
//- - - - - - - - -// | ||
x ++foo ++bar++++ | ||
//- - - - - - - - -// | ||
<p>x <ins>foo <ins>bar</ins></ins></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
5 | ||
//- - - - - - - - -// | ||
x ++++foo++++ | ||
//- - - - - - - - -// | ||
<p>x <ins><ins>foo</ins></ins></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
6 | ||
//- - - - - - - - -// | ||
**++test**++ | ||
|
||
++**test++** | ||
//- - - - - - - - -// | ||
<p><strong>++test</strong>++</p> | ||
<p><ins>**test</ins>**</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
7 | ||
//- - - - - - - - -// | ||
[++link]()++ | ||
|
||
++[link++]() | ||
//- - - - - - - - -// | ||
<p><a href="">++link</a>++</p> | ||
<p>++<a href="">link++</a></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
1 | ||
//- - - - - - - - -// | ||
==Hello==, world! | ||
//- - - - - - - - -// | ||
<p><mark>Hello</mark>, world!</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
2 | ||
//- - - - - - - - -// | ||
This mark ==has a | ||
|
||
new paragraph==. | ||
//- - - - - - - - -// | ||
<p>This mark ==has a</p> | ||
<p>new paragraph==.</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
3 | ||
//- - - - - - - - -// | ||
x ====foo== bar== | ||
//- - - - - - - - -// | ||
<p>x <mark><mark>foo</mark> bar</mark></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
4 | ||
//- - - - - - - - -// | ||
x ==foo ==bar==== | ||
//- - - - - - - - -// | ||
<p>x <mark>foo <mark>bar</mark></mark></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
5 | ||
//- - - - - - - - -// | ||
x ====foo==== | ||
//- - - - - - - - -// | ||
<p>x <mark><mark>foo</mark></mark></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
6 | ||
//- - - - - - - - -// | ||
**==test**== | ||
|
||
==**test==** | ||
//- - - - - - - - -// | ||
<p><strong>==test</strong>==</p> | ||
<p><mark>**test</mark>**</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
7 | ||
//- - - - - - - - -// | ||
[==link]()== | ||
|
||
==[link==]() | ||
//- - - - - - - - -// | ||
<p><a href="">==link</a>==</p> | ||
<p>==<a href="">link==</a></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
1: Surrounded by tildes | ||
//- - - - - - - - -// | ||
~foo~ | ||
//- - - - - - - - -// | ||
<p><sub>foo</sub></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
2: Formula with tildes in the middle | ||
//- - - - - - - - -// | ||
H~2~O | ||
//- - - - - - - - -// | ||
<p>H<sub>2</sub>O</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
3: Indices | ||
//- - - - - - - - -// | ||
x~i~ + x~j~ | ||
//- - - - - - - - -// | ||
<p>x<sub>i</sub> + x<sub>j</sub></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
4: Escaped tilde | ||
//- - - - - - - - -// | ||
~foo\~ | ||
//- - - - - - - - -// | ||
<p>~foo~</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
5: Non-breaking space entity | ||
//- - - - - - - - -// | ||
~foo bar~ | ||
//- - - - - - - - -// | ||
<p><sub>foo bar</sub></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
6: Non-breaking space UTF-8 | ||
//- - - - - - - - -// | ||
~foo bar~ | ||
//- - - - - - - - -// | ||
<p><sub>foo bar</sub></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
7: Mixed subscript and strikethrough | ||
//- - - - - - - - -// | ||
~~x~foobar~~~ | ||
//- - - - - - - - -// | ||
<p><del>x<sub>foobar</sub></del></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
8: Tildes in the middle and text before | ||
//- - - - - - - - -// | ||
text H~2~O | ||
//- - - - - - - - -// | ||
<p>text H<sub>2</sub>O</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
9: Tildes in the middle and text after | ||
//- - - - - - - - -// | ||
H~2~O text | ||
//- - - - - - - - -// | ||
<p>H<sub>2</sub>O text</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
1: Surrounded by cares | ||
//- - - - - - - - -// | ||
^foo^ | ||
//- - - - - - - - -// | ||
<p><sup>foo</sup></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
2: Ordinal indicator | ||
//- - - - - - - - -// | ||
2^nd^ | ||
//- - - - - - - - -// | ||
<p>2<sup>nd</sup></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
3: Powers | ||
//- - - - - - - - -// | ||
x^2^ + x^5^ | ||
//- - - - - - - - -// | ||
<p>x<sup>2</sup> + x<sup>5</sup></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
4: Escaped care | ||
//- - - - - - - - -// | ||
^foo\^ | ||
//- - - - - - - - -// | ||
<p>^foo^</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
5: : Cares surround text with a non-breaking space entity | ||
//- - - - - - - - -// | ||
^foo bar^ | ||
//- - - - - - - - -// | ||
<p><sup>foo bar</sup></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
6: Cares surround text Surround with a non-breaking space (UTF-8) | ||
//- - - - - - - - -// | ||
^foo bar^ | ||
//- - - - - - - - -// | ||
<p><sup>foo bar</sup></p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
7: Cares in the middle and text before | ||
//- - - - - - - - -// | ||
text C^foo^C | ||
//- - - - - - - - -// | ||
<p>text C<sup>foo</sup>C</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
8: Cares in the middle and text after | ||
//- - - - - - - - -// | ||
C^foo^C text | ||
//- - - - - - - - -// | ||
<p>C<sup>foo</sup>C text</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
9: Wrong markers in LaTeX style notation should be left untouched | ||
//- - - - - - - - -// | ||
x^2 + x^3 | ||
//- - - - - - - - -// | ||
<p>x^2 + x^3</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// | ||
|
||
10: Footnote markers should be left untouched | ||
//- - - - - - - - -// | ||
text[^1] text[^2] | ||
//- - - - - - - - -// | ||
<p>text[^1] text[^2]</p> | ||
//= = = = = = = = = = = = = = = = = = = = = = = =// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
package ast | ||
|
||
import ( | ||
gast "github.com/yuin/goldmark/ast" | ||
) | ||
|
||
type TagType int | ||
|
||
const ( | ||
Superscript TagType = iota + 1 | ||
Subscript | ||
Insert | ||
Mark | ||
) | ||
|
||
type Tag struct { | ||
TagType TagType | ||
Char byte | ||
Number int | ||
Html string | ||
WhitespaceAllowed bool | ||
ParsePriority int | ||
RenderPriority int | ||
} | ||
|
||
var SuperscriptTag = Tag{ | ||
TagType: Superscript, | ||
Char: '^', | ||
Number: 1, | ||
Html: "sup", | ||
WhitespaceAllowed: false, | ||
ParsePriority: 600, | ||
RenderPriority: 600, | ||
} | ||
|
||
var SubscriptTag = Tag{ | ||
TagType: Subscript, | ||
Char: '~', | ||
Number: 1, | ||
Html: "sub", | ||
WhitespaceAllowed: false, | ||
ParsePriority: 602, | ||
RenderPriority: 602, | ||
} | ||
|
||
var InsertTag = Tag{ | ||
TagType: Insert, | ||
Char: '+', | ||
Number: 2, | ||
Html: "ins", | ||
WhitespaceAllowed: true, | ||
ParsePriority: 501, | ||
RenderPriority: 501, | ||
} | ||
|
||
var MarkTag = Tag{ | ||
TagType: Mark, | ||
Char: '=', | ||
Number: 2, | ||
Html: "mark", | ||
WhitespaceAllowed: true, | ||
ParsePriority: 550, | ||
RenderPriority: 550, | ||
} | ||
|
||
type InlineTag struct { | ||
gast.BaseInline | ||
|
||
Tag | ||
} | ||
|
||
func NewInlineTag(tag Tag) *InlineTag { | ||
return &InlineTag{ | ||
BaseInline: gast.BaseInline{}, | ||
|
||
Tag: tag, | ||
} | ||
} | ||
|
||
var KindSuperscript = gast.NewNodeKind("Superscript") | ||
var KindSubscript = gast.NewNodeKind("Subscript") | ||
var KindInsert = gast.NewNodeKind("Insert") | ||
var KindMark = gast.NewNodeKind("Mark") | ||
|
||
func NewInlineTagKind(t TagType) gast.NodeKind { | ||
var kind gast.NodeKind | ||
switch t { | ||
case Superscript: | ||
kind = KindSuperscript | ||
case Subscript: | ||
kind = KindSubscript | ||
case Insert: | ||
kind = KindInsert | ||
case Mark: | ||
kind = KindMark | ||
} | ||
return kind | ||
} | ||
|
||
func (n *InlineTag) Kind() gast.NodeKind { | ||
return NewInlineTagKind(n.TagType) | ||
} | ||
|
||
func (n *InlineTag) Dump(source []byte, level int) { | ||
gast.DumpHelper(n, source, level, nil, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/gohugoio/hugo-goldmark-extensions/extras | ||
|
||
go 1.22.1 | ||
|
||
require github.com/yuin/goldmark v1.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= | ||
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= |
Oops, something went wrong.