mirror of
https://github.com/modernweb-dev/rocket.git
synced 2026-03-21 15:54:57 +00:00
Compare commits
13 Commits
@rocket/cr
...
@rocket/en
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b8a1b45953 | ||
|
|
379f08ff47 | ||
|
|
50bb68ab7f | ||
|
|
250ca87a9d | ||
|
|
6f88d8ef6f | ||
|
|
35ed64dca1 | ||
|
|
2555a8698d | ||
|
|
367529c211 | ||
|
|
ce3298d218 | ||
|
|
a22da493dd | ||
|
|
7a8f165625 | ||
|
|
c8081071f7 | ||
|
|
ab2436162c |
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@@ -7,5 +7,6 @@
|
|||||||
"search.exclude": {
|
"search.exclude": {
|
||||||
"**/*-mdjs-generated.js": true,
|
"**/*-mdjs-generated.js": true,
|
||||||
"**/dist-types": true,
|
"**/dist-types": true,
|
||||||
}
|
},
|
||||||
|
"editor.experimental.stickyScroll.enabled": true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<picture width="60%">
|
<picture width="60%">
|
||||||
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/modernweb-dev/rocket/next/site/src/assets/rocket-logo-dark-with-text.svg">
|
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/modernweb-dev/rocket/main/site/src/assets/rocket-logo-dark-with-text.svg">
|
||||||
<img alt="Rocket Logo" src="https://raw.githubusercontent.com/modernweb-dev/rocket/next/site/src/assets/rocket-logo-light-with-text.svg">
|
<img alt="Rocket Logo" src="https://raw.githubusercontent.com/modernweb-dev/rocket/main/site/src/assets/rocket-logo-light-with-text.svg">
|
||||||
</picture>
|
</picture>
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<a href="https://github.com/modernweb-dev/rocket/actions"
|
<a href="https://github.com/modernweb-dev/rocket/actions"
|
||||||
><img
|
><img
|
||||||
src="https://img.shields.io/github/workflow/status/modernweb-dev/rocket/Release/next?label=workflow&style=flat-square"
|
src="https://img.shields.io/github/workflow/status/modernweb-dev/rocket/Release/main?label=workflow&style=flat-square"
|
||||||
alt="GitHub Actions workflow status"
|
alt="GitHub Actions workflow status"
|
||||||
/></a>
|
/></a>
|
||||||
<a href="https://twitter.com/modern_web_dev"
|
<a href="https://twitter.com/modern_web_dev"
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
"@rocket/cli": "^0.20.0",
|
"@rocket/cli": "^0.20.0",
|
||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"@webcomponents/template-shadowroot": "^0.1.0",
|
"@webcomponents/template-shadowroot": "^0.1.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"@rocket/template-name": "Hydration Starter",
|
"@rocket/template-name": "Hydration Starter",
|
||||||
"imports": {
|
"imports": {
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rocket/cli": "^0.20.0",
|
"@rocket/cli": "^0.20.0",
|
||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"@rocket/template-name": "Blog Starter"
|
"@rocket/template-name": "Blog Starter"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@rocket/cli": "^0.20.0",
|
"@rocket/cli": "^0.20.0",
|
||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"@rocket/template-name": "Minimal Starter"
|
"@rocket/template-name": "Minimal Starter"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,7 +18,7 @@
|
|||||||
"@sanity/client": "^3.1.0",
|
"@sanity/client": "^3.1.0",
|
||||||
"@sanity/image-url": "^1.0.1",
|
"@sanity/image-url": "^1.0.1",
|
||||||
"dotenv": "^16.0.0",
|
"dotenv": "^16.0.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"@rocket/template-name": "Sanity Minimal Starter"
|
"@rocket/template-name": "Sanity Minimal Starter"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"@rocket/components": "^0.2.0",
|
"@rocket/components": "^0.2.0",
|
||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"@rocket/spark": "^0.2.0",
|
"@rocket/spark": "^0.2.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"@rocket/template-name": "Landing Page (@rocket/spark Theme)",
|
"@rocket/template-name": "Landing Page (@rocket/spark Theme)",
|
||||||
"imports": {
|
"imports": {
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"@rocket/launch": "^0.21.0",
|
"@rocket/launch": "^0.21.0",
|
||||||
"@rocket/search": "^0.7.0",
|
"@rocket/search": "^0.7.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"@rocket/template-name": "Documentation Website (@rocket/launch Theme)",
|
"@rocket/template-name": "Documentation Website (@rocket/launch Theme)",
|
||||||
"imports": {
|
"imports": {
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @rocket/building-rollup
|
# @rocket/building-rollup
|
||||||
|
|
||||||
|
## 0.4.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- a22da49: Make sure user provided `developmentMode` actually gets applied.
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rocket/building-rollup",
|
"name": "@rocket/building-rollup",
|
||||||
"version": "0.4.0",
|
"version": "0.4.1",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function createBasicConfig(userConfig) {
|
|||||||
|
|
||||||
export function createBasicMetaConfig(userConfig = { output: {} }) {
|
export function createBasicMetaConfig(userConfig = { output: {} }) {
|
||||||
const developmentMode =
|
const developmentMode =
|
||||||
typeof userConfig.developmentMode !== undefined
|
typeof userConfig.developmentMode !== 'undefined'
|
||||||
? userConfig.developmentMode
|
? userConfig.developmentMode
|
||||||
: !!process.env.ROLLUP_WATCH;
|
: !!process.env.ROLLUP_WATCH;
|
||||||
delete userConfig.developmentMode;
|
delete userConfig.developmentMode;
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export function createServiceWorkerConfig(userConfig) {
|
|||||||
|
|
||||||
export function createServiceWorkerMetaConfig(userConfig = { output: {} }) {
|
export function createServiceWorkerMetaConfig(userConfig = { output: {} }) {
|
||||||
const developmentMode =
|
const developmentMode =
|
||||||
typeof userConfig.developmentMode !== undefined
|
typeof userConfig.developmentMode !== 'undefined'
|
||||||
? userConfig.developmentMode
|
? userConfig.developmentMode
|
||||||
: !!process.env.ROLLUP_WATCH;
|
: !!process.env.ROLLUP_WATCH;
|
||||||
delete userConfig.developmentMode;
|
delete userConfig.developmentMode;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@
|
|||||||
"glob": "^7.0.0",
|
"glob": "^7.0.0",
|
||||||
"minimatch": "^3.0.4",
|
"minimatch": "^3.0.4",
|
||||||
"sax-wasm": "^2.0.0",
|
"sax-wasm": "^2.0.0",
|
||||||
"slash": "^3.0.0"
|
"slash": "^4.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/glob": "^7.0.0"
|
"@types/glob": "^7.0.0"
|
||||||
|
|||||||
@@ -43,7 +43,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@webcomponents/template-shadowroot": "^0.1.0",
|
"@webcomponents/template-shadowroot": "^0.1.0",
|
||||||
"fontawesome-free": "^1.0.4",
|
"fontawesome-free": "^1.0.4",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"types": "./dist-types/exports/index.d.ts",
|
"types": "./dist-types/exports/index.d.ts",
|
||||||
|
|||||||
@@ -1,5 +1,27 @@
|
|||||||
# @rocket/engine
|
# @rocket/engine
|
||||||
|
|
||||||
|
## 0.2.3
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 379f08f: Remove the lit workaround to globally load the `global-dom-shim` in the "main thread".
|
||||||
|
Which means only the worker that does the actual SSR rendering will load it.
|
||||||
|
|
||||||
|
## 0.2.2
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 6f88d8e: Get rid of the `rehype-prism` workaround by using latest esm version of mdjs that uses `rehype-prism-plus`
|
||||||
|
- Updated dependencies [35ed64d]
|
||||||
|
- Updated dependencies [6f88d8e]
|
||||||
|
- @mdjs/core@0.20.0
|
||||||
|
|
||||||
|
## 0.2.1
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- 367529c: Make sure user provided content in the folder `site/public/*` wins over public folders content provided by plugins.
|
||||||
|
|
||||||
## 0.2.0
|
## 0.2.0
|
||||||
|
|
||||||
### Minor Changes
|
### Minor Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@rocket/engine",
|
"name": "@rocket/engine",
|
||||||
"version": "0.2.0",
|
"version": "0.2.3",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
@@ -35,9 +35,9 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"debug": "DEBUG=engine:rendering yarn test",
|
"debug": "DEBUG=engine:rendering yarn test",
|
||||||
"debug:integration": "PWDEBUG=1 yarn test:integration",
|
"debug:integration": "PWDEBUG=1 yarn test:integration",
|
||||||
"test": "mocha --require ../../scripts/testMochaGlobalHooks.js --timeout 5000 test-node/**/*.test.{js,cjs} test-node/*.test.{js,cjs}",
|
"test": "mocha --require ../../scripts/testMochaGlobalHooks.js --timeout 8000 test-node/**/*.test.js test-node/*.test.js",
|
||||||
"test:integration": "playwright test test-node/*.spec.js",
|
"test:integration": "playwright test test-node/*.spec.js",
|
||||||
"test:watch": "onchange 'src/**/*.{js,cjs}' 'test-node/**/*.{js,cjs}' -- npm test",
|
"test:watch": "onchange 'src/**/*.js' 'test-node/**/*.js' -- npm test",
|
||||||
"types:copy": "copyfiles \"./types/**/*.d.ts\" dist-types/"
|
"types:copy": "copyfiles \"./types/**/*.d.ts\" dist-types/"
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
@@ -47,14 +47,15 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@d4kmor/tree-model": "^0.1.3",
|
"@d4kmor/tree-model": "^0.1.3",
|
||||||
"@lit-labs/ssr": "^2.0.4",
|
"@lit-labs/ssr": "^2.2.3",
|
||||||
"@mdjs/core": "^0.9.5",
|
"@mdjs/core": "^0.20.0",
|
||||||
"@parcel/watcher": "^2.0.5",
|
"@parcel/watcher": "^2.0.5",
|
||||||
"@web/dev-server": "^0.1.4",
|
"@web/dev-server": "^0.1.4",
|
||||||
"es-module-lexer": "^0.9.3",
|
"es-module-lexer": "^0.10.5",
|
||||||
"lit": "^2.2.5",
|
"lit": "^2.3.0",
|
||||||
"plugins-manager": "^0.3.0",
|
"plugins-manager": "^0.3.0",
|
||||||
"sax-wasm": "^2.1.3"
|
"sax-wasm": "^2.1.3",
|
||||||
|
"unist-util-visit": "^4.1.0"
|
||||||
},
|
},
|
||||||
"types": "./dist-types/src/index.d.ts",
|
"types": "./dist-types/src/index.d.ts",
|
||||||
"typesVersions": {
|
"typesVersions": {
|
||||||
|
|||||||
@@ -152,12 +152,7 @@ export class Engine {
|
|||||||
* @param {string} targetDir
|
* @param {string} targetDir
|
||||||
*/
|
*/
|
||||||
async copyPublicFilesTo(targetDir) {
|
async copyPublicFilesTo(targetDir) {
|
||||||
// copy public files
|
// 1. copy public files of plugins
|
||||||
const publicDir = path.join(this.docsDir, '..', 'public');
|
|
||||||
if (existsSync(publicDir)) {
|
|
||||||
await fse.copy(publicDir, targetDir);
|
|
||||||
}
|
|
||||||
// copy public files of plugins
|
|
||||||
if (this.options.plugins) {
|
if (this.options.plugins) {
|
||||||
for (const plugin of this.options.plugins) {
|
for (const plugin of this.options.plugins) {
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
@@ -171,6 +166,12 @@ export class Engine {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 2. copy public files from inputDir (e.g. user public folder always wins)
|
||||||
|
const publicDir = path.join(this.docsDir, '..', 'public');
|
||||||
|
if (existsSync(publicDir)) {
|
||||||
|
await fse.copy(publicDir, targetDir);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async start(options = {}) {
|
async start(options = {}) {
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ export function devServerAdjustAssetUrls({
|
|||||||
const outputFilePath = getOutputFilePath(sourceFilePath);
|
const outputFilePath = getOutputFilePath(sourceFilePath);
|
||||||
const sourceRelativeFilePath = path.relative(inputDir, sourceFilePath);
|
const sourceRelativeFilePath = path.relative(inputDir, sourceFilePath);
|
||||||
const outputRelativeFilePath = path.relative(outputDir, outputFilePath);
|
const outputRelativeFilePath = path.relative(outputDir, outputFilePath);
|
||||||
const newBody = await adjustAssetUrl.transform(context.body, {
|
const body = /** @type {string} */ (context.body);
|
||||||
|
const newBody = await adjustAssetUrl.transform(body, {
|
||||||
sourceFilePath,
|
sourceFilePath,
|
||||||
sourceRelativeFilePath,
|
sourceRelativeFilePath,
|
||||||
outputFilePath,
|
outputFilePath,
|
||||||
|
|||||||
@@ -1,16 +1,12 @@
|
|||||||
// we load this before the global-dom-shim as otherwise prism thinks it's running in a browser 🙈
|
|
||||||
// we need to load the global-dom-shim as otherwise import { html } from 'lit'; breaks
|
|
||||||
import 'rehype-prism';
|
|
||||||
import '@lit-labs/ssr/lib/install-global-dom-shim.js';
|
|
||||||
|
|
||||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
||||||
|
// @ts-ignore
|
||||||
import { mdjsProcess } from '@mdjs/core';
|
import { mdjsProcess } from '@mdjs/core';
|
||||||
import { existsSync } from 'fs';
|
import { existsSync } from 'fs';
|
||||||
import { readFile, writeFile } from 'fs/promises';
|
import { readFile, writeFile } from 'fs/promises';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { addPlugin } from 'plugins-manager';
|
import { addPlugin } from 'plugins-manager';
|
||||||
import markdown from 'remark-parse';
|
import markdown from 'remark-parse';
|
||||||
import visit from 'unist-util-visit';
|
import { visit } from 'unist-util-visit';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {string} string
|
* @param {string} string
|
||||||
@@ -22,7 +18,7 @@ function escapeRegExp(string) {
|
|||||||
|
|
||||||
const REGEX_REPLACE_ESCAPES = new RegExp(
|
const REGEX_REPLACE_ESCAPES = new RegExp(
|
||||||
escapeRegExp(
|
escapeRegExp(
|
||||||
'\\\\</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>',
|
'\\\\<span class="token interpolation"><span class="token interpolation-punctuation punctuation">${</span>',
|
||||||
),
|
),
|
||||||
'g',
|
'g',
|
||||||
);
|
);
|
||||||
@@ -145,7 +141,7 @@ export async function mdInJsToMdHtmlInJs(toImportFilePath) {
|
|||||||
// this corrects it - escaped
|
// this corrects it - escaped
|
||||||
mdHTML = mdHTML.replace(
|
mdHTML = mdHTML.replace(
|
||||||
REGEX_REPLACE_ESCAPES,
|
REGEX_REPLACE_ESCAPES,
|
||||||
'</span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">\\\\${</span>',
|
'<span class="token interpolation"><span class="token interpolation-punctuation punctuation">\\\\${</span>',
|
||||||
);
|
);
|
||||||
return [mdHTML, ...mdjsScriptTag].join('\n');
|
return [mdHTML, ...mdjsScriptTag].join('\n');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
// we load this before the global-dom-shim as otherwise prism thinks it's running in a browser 🙈
|
|
||||||
// we need to load the global-dom-shim as otherwise import { html } from 'lit'; breaks
|
|
||||||
import 'rehype-prism';
|
|
||||||
import '@lit-labs/ssr/lib/install-global-dom-shim.js';
|
|
||||||
|
|
||||||
export { renderJoiningGroup } from './helpers/renderJoiningGroup.js';
|
export { renderJoiningGroup } from './helpers/renderJoiningGroup.js';
|
||||||
export { inlineFile } from './helpers/inlineFile.js';
|
export { inlineFile } from './helpers/inlineFile.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
// we load this before the global-dom-shim as otherwise prism thinks it's running in a browser 🙈
|
|
||||||
// we need to load the global-dom-shim as otherwise import { html } from 'lit'; breaks
|
|
||||||
import 'rehype-prism';
|
|
||||||
import '@lit-labs/ssr/lib/install-global-dom-shim.js';
|
|
||||||
|
|
||||||
import { parentPort } from 'worker_threads';
|
import { parentPort } from 'worker_threads';
|
||||||
// import { convertMdFile, convertHtmlFile } from '../converts.js';
|
// import { convertMdFile, convertHtmlFile } from '../converts.js';
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,3 @@
|
|||||||
// we load this before the global-dom-shim as otherwise prism thinks it's running in a browser 🙈
|
|
||||||
// we need to load the global-dom-shim as otherwise import { html } from 'lit'; breaks
|
|
||||||
import 'rehype-prism';
|
|
||||||
import '@lit-labs/ssr/lib/install-global-dom-shim.js';
|
|
||||||
|
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { parentPort } from 'worker_threads';
|
import { parentPort } from 'worker_threads';
|
||||||
import { mkdir, writeFile } from 'fs/promises';
|
import { mkdir, writeFile } from 'fs/promises';
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ describe('Format Markdown', () => {
|
|||||||
'<p>Escape JS</p>',
|
'<p>Escape JS</p>',
|
||||||
'<pre',
|
'<pre',
|
||||||
' class="language-js"',
|
' class="language-js"',
|
||||||
'><code class="language-js"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">\'one\'</span><span class="token punctuation">;</span>',
|
'><code class="language-js code-highlight"><span class="code-line"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token string">\'one\'</span><span class="token punctuation">;</span>',
|
||||||
'<span class="token keyword">const</span> bar <span class="token operator">=</span> html<span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string"><p>${foo}</p></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>',
|
'</span><span class="code-line"><span class="token keyword">const</span> bar <span class="token operator">=</span> html<span class="token template-string"><span class="token template-punctuation string">`</span><span class="token html language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>p</span><span class="token punctuation">></span></span>${foo}<span class="token tag"><span class="token tag"><span class="token punctuation"></</span>p</span><span class="token punctuation">></span></span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>',
|
||||||
'<span class="token keyword">const</span> baz <span class="token operator">=</span> html<span class="token template-string"><span class="token template-punctuation string">`</span><span class="token string"><span></span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">\\${</span>foo<span class="token interpolation-punctuation punctuation">}</span></span><span class="token string"></span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>',
|
'</span><span class="code-line"><span class="token keyword">const</span> baz <span class="token operator">=</span> html<span class="token template-string"><span class="token template-punctuation string">`</span><span class="token html language-html"><span class="token tag"><span class="token tag"><span class="token punctuation"><</span>span</span><span class="token punctuation">></span></span><span class="token interpolation"><span class="token interpolation-punctuation punctuation">\\${</span>foo<span class="token interpolation-punctuation punctuation">}</span></span><span class="token tag"><span class="token tag"><span class="token punctuation"></</span>span</span><span class="token punctuation">></span></span></span><span class="token template-punctuation string">`</span></span><span class="token punctuation">;</span>',
|
||||||
'</code></pre>',
|
'</span></code></pre>',
|
||||||
].join('\n'),
|
].join('\n'),
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
import chai from 'chai';
|
import chai from 'chai';
|
||||||
// import '@lit-labs/ssr/lib/install-global-dom-shim.js';
|
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { renderJoiningGroup } from '../src/helpers/renderJoiningGroup.js';
|
import { renderJoiningGroup } from '../src/helpers/renderJoiningGroup.js';
|
||||||
import { testLitServerRender } from './test-helpers.js';
|
import { testLitServerRender } from './test-helpers.js';
|
||||||
|
|||||||
@@ -4,23 +4,42 @@ import { setupTestEngine } from './test-helpers.js';
|
|||||||
|
|
||||||
const { expect } = chai;
|
const { expect } = chai;
|
||||||
|
|
||||||
class MyPlugin {
|
|
||||||
static publicFolder = new URL(
|
|
||||||
'./fixtures/10-plugins/01-add-public-files/plugin-add-to-public/preset/__public',
|
|
||||||
import.meta.url,
|
|
||||||
).pathname;
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('Plugins', () => {
|
describe('Plugins', () => {
|
||||||
it('add plugin with custom public files', async () => {
|
it('01: add plugin with custom public files', async () => {
|
||||||
|
class TestPlugin01 {
|
||||||
|
static publicFolder = new URL(
|
||||||
|
'./fixtures/10-plugins/01-add-public-files/plugin-add-to-public/preset/__public',
|
||||||
|
import.meta.url,
|
||||||
|
).pathname;
|
||||||
|
}
|
||||||
const { build, outputExists } = await setupTestEngine(
|
const { build, outputExists } = await setupTestEngine(
|
||||||
'fixtures/10-plugins/01-add-public-files/docs',
|
'fixtures/10-plugins/01-add-public-files/docs',
|
||||||
{
|
{
|
||||||
setupPlugins: [addPlugin(MyPlugin)],
|
setupPlugins: [addPlugin(TestPlugin01)],
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
await build();
|
await build();
|
||||||
|
|
||||||
expect(outputExists('added-via-plugin.txt')).to.be.true;
|
expect(outputExists('added-via-plugin.txt')).to.be.true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('02: add plugin with custom public files', async () => {
|
||||||
|
class TestPlugin02 {
|
||||||
|
static publicFolder = new URL(
|
||||||
|
'./fixtures/10-plugins/02-input-folder-public-always-wins/plugin-add-to-public/preset/__public',
|
||||||
|
import.meta.url,
|
||||||
|
).pathname;
|
||||||
|
}
|
||||||
|
const { build, readOutput } = await setupTestEngine(
|
||||||
|
'fixtures/10-plugins/02-input-folder-public-always-wins/docs',
|
||||||
|
{
|
||||||
|
setupPlugins: [addPlugin(TestPlugin02)],
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await build();
|
||||||
|
|
||||||
|
expect(readOutput('added-via-plugin-and-input-public.txt')).to.equal(
|
||||||
|
'from input public folder\n',
|
||||||
|
);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -179,15 +179,16 @@ test.describe('hydration', async () => {
|
|||||||
await cleanup();
|
await cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
test("55: hydrate onMedia('(min-width: 640px)') || onClick", async ({ page }) => {
|
test("55: hydrate onMedia('(min-width: 640px)') || onClick - on desktop", async ({ page }) => {
|
||||||
const { engine, cleanup } = await setupTestEngine(
|
const { engine, cleanup } = await setupTestEngine(
|
||||||
'fixtures/14-components/55-hydration-onMedia-or-onClick/docs',
|
'fixtures/14-components/55-hydration-onMedia-or-onClick/docs',
|
||||||
);
|
);
|
||||||
await engine.start();
|
await engine.start();
|
||||||
const { port } = engine.devServer.config;
|
const { port } = engine.devServer.config;
|
||||||
|
|
||||||
|
// 1. start on small screen
|
||||||
await page.setViewportSize({
|
await page.setViewportSize({
|
||||||
width: 640,
|
width: 320,
|
||||||
height: 480,
|
height: 480,
|
||||||
});
|
});
|
||||||
await page.goto(`localhost:${port}`);
|
await page.goto(`localhost:${port}`);
|
||||||
@@ -195,25 +196,40 @@ test.describe('hydration', async () => {
|
|||||||
const hydrated1 = await myEl.getAttribute('hydrated');
|
const hydrated1 = await myEl.getAttribute('hydrated');
|
||||||
expect(hydrated1).toBe(null); // not hydrated
|
expect(hydrated1).toBe(null); // not hydrated
|
||||||
|
|
||||||
|
// 2. go bigger
|
||||||
|
await page.setViewportSize({
|
||||||
|
width: 640,
|
||||||
|
height: 480,
|
||||||
|
});
|
||||||
await page.waitForLoadState('networkidle0');
|
await page.waitForLoadState('networkidle0');
|
||||||
|
|
||||||
const hydrated2 = await myEl.getAttribute('hydrated');
|
const hydrated2 = await myEl.getAttribute('hydrated');
|
||||||
expect(hydrated2).toBe(''); // boolean attribute is there
|
expect(hydrated2).toBe(''); // boolean attribute is there
|
||||||
|
|
||||||
// revisit page on "mobile"
|
await cleanup();
|
||||||
|
});
|
||||||
|
|
||||||
|
test("55b: hydrate onMedia('(min-width: 640px)') || onClick - on mobile", async ({ page }) => {
|
||||||
|
const { engine, cleanup } = await setupTestEngine(
|
||||||
|
'fixtures/14-components/55-hydration-onMedia-or-onClick/docs',
|
||||||
|
);
|
||||||
|
await engine.start();
|
||||||
|
const { port } = engine.devServer.config;
|
||||||
|
|
||||||
await page.setViewportSize({
|
await page.setViewportSize({
|
||||||
width: 320,
|
width: 320,
|
||||||
height: 480,
|
height: 480,
|
||||||
});
|
});
|
||||||
await page.reload();
|
await page.goto(`localhost:${port}`);
|
||||||
const myEl2 = await page.locator('my-el');
|
const myEl = await page.locator('my-el');
|
||||||
const hydrated3 = await myEl2.getAttribute('hydrated');
|
|
||||||
|
const hydrated3 = await myEl.getAttribute('hydrated');
|
||||||
expect(hydrated3).toBe(null); // not hydrated
|
expect(hydrated3).toBe(null); // not hydrated
|
||||||
|
|
||||||
await myEl.click();
|
await myEl.click();
|
||||||
await page.waitForLoadState('networkidle0');
|
await page.waitForLoadState('networkidle0');
|
||||||
|
|
||||||
const hydrated4 = await myEl2.getAttribute('hydrated');
|
const hydrated4 = await myEl.getAttribute('hydrated');
|
||||||
expect(hydrated4).toBe(''); // boolean attribute is there
|
expect(hydrated4).toBe(''); // boolean attribute is there
|
||||||
|
|
||||||
await cleanup();
|
await cleanup();
|
||||||
@@ -243,7 +259,7 @@ test.describe('hydration', async () => {
|
|||||||
const focusInEv = await myEl.getAttribute('focusin-ev');
|
const focusInEv = await myEl.getAttribute('focusin-ev');
|
||||||
expect(focusInEv).toBe('');
|
expect(focusInEv).toBe('');
|
||||||
|
|
||||||
// NOTE: focus event is NOT supported as it does not bubble
|
// NOTE: we are using the focusin event as the focus event is NOT supported as it does not bubble
|
||||||
await cleanup();
|
await cleanup();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
/* START - Rocket auto generated - do not touch */
|
||||||
|
export const sourceRelativeFilePath = 'index.rocket.js';
|
||||||
|
/* END - Rocket auto generated - do not touch */
|
||||||
|
|
||||||
|
import { html } from 'lit';
|
||||||
|
|
||||||
|
export default () => html`<p>content</p>`;
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
{
|
||||||
|
"name": "index.rocket.js",
|
||||||
|
"menuLinkText": "index.rocket.js",
|
||||||
|
"url": "/",
|
||||||
|
"outputRelativeFilePath": "index.html",
|
||||||
|
"sourceRelativeFilePath": "index.rocket.js",
|
||||||
|
"level": 0
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
from plugin
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
from input public folder
|
||||||
@@ -50,7 +50,7 @@
|
|||||||
"@rocket/components": "^0.2.0",
|
"@rocket/components": "^0.2.0",
|
||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"@webcomponents/template-shadowroot": "^0.1.0",
|
"@webcomponents/template-shadowroot": "^0.1.0",
|
||||||
"lit": "^2.2.5",
|
"lit": "^2.3.0",
|
||||||
"workbox-window": "^6.1.5"
|
"workbox-window": "^6.1.5"
|
||||||
},
|
},
|
||||||
"types": "./dist-types/src/index.d.ts",
|
"types": "./dist-types/src/index.d.ts",
|
||||||
|
|||||||
@@ -1,5 +1,12 @@
|
|||||||
# Change Log
|
# Change Log
|
||||||
|
|
||||||
|
## 0.20.0
|
||||||
|
|
||||||
|
### Minor Changes
|
||||||
|
|
||||||
|
- 35ed64d: BREAKING: Refactor to ESM-only package, use latest rehype/remark/unified dependencies.
|
||||||
|
- 6f88d8e: BREAKING: Replace `rehype-prism` with `rehype-prism-plus` as it does not get confused as running in the browser in the SSR context.
|
||||||
|
|
||||||
## 0.9.5
|
## 0.9.5
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -2,18 +2,11 @@
|
|||||||
/** @typedef {import('./types/code.js').Story} Story */
|
/** @typedef {import('./types/code.js').Story} Story */
|
||||||
/** @typedef {import('./types/code.js').MdjsProcessPlugin} MdjsProcessPlugin */
|
/** @typedef {import('./types/code.js').MdjsProcessPlugin} MdjsProcessPlugin */
|
||||||
|
|
||||||
const { mdjsParse } = require('./src/mdjsParse.js');
|
import { mdjsParse } from './src/mdjsParse.js';
|
||||||
const { mdjsSetupCode } = require('./src/mdjsSetupCode.js');
|
import { mdjsSetupCode } from './src/mdjsSetupCode.js';
|
||||||
const { mdjsStoryParse } = require('./src/mdjsStoryParse.js');
|
import { mdjsStoryParse } from './src/mdjsStoryParse.js';
|
||||||
const { mdjsDocPage } = require('./src/mdjsDocPage.js');
|
import { mdjsDocPage } from './src/mdjsDocPage.js';
|
||||||
const { mdjsProcess } = require('./src/mdjsProcess.js');
|
import { mdjsProcess } from './src/mdjsProcess.js';
|
||||||
const { isMdjsContent } = require('./src/isMdjsContent.js');
|
import { isMdjsContent } from './src/isMdjsContent.js';
|
||||||
|
|
||||||
module.exports = {
|
export { mdjsParse, mdjsStoryParse, mdjsDocPage, mdjsProcess, isMdjsContent, mdjsSetupCode };
|
||||||
mdjsParse,
|
|
||||||
mdjsStoryParse,
|
|
||||||
mdjsDocPage,
|
|
||||||
mdjsProcess,
|
|
||||||
isMdjsContent,
|
|
||||||
mdjsSetupCode,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
import cjsEntrypoint from './index.js';
|
|
||||||
|
|
||||||
const { mdjsParse, mdjsStoryParse, mdjsDocPage, mdjsProcess, isMdjsContent, mdjsSetupCode } =
|
|
||||||
cjsEntrypoint;
|
|
||||||
|
|
||||||
export { mdjsParse, mdjsStoryParse, mdjsDocPage, mdjsProcess, isMdjsContent, mdjsSetupCode };
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mdjs/core",
|
"name": "@mdjs/core",
|
||||||
"version": "0.9.5",
|
"version": "0.20.0",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
@@ -14,11 +14,11 @@
|
|||||||
"author": "Modern Web <hello@modern-web.dev> (https://modern-web.dev/)",
|
"author": "Modern Web <hello@modern-web.dev> (https://modern-web.dev/)",
|
||||||
"homepage": "https://rocket.modern-web.dev/docs/markdown-javascript/overview/",
|
"homepage": "https://rocket.modern-web.dev/docs/markdown-javascript/overview/",
|
||||||
"main": "./index.js",
|
"main": "./index.js",
|
||||||
|
"type": "module",
|
||||||
"exports": {
|
"exports": {
|
||||||
".": {
|
".": {
|
||||||
"types": "./dist-types/index.d.ts",
|
"types": "./dist-types/index.d.ts",
|
||||||
"require": "./index.js",
|
"default": "./index.js"
|
||||||
"default": "./index.mjs"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -46,32 +46,32 @@
|
|||||||
"remark"
|
"remark"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@mdjs/mdjs-preview": "^0.5.8",
|
"@mdjs/mdjs-preview": "^0.5.9",
|
||||||
"@mdjs/mdjs-story": "^0.3.2",
|
"@mdjs/mdjs-story": "^0.3.2",
|
||||||
"@types/unist": "^2.0.3",
|
"@types/unist": "^2.0.6",
|
||||||
"es-module-lexer": "^0.9.3",
|
"es-module-lexer": "^0.10.5",
|
||||||
"github-markdown-css": "^4.0.0",
|
"github-markdown-css": "^5.1.0",
|
||||||
"plugins-manager": "^0.3.0",
|
"plugins-manager": "^0.3.1",
|
||||||
"rehype-autolink-headings": "^5.0.1",
|
"rehype-autolink-headings": "^6.1.1",
|
||||||
"rehype-prism": "^1.0.1",
|
"rehype-prism-plus": "^1.4.2",
|
||||||
"rehype-raw": "^5.0.0",
|
"rehype-raw": "^6.1.1",
|
||||||
"rehype-slug": "^4.0.1",
|
"rehype-slug": "^5.0.1",
|
||||||
"rehype-stringify": "^8.0.0",
|
"rehype-stringify": "^9.0.3",
|
||||||
"remark": "^13.0.0",
|
"remark": "^14.0.2",
|
||||||
"remark-gfm": "^1.0.0",
|
"remark-gfm": "^3.0.1",
|
||||||
"remark-parse": "^9.0.0",
|
"remark-parse": "^10.0.1",
|
||||||
"remark-rehype": "^8.0.0",
|
"remark-rehype": "^10.1.0",
|
||||||
"slash": "^3.0.0",
|
"slash": "^4.0.0",
|
||||||
"unified": "^9.2.0",
|
"unified": "^10.1.2",
|
||||||
"unist-util-remove": "^2.0.1",
|
"unist-util-remove": "^3.1.0",
|
||||||
"unist-util-visit": "^2.0.3"
|
"unist-util-visit": "^4.1.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"demo-wc-card": "^0.1.0",
|
"demo-wc-card": "^0.1.0",
|
||||||
"remark-autolink-headings": "^6.0.1",
|
"remark-autolink-headings": "^7.0.1",
|
||||||
"remark-html": "^13.0.2",
|
"remark-html": "^15.0.1",
|
||||||
"remark-slug": "^6.0.0",
|
"remark-slug": "^7.0.1",
|
||||||
"remark-stringify": "^9.0.1"
|
"remark-stringify": "^10.0.2"
|
||||||
},
|
},
|
||||||
"types": "dist-types/index.d.ts"
|
"types": "dist-types/index.d.ts"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
* @param {string} text
|
* @param {string} text
|
||||||
* @returns {boolean}
|
* @returns {boolean}
|
||||||
*/
|
*/
|
||||||
function isMdjsContent(text) {
|
export function isMdjsContent(text) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -18,7 +18,3 @@ function isMdjsContent(text) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
isMdjsContent,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
const { mdjsProcess } = require('./mdjsProcess.js');
|
import { mdjsProcess } from './mdjsProcess.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @param {string} body
|
* @param {string} body
|
||||||
* @returns {Promise<string>}
|
* @returns {Promise<string>}
|
||||||
*/
|
*/
|
||||||
async function mdjsDocPage(body) {
|
export async function mdjsDocPage(body) {
|
||||||
const data = await mdjsProcess(body);
|
const data = await mdjsProcess(body);
|
||||||
return `
|
return `
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
@@ -92,7 +92,3 @@ async function mdjsDocPage(body) {
|
|||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mdjsDocPage,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
import { visit } from 'unist-util-visit';
|
||||||
const visit = require('unist-util-visit');
|
import { remove } from 'unist-util-remove';
|
||||||
// @ts-ignore
|
|
||||||
const remove = require('unist-util-remove');
|
|
||||||
|
|
||||||
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
||||||
/** @typedef {import('unist').Node} Node */
|
/** @typedef {import('unist').Node} Node */
|
||||||
|
|
||||||
function mdjsParse() {
|
export function mdjsParse() {
|
||||||
let jsCode = '';
|
let jsCode = '';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,26 +12,37 @@ function mdjsParse() {
|
|||||||
* @param {VFileOptions} file
|
* @param {VFileOptions} file
|
||||||
*/
|
*/
|
||||||
function transformer(tree, file) {
|
function transformer(tree, file) {
|
||||||
visit(tree, 'code', node => {
|
visit(
|
||||||
if (node.lang === 'js' && node.meta === 'script') {
|
tree,
|
||||||
jsCode += node.value;
|
'code',
|
||||||
}
|
/** @param {Node & {[key: string]: unknown;}} node */ node => {
|
||||||
if (node.lang === 'js' && node.meta === 'client') {
|
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
|
||||||
// eslint-disable-next-line no-param-reassign
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
if (!file.data) {
|
||||||
|
file.data = {};
|
||||||
|
}
|
||||||
file.data.jsCode = jsCode;
|
file.data.jsCode = jsCode;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {Node} node
|
* @param {Node} node
|
||||||
*/
|
*/
|
||||||
const removeFunction = node =>
|
const removeFunction = node => {
|
||||||
node.type === 'code' &&
|
const _node = /** @type {Node & {[key: string]: unknown;}} */ (node);
|
||||||
node.lang === 'js' &&
|
return (
|
||||||
(node.meta === 'script' || node.meta === 'client');
|
_node.type === 'code' &&
|
||||||
|
_node.lang === 'js' &&
|
||||||
|
(_node.meta === 'script' || _node.meta === 'client')
|
||||||
|
);
|
||||||
|
};
|
||||||
remove(tree, removeFunction);
|
remove(tree, removeFunction);
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
@@ -41,7 +50,3 @@ function mdjsParse() {
|
|||||||
|
|
||||||
return transformer;
|
return transformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mdjsParse,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -4,23 +4,19 @@
|
|||||||
/** @typedef {import('../types/code').ProcessResult} ProcessResult */
|
/** @typedef {import('../types/code').ProcessResult} ProcessResult */
|
||||||
/** @typedef {import('../types/code').MdjsProcessPlugin} MdjsProcessPlugin */
|
/** @typedef {import('../types/code').MdjsProcessPlugin} MdjsProcessPlugin */
|
||||||
|
|
||||||
const unified = require('unified');
|
import { unified } from 'unified';
|
||||||
const markdown = require('remark-parse');
|
import markdown from 'remark-parse';
|
||||||
const gfm = require('remark-gfm');
|
import gfm from 'remark-gfm';
|
||||||
const remark2rehype = require('remark-rehype');
|
import remark2rehype from 'remark-rehype';
|
||||||
const raw = require('rehype-raw');
|
import raw from 'rehype-raw';
|
||||||
const htmlStringify = require('rehype-stringify');
|
import htmlSlug from 'rehype-slug';
|
||||||
const htmlSlug = require('rehype-slug');
|
import htmlHeading from 'rehype-autolink-headings';
|
||||||
const htmlHeading = require('rehype-autolink-headings');
|
import rehypePrism from 'rehype-prism-plus';
|
||||||
// @ts-ignore
|
import htmlStringify from 'rehype-stringify';
|
||||||
const { executeSetupFunctions } = require('plugins-manager');
|
import { executeSetupFunctions } from 'plugins-manager';
|
||||||
const loadLanguages = require('prismjs/components/');
|
import { mdjsParse } from './mdjsParse.js';
|
||||||
|
import { mdjsStoryParse } from './mdjsStoryParse.js';
|
||||||
const { mdjsParse } = require('./mdjsParse.js');
|
import { mdjsSetupCode } from './mdjsSetupCode.js';
|
||||||
const { mdjsStoryParse } = require('./mdjsStoryParse.js');
|
|
||||||
const { mdjsSetupCode } = require('./mdjsSetupCode.js');
|
|
||||||
|
|
||||||
let prismLoaded = false;
|
|
||||||
|
|
||||||
/** @type {MdjsProcessPlugin[]} */
|
/** @type {MdjsProcessPlugin[]} */
|
||||||
const defaultMetaPlugins = [
|
const defaultMetaPlugins = [
|
||||||
@@ -37,6 +33,7 @@ const defaultMetaPlugins = [
|
|||||||
{ plugin: htmlSlug, options: {} },
|
{ plugin: htmlSlug, options: {} },
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
{ plugin: htmlHeading, options: {} },
|
{ plugin: htmlHeading, options: {} },
|
||||||
|
{ plugin: rehypePrism, options: {} },
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
{ plugin: htmlStringify, options: {} },
|
{ plugin: htmlStringify, options: {} },
|
||||||
];
|
];
|
||||||
@@ -52,15 +49,8 @@ const defaultMetaPlugins = [
|
|||||||
* @param {function[]} [options.setupUnifiedPlugins]
|
* @param {function[]} [options.setupUnifiedPlugins]
|
||||||
* @param {MdjsProcessPlugin[]} [options.plugins] deprecated option use setupUnifiedPlugins instead
|
* @param {MdjsProcessPlugin[]} [options.plugins] deprecated option use setupUnifiedPlugins instead
|
||||||
*/
|
*/
|
||||||
async function mdjsProcess(mdjs, { setupUnifiedPlugins = [] } = {}) {
|
export async function mdjsProcess(mdjs, { setupUnifiedPlugins = [] } = {}) {
|
||||||
const parser = unified();
|
const parser = unified();
|
||||||
if (!prismLoaded) {
|
|
||||||
prismLoaded = true;
|
|
||||||
const rehypePrism = (await import('rehype-prism/lib/src/index.js')).default;
|
|
||||||
loadLanguages(['md', 'shell', 'yml', 'diff']);
|
|
||||||
defaultMetaPlugins.splice(6, 0, { plugin: rehypePrism, options: {} });
|
|
||||||
}
|
|
||||||
|
|
||||||
const metaPlugins = executeSetupFunctions(setupUnifiedPlugins, defaultMetaPlugins);
|
const metaPlugins = executeSetupFunctions(setupUnifiedPlugins, defaultMetaPlugins);
|
||||||
|
|
||||||
for (const pluginObj of metaPlugins) {
|
for (const pluginObj of metaPlugins) {
|
||||||
@@ -74,9 +64,5 @@ async function mdjsProcess(mdjs, { setupUnifiedPlugins = [] } = {}) {
|
|||||||
|
|
||||||
const { stories, setupJsCode } = result.data;
|
const { stories, setupJsCode } = result.data;
|
||||||
|
|
||||||
return { stories, jsCode: setupJsCode, html: result.contents };
|
return { stories, jsCode: setupJsCode, html: result.value };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mdjsProcess,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
const path = require('path');
|
import path from 'path';
|
||||||
const slash = require('slash');
|
import slash from 'slash';
|
||||||
|
|
||||||
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
||||||
/** @typedef {import('unist').Node} Node */
|
/** @typedef {import('unist').Node} Node */
|
||||||
@@ -22,7 +22,7 @@ const slash = require('slash');
|
|||||||
* @param {rocketConfig} [options.rocketConfig]
|
* @param {rocketConfig} [options.rocketConfig]
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
function mdjsSetupCode({
|
export function mdjsSetupCode({
|
||||||
rootNodeQueryCode = 'document',
|
rootNodeQueryCode = 'document',
|
||||||
simulationSettings = {},
|
simulationSettings = {},
|
||||||
rocketConfig = {},
|
rocketConfig = {},
|
||||||
@@ -43,11 +43,13 @@ function mdjsSetupCode({
|
|||||||
* @param {VFileOptions} file
|
* @param {VFileOptions} file
|
||||||
*/
|
*/
|
||||||
async function transformer(tree, file) {
|
async function transformer(tree, file) {
|
||||||
|
if (!file.data) {
|
||||||
|
file.data = {};
|
||||||
|
}
|
||||||
const { stories, jsCode } = file.data;
|
const { stories, jsCode } = file.data;
|
||||||
|
|
||||||
file.data.setupJsCode = jsCode;
|
file.data.setupJsCode = jsCode;
|
||||||
|
|
||||||
if (stories && stories.length > 0) {
|
if (Array.isArray(stories) && stories.length > 0) {
|
||||||
const storiesCode = stories.map(/** @param {Story} story */ story => story.code).join('\n');
|
const storiesCode = stories.map(/** @param {Story} story */ story => story.code).join('\n');
|
||||||
|
|
||||||
const invokeStoriesCode = [];
|
const invokeStoriesCode = [];
|
||||||
@@ -86,7 +88,3 @@ function mdjsSetupCode({
|
|||||||
|
|
||||||
return transformer;
|
return transformer;
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mdjsSetupCode,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
/** @typedef {import('unist').Parent} UnistParent */
|
/** @typedef {import('unist').Parent} UnistParent */
|
||||||
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
/** @typedef {import('vfile').VFileOptions} VFileOptions */
|
||||||
|
|
||||||
const visit = require('unist-util-visit');
|
import { visit } from 'unist-util-visit';
|
||||||
const { init, parse } = require('es-module-lexer');
|
import { init, parse } from 'es-module-lexer';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @typedef {object} MDJSNodeProperties
|
* @typedef {object} MDJSNodeProperties
|
||||||
@@ -50,7 +50,7 @@ function defaultPreviewStoryTag(name) {
|
|||||||
* @param {TagFunction} [arg.previewStoryTag]
|
* @param {TagFunction} [arg.previewStoryTag]
|
||||||
* @param {number} [arg.counter]
|
* @param {number} [arg.counter]
|
||||||
*/
|
*/
|
||||||
function mdjsStoryParse({
|
export function mdjsStoryParse({
|
||||||
storyTag = defaultStoryTag,
|
storyTag = defaultStoryTag,
|
||||||
previewStoryTag = defaultPreviewStoryTag,
|
previewStoryTag = defaultPreviewStoryTag,
|
||||||
} = {}) {
|
} = {}) {
|
||||||
@@ -61,11 +61,12 @@ function mdjsStoryParse({
|
|||||||
/* eslint-disable no-param-reassign */
|
/* eslint-disable no-param-reassign */
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param {UnistNode} node
|
* @param {UnistNode} _node
|
||||||
* @param {number} index
|
* @param {number} index
|
||||||
* @param {UnistParent} parent
|
* @param {UnistParent} parent
|
||||||
*/
|
*/
|
||||||
const nodeCodeVisitor = (node, index, parent) => {
|
const nodeCodeVisitor = (_node, index, parent) => {
|
||||||
|
let node = /** @type {UnistNode & {[key: string]: unknown}} */ (_node);
|
||||||
if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
|
if (node.lang === 'js' && node.meta === 'story' && typeof node.value === 'string') {
|
||||||
const storyData = extractStoryData(node.value);
|
const storyData = extractStoryData(node.value);
|
||||||
node.type = 'html';
|
node.type = 'html';
|
||||||
@@ -80,12 +81,17 @@ function mdjsStoryParse({
|
|||||||
|
|
||||||
const inside = [node];
|
const inside = [node];
|
||||||
let skipAmount = 1;
|
let skipAmount = 1;
|
||||||
const next = parent.children[index + 1];
|
|
||||||
|
const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||||
|
parent.children[index + 1]
|
||||||
|
);
|
||||||
if (next && next.type === 'code' && next.meta === 'story-code') {
|
if (next && next.type === 'code' && next.meta === 'story-code') {
|
||||||
inside.push(next);
|
inside.push(next);
|
||||||
skipAmount += 1;
|
skipAmount += 1;
|
||||||
|
|
||||||
const next2 = parent.children[index + 2];
|
const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||||
|
parent.children[index + 2]
|
||||||
|
);
|
||||||
if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
||||||
inside.push(next2);
|
inside.push(next2);
|
||||||
skipAmount += 1;
|
skipAmount += 1;
|
||||||
@@ -132,12 +138,16 @@ function mdjsStoryParse({
|
|||||||
const tagParts = newValue.split('[[CODE SLOT]]');
|
const tagParts = newValue.split('[[CODE SLOT]]');
|
||||||
const inside = [node];
|
const inside = [node];
|
||||||
let skipAmount = 1;
|
let skipAmount = 1;
|
||||||
const next = parent.children[index + 1];
|
const next = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||||
|
parent.children[index + 1]
|
||||||
|
);
|
||||||
if (next && next.type === 'code' && next.meta === 'story-code') {
|
if (next && next.type === 'code' && next.meta === 'story-code') {
|
||||||
inside.push(next);
|
inside.push(next);
|
||||||
skipAmount += 1;
|
skipAmount += 1;
|
||||||
|
|
||||||
const next2 = parent.children[index + 2];
|
const next2 = /** @type {UnistNode & {[key: string]: unknown}} */ (
|
||||||
|
parent.children[index + 2]
|
||||||
|
);
|
||||||
if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
if (next2 && next2.type === 'code' && next2.meta === 'story-code') {
|
||||||
inside.push(next2);
|
inside.push(next2);
|
||||||
skipAmount += 1;
|
skipAmount += 1;
|
||||||
@@ -176,6 +186,9 @@ function mdjsStoryParse({
|
|||||||
visit(tree, 'code', nodeCodeVisitor);
|
visit(tree, 'code', nodeCodeVisitor);
|
||||||
// we can only return/modify the tree but stories should not be part of the tree
|
// we can only return/modify the tree but stories 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
|
||||||
|
if (!file.data) {
|
||||||
|
file.data = {};
|
||||||
|
}
|
||||||
file.data.stories = stories;
|
file.data.stories = stories;
|
||||||
|
|
||||||
return tree;
|
return tree;
|
||||||
@@ -184,7 +197,3 @@ function mdjsStoryParse({
|
|||||||
return transformer;
|
return transformer;
|
||||||
/* eslint-enable no-param-reassign */
|
/* eslint-enable no-param-reassign */
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
mdjsStoryParse,
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
/* eslint-disable no-template-curly-in-string */
|
/* eslint-disable no-template-curly-in-string */
|
||||||
|
|
||||||
const unified = require('unified');
|
import { unified } from 'unified';
|
||||||
const markdown = require('remark-parse');
|
import markdown from 'remark-parse';
|
||||||
const remark2rehype = require('remark-rehype');
|
import remark2rehype from 'remark-rehype';
|
||||||
const htmlStringify = require('rehype-stringify');
|
import htmlStringify from 'rehype-stringify';
|
||||||
const htmlSlug = require('rehype-slug');
|
import htmlSlug from 'rehype-slug';
|
||||||
const htmlHeading = require('rehype-autolink-headings');
|
import htmlHeading from 'rehype-autolink-headings';
|
||||||
const raw = require('rehype-raw');
|
import raw from 'rehype-raw';
|
||||||
|
|
||||||
const mdSlug = require('remark-slug');
|
import mdSlug from 'remark-slug';
|
||||||
const mdHeadings = require('remark-autolink-headings');
|
import mdHeadings from 'remark-autolink-headings';
|
||||||
const mdStringify = require('remark-html');
|
import mdStringify from 'remark-html';
|
||||||
|
|
||||||
const chai = require('chai');
|
import { expect } from 'chai';
|
||||||
const { mdjsParse } = require('../src/mdjsParse.js');
|
import { mdjsParse } from '../src/mdjsParse.js';
|
||||||
const { mdjsStoryParse } = require('../src/mdjsStoryParse.js');
|
import { mdjsStoryParse } from '../src/mdjsStoryParse.js';
|
||||||
|
|
||||||
const { expect } = chai;
|
|
||||||
|
|
||||||
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
||||||
|
|
||||||
@@ -67,8 +65,8 @@ describe('Integration', () => {
|
|||||||
.use(htmlHeading)
|
.use(htmlHeading)
|
||||||
.use(htmlStringify);
|
.use(htmlStringify);
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
if (result.contents instanceof Buffer) throw new Error('contents should not be a buffer');
|
if (result.value instanceof Buffer) throw new Error('contents should not be a buffer');
|
||||||
expect(result.contents.split('\n')).to.deep.equal(expected);
|
expect(result.value.split('\n')).to.deep.equal(expected);
|
||||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -108,7 +106,7 @@ describe('Integration', () => {
|
|||||||
.use(mdHeadings)
|
.use(mdHeadings)
|
||||||
.use(mdStringify, { sanitize: false });
|
.use(mdStringify, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(expected);
|
expect(result.value).to.equal(expected);
|
||||||
expect(/** @type {MDJSVFileData} */ (result.data).stories).to.deep.equal([
|
expect(/** @type {MDJSVFileData} */ (result.data).stories).to.deep.equal([
|
||||||
{
|
{
|
||||||
key: 'fooStory',
|
key: 'fooStory',
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
/* eslint-disable no-template-curly-in-string */
|
/* eslint-disable no-template-curly-in-string */
|
||||||
|
import { adjustPluginOptions } from 'plugins-manager';
|
||||||
|
import { mdjsProcess } from '../src/mdjsProcess.js';
|
||||||
|
import { mdjsSetupCode } from '../src/mdjsSetupCode.js';
|
||||||
|
import { mdjsStoryParse } from '../src/mdjsStoryParse.js';
|
||||||
|
|
||||||
const chai = require('chai');
|
import { expect } from 'chai';
|
||||||
const { adjustPluginOptions } = require('plugins-manager');
|
|
||||||
const { mdjsProcess } = require('../src/mdjsProcess.js');
|
|
||||||
const { mdjsSetupCode } = require('../src/mdjsSetupCode.js');
|
|
||||||
const { mdjsStoryParse } = require('../src/mdjsStoryParse.js');
|
|
||||||
|
|
||||||
const { expect } = chai;
|
|
||||||
|
|
||||||
describe('mdjsProcess', () => {
|
describe('mdjsProcess', () => {
|
||||||
const input = [
|
const input = [
|
||||||
@@ -28,15 +26,15 @@ describe('mdjsProcess', () => {
|
|||||||
it('extracts code blocks with "js story" and "js preview-story" and places marker tags', async () => {
|
it('extracts code blocks with "js story" and "js preview-story" and places marker tags', async () => {
|
||||||
const expected = [
|
const expected = [
|
||||||
'<p>Intro</p>',
|
'<p>Intro</p>',
|
||||||
'<pre class="language-js"><code class="language-js"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>',
|
'<pre class="language-js"><code class="language-js code-highlight"><span class="code-line"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>',
|
||||||
'</code></pre>',
|
'</span></code></pre>',
|
||||||
'<mdjs-story mdjs-story-name="fooStory"></mdjs-story>',
|
'<mdjs-story mdjs-story-name="fooStory"></mdjs-story>',
|
||||||
'<mdjs-preview mdjs-story-name="fooPreviewStory">',
|
'<mdjs-preview mdjs-story-name="fooPreviewStory">',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'<pre class="language-js"><code class="language-js"><span class="token keyword">export</span> <span class="token keyword">const</span> <span class="token function-variable function">fooPreviewStory</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=></span> <span class="token punctuation">{</span><span class="token punctuation">}</span>',
|
'<pre class="language-js"><code class="language-js code-highlight"><span class="code-line"><span class="token keyword module">export</span> <span class="token keyword">const</span> <span class="token function-variable function">fooPreviewStory</span> <span class="token operator">=</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token arrow operator">=></span> <span class="token punctuation">{</span><span class="token punctuation">}</span>',
|
||||||
'</code></pre>',
|
'</span></code></pre>',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
'',
|
'',
|
||||||
@@ -68,7 +66,6 @@ describe('mdjsProcess', () => {
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
|
|
||||||
const result = await mdjsProcess(input);
|
const result = await mdjsProcess(input);
|
||||||
|
|
||||||
expect(result.html).to.equal(expected);
|
expect(result.html).to.equal(expected);
|
||||||
expect(result.jsCode).to.equal(expectedJsCode);
|
expect(result.jsCode).to.equal(expectedJsCode);
|
||||||
});
|
});
|
||||||
@@ -100,8 +97,8 @@ describe('mdjsProcess', () => {
|
|||||||
it('can setup all unified plugins via "setupUnifiedPlugins" which accepts a single function or an array of functions', async () => {
|
it('can setup all unified plugins via "setupUnifiedPlugins" which accepts a single function or an array of functions', async () => {
|
||||||
const expected = [
|
const expected = [
|
||||||
'<p>Intro</p>',
|
'<p>Intro</p>',
|
||||||
'<pre class="language-js"><code class="language-js"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>',
|
'<pre class="language-js"><code class="language-js code-highlight"><span class="code-line"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>',
|
||||||
'</code></pre>',
|
'</span></code></pre>',
|
||||||
'<my-story mdjs-story-name="fooStory"></my-story>',
|
'<my-story mdjs-story-name="fooStory"></my-story>',
|
||||||
'<my-preview mdjs-story-name="fooPreviewStory"></my-preview>',
|
'<my-preview mdjs-story-name="fooPreviewStory"></my-preview>',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
@@ -130,8 +127,8 @@ describe('mdjsProcess', () => {
|
|||||||
|
|
||||||
const expectedForArray = [
|
const expectedForArray = [
|
||||||
'<p>Intro</p>',
|
'<p>Intro</p>',
|
||||||
'<pre class="language-js"><code class="language-js"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>',
|
'<pre class="language-js"><code class="language-js code-highlight"><span class="code-line"><span class="token keyword">const</span> foo <span class="token operator">=</span> <span class="token number">1</span><span class="token punctuation">;</span>',
|
||||||
'</code></pre>',
|
'</span></code></pre>',
|
||||||
'<my-story2 mdjs-story-name="fooStory"></my-story2>',
|
'<my-story2 mdjs-story-name="fooStory"></my-story2>',
|
||||||
'<my-preview2 mdjs-story-name="fooPreviewStory"></my-preview2>',
|
'<my-preview2 mdjs-story-name="fooPreviewStory"></my-preview2>',
|
||||||
].join('\n');
|
].join('\n');
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
const unified = require('unified');
|
import { unified } from 'unified';
|
||||||
const markdown = require('remark-parse');
|
import markdown from 'remark-parse';
|
||||||
const html = require('remark-html');
|
import html from 'remark-html';
|
||||||
|
import { mdjsParse } from '../src/mdjsParse.js';
|
||||||
|
|
||||||
const chai = require('chai');
|
import { expect } from 'chai';
|
||||||
const { mdjsParse } = require('../src/mdjsParse.js');
|
|
||||||
|
|
||||||
const { expect } = chai;
|
|
||||||
|
|
||||||
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
||||||
|
|
||||||
@@ -22,7 +20,7 @@ describe('mdjsParse', () => {
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(
|
expect(result.value).to.equal(
|
||||||
'<h2>Intro</h2>\n<pre><code class="language-js">const foo = 1;\n</code></pre>\n',
|
'<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;');
|
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||||
@@ -40,7 +38,7 @@ describe('mdjsParse', () => {
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(
|
expect(result.value).to.equal(
|
||||||
'<h2>Intro</h2>\n<pre><code class="language-js">const foo = 1;\n</code></pre>\n',
|
'<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;');
|
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||||
@@ -56,7 +54,7 @@ describe('mdjsParse', () => {
|
|||||||
].join('\n');
|
].join('\n');
|
||||||
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal('');
|
expect(result.value).to.equal('');
|
||||||
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
expect(/** @type {MDJSVFileData} */ (result.data).jsCode).to.equal('const bar = 22;');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,13 +1,11 @@
|
|||||||
/* eslint-disable no-template-curly-in-string */
|
/* eslint-disable no-template-curly-in-string */
|
||||||
|
|
||||||
const unified = require('unified');
|
import { unified } from 'unified';
|
||||||
const markdown = require('remark-parse');
|
import markdown from 'remark-parse';
|
||||||
const html = require('remark-html');
|
import html from 'remark-html';
|
||||||
|
import { mdjsStoryParse } from '../src/mdjsStoryParse.js';
|
||||||
|
|
||||||
const chai = require('chai');
|
import { expect } from 'chai';
|
||||||
const { mdjsStoryParse } = require('../src/mdjsStoryParse.js');
|
|
||||||
|
|
||||||
const { expect } = chai;
|
|
||||||
|
|
||||||
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
/** @typedef {import("../src/mdjsParse.js").MDJSVFileData} MDJSVFileData */
|
||||||
|
|
||||||
@@ -63,7 +61,7 @@ describe('mdjsStoryParse', () => {
|
|||||||
|
|
||||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(expected);
|
expect(result.value).to.equal(expected);
|
||||||
expect(/** @type {MDJSVFileData} */ (result.data).stories).to.deep.equal([
|
expect(/** @type {MDJSVFileData} */ (result.data).stories).to.deep.equal([
|
||||||
{
|
{
|
||||||
key: 'fooStory',
|
key: 'fooStory',
|
||||||
@@ -112,7 +110,7 @@ describe('mdjsStoryParse', () => {
|
|||||||
})
|
})
|
||||||
.use(html, { sanitize: false });
|
.use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(expected);
|
expect(result.value).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will wrap following story-code blocks', async () => {
|
it('will wrap following story-code blocks', async () => {
|
||||||
@@ -150,7 +148,7 @@ describe('mdjsStoryParse', () => {
|
|||||||
|
|
||||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(expected);
|
expect(result.value).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will wrap following story-code blocks also for html stories', async () => {
|
it('will wrap following story-code blocks also for html stories', async () => {
|
||||||
@@ -188,7 +186,7 @@ describe('mdjsStoryParse', () => {
|
|||||||
|
|
||||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(expected);
|
expect(result.value).to.equal(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('will wrap only following story-code blocks', async () => {
|
it('will wrap only following story-code blocks', async () => {
|
||||||
@@ -244,6 +242,6 @@ describe('mdjsStoryParse', () => {
|
|||||||
|
|
||||||
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
const parser = unified().use(markdown).use(mdjsStoryParse).use(html, { sanitize: false });
|
||||||
const result = await parser.process(input);
|
const result = await parser.process(input);
|
||||||
expect(result.contents).to.equal(expected);
|
expect(result.value).to.equal(expected);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
{
|
{
|
||||||
"extends": "../../tsconfig.node-base.json",
|
"extends": "../../tsconfig.node-base.json",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"module": "commonjs",
|
"module": "ESNext",
|
||||||
"outDir": "./dist-types",
|
"outDir": "./dist-types",
|
||||||
"rootDir": ".",
|
"rootDir": ".",
|
||||||
"composite": true,
|
"composite": true,
|
||||||
|
|||||||
2
packages/mdjs-core/types/code.d.ts
vendored
2
packages/mdjs-core/types/code.d.ts
vendored
@@ -23,7 +23,7 @@ export interface ProcessResult {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ParseResult {
|
export interface ParseResult {
|
||||||
contents: string;
|
value: string;
|
||||||
data: {
|
data: {
|
||||||
stories: Story[];
|
stories: Story[];
|
||||||
jsCode: string;
|
jsCode: string;
|
||||||
|
|||||||
8
packages/mdjs-core/types/remark.d.ts
vendored
8
packages/mdjs-core/types/remark.d.ts
vendored
@@ -27,11 +27,3 @@ declare module 'rehype-autolink-headings' {
|
|||||||
|
|
||||||
export = unified.Plugin;
|
export = unified.Plugin;
|
||||||
}
|
}
|
||||||
|
|
||||||
declare module 'unist-util-remove' {
|
|
||||||
import unified from 'unified';
|
|
||||||
|
|
||||||
function remove(ast: unified.Node, opts: any, test?: any): unified.Node;
|
|
||||||
|
|
||||||
export = remove;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,5 +1,11 @@
|
|||||||
# @mdjs/mdjs-preview
|
# @mdjs/mdjs-preview
|
||||||
|
|
||||||
|
## 0.5.9
|
||||||
|
|
||||||
|
### Patch Changes
|
||||||
|
|
||||||
|
- ab24361: Add server folder to the published npm package
|
||||||
|
|
||||||
## 0.5.8
|
## 0.5.8
|
||||||
|
|
||||||
### Patch Changes
|
### Patch Changes
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@mdjs/mdjs-preview",
|
"name": "@mdjs/mdjs-preview",
|
||||||
"version": "0.5.8",
|
"version": "0.5.9",
|
||||||
"publishConfig": {
|
"publishConfig": {
|
||||||
"access": "public"
|
"access": "public"
|
||||||
},
|
},
|
||||||
@@ -30,12 +30,13 @@
|
|||||||
"*.js",
|
"*.js",
|
||||||
"assets",
|
"assets",
|
||||||
"dist-types",
|
"dist-types",
|
||||||
|
"server",
|
||||||
"src"
|
"src"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lion/accordion": "^0.9.0",
|
"@lion/accordion": "^0.9.0",
|
||||||
"@open-wc/scoped-elements": "^2.0.0",
|
"@open-wc/scoped-elements": "^2.0.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"types": "dist-types/index.d.ts"
|
"types": "dist-types/index.d.ts"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@
|
|||||||
"src"
|
"src"
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"types": "dist-types/index.d.ts"
|
"types": "dist-types/index.d.ts"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,12 +57,13 @@ describe('rocket-search', () => {
|
|||||||
expect(el.miniSearch).to.not.be.null;
|
expect(el.miniSearch).to.not.be.null;
|
||||||
});
|
});
|
||||||
|
|
||||||
it('initialize the search on focus', async () => {
|
// flaky on firefox 🤔
|
||||||
|
it.skip('initialize the search on focus', async () => {
|
||||||
const el = await fixture(html`<rocket-search json-url=${fixtureOneResultUrl}></rocket-search>`);
|
const el = await fixture(html`<rocket-search json-url=${fixtureOneResultUrl}></rocket-search>`);
|
||||||
expect(el.miniSearch).to.be.null;
|
expect(el.miniSearch).to.be.null;
|
||||||
|
|
||||||
el.focus();
|
el.focus();
|
||||||
await aTimeout(10);
|
await aTimeout(50);
|
||||||
expect(el.miniSearch).to.not.be.null;
|
expect(el.miniSearch).to.not.be.null;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -42,7 +42,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@rocket/components": "^0.2.0",
|
"@rocket/components": "^0.2.0",
|
||||||
"@rocket/engine": "^0.2.0",
|
"@rocket/engine": "^0.2.0",
|
||||||
"lit": "^2.2.5"
|
"lit": "^2.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {},
|
"devDependencies": {},
|
||||||
"types": "./dist-types/src/index.d.ts",
|
"types": "./dist-types/src/index.d.ts",
|
||||||
|
|||||||
@@ -332,7 +332,3 @@ export function myPreset() {
|
|||||||
```
|
```
|
||||||
|
|
||||||
</inline-notification>
|
</inline-notification>
|
||||||
|
|
||||||
```js script
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export const needsLoader = true;
|
|||||||
|
|
||||||
# Overview
|
# Overview
|
||||||
|
|
||||||
```js script
|
```js client
|
||||||
import '@mdjs/mdjs-story/define';
|
import '@mdjs/mdjs-story/define';
|
||||||
import '@mdjs/mdjs-preview/define';
|
import '@mdjs/mdjs-preview/define';
|
||||||
import { html } from '@mdjs/mdjs-story';
|
import { html } from '@mdjs/mdjs-story';
|
||||||
@@ -34,10 +34,10 @@ import { html } from '@mdjs/mdjs-story';
|
|||||||
|
|
||||||
Markdown JavaScript (mdjs) is a format that allows you to use JavaScript with Markdown, to create interactive demos. It does so by "annotating" JavaScript that should be executed in Markdown.
|
Markdown JavaScript (mdjs) is a format that allows you to use JavaScript with Markdown, to create interactive demos. It does so by "annotating" JavaScript that should be executed in Markdown.
|
||||||
|
|
||||||
To annotate we use a code block with `js script`.
|
To annotate we use a code block with `js client`.
|
||||||
|
|
||||||
````md
|
````md
|
||||||
```js script
|
```js client
|
||||||
// execute me
|
// execute me
|
||||||
```
|
```
|
||||||
````
|
````
|
||||||
@@ -69,7 +69,7 @@ You can even execute some JavaScript:
|
|||||||
|
|
||||||
<my-el></my-el>
|
<my-el></my-el>
|
||||||
|
|
||||||
```js script
|
```js client
|
||||||
import { LitElement, html } from 'https://unpkg.com/lit-element?module';
|
import { LitElement, html } from 'https://unpkg.com/lit-element?module';
|
||||||
|
|
||||||
class MyEl extends LitElement {
|
class MyEl extends LitElement {
|
||||||
@@ -87,7 +87,7 @@ customElements.define('my-el', MyEl);
|
|||||||
mdjs comes with some additional helpers you can choose to import:
|
mdjs comes with some additional helpers you can choose to import:
|
||||||
|
|
||||||
````md
|
````md
|
||||||
```js script
|
```js client
|
||||||
import '@mdjs/mdjs-story/define';
|
import '@mdjs/mdjs-story/define';
|
||||||
import '@mdjs/mdjs-preview/define';
|
import '@mdjs/mdjs-preview/define';
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ You can showcase live running code by annotating a code block with `js preview-s
|
|||||||
- Settings are ”global” for all Simulators (e.g. changing one will change all)
|
- Settings are ”global” for all Simulators (e.g. changing one will change all)
|
||||||
- Settings can be remembered for other pages / return visits
|
- Settings can be remembered for other pages / return visits
|
||||||
|
|
||||||
```js script
|
```js client
|
||||||
import { html } from '@mdjs/mdjs-preview';
|
import { html } from '@mdjs/mdjs-preview';
|
||||||
import './assets/demo-element.js';
|
import './assets/demo-element.js';
|
||||||
```
|
```
|
||||||
@@ -52,7 +52,7 @@ import './assets/demo-element.js';
|
|||||||
## JavaScript Story
|
## JavaScript Story
|
||||||
|
|
||||||
````md
|
````md
|
||||||
```js script
|
```js client
|
||||||
import { html } from '@mdjs/mdjs-preview';
|
import { html } from '@mdjs/mdjs-preview';
|
||||||
import './assets/demo-element.js';
|
import './assets/demo-element.js';
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -28,12 +28,12 @@ export const needsLoader = true;
|
|||||||
|
|
||||||
You can showcase live running code by annotating a code block with `js story`.
|
You can showcase live running code by annotating a code block with `js story`.
|
||||||
|
|
||||||
```js script
|
```js client
|
||||||
import { html } from '@mdjs/mdjs-story';
|
import { html } from '@mdjs/mdjs-story';
|
||||||
```
|
```
|
||||||
|
|
||||||
````md
|
````md
|
||||||
```js script
|
```js client
|
||||||
import { html } from '@mdjs/mdjs-story';
|
import { html } from '@mdjs/mdjs-story';
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
@@ -2529,6 +2529,11 @@
|
|||||||
"text": "Simulator states",
|
"text": "Simulator states",
|
||||||
"id": "simulator-states",
|
"id": "simulator-states",
|
||||||
"level": 2
|
"level": 2
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"text": "Extending mdjs-preview",
|
||||||
|
"id": "extending-mdjs-preview",
|
||||||
|
"level": 2
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"name": "Preview",
|
"name": "Preview",
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ const packages = [
|
|||||||
{ name: 'search', type: 'js', environment: 'node-esm' },
|
{ name: 'search', type: 'js', environment: 'node-esm' },
|
||||||
// { name: 'check-html-links', type: 'js', environment: 'node-esm' },
|
// { name: 'check-html-links', type: 'js', environment: 'node-esm' },
|
||||||
// { name: 'drawer', type: 'js', environment: 'browser' },
|
// { name: 'drawer', type: 'js', environment: 'browser' },
|
||||||
{ name: 'mdjs-core', type: 'js', environment: 'node' },
|
{ name: 'mdjs-core', type: 'js', environment: 'node-esm' },
|
||||||
// { name: 'mdjs-preview', type: 'js', environment: 'browser' },
|
// { name: 'mdjs-preview', type: 'js', environment: 'browser' },
|
||||||
// { name: 'mdjs-story', type: 'js', environment: 'browser' },
|
// { name: 'mdjs-story', type: 'js', environment: 'browser' },
|
||||||
];
|
];
|
||||||
|
|||||||
Reference in New Issue
Block a user