Skip to content

Commit dbd1aad

Browse files
authored
Merge pull request #54 from andrewbranch/bug/code-meta
Fix code fence option parsing with space after language name
2 parents a8feb4c + 5773345 commit dbd1aad

File tree

4 files changed

+82
-3
lines changed

4 files changed

+82
-3
lines changed

src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ function createPlugin() {
7373
/** @type {string} */
7474
const text = node.value || (node.children && node.children[0] && node.children[0].value);
7575
if (!text) continue;
76-
const { languageName, options } = parseCodeFenceHeader(node.lang ? node.lang.toLowerCase() : '');
76+
const { languageName, options } = parseCodeFenceHeader(node.lang ? node.lang.toLowerCase() : '', node.meta);
7777
await downloadExtensionsIfNeeded({
7878
extensions,
7979
cache,

src/parseCodeFenceHeader.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,14 @@ function test(input, pattern) {
1414
}
1515

1616
/**
17-
* @param {string} input
17+
* @param {string} lang
18+
* @param {string | undefined} meta
1819
*/
19-
function parseCodeFenceHeader(input) {
20+
function parseCodeFenceHeader(lang, meta) {
2021
let pos = 0;
2122
let options = {};
2223
let languageName = '';
24+
const input = lang + (meta || '');
2325
skipTrivia();
2426
if (!isEnd() && current() !== '{') {
2527
languageName = parseIdentifier();
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
<pre class="default-dark vscode-highlight" data-language="js"><code class="vscode-highlight-code"><span class="vscode-highlight-line vscode-highlight-line-highlighted"><span class="mtk3">// should be highlighted</span></span></code></pre>
2+
<style class="vscode-highlight-styles">
3+
:root {
4+
--vscode-highlight-padding-v: 1rem;
5+
--vscode-highlight-padding-h: 1.5rem;
6+
--vscode-highlight-padding-top: var(--vscode-highlight-padding-v);
7+
--vscode-highlight-padding-right: var(--vscode-highlight-padding-h);
8+
--vscode-highlight-padding-bottom: var(--vscode-highlight-padding-v);
9+
--vscode-highlight-padding-left: var(--vscode-highlight-padding-h);
10+
--vscode-highlight-border-radius: 8px;
11+
12+
--vscode-highlight-line-highlighted-background-color: transparent;
13+
--vscode-highlight-line-highlighted-border-width: 4px;
14+
--vscode-highlight-line-highlighted-border-color: transparent;
15+
}
16+
17+
.vscode-highlight {
18+
overflow: auto;
19+
-webkit-overflow-scrolling: touch;
20+
padding-top: 1rem;
21+
padding-top: var(--vscode-highlight-padding-top);
22+
padding-bottom: 1rem;
23+
padding-bottom: var(--vscode-highlight-padding-bottom);
24+
border-radius: 8px;
25+
border-radius: var(--vscode-highlight-border-radius);
26+
font-feature-settings: normal;
27+
}
28+
29+
.vscode-highlight-code {
30+
display: inline-block;
31+
min-width: 100%;
32+
}
33+
34+
.vscode-highlight-line {
35+
display: inline-block;
36+
box-sizing: border-box;
37+
width: 100%;
38+
padding-left: 1.5rem;
39+
padding-left: var(--vscode-highlight-padding-left);
40+
padding-right: 1.5rem;
41+
padding-right: var(--vscode-highlight-padding-right);
42+
}
43+
44+
.vscode-highlight-line-highlighted {
45+
background-color: var(--vscode-highlight-line-highlighted-background-color);
46+
box-shadow: inset var(--vscode-highlight-line-highlighted-border-width) 0 0 0 var(--vscode-highlight-line-highlighted-border-color);
47+
}
48+
49+
.default-dark {
50+
background-color: #1E1E1E;
51+
color: #D4D4D4;
52+
}
53+
54+
.default-dark .mtk1 { color: #D4D4D4; }
55+
.default-dark .mtk2 { color: #1E1E1E; }
56+
.default-dark .mtk3 { color: #6A9955; }
57+
.default-dark .mtk4 { color: #569CD6; }
58+
.default-dark .mtk5 { color: #D16969; }
59+
.default-dark .mtk6 { color: #D7BA7D; }
60+
.default-dark .mtk7 { color: #B5CEA8; }
61+
.default-dark .mtk8 { color: #CE9178; }
62+
.default-dark .mtk9 { color: #646695; }
63+
.default-dark .mtk10 { color: #4EC9B0; }
64+
.default-dark .mtk11 { color: #DCDCAA; }
65+
.default-dark .mtk12 { color: #9CDCFE; }
66+
.default-dark .mtk13 { color: #000080; }
67+
.default-dark .mtk14 { color: #F44747; }
68+
.default-dark .mtk15 { color: #C586C0; }
69+
.default-dark .mtk16 { color: #6796E6; }
70+
.default-dark .mtk17 { color: #808080; }
71+
.default-dark .mtki { font-style: italic; }
72+
.default-dark .mtkb { font-weight: bold; }
73+
.default-dark .mtku { text-decoration: underline; text-underline-position: under; }
74+
</style>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```js {1}
2+
// should be highlighted
3+
```

0 commit comments

Comments
 (0)