Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add diagrams support #291

Merged
merged 4 commits into from
Nov 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lerna.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"lerna": "4.0.0",
"lerna": "6.0.3",
"packages": [
"packages/*"
],
Expand Down
9,113 changes: 4,689 additions & 4,424 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@
},
"homepage": "https://diffhtml.org/",
"devDependencies": {
"lerna": "^4.0.0"
"lerna": "^6.0.3"
}
}
2 changes: 1 addition & 1 deletion packages/babel-preset-diffhtml-imports/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/diffhtml-middleware-worker/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"devDependencies": {
"@babel/cli": "^7.12.10",
"@babel/core": "^7.12.10",
"babel-preset-diffhtml-imports": "^1.0.0-beta.23",
"babel-preset-diffhtml-imports": "^1.0.0-beta.29",
"diffhtml": "^1.0.0-beta.23",
"rollup": "^1.21.4",
"rollup-plugin-babel": "^4.3.3",
Expand Down
13 changes: 2 additions & 11 deletions packages/diffhtml-static-sync/sync.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ process.env.NODE_ENV = 'production';

let interval = null;
const domNodes = new Map();
const { html, outerHTML } = diffhtml;
const { outerHTML, html } = diffhtml;

window.staticSyncHandlers = new Set();
window.staticSyncSocket = undefined;
Expand Down Expand Up @@ -80,16 +80,7 @@ function open() {
ext === 'md'
)
) {
const children = html(markup);

console.log(children, markup);

if (children.childNodes.length > 1) {
outerHTML(document.documentElement, children.childNodes[1]);
}
else {
outerHTML(document.documentElement, children);
}
outerHTML(document.documentElement, html(markup));
}
// All other files cause a full page reload.
else {
Expand Down
42 changes: 40 additions & 2 deletions packages/diffhtml-website/build/generate.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,53 @@
const { readFileSync, writeFileSync, existsSync, mkdirSync } = require('fs');
const { join, dirname } = require('path');
const { html, toString, use } = require('diffhtml');
const { html, toString, use, Internals } = require('diffhtml');
const { marked } = require('marked');
const mermaid = require('mermaid');
const flattenPages = require('./util/flatten-pages');
const { keys } = Object;
const { assign, keys } = Object;

// Ensure Components middleware is loaded since Layout is a class
// component and toString will pick it up automatically.
require('diffhtml-components');
//use(require('diffhtml-middleware-linter')());

// Create a jsdom and svgdom merged environment for Mermaid to work.
const SVG = require('svgdom');
const { JSDOM } = require('jsdom');
const { window } = new JSDOM('');

// Patch the Element constructor which is inherited by SVGElement to contain
// the getBBox method to avoid runtime errors with mermaid.
window.Element.prototype.getBBox = SVG.SVGGraphicsElement.prototype.getBBox;

// Unfortunately this patching has to occur in order for the sanitize method
// to return the input and not break under mermaid. Would be great to have
// a fix that didn't involve this.
Object.prototype.sanitize = x => x;

assign(globalThis, {
document: window.document,
window,
});

// Mermaid parsing
use({
createTreeHook({ nodeName, childNodes }) {
if (nodeName === 'mermaid') {
if (childNodes[0].nodeType === Internals.NODE_TYPE.TEXT) {
try {
mermaid.render('mermaid', childNodes[0].nodeValue.trim(), svg => {
// Replace with the newly rendered SVG
childNodes[0] = html(svg);
});
} catch (e) {
childNodes[0] = html`<pre>${e.stack}</pre>`;
}
}
}
},
});

const renderer = {};

// Patch the renderer to allow for better anchor tags to be generated.
Expand Down
Loading