added content style to tar html export as well

This commit is contained in:
zadam 2019-12-25 11:34:45 +01:00
parent cec71f65b3
commit ab79f24729
3 changed files with 83 additions and 61 deletions

View File

@ -1,5 +1,6 @@
/* /*
* !!!!!!! This stylesheet is heavily modified compared to the original for similarity with in-editor look !!!!!!! * !!!!!!! This stylesheet is heavily modified compared to the original for similarity with in-editor look !!!!!!!
* This is used for printing and tar HTML export
* *
* CKEditor 5 (v15.0.0) content styles. * CKEditor 5 (v15.0.0) content styles.
* Generated on Wed, 27 Nov 2019 13:26:13 GMT. * Generated on Wed, 27 Nov 2019 13:26:13 GMT.
@ -15,26 +16,23 @@
--ck-highlight-pen-red: #e91313; --ck-highlight-pen-red: #e91313;
--ck-image-style-spacing: 1.5em; --ck-image-style-spacing: 1.5em;
--ck-todo-list-checkmark-size: 16px; --ck-todo-list-checkmark-size: 16px;
}
.ck-content {
font-family: Arial, Sans-Serif; font-family: Arial, Sans-Serif;
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list { .todo-list {
list-style: none; list-style: none;
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list li { .todo-list li {
margin-bottom: 5px; margin-bottom: 5px;
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list li .todo-list { .todo-list li .todo-list {
margin-top: 5px; margin-top: 5px;
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list .todo-list__label > input { .todo-list .todo-list__label > input {
-webkit-appearance: none; -webkit-appearance: none;
display: inline-block; display: inline-block;
position: relative; position: relative;
@ -48,7 +46,7 @@
margin-left: 0; margin-left: 0;
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list .todo-list__label > input::before { .todo-list .todo-list__label > input::before {
display: block; display: block;
position: absolute; position: absolute;
box-sizing: border-box; box-sizing: border-box;
@ -60,7 +58,7 @@
transition: 250ms ease-in-out box-shadow, 250ms ease-in-out background, 250ms ease-in-out border; transition: 250ms ease-in-out box-shadow, 250ms ease-in-out background, 250ms ease-in-out border;
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list .todo-list__label > input::after { .todo-list .todo-list__label > input::after {
display: block; display: block;
position: absolute; position: absolute;
box-sizing: content-box; box-sizing: content-box;
@ -76,38 +74,33 @@
transform: rotate(45deg); transform: rotate(45deg);
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list .todo-list__label > input[checked]::before { .todo-list .todo-list__label > input[checked]::before {
background: hsl(126, 64%, 41%);
border-color: hsl(126, 64%, 41%);
}
/* ckeditor5-list/theme/todolist.css
checked button is presented as green rectangle otherwise printing is broken for todos
*/
.ck-content .todo-list .todo-list__label > input[checked]::after {
background: hsl(126, 64%, 41%);
border-color: hsl(126, 64%, 41%); border-color: hsl(126, 64%, 41%);
} }
/* ckeditor5-list/theme/todolist.css */ /* ckeditor5-list/theme/todolist.css */
.ck-content .todo-list .todo-list__label .todo-list__label__description { .todo-list .todo-list__label > input[checked]::after {
border-color: hsl(126, 64%, 41%);
}
/* ckeditor5-list/theme/todolist.css */
.todo-list .todo-list__label .todo-list__label__description {
vertical-align: middle; vertical-align: middle;
} }
/* ckeditor5-image/theme/image.css */ /* ckeditor5-image/theme/image.css */
.ck-content .image { .image {
display: table; display: table;
clear: both; clear: both;
text-align: center; text-align: center;
margin: 1em auto; margin: 1em auto;
} }
/* ckeditor5-image/theme/image.css */ /* ckeditor5-image/theme/image.css */
.ck-content .image > img { .image > img {
display: block; display: block;
margin: 0 auto; margin: 0 auto;
max-width: 100%; max-width: 100%;
min-width: 50px; min-width: 50px;
} }
/* ckeditor5-block-quote/theme/blockquote.css */ /* ckeditor5-block-quote/theme/blockquote.css */
.ck-content blockquote { blockquote {
overflow: hidden; overflow: hidden;
padding-right: 1.5em; padding-right: 1.5em;
padding-left: 1.5em; padding-left: 1.5em;
@ -122,105 +115,105 @@
border-right: solid 5px hsl(0, 0%, 80%); border-right: solid 5px hsl(0, 0%, 80%);
} }
/* ckeditor5-image/theme/imageresize.css */ /* ckeditor5-image/theme/imageresize.css */
.ck-content .image.image_resized { .image.image_resized {
max-width: 100%; max-width: 100%;
display: block; display: block;
box-sizing: border-box; box-sizing: border-box;
} }
/* ckeditor5-image/theme/imageresize.css */ /* ckeditor5-image/theme/imageresize.css */
.ck-content .image.image_resized img { .image.image_resized img {
width: 100%; width: 100%;
} }
/* ckeditor5-image/theme/imageresize.css */ /* ckeditor5-image/theme/imageresize.css */
.ck-content .image.image_resized > figcaption { .image.image_resized > figcaption {
display: block; display: block;
} }
/* ckeditor5-image/theme/imagestyle.css */ /* ckeditor5-image/theme/imagestyle.css */
.ck-content .image-style-side, .image-style-side,
.ck-content .image-style-align-left, .image-style-align-left,
.ck-content .image-style-align-center, .image-style-align-center,
.ck-content .image-style-align-right { .image-style-align-right {
max-width: 50%; max-width: 50%;
} }
/* ckeditor5-image/theme/imagestyle.css */ /* ckeditor5-image/theme/imagestyle.css */
.ck-content .image-style-side { .image-style-side {
float: right; float: right;
margin-left: var(--ck-image-style-spacing); margin-left: var(--ck-image-style-spacing);
} }
/* ckeditor5-image/theme/imagestyle.css */ /* ckeditor5-image/theme/imagestyle.css */
.ck-content .image-style-align-left { .image-style-align-left {
float: left; float: left;
margin-right: var(--ck-image-style-spacing); margin-right: var(--ck-image-style-spacing);
} }
/* ckeditor5-image/theme/imagestyle.css */ /* ckeditor5-image/theme/imagestyle.css */
.ck-content .image-style-align-center { .image-style-align-center {
margin-left: auto; margin-left: auto;
margin-right: auto; margin-right: auto;
} }
/* ckeditor5-image/theme/imagestyle.css */ /* ckeditor5-image/theme/imagestyle.css */
.ck-content .image-style-align-right { .image-style-align-right {
float: right; float: right;
margin-left: var(--ck-image-style-spacing); margin-left: var(--ck-image-style-spacing);
} }
/* ckeditor5-media-embed/theme/mediaembed.css */ /* ckeditor5-media-embed/theme/mediaembed.css */
.ck-content .media { .media {
clear: both; clear: both;
margin: 1em 0; margin: 1em 0;
display: block; display: block;
min-width: 15em; min-width: 15em;
} }
/* ckeditor5-table/theme/table.css */ /* ckeditor5-table/theme/table.css */
.ck-content .table { .table {
display: table; display: table;
margin: 0; margin: 0;
} }
/* ckeditor5-table/theme/table.css */ /* ckeditor5-table/theme/table.css */
.ck-content .table table { .table table {
border-collapse: collapse; border-collapse: collapse;
border-spacing: 0; border-spacing: 0;
border: 1px double hsl(0, 0%, 70%); border: 1px double hsl(0, 0%, 70%);
} }
/* ckeditor5-table/theme/table.css */ /* ckeditor5-table/theme/table.css */
.ck-content .table table td, .table table td,
.ck-content .table table th { .table table th {
min-width: 2em; min-width: 2em;
padding: .4em; padding: .4em;
border: 1px solid #d9d9d9; border: 1px solid #d9d9d9;
} }
/* ckeditor5-table/theme/table.css */ /* ckeditor5-table/theme/table.css */
.ck-content .table table th { .table table th {
font-weight: bold; font-weight: bold;
background-color: #f5f5f5; background-color: #f5f5f5;
text-align: left; text-align: left;
} }
/* ckeditor5-highlight/theme/highlight.css */ /* ckeditor5-highlight/theme/highlight.css */
.ck-content .marker-yellow { .marker-yellow {
background-color: var(--ck-highlight-marker-yellow); background-color: var(--ck-highlight-marker-yellow);
} }
/* ckeditor5-highlight/theme/highlight.css */ /* ckeditor5-highlight/theme/highlight.css */
.ck-content .marker-green { .marker-green {
background-color: var(--ck-highlight-marker-green); background-color: var(--ck-highlight-marker-green);
} }
/* ckeditor5-highlight/theme/highlight.css */ /* ckeditor5-highlight/theme/highlight.css */
.ck-content .marker-pink { .marker-pink {
background-color: var(--ck-highlight-marker-pink); background-color: var(--ck-highlight-marker-pink);
} }
/* ckeditor5-highlight/theme/highlight.css */ /* ckeditor5-highlight/theme/highlight.css */
.ck-content .marker-blue { .marker-blue {
background-color: var(--ck-highlight-marker-blue); background-color: var(--ck-highlight-marker-blue);
} }
/* ckeditor5-highlight/theme/highlight.css */ /* ckeditor5-highlight/theme/highlight.css */
.ck-content .pen-red { .pen-red {
color: var(--ck-highlight-pen-red); color: var(--ck-highlight-pen-red);
background-color: transparent; background-color: transparent;
} }
/* ckeditor5-highlight/theme/highlight.css */ /* ckeditor5-highlight/theme/highlight.css */
.ck-content .pen-green { .pen-green {
color: var(--ck-highlight-pen-green); color: var(--ck-highlight-pen-green);
background-color: transparent; background-color: transparent;
} }
/* ckeditor5-page-break/theme/pagebreak.css */ /* ckeditor5-page-break/theme/pagebreak.css */
.ck-content .page-break { .page-break {
position: relative; position: relative;
clear: both; clear: both;
padding: 5px 0; padding: 5px 0;
@ -229,14 +222,14 @@
justify-content: center; justify-content: center;
} }
/* ckeditor5-page-break/theme/pagebreak.css */ /* ckeditor5-page-break/theme/pagebreak.css */
.ck-content .page-break::after { .page-break::after {
content: ''; content: '';
position: absolute; position: absolute;
border-bottom: 2px dashed hsl(0, 0%, 77%); border-bottom: 2px dashed hsl(0, 0%, 77%);
width: 100%; width: 100%;
} }
/* ckeditor5-page-break/theme/pagebreak.css */ /* ckeditor5-page-break/theme/pagebreak.css */
.ck-content .page-break__label { .page-break__label {
position: relative; position: relative;
z-index: 1; z-index: 1;
padding: .3em .6em; padding: .3em .6em;
@ -256,13 +249,13 @@
user-select: none; user-select: none;
} }
/* ckeditor5-basic-styles/theme/code.css */ /* ckeditor5-basic-styles/theme/code.css */
.ck-content code { code {
background-color: hsla(0, 0%, 78%, 0.3); background-color: hsla(0, 0%, 78%, 0.3);
padding: .15em; padding: .15em;
border-radius: 2px; border-radius: 2px;
} }
/* ckeditor5-image/theme/imagecaption.css */ /* ckeditor5-image/theme/imagecaption.css */
.ck-content .image > figcaption { .image > figcaption {
display: table-caption; display: table-caption;
caption-side: bottom; caption-side: bottom;
word-break: break-word; word-break: break-word;
@ -273,14 +266,14 @@
outline-offset: -1px; outline-offset: -1px;
} }
/* ckeditor5-horizontal-line/theme/horizontalline.css */ /* ckeditor5-horizontal-line/theme/horizontalline.css */
.ck-content hr { hr {
border-width: 1px 0 0; border-width: 1px 0 0;
border-style: solid; border-style: solid;
border-color: hsl(0, 0%, 37%); border-color: hsl(0, 0%, 37%);
margin: 0; margin: 0;
} }
/* ckeditor5-code-block/theme/codeblock.css */ /* ckeditor5-code-block/theme/codeblock.css */
.ck-content pre { pre {
padding: 1em; padding: 1em;
color: #353535; color: #353535;
background: hsla(0, 0%, 78%, 0.3); background: hsla(0, 0%, 78%, 0.3);
@ -294,24 +287,24 @@
min-width: 200px; min-width: 200px;
} }
/* ckeditor5-code-block/theme/codeblock.css */ /* ckeditor5-code-block/theme/codeblock.css */
.ck-content pre code { pre code {
background: unset; background: unset;
padding: 0; padding: 0;
border-radius: 0; border-radius: 0;
} }
.ck-content .ck-widget__selection-handle { .ck-widget__selection-handle {
display: none; display: none;
} }
@media print { @media print {
/* ckeditor5-page-break/theme/pagebreak.css */ /* ckeditor5-page-break/theme/pagebreak.css */
.ck-content .page-break { .page-break {
padding: 0; padding: 0;
} }
/* ckeditor5-page-break/theme/pagebreak.css */ /* ckeditor5-page-break/theme/pagebreak.css */
.ck-content .page-break::after { .page-break::after {
display: none; display: none;
} }
} }

