Skip to content

Commit 098682c

Browse files
authored
Copy changes from #543
1 parent caae6e2 commit 098682c

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed

.github/linters/.markdown-lint.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"MD007": { "indent": 4 },
33
"MD013": false,
4-
"MD026": false
4+
"MD026": false,
5+
"MD042": false
56
}

.spelling-wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ FFI
2828
filesystem
2929
finaliser
3030
finalisers
31+
fontawesome
3132
forgeable
3233
GC
3334
GDB

docs/assets/snippets.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/**
2+
* @param {MouseEvent} evt
3+
*/
4+
async function runSnippetInline(evt) {
5+
evt.preventDefault();
6+
const snippetRes = await fetch(`https://raw.githubusercontent.com/ponylang/pony-tutorial/main/code-samples/${evt.target.dataset.snippet}`)
7+
const snippetCode = await snippetRes.text()
8+
const evaluateRes = await fetch('https://playground.ponylang.io/evaluate.json', {
9+
method: 'POST',
10+
headers: {
11+
'Content-Type': 'application/json',
12+
},
13+
body: JSON.stringify({
14+
"code": snippetCode,
15+
"separate_output": true,
16+
"color": true,
17+
"branch": "release"
18+
})
19+
})
20+
const json = await evaluateRes.json()
21+
evt.target.previousElementSibling.querySelector('pre').append(Object.assign(document.create('pre'), {
22+
innerHTML: json.success ? json.stdout : json.compiler,
23+
}))
24+
}
25+
26+
document$.subscribe(function() {
27+
const inlineRunButtons = document.querySelectorAll('.md-button[data-snippet]')
28+
29+
for (const button of inlineRunButtons) {
30+
button.addEventListener('click', runSnippetInline)
31+
}
32+
})

docs/getting-started/hello-world.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ In your file, put the following code:
2121
--8<-- "hello-world-main.pony"
2222
```
2323

24+
[:fontawesome-solid-play: Run inline](#){ .md-button .md-button--primary data-snippet="hello-world-main.pony" }
25+
2426
## Compiling the program
2527

2628
Now compile it:

mkdocs.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ repo_url: https://github.com/ponylang/pony-tutorial/
66
site_url: https://tutorial.ponylang.io/
77
use_directory_urls: false
88

9+
extra_javascript:
10+
- assets/snippets.js
11+
912
extra:
1013
generator: false
1114
social:
@@ -25,6 +28,10 @@ markdown_extensions:
2528
- pymdownx.snippets:
2629
base_path: ['code-samples']
2730
check_paths: true
31+
- pymdownx.emoji:
32+
emoji_index: !!python/name:material.extensions.emoji.twemoji
33+
emoji_generator: !!python/name:material.extensions.emoji.to_svg
34+
- attr_list
2835
- smarty
2936
- toc:
3037
permalink: true

0 commit comments

Comments
 (0)