Skip to content

Commit dd62f13

Browse files
authored
feat: Use gfm mode (#54)
* Use `gfm` mode by default * Add tests
1 parent 4864d65 commit dd62f13

File tree

5 files changed

+71
-4
lines changed

5 files changed

+71
-4
lines changed

cmd/app.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func findReadme(dir string) (string, error) {
4444
}
4545

4646
func toHTML(markdown string) (string, error) {
47-
sout, _, err := gh("api", "-X", "POST", "/markdown", "-f", fmt.Sprintf("text=%s", markdown))
47+
sout, _, err := gh("api", "-X", "POST", "/markdown", "-f", fmt.Sprintf("text=%s", markdown), "-f", "mode=gfm")
4848
if err != nil {
4949
return "", err
5050
}

cmd/app_test.go

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,54 @@ func TestToHTML(t *testing.T) {
8585
t.Errorf("got %v\n want %v", actual, expected)
8686
}
8787
}
88+
89+
func TestGfmCheckboxes(t *testing.T) {
90+
string, err := slurp("../testdata/gfm-checkboxes.md")
91+
if err != nil {
92+
t.Errorf(err.Error())
93+
}
94+
html, err := toHTML(string)
95+
if err != nil {
96+
t.Errorf(err.Error())
97+
}
98+
actual := strings.TrimSpace(html)
99+
100+
checkBoxes := 0
101+
checkedCheckBoxes := 0
102+
uncheckedCheckBoxes := 0
103+
for _, line := range strings.Split(actual, "\n") {
104+
if strings.Contains(line, "<input type=\"checkbox\"") {
105+
checkBoxes++
106+
if strings.Contains(line, "checked") {
107+
checkedCheckBoxes++
108+
} else {
109+
uncheckedCheckBoxes++
110+
}
111+
}
112+
}
113+
if checkBoxes != 2 {
114+
t.Errorf("got %v checkboxes, want 2", checkBoxes)
115+
}
116+
if checkedCheckBoxes != 1 {
117+
t.Errorf("got %v checked checkboxes, want 1", checkedCheckBoxes)
118+
}
119+
if uncheckedCheckBoxes != 1 {
120+
t.Errorf("got %v unchecked checkboxes, want 1", uncheckedCheckBoxes)
121+
}
122+
}
123+
124+
func TestGfmAlerts(t *testing.T) {
125+
string, err := slurp("../testdata/gfm-alerts.md")
126+
if err != nil {
127+
t.Errorf(err.Error())
128+
}
129+
html, err := toHTML(string)
130+
if err != nil {
131+
t.Errorf(err.Error())
132+
}
133+
actual := strings.TrimSpace(html)
134+
135+
if strings.Contains(actual, "<blockquote") {
136+
t.Error("got blockquote tag instead of alerts")
137+
}
138+
}

cmd/template.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<title>{{ .Title }}</title>
55
<link rel="icon" type="image/svg+xml" href="https://github.githubassets.com/favicons/favicon.svg">
66
{{ $cssURL :=
7-
"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.0.0/github-markdown.min.css" }} {{
7+
"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.6.1/github-markdown.min.css" }} {{
88
if eq .Mode "dark" }} {{ $cssURL =
9-
"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.0.0/github-markdown-dark.min.css"
9+
"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.6.1/github-markdown-dark.min.css"
1010
}} {{ else if eq .Mode "light" }} {{ $cssURL =
11-
"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.0.0/github-markdown-light.min.css"
11+
"https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/5.6.1/github-markdown-light.min.css"
1212
}}{{ end }}
1313
<link rel="stylesheet" href="{{ $cssURL }}" />
1414
<style>

testdata/gfm-alerts.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
> [!NOTE]
2+
> Useful information that users should know, even when skimming content.
3+
4+
> [!TIP]
5+
> Helpful advice for doing things better or more easily.
6+
7+
> [!IMPORTANT]
8+
> Key information users need to know to achieve their goal.
9+
10+
> [!WARNING]
11+
> Urgent info that needs immediate user attention to avoid problems.
12+
13+
> [!CAUTION]
14+
> Advises about risks or negative outcomes of certain actions.

testdata/gfm-checkboxes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- [ ] Not done
2+
- [x] Done

0 commit comments

Comments
 (0)