-
-
Notifications
You must be signed in to change notification settings - Fork 5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Show note title in pdf export (#890) #937
Conversation
An example of a possible approach, to temporarily change the html in the webview to show the note title. Works, but there may be a more elegant fix.
ElectronClient/app/gui/NoteText.jsx
Outdated
|
||
// refresh the webview contents, undoing our temporary change | ||
this.lastSetHtml_ = ''; | ||
this.render() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A bit hacky but indeed probably the best way to refresh the content. Could we use this.forceUpdate() though instead of calling render directly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Thanks, your approach is the right way as the app is going to print to PDF whatever is displayed in the HTML view so the HTML code indeed needs to be modified that way. |
ElectronClient/app/gui/NoteText.jsx
Outdated
const tag = 'h2'; | ||
let splitStyle = s.split('</style>'); | ||
const index = splitStyle.length > 1 ? 1 : 0; | ||
let toInsert = heading.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was sure there was already a function to escape HTML somewhere but looks like there isn't. Any chance you could add an escapeHtml function to string-utils and use it here? Something like this for instance https://stackoverflow.com/a/4835406/561309
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had looked, and the only one was buried within React and not exposed. Done.
ElectronClient/app/gui/NoteText.jsx
Outdated
|
||
insertHtmlHeading_(s, heading) { | ||
const tag = 'h2'; | ||
let splitStyle = s.split('</style>'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm... what if later on a style block is added at the bottom of a note - wouldn't that mean that the title would end up there too? Is it not possible to insert the title based on the tag? Or maybe a hidden placeholder could be added to the generated HTML for example as a comment - <!-- TITLE_PLACEHOLDER -->
then this placeholder would be replaced here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure what you mean by "insert the title based on the tag"? the code as written inserts the heading after the first </style>, so it would still work as expected if there are other </style> blocks.
I'm now using a comment placeholder now which is less fragile in the long term.
Revising based on feedback Also, a couple changes to tests so that they pass in Windows.
Looks good now, thanks @downpoured! |
An example of a possible approach, to temporarily change the html in the webview to show the note title. Works, but there may be a more elegant fix.