File tree Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Expand file tree Collapse file tree 3 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' @mdjs/core ' : patch
3
+ ---
4
+
5
+ Support ` js client ` as an alias to ` js script `
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ function mdjsParse() {
16
16
if ( node . lang === 'js' && node . meta === 'script' ) {
17
17
jsCode += node . value ;
18
18
}
19
+ if ( node . lang === 'js' && node . meta === 'client' ) {
20
+ jsCode += node . value ;
21
+ }
19
22
} ) ;
20
23
// we can only return/modify the tree but jsCode should not be part of the tree
21
24
// so we attach it globally to the file.data
@@ -26,7 +29,9 @@ function mdjsParse() {
26
29
* @param {Node } node
27
30
*/
28
31
const removeFunction = node =>
29
- node . type === 'code' && node . lang === 'js' && node . meta === 'script' ;
32
+ node . type === 'code' &&
33
+ node . lang === 'js' &&
34
+ ( node . meta === 'script' || node . meta === 'client' ) ;
30
35
remove ( tree , removeFunction ) ;
31
36
32
37
return tree ;
Original file line number Diff line number Diff line change @@ -28,6 +28,24 @@ describe('mdjsParse', () => {
28
28
expect ( /** @type {MDJSVFileData } */ ( result . data ) . jsCode ) . to . equal ( 'const bar = 22;' ) ;
29
29
} ) ;
30
30
31
+ it ( 'extracts "js client" code blocks' , async ( ) => {
32
+ const input = [
33
+ '## Intro' ,
34
+ '```js' ,
35
+ 'const foo = 1;' ,
36
+ '```' ,
37
+ '```js client' ,
38
+ 'const bar = 22;' ,
39
+ '```' ,
40
+ ] . join ( '\n' ) ;
41
+ const parser = unified ( ) . use ( markdown ) . use ( mdjsParse ) . use ( html , { sanitize : false } ) ;
42
+ const result = await parser . process ( input ) ;
43
+ expect ( result . contents ) . to . equal (
44
+ '<h2>Intro</h2>\n<pre><code class="language-js">const foo = 1;\n</code></pre>\n' ,
45
+ ) ;
46
+ expect ( /** @type {MDJSVFileData } */ ( result . data ) . jsCode ) . to . equal ( 'const bar = 22;' ) ;
47
+ } ) ;
48
+
31
49
// TODO: fix this bug - maybe something in unified itself 🤔
32
50
it . skip ( 'handling only "js script" code blocks' , async ( ) => {
33
51
const input = [
You can’t perform that action at this time.
0 commit comments