-
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
1 parent
fa41260
commit 89d8ef7
Showing
4 changed files
with
92 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,5 @@ | ||
# 管理checkout的eol | ||
# 確保test的文本內容,不會因為eol的問題導致不相等 | ||
* text eol=lf | ||
# *.html text eol=lf | ||
*.exe binary |
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,45 @@ | ||
package highlighting_test | ||
|
||
import ( | ||
"bytes" | ||
"errors" | ||
"fmt" | ||
highlighting "github.com/CarsonSlovoka/goldmark-highlighting/v2" | ||
"github.com/yuin/goldmark" | ||
"log" | ||
"os" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func startTest(markdown goldmark.Markdown, testDir string) error { | ||
content, err := os.ReadFile(fmt.Sprintf("testData/%s/input.md", testDir)) | ||
if err != nil { | ||
return err | ||
} | ||
got := bytes.NewBuffer(make([]byte, 0)) | ||
if err = markdown.Convert(content, got); err != nil { | ||
return err | ||
} | ||
want, err := os.ReadFile(fmt.Sprintf("testData/%s/expected.html", testDir)) | ||
if err != nil { | ||
return err | ||
} | ||
if got.String() != strings.TrimRight(string(want), "\n") { // 移除結尾多出的空行,避免editorconfig中的insert_final_newline與其衝突 | ||
log.Printf("[error]\ngot:\n%s\nwant:\n%s", got, want) | ||
return errors.New("got != want") | ||
} | ||
return nil | ||
} | ||
|
||
func Test_NewHighlightingExtender(t *testing.T) { | ||
markdown := goldmark.New( | ||
goldmark.WithExtensions( | ||
highlighting.NewHighlightingExtender(), | ||
), | ||
) | ||
|
||
if err := startTest(markdown, "basic"); err != nil { | ||
t.Fatal(err) | ||
} | ||
} |
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 @@ | ||
<h2>Demo</h2> | ||
<pre> | ||
<code>package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello World") | ||
} | ||
</code> | ||
</pre> | ||
<div class="highlight Go"> | ||
<pre tabindex="0" style="color:#f8f8f2;background-color:#272822;"><code><span style="display:flex;"><span><span style="color:#f92672">package</span> <span style="color:#a6e22e">main</span> | ||
</span></span><span style="display:flex;"><span> | ||
</span></span><span style="display:flex;"><span><span style="color:#f92672">import</span> <span style="color:#e6db74">"fmt"</span> | ||
</span></span><span style="display:flex;"><span> | ||
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">func</span> <span style="color:#a6e22e">main</span>() { | ||
</span></span><span style="display:flex;"><span> <span style="color:#a6e22e">fmt</span>.<span style="color:#a6e22e">Println</span>(<span style="color:#e6db74">"Hello World"</span>) | ||
</span></span><span style="display:flex;"><span>} | ||
</span></span></code></pre> | ||
</div> |
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 @@ | ||
## Demo | ||
|
||
``` | ||
package main | ||
import "fmt" | ||
func main() { | ||
fmt.Println("Hello World") | ||
} | ||
``` | ||
|
||
```go | ||
package main | ||
|
||
import "fmt" | ||
|
||
func main() { | ||
fmt.Println("Hello World") | ||
} | ||
``` |