View File

@ -146,7 +146,7 @@ async function printActiveNote() {
importCSS: false, importCSS: false,
loadCSS: [ loadCSS: [
"libraries/codemirror/codemirror.css", "libraries/codemirror/codemirror.css",
"libraries/ckeditor/ckeditor-print.css" "libraries/ckeditor/ckeditor-content.css"
], ],
debug: true debug: true
}); });

View File

@ -11,6 +11,8 @@ const packageInfo = require('../../../package.json');
const utils = require('../utils'); const utils = require('../utils');
const protectedSessionService = require('../protected_session'); const protectedSessionService = require('../protected_session');
const sanitize = require("sanitize-filename"); const sanitize = require("sanitize-filename");
const fs = require("fs");
const RESOURCE_DIR = require('../../services/resource_dir').RESOURCE_DIR;
/** /**
* @param {TaskContext} taskContext * @param {TaskContext} taskContext
@ -224,8 +226,13 @@ async function exportToTar(taskContext, branch, format, res) {
if (noteMeta.format === 'html') { if (noteMeta.format === 'html') {
if (!content.substr(0, 100).toLowerCase().includes("<html")) { if (!content.substr(0, 100).toLowerCase().includes("<html")) {
const cssUrl = "../".repeat(noteMeta.notePath.length - 1) + 'style.css';
content = `<html> content = `<html>
<head><meta charset="utf-8"></head> <head>
<meta charset="utf-8">
<link rel="stylesheet" href="${cssUrl}">
</head>
<body> <body>
<h1>${utils.escapeHtml(title)}</h1> <h1>${utils.escapeHtml(title)}</h1>
${content} ${content}
@ -323,7 +330,15 @@ ${content}
return html + '</li>'; return html + '</li>';
} }
const fullHtml = '<html><head><meta charset="utf-8"></head><body><ul>' + saveNavigationInner(rootMeta) + '</ul></body></html>' const fullHtml = `<html>
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css">
</head>
<body>
<ul>${saveNavigationInner(rootMeta)}</ul>
</body>
</html>`;
const prettyHtml = html.prettyPrint(fullHtml, {indent_size: 2}); const prettyHtml = html.prettyPrint(fullHtml, {indent_size: 2});
pack.entry({name: navigationMeta.dataFileName, size: prettyHtml.length}, prettyHtml); pack.entry({name: navigationMeta.dataFileName, size: prettyHtml.length}, prettyHtml);
@ -360,6 +375,12 @@ ${content}
pack.entry({name: indexMeta.dataFileName, size: fullHtml.length}, fullHtml); pack.entry({name: indexMeta.dataFileName, size: fullHtml.length}, fullHtml);
} }
function saveCss(rootMeta, cssMeta) {
const cssContent = fs.readFileSync(RESOURCE_DIR + '/libraries/ckeditor/ckeditor-content.css');
pack.entry({name: cssMeta.dataFileName, size: cssContent.length}, cssContent);
}
const existingFileNames = format === 'html' ? ['navigation', 'index'] : []; const existingFileNames = format === 'html' ? ['navigation', 'index'] : [];
const rootMeta = await getNoteMeta(branch, { notePath: [] }, existingFileNames); const rootMeta = await getNoteMeta(branch, { notePath: [] }, existingFileNames);
@ -369,7 +390,7 @@ ${content}
files: [ rootMeta ] files: [ rootMeta ]
}; };
let navigationMeta, indexMeta; let navigationMeta, indexMeta, cssMeta;
if (format === 'html') { if (format === 'html') {
navigationMeta = { navigationMeta = {
@ -385,6 +406,13 @@ ${content}
}; };
metaFile.files.push(indexMeta); metaFile.files.push(indexMeta);
cssMeta = {
noImport: true,
dataFileName: "style.css"
};
metaFile.files.push(cssMeta);
} }
for (const noteMeta of Object.values(noteIdToMeta)) { for (const noteMeta of Object.values(noteIdToMeta)) {
@ -406,6 +434,7 @@ ${content}
if (format === 'html') { if (format === 'html') {
saveNavigation(rootMeta, navigationMeta); saveNavigation(rootMeta, navigationMeta);
saveIndex(rootMeta, indexMeta); saveIndex(rootMeta, indexMeta);
saveCss(rootMeta, cssMeta);
} }
pack.finalize(); pack.finalize();