waldyrious / rst-playground

Browser-based reStructuredText playground, built on Pyodide and docutils.
https://waldyrious.github.io/rst-playground
ISC License
1 stars 4 forks source link

Remove grey background from docutils' output #19

Closed waldyrious closed 1 year ago

waldyrious commented 1 year ago

This has to be done via string manipulation instead of DOM manipulation, because the iframe's contents are set by passing a string with HTML markup to the srcdoc attribute (see PR #12).

Fixes #15.

waldyrious commented 1 year ago

This works, but feels rather hacky. @not-my-profile do you have any suggestions here?

In any case, I eventually would like to do a more deliberate handling of Docutils' output, rather than directly accept the full HTML page it produces (see #5), so perhaps this is OK as a stop-gap solution.

waldyrious commented 1 year ago

For the record, the DOM manipulation approach would look something like this:

const newStyle = outputFrame.contentDocument.createElement("style");
newStyle.textContent = "body { background-color: unset; }";
outputFrame.contentDocument.head.appendChild(newStyle);
waldyrious commented 1 year ago

Update: I found a cleaner approach, thanks to https://stackoverflow.com/a/13959836/266309.

I force-pushed the branch to allow for a clean git history; for reference, the original commit was 2cfa017ae.

waldyrious commented 1 year ago

Merging since this no longer uses a hacky string replacement approach.