Skip to content

Commit 02b28dd

Browse files
authored
Merge pull request #83 from instant-markdown/fix/highlight-js
Tests for highlight.js
2 parents 88d8d73 + a1e1fad commit 02b28dd

File tree

6 files changed

+53
-7
lines changed

6 files changed

+53
-7
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,9 @@ jobs:
1616
os:
1717
- ubuntu-latest
1818
node_version:
19-
- 8
20-
- 10
2119
- 12
2220
- 14
21+
- 16
2322
include:
2423
- os: windows-latest
2524
node_version: 14

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"license": "Apache-2.0",
1111
"homepage": "https://github.com/instant-markdown/instant-markdown-d",
1212
"engines": {
13-
"node": ">=8.0.0"
13+
"node": ">=12.0.0"
1414
},
1515
"main": "./src/cli.js",
1616
"preferGlobal": "true",

src/cli.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ let md = new MarkdownIt({
7373
highlight: function(str, lang) {
7474
if (lang && hljs.getLanguage(lang)) {
7575
try {
76-
return hljs.highlight(lang, str).value;
76+
return hljs.highlight(str, {language: lang}).value;
7777
} catch (err) {
7878
// Do nothing
7979
}

tests/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ def send(self, via, markdown_file):
124124
"Has instant-markdown-d failed to start?"
125125
)
126126

127-
method = getattr(self, f"send_{via}")
127+
method = getattr(self, f"_send_{via}")
128128
method(markdown_file)
129129

130-
def send_stdin(self, markdown_file):
130+
def _send_stdin(self, markdown_file):
131131
logger.info(f"send via stdin {markdown_file}")
132132
with open(markdown_file, "rb") as file:
133133
text = file.read()
@@ -138,7 +138,7 @@ def send_stdin(self, markdown_file):
138138
except subprocess.TimeoutExpired:
139139
pass
140140

141-
def send_curl(self, markdown_file):
141+
def _send_curl(self, markdown_file):
142142
logger.info(f"send via curl using REST API {markdown_file}")
143143

144144
# Equivalent to

tests/test_code.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<span class="test-case"></span>
2+
3+
# Code with Highlight.js
4+
5+
Courtesy: [Rosetta Code](https://rosettacode.org/wiki/Factorial)
6+
7+
## JavaScript / ES6
8+
9+
```js
10+
var factorial = n => (n < 2) ? 1 : n * factorial(n - 1);
11+
```
12+
13+
## Python
14+
15+
```python
16+
def factorial(n):
17+
return n * factorial(n - 1) if n else 1
18+
```
19+
20+
21+
## Vim script
22+
23+
```vim
24+
function! Factorial(n)
25+
if a:n < 2
26+
return 1
27+
else
28+
return a:n * Factorial(a:n-1)
29+
endif
30+
endfunction
31+
```

tests/test_code.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import pytest
2+
3+
4+
def test_code(browser, Server):
5+
6+
with Server("--debug", 8090) as srv:
7+
srv.send("curl", "tests/test_code.md")
8+
9+
result = browser.get(srv.port)
10+
11+
assert '<span class="test-case"></span>' in result, "No text was rendered"
12+
13+
elems = browser.find_elements_by_xpath("//pre/code/span")
14+
assert all(
15+
e.get_attribute("class").startswith("hljs-") for e in elems
16+
), "Highlight.js processing not completed"

0 commit comments

Comments
 (0)