Skip to content

Commit

Permalink
add targetDir parameter to outputFormatter
Browse files Browse the repository at this point in the history
  • Loading branch information
AgentEpsilon committed Feb 11, 2019
1 parent 4d727b0 commit bc24acd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
11 changes: 6 additions & 5 deletions browser/components/MarkdownPreview.js
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ export default class MarkdownPreview extends React.Component {
this.exportAsDocument('md')
}

htmlContentFormatter (noteContent, exportTasks) {
htmlContentFormatter (noteContent, exportTasks, targetDir) {
const {
fontFamily,
fontSize,
Expand Down Expand Up @@ -339,6 +339,7 @@ export default class MarkdownPreview extends React.Component {

return `<html>
<head>
<base href="file://${targetDir}/">

This comment has been minimized.

Copy link
@shmolf

shmolf Dec 13, 2019

Contributor

@AgentEpsilon May I ask, was there a reason for declaring the base? I'm wondering if it'd harm anything, or resurface an old bug, to remove it.

By removing it, I believe it'll fix ID links from the Table of Contents for Exported HTML files.
And may also help when referencing assets relative to the HTML file's current directory, rather than relative to the base href.

Your thoughts?

This comment has been minimized.

Copy link
@shmolf

shmolf Dec 28, 2019

Contributor

So, it looks like this line is needed in order for PDF exports to work.

<meta charset="UTF-8">
<meta name = "viewport" content = "width = device-width, initial-scale = 1, maximum-scale = 1">
<style id="style">${inlineStyles}</style>
Expand All @@ -349,13 +350,13 @@ export default class MarkdownPreview extends React.Component {
}

handleSaveAsHtml () {
this.exportAsDocument('html', (noteContent, exportTasks) => Promise.resolve(this.htmlContentFormatter(noteContent, exportTasks)))
this.exportAsDocument('html', (noteContent, exportTasks, targetDir) => Promise.resolve(this.htmlContentFormatter(noteContent, exportTasks, targetDir)))
}

handleSaveAsPdf () {
this.exportAsDocument('pdf', (noteContent, exportTasks) => {
const printout = new remote.BrowserWindow({show: false})
printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks))
this.exportAsDocument('pdf', (noteContent, exportTasks, targetDir) => {
const printout = new remote.BrowserWindow({show: true})
printout.loadURL('data:text/html;charset=UTF-8,' + this.htmlContentFormatter(noteContent, exportTasks, targetDir))
return new Promise((resolve, reject) => {
printout.webContents.on('did-finish-load', () => {
printout.webContents.printToPDF({}, (err, data) => {
Expand Down
2 changes: 1 addition & 1 deletion browser/main/lib/dataApi/exportNote.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function exportNote (nodeKey, storageKey, noteContent, targetPath, outputFormatt
)

if (outputFormatter) {
exportedData = outputFormatter(exportedData, exportTasks)
exportedData = outputFormatter(exportedData, exportTasks, path.dirname(targetPath))
} else {
exportedData = Promise.resolve(exportedData)
}
Expand Down

0 comments on commit bc24acd

Please sign in to comment.