mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-22 15:54:02 +00:00
Compare commits
2 Commits
plugins-ma
...
@mdjs/core
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
db03f69210 | ||
|
|
e6c3d274cf |
@@ -1,5 +1,11 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## 0.9.4
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- e6c3d27: Support `js client` as an alias to `js script`
|
||||||
|
|
||||||
## 0.9.3
|
## 0.9.3
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mdjs/core",
|
"name": "@mdjs/core",
|
||||||
"version": "0.9.3",
|
"version": "0.9.4",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ function mdjsParse() {
|
|||||||
if (node.lang === 'js' && node.meta === 'script') {
|
if (node.lang === 'js' && node.meta === 'script') {
|
||||||
jsCode += node.value;
|
jsCode += node.value;
|
||||||
}
|
}
|
||||||
|
if (node.lang === 'js' && node.meta === 'client') {
|
||||||
|
jsCode += node.value;
|
||||||
|
}
|
||||||
});
|
});
|
||||||
// we can only return/modify the tree but jsCode should not be part of the tree
|
// we can only return/modify the tree but jsCode should not be part of the tree
|
||||||
// so we attach it globally to the file.data
|
// so we attach it globally to the file.data
|
||||||
@@ -26,7 +29,9 @@ function mdjsParse() {
|
|||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
*/
|
*/
|
||||||
const removeFunction = node =>
|
const removeFunction = node =>
|
||||||
node.type === 'code' && node.lang === 'js' && node.meta === 'script';
|
node.type === 'code' &&
|
||||||
|
node.lang === 'js' &&
|
||||||
|
(node.meta === 'script' || node.meta === 'client');
|
||||||
remove(tree, removeFunction);
|
remove(tree, removeFunction);
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
|
|||||||
@@ -28,6 +28,24 @@ describe('mdjsParse', () => {
|
|||||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('extracts "js client" code blocks', async () => {
|
||||||
|
const input = [
|
||||||
|
'## Intro',
|
||||||
|
'```js',
|
||||||
|
'const foo = 1;',
|
||||||
|
'```',
|
||||||
|
'```js client',
|
||||||
|
'const bar = 22;',
|
||||||
|
'```',
|
||||||
|
].join('\n');
|
||||||
|
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||||
|
const result = await parser.process(input);
|
||||||
|
expect(result.contents).to.equal(
|
||||||
|
'<h2>Intro</h2>\n<pre><code class="language-js">const foo = 1;\n</code></pre>\n',
|
||||||
|
);
|
||||||
|
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||||
|
});
|
||||||
|
|
||||||
// TODO: fix this bug - maybe something in unified itself 🤔
|
// TODO: fix this bug - maybe something in unified itself 🤔
|
||||||
it.skip('handling only "js script" code blocks', async () => {
|
it.skip('handling only "js script" code blocks', async () => {
|
||||||
const input = [
|
const input = [
|
||||||
|
|||||||
Reference in New Issue
Block a user