Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

fix incorrect styling in pdf and html export

ammarahm-edf840ab0b2ff5
diff --git a/apps/mobile/src/services/Exporter.js b/apps/mobile/src/services/Exporter.js
index b650beac8..7352d9c5a 100644
--- a/apps/mobile/src/services/Exporter.js
+++ b/apps/mobile/src/services/Exporter.js
@@ -9,6 +9,54 @@ import { sanitizeFilename } from '../utils/filename';
let RNFetchBlob;
+const defaultStyle = `<style>
+.img_size_one {
+ width:100%;
+}
+.img_size_two {
+ width:50%;
+}
+.img_size_three {
+ width:25%;
+}
+img {
+ max-width:100% !important;
+ height:auto !important;
+}
+
+.img_float_left {
+ float:left;
+}
+.img_float_right {
+ float:right;
+}
+.img_float_none {
+ float:none;
+}
+body {
+ background-color:transparent !important;
+}
+pre.codeblock {
+ overflow-x:auto;
+}
+
+iframe {
+ max-width:100% !important;
+ background-color:transparent !important;
+}
+table {
+ display: block !important;
+ overflow-x: auto !important;
+ white-space: nowrap !important;
+ max-width:100% !important;
+ width:100% !important;
+ height:auto !important;
+}
+td {
+ min-width:10vw !important;
+}
+</style>`
+
async function saveToPDF(note) {
let androidSavePath = '/Notesnook/exported/PDF';
if (Platform.OS === 'android') {
@@ -28,9 +76,16 @@ async function saveToPDF(note) {
let html = await db.notes.note(note).export('html');
let he = require('he');
html = he.decode(html);
- let fileName = sanitizeFilename(note.title, {replacement: '_'});
+ let fileName = sanitizeFilename(note.title + Date.now(), {replacement: '_'});
+ let html3 = html;
+ if (html.indexOf("<head>") > -1) {
+ let html1 = html.substring(0,html.indexOf("<head>") + 6);
+ let html2 = html.substring(html.indexOf("<head>") + 6);
+ html3 = html1 + defaultStyle + html2
+ }
+
let options = {
- html: html,
+ html: html3,
fileName: Platform.OS === 'ios' ? '/exported/PDF/' + fileName : fileName,
directory: Platform.OS === 'ios' ? 'Documents' : androidSavePath,
};
@@ -68,7 +123,7 @@ async function saveToMarkdown(note) {
markdown = await db.notes.note(note.id).export('md', markdown);
- let fileName = sanitizeFilename(note.title, {replacement: '_'});
+ let fileName = sanitizeFilename(note.title + Date.now(), {replacement: '_'});
path = path + fileName + '.md';
await RNFetchBlob.fs.writeFile(path, markdown, 'utf8');
@@ -97,7 +152,7 @@ async function saveToText(note) {
RNFetchBlob = require('rn-fetch-blob').default;
let text = await db.notes.note(note.id).export('txt');
- let fileName = sanitizeFilename(note.title, {replacement: '_'});
+ let fileName = sanitizeFilename(note.title + Date.now(), {replacement: '_'});
path = path + fileName + '.txt';
await RNFetchBlob.fs.writeFile(path, text, 'utf8');
@@ -125,9 +180,17 @@ async function saveToHTML(note) {
}
RNFetchBlob = require('rn-fetch-blob').default;
let html = await db.notes.note(note.id).export('html');
- let fileName = sanitizeFilename(note.title, {replacement: '_'});
+ let fileName = sanitizeFilename(note.title + Date.now(), {replacement: '_'});
+ let html3 = html;
+ if (html.indexOf("<head>") > -1) {
+ let html1 = html.substring(0,html.indexOf("<head>") + 6);
+ let html2 = html.substring(html.indexOf("<head>") + 6);
+ html3 = html1 + defaultStyle + html2
+ }
+
+
path = path + fileName + '.html';
- await RNFetchBlob.fs.writeFile(path, html, 'utf8');
+ await RNFetchBlob.fs.writeFile(path, html3, 'utf8');
return {
filePath: path,