Skip to content

Commit 6de54e5

Browse files
authored
Merge pull request #42 from Kristina-Pianykh/support-multiple-formats
Add support for code snippets for more file formats
2 parents 51cb141 + 46e52ff commit 6de54e5

File tree

10 files changed

+87
-10
lines changed

10 files changed

+87
-10
lines changed

.github/workflows/hype.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ jobs:
1111
steps:
1212
- uses: actions/checkout@v4
1313
with:
14-
ref: ${{ github.head_ref }}
14+
ref: ${{github.event.pull_request.head.ref}}
15+
repository: ${{github.event.pull_request.head.repo.full_name}}
1516
- name: Set up Go
1617
uses: actions/setup-go@v4
1718
with:

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,8 @@ jobs:
422422
steps:
423423
- uses: actions/checkout@v4
424424
with:
425-
ref: ${{ github.head_ref }}
425+
ref: ${{github.event.pull_request.head.ref}}
426+
repository: ${{github.event.pull_request.head.repo.full_name}}
426427
- name: Set up Go
427428
uses: actions/setup-go@v4
428429
with:

snippet.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -125,12 +125,17 @@ func (sm *Snippets) init() {
125125

126126
if sm.rules == nil {
127127
sm.rules = map[string]string{
128-
".go": "// %s",
129-
".html": "<!-- %s -->",
130-
".js": "// %s",
131-
".md": "<!-- %s -->",
132-
".rb": "# %s",
133-
".ts": "// %s",
128+
".go": "// %s",
129+
".html": "<!-- %s -->",
130+
".js": "// %s",
131+
".md": "<!-- %s -->",
132+
".rb": "# %s",
133+
".ts": "// %s",
134+
".sh": "# %s",
135+
".yaml": "# %s",
136+
".yml": "# %s",
137+
".env": "# %s",
138+
".envrc": "# %s",
134139
}
135140
}
136141
})

snippet_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@ func Test_Parse_Snippets(t *testing.T) {
2727
const rbexp = "def goodbye\n puts \"Goodbye, World!\"\nend"
2828
const jsexp = "function goodbye() {\n console.log('Goodbye, World!');\n}"
2929
const htmlexp = "<p>Goodbye World</p>"
30+
const yamlexp = "address:\n street: 123 Main St\n city: Springfield\n zip: 12345"
31+
const ymlexp = "address:\n street: 123 Main St\n city: Springfield\n zip: 12345"
32+
const shexp = "echo \"Goodbye, World!\""
33+
const envexp = "GOODBYE=\"goodbye\""
34+
const envrcexp = "export GOODBYE=\"goodbye\""
3035

3136
table := []struct {
3237
path string
@@ -39,6 +44,11 @@ func Test_Parse_Snippets(t *testing.T) {
3944
{path: "snippets.rb", lang: "rb", start: 7, end: 11, exp: rbexp},
4045
{path: "snippets.js", lang: "js", start: 7, end: 11, exp: jsexp},
4146
{path: "snippets.html", lang: "html", start: 16, end: 18, exp: htmlexp},
47+
{path: "snippets.yaml", lang: "yaml", start: 5, end: 10, exp: yamlexp},
48+
{path: "snippets.yml", lang: "yml", start: 5, end: 10, exp: ymlexp},
49+
{path: "snippets.sh", lang: "sh", start: 3, end: 5, exp: shexp},
50+
{path: "snippets.env", lang: "env", start: 1, end: 3, exp: envexp},
51+
{path: ".envrc", lang: "envrc", start: 1, end: 3, exp: envrcexp},
4252
}
4353

4454
for _, tc := range table {

testdata/json/document.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,17 @@
262262
"section_id": 1,
263263
"snippets": {
264264
"rules": {
265+
".env": "# %s",
266+
".envrc": "# %s",
265267
".go": "// %s",
266268
".html": "\u003c!-- %s --\u003e",
267269
".js": "// %s",
268270
".md": "\u003c!-- %s --\u003e",
269271
".rb": "# %s",
270-
".ts": "// %s"
272+
".sh": "# %s",
273+
".ts": "// %s",
274+
".yaml": "# %s",
275+
".yml": "# %s"
271276
},
272277
"snippets": {
273278
"src/main.ts": {
@@ -292,4 +297,4 @@
292297
},
293298
"title": "Hello",
294299
"type": "hype.Document"
295-
}
300+
}

testdata/snippets/.envrc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# snippet: goodbye
2+
export GOODBYE="goodbye"
3+
# snippet: goodbye
4+
# snippet: hello
5+
export HELLO="hello"
6+
# snippet: hello

testdata/snippets/snippets.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# snippet: goodbye
2+
GOODBYE="goodbye"
3+
# snippet: goodbye
4+
# snippet: hello
5+
HELLO="hello"
6+
# snippet: hello

testdata/snippets/snippets.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
# snippet: goodbye
4+
echo "Goodbye, World!"
5+
# snippet: goodbye
6+
7+
# snippet: hello
8+
echo "Hello, World!"
9+
# snippet: hello

testdata/snippets/snippets.yaml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Jane Doe
3+
age: 30
4+
isEmployed: true
5+
# snippet: goodbye
6+
address:
7+
street: 123 Main St
8+
city: Springfield
9+
zip: 12345
10+
# snippet: goodbye
11+
pets:
12+
- type: dog
13+
name: Rex
14+
# snippet: hello
15+
- type: cat
16+
name: Whiskers
17+
# snippet: hello

testdata/snippets/snippets.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
name: Jane Doe
3+
age: 30
4+
isEmployed: true
5+
# snippet: goodbye
6+
address:
7+
street: 123 Main St
8+
city: Springfield
9+
zip: 12345
10+
# snippet: goodbye
11+
pets:
12+
- type: dog
13+
name: Rex
14+
# snippet: hello
15+
- type: cat
16+
name: Whiskers
17+
# snippet: hello

0 commit comments

Comments
 (0)