Skip to content

Commit

Permalink
Merge pull request #13 from adrianmarinwork/main
Browse files Browse the repository at this point in the history
easier fix for issue #2 - fixes lists, texts and codeblocks
  • Loading branch information
liady authored Dec 11, 2022
2 parents 609bd89 + 9619589 commit 61c28d1
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/content_script.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,24 +70,18 @@ function downloadThread({ as = Format.PNG } = {}) {
const pixelRatio = window.devicePixelRatio;
const minRatio = as === Format.PDF ? 2 : 2.5;
window.devicePixelRatio = Math.max(pixelRatio, minRatio);

//Fix to the text shifting down when generating the canvas
document.body.style.lineHeight = '0.5';

html2canvas(elements.thread, {
letterRendering: true,
onclone: function (cloneDoc) {
//Make small fix of position to all the text containers
let listOfTexts = cloneDoc.getElementsByClassName("min-h-[20px]");
Array.from(listOfTexts).forEach((text) => {
text.style.position = "relative";
text.style.top = "-8px";
});

//Delete copy button from code blocks
let listOfCopyBtns = cloneDoc.querySelectorAll("button.flex");
Array.from(listOfCopyBtns).forEach(
(btn) => (btn.style.visibility = "hidden")
);
},
}).then(async function (canvas) {
elements.restoreLocation();

//Restore style
document.body.style.lineHeight = null;

window.devicePixelRatio = pixelRatio;
const imgData = canvas.toDataURL("image/png");
requestAnimationFrame(() => {
Expand Down

0 comments on commit 61c28d1

Please sign in to comment.