Skip to content

Commit 9aec25e

Browse files
committed
preview with keybindings and fix scrolling issue
1 parent 86579bc commit 9aec25e

File tree

1 file changed

+34
-6
lines changed

1 file changed

+34
-6
lines changed

src/preview.md

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: Preview
2+
title: Article Preview
33
hide:
44
- navigation
55
---
@@ -11,25 +11,53 @@ hide:
1111
var URL = "https://us-central1-cp-algorithms.cloudfunctions.net/convert-markdown-mkdocs";
1212
var data = {"markdown": markdown};
1313
var refresh_script = `<scr` + `ipt>MathJax.typeset();</scr` + `ipt>`;
14-
$("#previewArea").html("Loading...");
14+
$("#previewBtn").html("Loading...");
1515
$.ajax({
1616
url: URL,
1717
contentType: "application/json",
1818
method: 'POST',
1919
data: JSON.stringify(data),
20-
success: function(data) { $("#previewArea").html(data + "\n" + refresh_script); },
20+
success: function(data) {
21+
$("#previewArea").html(data + "\n" + refresh_script);
22+
$("#previewBtn").html("Preview (Ctrl + Enter)");
23+
},
2124
error: function() {$("#previewArea").html("Internal error!")}
2225
});
2326
});
27+
28+
$('form').keydown(function(event) {
29+
if (event.ctrlKey && event.keyCode === 13) {
30+
$("#previewBtn").click();
31+
}
32+
})
2433
});
2534
</script>
26-
# Preview the rendering of your article
35+
# Article Preview
2736

37+
<a href="contrib.md">Information for contributors</a>
38+
<center>
2839
<form>
29-
<textarea style="width:90%;height:400px;" id="markdownInput" placeholder="paste your text here..."></textarea>
40+
<textarea style="width:100%;height:300px;" id="markdownInput">
41+
---
42+
title: Example article
43+
hide:
44+
- navigation
45+
---
46+
# Example article
47+
48+
$$a^2 + b^2 = c^2$$
49+
50+
```cpp
51+
int gcd (int a, int b) {
52+
if (b == 0)
53+
return a;
54+
else
55+
return gcd (b, a % b);
56+
}
57+
```</textarea>
3058
<br/>
3159
<br/>
32-
<button type='button' class="md-button md-button--primary" id="previewBtn">Preview</button>
60+
<button type='button' class="md-button md-button--primary" id="previewBtn">Preview (Ctrl + Enter)</button>
3361
</form>
3462
</center>
3563
<hr/>

0 commit comments

Comments
 (0)