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

feat(core/respec-global): add toHTML() method #3403

Merged
merged 12 commits into from
Mar 29, 2021
2 changes: 1 addition & 1 deletion src/core/exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function rsDocToDataURL(mimeType, doc = document) {
return `data:${mimeType};charset=utf-8,${encodedString}`;
}

function serialize(format, doc) {
export function serialize(format, doc) {
const cloneDoc = doc.cloneNode(true);
cleanup(cloneDoc);
let result = "";
Expand Down
5 changes: 5 additions & 0 deletions src/core/respec-global.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* This module also adds the legacy `document.respecIsReady` property for
* backward compatibility. It is now an alias to `document.respec.ready`.
*/
import { serialize } from "../core/exporter.js";
import { showWarning } from "../core/utils.js";
import { sub } from "./pubsubhub.js";

Expand Down Expand Up @@ -40,6 +41,10 @@ class ReSpec {
get ready() {
return this._respecDonePromise;
}

async toHTML() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Async in case we need it in future

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also add it in the future...

return serialize("html", document);
}
}

export function init() {
Expand Down
4 changes: 3 additions & 1 deletion tools/respecDocWriter.js
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ async function evaluateHTML(version, timer) {
});
});
return exportDocument("html", "text/html");
} else {
} else if (!document.respec || !document.respec.toHTML) {
const { rsDocToDataURL } = await new Promise((resolve, reject) => {
require(["core/exporter"], resolve, err => {
reject(new Error(err.message));
Expand All @@ -249,6 +249,8 @@ async function evaluateHTML(version, timer) {
const dataURL = rsDocToDataURL("text/html");
const encodedString = dataURL.replace(/^data:\w+\/\w+;charset=utf-8,/, "");
return decodeURIComponent(encodedString);
} else {
return await document.respec.toHTML();
}

function timeout(promise, ms) {
Expand Down