Skip to content

Commit

Permalink
fix page menu command
Browse files Browse the repository at this point in the history
  • Loading branch information
sawhney17 committed Mar 23, 2022
1 parent fa16884 commit 8a45eaf
Showing 1 changed file with 14 additions and 21 deletions.
35 changes: 14 additions & 21 deletions src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { jsPDF } from "jspdf";
import html2canvas from "html2canvas";
import markdownMark from "markdown-it-mark";


const propertyOptions = [
"Hide Page Properties",
"Hide Brackets",
Expand Down Expand Up @@ -76,7 +75,7 @@ export function downloadPDF() {
// var getContent = "<div style='font-size:11px; border:1px solid; background-color: rgb(239 240 240); padding: 05px 15px; width:300px;'>"+document.body+"</div>";

pdf.html(document.getElementById("you are cool"), {
callback: (doc) => doc.save("logseqDownloaded.pdf"),
callback: (doc) => doc.save("download.pdf"),
margin: 0,
width: 595,
windowWidth: 595,
Expand All @@ -103,9 +102,7 @@ async function formatText(text2, template) {
text = text.substring(0, text.indexOf("CLOCK: ["));
}

if (
logseq.settings[`${template}Options`].includes("Hide Page Properties")
) {
if (logseq.settings[`${template}Options`].includes("Hide Page Properties")) {
text = text.replaceAll(/((?<=::).*|.*::)/g, "");
}
if (logseq.settings[`${template}Options`].includes("Hide Brackets")) {
Expand All @@ -120,7 +117,6 @@ async function formatText(text2, template) {
includeChildren: true,
});
//optional based on setting enabled


if (block != null) {
text = text.replace(
Expand Down Expand Up @@ -165,7 +161,7 @@ export async function createPDF(templateName) {

finalString = finalString.replaceAll("#+BEGIN_QUOTE", "");
finalString = finalString.replaceAll("#+END_QUOTE", "");

const baseCSS =
"h1 { display: block; font-size: 2em; margin-block-start: 0.67__qem; margin-block-end: 0.67em; margin-inline-start: 0; margin-inline-end: 0; font-weight: bold; } :is(article, aside, nav, section) h1 { font-size: 1.5em; margin-block-start: 0.83__qem; margin-block-end: 0.83em; } :is(article, aside, nav, section) :is(article, aside, nav, section) h1 { font-size: 1.17em; margin-block-start: 1__qem; margin-block-end: 1em; } :is(article, aside, nav, section) :is(article, aside, nav, section) :is(article, aside, nav, section) h1 { font-size: 1.00em; margin-block-start: 1.33__qem; margin-block-end: 1.33em; } :is(article, aside, nav, section) :is(article, aside, nav, section) :is(article, aside, nav, section) :is(article, aside, nav, section) h1 { font-size: .83em; margin-block-start: 1.67__qem; margin-block-end: 1.67em; } :is(article, aside, nav, section) :is(article, aside, nav, section) :is(article, aside, nav, section) :is(article, aside, nav, section) :is(article, aside, nav, section) h1 { font-size: .67em; margin-block-start: 2.33__qem; margin-block-end: 2.33em; } h2 { display: block; font-size: 1.5em; margin-block-start: 0.83__qem; margin-block-end: 0.83em; margin-inline-start: 0; margin-inline-end: 0; font-weight: bold; } h3 { display: block; font-size: 1.17em; margin-block-start: 1__qem; margin-block-end: 1em; margin-inline-start: 0; margin-inline-end: 0; font-weight: bold; } h4 { display: block; margin-block-start: 1.33__qem; margin-block-end: 1.33em; margin-inline-start: 0; margin-inline-end: 0; font-weight: bold; } h5 { display: block; font-size: .83em; margin-block-start: 1.67__qem; margin-block-end: 1.67em; margin-inline-start: 0; margin-inline-end: 0; font-weight: bold; } h6 { display: block; font-size: .67em; margin-block-start: 2.33__qem; margin-block-end: 2.33em; margin-inline-start: 0; margin-inline-end: 0; font-weight: bold; } /* lists */ ul, menu, dir { display: block; margin-block-start: 1__qem; margin-block-end: 1em; margin-inline-start: 0; margin-inline-end: 0; padding-inline-start: 40px; } ol { display: block; list-style-type: decimal; margin-block-start: 1__qem; margin-block-end: 1em; margin-inline-start: 0; margin-inline-end: 0; padding-inline-start: 40px; } li { display: list-item; text-align: match-parent; } /* FIXME: this should also match ::before::marker and ::after::marker but we don't support this yet. When we do, we can remove the code specific to ::before and ::after in RenderListItem::computeMarkerStyle(), see bugs.webkit.org/b/218897. */ ::marker { unicode-bidi: isolate; font-variant-numeric: tabular-nums; white-space: pre; text-transform: none; transform-origin: 0px 5px 5px;} ul ul, ol ul { } ol ol ul, ol ul ul, ul ol ul, ul ul ul { } dd { display: block; margin-inline-start: 40px; } dl { display: block; margin-block-start: 1__qem; margin-block-end: 1em; margin-inline-start: 0; margin-inline-end: 0; } dt { display: block; } ol ul, ul ol, ul ul, ol ol { margin-block-start: 0; margin-block-end: 0; } .italic{font-style: italic;} .bold{font-weight: bold;} .codeme{font-family: Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;}";
const settings = logseq.settings;
Expand All @@ -176,7 +172,6 @@ export async function createPDF(templateName) {
final3String = `<html><head><style>${baseCSS}</style></head><body><style>${css3}</style><div id = "you are cool" style='padding: 1rem'">${final2String}</div></body></html>`;

logseq.App.getCurrentGraph().then(async (graph) => {

var final4String = final3String
.replaceAll("../assets", `${graph.path}/assets`)
.replaceAll("<strong>", "</span><strong>")
Expand All @@ -187,10 +182,9 @@ export async function createPDF(templateName) {
.replaceAll("</li>", "</span></li>")
.replaceAll("<img>", "\n<img>");

if (logseq.settings[templateName+"Options"].includes("Hide Bullets")){
final4String = final4String.replaceAll("<p>", "<p><span>•")
}
else(final4String = final4String.replaceAll("<p>", "<p><span>"))
if (logseq.settings[templateName + "Options"].includes("Hide Bullets")) {
final4String = final4String.replaceAll("<p>", "<p><span>•");
} else final4String = final4String.replaceAll("<p>", "<p><span>");
handleClosePopup();
renderApp(final4String);
});
Expand All @@ -212,22 +206,22 @@ function parseBlocksTree(obj) {
}
}
const main = async () => {

logseq.App.registerUIItem("toolbar", {
key: "logseq-plugin-react-boilerplate",
template:
'<a data-on-click="show" class="button"><i class="ti ti-file-export"></i></a>',
});
logseq.provideModel({
show() {
// renderApp('logseq')
// logseq.showMainUI()
// createPDF()
renderSecondApp();
logseq.showMainUI();
handleClosePopup();
initializeApp();
},
});

function initializeApp() {
renderSecondApp();
logseq.showMainUI();
handleClosePopup();
}
function renderSecondApp() {
ReactDOM.render(
<React.StrictMode>
Expand All @@ -237,8 +231,7 @@ const main = async () => {
);
}


logseq.App.registerPageMenuItem("Download Page as PDF", renderSecondApp);
logseq.App.registerPageMenuItem("Download Page as PDF", initializeApp);
};

logseq.ready(main).catch(console.error);

0 comments on commit 8a45eaf

Please sign in to comment.