-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 1901987
Showing
22 changed files
with
1,007 additions
and
0 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,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 skunkie | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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,68 @@ | ||
goldmark-tg | ||
========================= | ||
|
||
goldmark-tg is a collection of extensions for the [goldmark](http://github.com/yuin/goldmark) | ||
that adds Telegram Markdown and MarkdownV2 functionalities. | ||
|
||
### Examples | ||
|
||
Markdown: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/yuin/goldmark" | ||
|
||
tg "github.com/skunkie/goldmark-tg" | ||
) | ||
|
||
func main() { | ||
md := goldmark.New(tg.Markdown()...) | ||
... | ||
} | ||
``` | ||
|
||
MarkdownV2: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"github.com/yuin/goldmark" | ||
|
||
tg "github.com/skunkie/goldmark-tg" | ||
) | ||
|
||
func main() { | ||
md := goldmark.New(tg.MarkdownV2()...) | ||
... | ||
} | ||
``` | ||
|
||
MarkdownV2 with Go Template extension: | ||
|
||
```go | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/yuin/goldmark" | ||
|
||
tg "github.com/skunkie/goldmark-tg" | ||
"github.com/skunkie/goldmark-tg/extension" | ||
) | ||
|
||
var template = []byte(`*{{ if eq .Status "firing" }}2{{ else }}0{{ end }}*`) | ||
|
||
func main() { | ||
var buf strings.Builder | ||
md := goldmark.New(append(tg.MarkdownV2(), goldmark.WithExtensions(extension.Template))...) | ||
if err := md.Convert(template, &buf); err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("%q\n", buf.String()) | ||
} | ||
``` |
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,11 @@ | ||
*bold text* | ||
_italic text_ | ||
[inline URL](http://www.example.com/) | ||
[inline mention of a user](tg://user?id=123456789) | ||
`inline fixed-width code` | ||
``` | ||
pre-formatted fixed-width code block | ||
``` | ||
```python | ||
pre-formatted fixed-width code block written in the Python programming language | ||
``` |
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,19 @@ | ||
*bold \*text* | ||
_italic \*text_ | ||
__underline__ | ||
~strikethrough~ | ||
||spoiler|| | ||
*bold _italic bold ~italic bold strikethrough ||italic bold strikethrough spoiler||~ __underline italic bold___ bold* | ||
[inline URL](http://www.example.com/) | ||
[inline mention of a user](tg://user?id=123456789) | ||
![👍](tg://emoji?id=5368324170671202286) | ||
`inline fixed-width code` | ||
``` | ||
pre-formatted fixed-width code block | ||
``` | ||
```python | ||
pre-formatted fixed-width code block written in the Python programming language | ||
``` | ||
>Block quotation started | ||
>Block quotation continued | ||
>The last line of the block quotation |
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,4 @@ | ||
*{{ if eq .Status "firing" }}2{{ else }}0{{ end }}* | ||
_T1_ __{{ __T2__ | ||
||"T3"|| }}__ | ||
}} ||"T4"|| {{ |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/yuin/goldmark" | ||
|
||
tg "github.com/skunkie/goldmark-tg" | ||
"github.com/skunkie/goldmark-tg/extension" | ||
) | ||
|
||
var template = []byte(`*{{ if eq .Status "firing" }}2{{ else }}0{{ end }}*`) | ||
|
||
func main() { | ||
var buf strings.Builder | ||
md := goldmark.New(append(tg.MarkdownV2(), goldmark.WithExtensions(extension.Template))...) | ||
if err := md.Convert(template, &buf); err != nil { | ||
panic(err) | ||
} | ||
fmt.Printf("%q\n", buf.String()) //nolint:forbidigo | ||
} |
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,31 @@ | ||
package ast | ||
|
||
import ( | ||
gast "github.com/yuin/goldmark/ast" | ||
) | ||
|
||
// A Emphasis struct represents a emphasis of Telegram Markdown text. | ||
type Emphasis struct { | ||
gast.BaseInline | ||
|
||
Delimiter byte | ||
Level int | ||
} | ||
|
||
// Dump implements Node.Dump. | ||
func (n *Emphasis) Dump(source []byte, level int) { | ||
gast.DumpHelper(n, source, level, nil, nil) | ||
} | ||
|
||
// KindEmphasis is a NodeKind of the Emphasis node. | ||
var KindEmphasis = gast.NewNodeKind("Emphasis") | ||
|
||
// Kind implements Node.Kind. | ||
func (n *Emphasis) Kind() gast.NodeKind { | ||
return KindEmphasis | ||
} | ||
|
||
// NewEmphasis returns a new Emphasis node. | ||
func NewEmphasis(delimiter byte, level int) *Emphasis { | ||
return &Emphasis{Delimiter: delimiter, Level: level} | ||
} |
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,28 @@ | ||
package ast | ||
|
||
import ( | ||
gast "github.com/yuin/goldmark/ast" | ||
) | ||
|
||
// A Spoiler struct represents a spoiler of Telegram MarkdownV2 text. | ||
type Spoiler struct { | ||
gast.BaseInline | ||
} | ||
|
||
// Dump implements Node.Dump. | ||
func (n *Spoiler) Dump(source []byte, level int) { | ||
gast.DumpHelper(n, source, level, nil, nil) | ||
} | ||
|
||
// KindSpoiler is a NodeKind of the Spoiler node. | ||
var KindSpoiler = gast.NewNodeKind("Spoiler") | ||
|
||
// Kind implements Node.Kind. | ||
func (n *Spoiler) Kind() gast.NodeKind { | ||
return KindSpoiler | ||
} | ||
|
||
// NewSpoiler returns a new Spoiler node. | ||
func NewSpoiler() *Spoiler { | ||
return &Spoiler{} | ||
} |
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,28 @@ | ||
package ast | ||
|
||
import ( | ||
gast "github.com/yuin/goldmark/ast" | ||
) | ||
|
||
// A Strikethrough struct represents a strikethrough of Telegram MarkdownV2 text. | ||
type Strikethrough struct { | ||
gast.BaseInline | ||
} | ||
|
||
// Dump implements Node.Dump. | ||
func (n *Strikethrough) Dump(source []byte, level int) { | ||
gast.DumpHelper(n, source, level, nil, nil) | ||
} | ||
|
||
// KindStrikethrough is a NodeKind of the Strikethrough node. | ||
var KindStrikethrough = gast.NewNodeKind("Strikethrough") | ||
|
||
// Kind implements Node.Kind. | ||
func (n *Strikethrough) Kind() gast.NodeKind { | ||
return KindStrikethrough | ||
} | ||
|
||
// NewStrikethrough returns a new Strikethrough node. | ||
func NewStrikethrough() *Strikethrough { | ||
return &Strikethrough{} | ||
} |
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,31 @@ | ||
package ast | ||
|
||
import ( | ||
gast "github.com/yuin/goldmark/ast" | ||
textm "github.com/yuin/goldmark/text" | ||
) | ||
|
||
// A Template struct represents a Go template like {{ if eq .Status "firing" }}. | ||
type Template struct { | ||
gast.BaseInline | ||
|
||
Segment textm.Segment | ||
} | ||
|
||
// Dump implements Node.Dump. | ||
func (n *Template) Dump(source []byte, level int) { | ||
gast.DumpHelper(n, source, level, nil, nil) | ||
} | ||
|
||
// KindTemplate is a NodeKind of the Template node. | ||
var KindTemplate = gast.NewNodeKind("Template") | ||
|
||
// Kind implements Node.Kind. | ||
func (n *Template) Kind() gast.NodeKind { | ||
return KindTemplate | ||
} | ||
|
||
// NewTemplate returns a new Template node. | ||
func NewTemplate() *Template { | ||
return &Template{} | ||
} |
Oops, something went wrong.