Skip to content

Commit

Permalink
pod2html: fix rendering in chrome
Browse files Browse the repository at this point in the history
Elements that are part of a DocumentFragment don't seem to have a
working outerHTML property in Chrome.
  • Loading branch information
haarg committed Nov 4, 2024
1 parent d3785c2 commit f0e0803
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions root/static/js/pod2html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ if (pod2htmlForm) {
const error = document.querySelector('#metacpan-pod-renderer-error');
const template = document.querySelector('#metacpan-pod-renderer-content');

const parseHTML = (html) => {
const template = document.createElement('template');
template.innerHTML = html;
return template.content;
};
const updateHTML = async (pod) => {
if (!pod) {
pod = textInput.value;
Expand Down Expand Up @@ -47,8 +52,9 @@ if (pod2htmlForm) {
document.title = "Pod Renderer - " + data.pod_title + " - metacpan.org";

const body = template.content.cloneNode(true);
body.querySelector('.toc-body').outerHTML = data.pod_index;
body.querySelector('.pod-body').outerHTML = data.pod_html;
body.querySelector('.toc-body').replaceWith(parseHTML(data.pod_index));
body.querySelector('.pod-body').replaceWith(parseHTML(data.pod_html));

rendered.replaceChildren(body);

formatTOC(rendered.querySelector('nav'));
Expand Down

0 comments on commit f0e0803

Please sign in to comment.