mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Desktop, CLI: When exporting as HTML, pack all images, styles and scripts inside the HTML file
This commit is contained in:
parent
2b66759e3a
commit
98ed2be518
172
packages/htmlpack/package-lock.json
generated
172
packages/htmlpack/package-lock.json
generated
@ -1,15 +1,14 @@
|
||||
{
|
||||
"name": "@joplin/htmlpack",
|
||||
"version": "1.0.1",
|
||||
"version": "2.6",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "@joplin/htmlpack",
|
||||
"version": "1.0.0",
|
||||
"version": "2.6",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@joplin/fork-htmlparser2": "^4.1.34",
|
||||
"css": "^3.0.0",
|
||||
"datauri": "^4.1.0",
|
||||
"fs-extra": "^10.0.0",
|
||||
@ -45,17 +44,6 @@
|
||||
"typescript": "^3.5.3"
|
||||
}
|
||||
},
|
||||
"node_modules/@joplin/fork-htmlparser2": {
|
||||
"version": "4.1.34",
|
||||
"resolved": "https://registry.npmjs.org/@joplin/fork-htmlparser2/-/fork-htmlparser2-4.1.34.tgz",
|
||||
"integrity": "sha512-1/tQZEDnI36RaEJte0eumw1/c8OhmJOpgFyW+Nxsk2u/vvcgnEvjFjauiH2ZxtO5FTJB3BMQ4M23+Y5dw2cnnw==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.0.1",
|
||||
"domhandler": "^3.0.0",
|
||||
"domutils": "^2.0.0",
|
||||
"entities": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"node_modules/@types/fs-extra": {
|
||||
"version": "9.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz",
|
||||
@ -112,93 +100,6 @@
|
||||
"node": ">=0.10"
|
||||
}
|
||||
},
|
||||
"node_modules/dom-serializer": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-1.3.2.tgz",
|
||||
"integrity": "sha512-5c54Bk5Dw4qAxNOI1pFEizPSjVsx5+bpJKmL2kPn8JhBUq2q09tTCa3mjijun2NfK78NMouDYNMBkOrPZiS+ig==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.0.1",
|
||||
"domhandler": "^4.2.0",
|
||||
"entities": "^2.0.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/cheeriojs/dom-serializer?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/dom-serializer/node_modules/domhandler": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.2.tgz",
|
||||
"integrity": "sha512-PzE9aBMsdZO8TK4BnuJwH0QT41wgMbRzuZrHUcpYncEjmQazq8QEaBWgLG7ZyC/DAZKEgglpIA6j4Qn/HmxS3w==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domhandler?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/domelementtype": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.2.0.tgz",
|
||||
"integrity": "sha512-DtBMo82pv1dFtUmHyr48beiuq792Sxohr+8Hm9zoxklYPfa6n0Z3Byjj2IV7bmr2IyqClnqEQhfgHJJ5QF0R5A==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/fb55"
|
||||
}
|
||||
]
|
||||
},
|
||||
"node_modules/domhandler": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-3.3.0.tgz",
|
||||
"integrity": "sha512-J1C5rIANUbuYK+FuFL98650rihynUOEzRLxW+90bKZRWB6A1X1Tf82GxR1qAWLyfNPRvjqfip3Q5tdYlmAa9lA==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.0.1"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domhandler?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/domutils": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz",
|
||||
"integrity": "sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==",
|
||||
"dependencies": {
|
||||
"dom-serializer": "^1.0.1",
|
||||
"domelementtype": "^2.2.0",
|
||||
"domhandler": "^4.2.0"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domutils?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/domutils/node_modules/domhandler": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.2.tgz",
|
||||
"integrity": "sha512-PzE9aBMsdZO8TK4BnuJwH0QT41wgMbRzuZrHUcpYncEjmQazq8QEaBWgLG7ZyC/DAZKEgglpIA6j4Qn/HmxS3w==",
|
||||
"dependencies": {
|
||||
"domelementtype": "^2.2.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 4"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/domhandler?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/entities": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
|
||||
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A==",
|
||||
"funding": {
|
||||
"url": "https://github.com/fb55/entities?sponsor=1"
|
||||
}
|
||||
},
|
||||
"node_modules/fs-extra": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz",
|
||||
@ -298,17 +199,6 @@
|
||||
}
|
||||
},
|
||||
"dependencies": {
|
||||
"@joplin/fork-htmlparser2": {
|
||||
"version": "4.1.34",
|
||||
"resolved": "https://registry.npmjs.org/@joplin/fork-htmlparser2/-/fork-htmlparser2-4.1.34.tgz",
|
||||
"integrity": "sha512-1/tQZEDnI36RaEJte0eumw1/c8OhmJOpgFyW+Nxsk2u/vvcgnEvjFjauiH2ZxtO5FTJB3BMQ4M23+Y5dw2cnnw==",
|
||||
"requires": {
|
||||
"domelementtype": "^2.0.1",
|
||||
"domhandler": "^3.0.0",
|
||||
"domutils": "^2.0.0",
|
||||
"entities": "^2.0.0"
|
||||
}
|
||||
},
|
||||
"@types/fs-extra": {
|
||||
"version": "9.0.13",
|
||||
"resolved": "https://registry.npmjs.org/@types/fs-extra/-/fs-extra-9.0.13.tgz",
|
||||
@ -353,64 +243,6 @@
|
||||
"resolved": "https://registry.npmjs.org/decode-uri-component/-/decode-uri-component-0.2.0.tgz",
|
||||
"integrity": "sha1-6zkTMzRYd1y4TNGh+uBiEGu4dUU="
|
||||
},
|
||||
"dom-serializer": {
|
||||
"version": "1.3.2",
|
||||
"resolved": "https://registry.npmjs.org/dom-serializer/-/dom-serializer-1.3.2.tgz",
|
||||
"integrity": "sha512-5c54Bk5Dw4qAxNOI1pFEizPSjVsx5+bpJKmL2kPn8JhBUq2q09tTCa3mjijun2NfK78NMouDYNMBkOrPZiS+ig==",
|
||||
"requires": {
|
||||
"domelementtype": "^2.0.1",
|
||||
"domhandler": "^4.2.0",
|
||||
"entities": "^2.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"domhandler": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.2.tgz",
|
||||
"integrity": "sha512-PzE9aBMsdZO8TK4BnuJwH0QT41wgMbRzuZrHUcpYncEjmQazq8QEaBWgLG7ZyC/DAZKEgglpIA6j4Qn/HmxS3w==",
|
||||
"requires": {
|
||||
"domelementtype": "^2.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"domelementtype": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/domelementtype/-/domelementtype-2.2.0.tgz",
|
||||
"integrity": "sha512-DtBMo82pv1dFtUmHyr48beiuq792Sxohr+8Hm9zoxklYPfa6n0Z3Byjj2IV7bmr2IyqClnqEQhfgHJJ5QF0R5A=="
|
||||
},
|
||||
"domhandler": {
|
||||
"version": "3.3.0",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-3.3.0.tgz",
|
||||
"integrity": "sha512-J1C5rIANUbuYK+FuFL98650rihynUOEzRLxW+90bKZRWB6A1X1Tf82GxR1qAWLyfNPRvjqfip3Q5tdYlmAa9lA==",
|
||||
"requires": {
|
||||
"domelementtype": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"domutils": {
|
||||
"version": "2.8.0",
|
||||
"resolved": "https://registry.npmjs.org/domutils/-/domutils-2.8.0.tgz",
|
||||
"integrity": "sha512-w96Cjofp72M5IIhpjgobBimYEfoPjx1Vx0BSX9P30WBdZW2WIKU0T1Bd0kz2eNZ9ikjKgHbEyKx8BB6H1L3h3A==",
|
||||
"requires": {
|
||||
"dom-serializer": "^1.0.1",
|
||||
"domelementtype": "^2.2.0",
|
||||
"domhandler": "^4.2.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"domhandler": {
|
||||
"version": "4.2.2",
|
||||
"resolved": "https://registry.npmjs.org/domhandler/-/domhandler-4.2.2.tgz",
|
||||
"integrity": "sha512-PzE9aBMsdZO8TK4BnuJwH0QT41wgMbRzuZrHUcpYncEjmQazq8QEaBWgLG7ZyC/DAZKEgglpIA6j4Qn/HmxS3w==",
|
||||
"requires": {
|
||||
"domelementtype": "^2.2.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"entities": {
|
||||
"version": "2.2.0",
|
||||
"resolved": "https://registry.npmjs.org/entities/-/entities-2.2.0.tgz",
|
||||
"integrity": "sha512-p92if5Nz619I0w+akJrLZH0MX0Pb5DX39XOwQTtXSdQQOaYH03S1uIQp4mhOZtAXrxq4ViO67YTiLBo2638o9A=="
|
||||
},
|
||||
"fs-extra": {
|
||||
"version": "10.0.0",
|
||||
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.0.0.tgz",
|
||||
|
@ -1,9 +1,12 @@
|
||||
{
|
||||
"name": "@joplin/htmlpack",
|
||||
"version": "1.0.1",
|
||||
"version": "2.6.0",
|
||||
"description": "Pack an HTML file and all its linked resources into a single HTML file",
|
||||
"main": "dist/index.js",
|
||||
"private": true,
|
||||
"types": "src/index.ts",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
"scripts": {
|
||||
"tsc": "tsc --project tsconfig.json",
|
||||
"watch": "tsc --watch --project tsconfig.json"
|
||||
|
@ -137,7 +137,7 @@ function dirname(path: string) {
|
||||
return s.join('/');
|
||||
}
|
||||
|
||||
export default async function htmlpack(inputFile: string, outputFile: string) {
|
||||
export default async function htmlpack(inputFile: string, outputFile: string): Promise<void> {
|
||||
const inputHtml = await fs.readFile(inputFile, 'utf8');
|
||||
const baseDir = dirname(inputFile);
|
||||
|
||||
|
2
packages/lib/package-lock.json
generated
2
packages/lib/package-lock.json
generated
@ -7,7 +7,7 @@
|
||||
"": {
|
||||
"name": "@joplin/lib",
|
||||
"version": "2.6.2",
|
||||
"license": "ISC",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"async-mutex": "^0.1.3",
|
||||
"aws-sdk": "^2.588.0",
|
||||
|
@ -4,7 +4,7 @@
|
||||
"description": "Joplin Core library",
|
||||
"author": "Laurent Cozic",
|
||||
"homepage": "",
|
||||
"license": "ISC",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"access": "public"
|
||||
},
|
||||
@ -30,7 +30,8 @@
|
||||
"dependencies": {
|
||||
"@joplin/fork-htmlparser2": "^4.1.38",
|
||||
"@joplin/fork-sax": "^1.2.42",
|
||||
"@joplin/renderer": "^2.6.2",
|
||||
"@joplin/renderer": "~2.6",
|
||||
"@joplin/htmlpack": "~2.6",
|
||||
"@joplin/turndown": "^4.0.60",
|
||||
"@joplin/turndown-plugin-gfm": "^1.0.42",
|
||||
"async-mutex": "^0.1.3",
|
||||
|
@ -9,6 +9,7 @@ import { MarkupToHtml } from '@joplin/renderer';
|
||||
import { ResourceEntity } from '../database/types';
|
||||
import { contentScriptsToRendererRules } from '../plugins/utils/loadContentScripts';
|
||||
import { basename, friendlySafeFilename, rtrimSlashes, dirname } from '../../path-utils';
|
||||
import htmlpack from '@joplin/htmlpack';
|
||||
const { themeStyle } = require('../../theme');
|
||||
const { escapeHtml } = require('../../string-utils.js');
|
||||
const { assetsToHeaders } = require('@joplin/renderer');
|
||||
@ -23,6 +24,7 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
||||
private markupToHtml_: MarkupToHtml;
|
||||
private resources_: ResourceEntity[] = [];
|
||||
private style_: any;
|
||||
private packIntoSingleFile_: boolean = false;
|
||||
|
||||
async init(path: string, options: any = {}) {
|
||||
this.customCss_ = options.customCss ? options.customCss : '';
|
||||
@ -30,6 +32,7 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
||||
if (this.metadata().target === 'file') {
|
||||
this.destDir_ = dirname(path);
|
||||
this.filePath_ = path;
|
||||
this.packIntoSingleFile_ = true;
|
||||
} else {
|
||||
this.destDir_ = path;
|
||||
this.filePath_ = null;
|
||||
@ -118,7 +121,9 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
||||
const asset = result.pluginAssets[i];
|
||||
const filePath = asset.pathIsAbsolute ? asset.path : `${libRootPath}/node_modules/@joplin/renderer/assets/${asset.name}`;
|
||||
const destPath = `${dirname(noteFilePath)}/pluginAssets/${asset.name}`;
|
||||
await shim.fsDriver().mkdir(dirname(destPath));
|
||||
const dir = dirname(destPath);
|
||||
await shim.fsDriver().mkdir(dir);
|
||||
this.createdDirs_.push(dir);
|
||||
await shim.fsDriver().copy(filePath, destPath);
|
||||
}
|
||||
|
||||
@ -147,5 +152,20 @@ export default class InteropService_Exporter_Html extends InteropService_Exporte
|
||||
this.resources_.push(resource);
|
||||
}
|
||||
|
||||
async close() {}
|
||||
public async close() {
|
||||
if (this.packIntoSingleFile_) {
|
||||
const tempFilePath = `${this.filePath_}.tmp`;
|
||||
await shim.fsDriver().move(this.filePath_, tempFilePath);
|
||||
await htmlpack(tempFilePath, this.filePath_);
|
||||
await shim.fsDriver().remove(tempFilePath);
|
||||
|
||||
for (const d of this.createdDirs_) {
|
||||
await shim.fsDriver().remove(d);
|
||||
}
|
||||
|
||||
await shim.fsDriver().remove(this.resourceDir_);
|
||||
await shim.fsDriver().remove(`${this.destDir_}/pluginAssets`);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -118,13 +118,14 @@ async function main() {
|
||||
|
||||
if (!options.updateDependenciesVersion && !options.updateVersion) throw new Error('Nothing to do!');
|
||||
|
||||
await updatePackageVersion(`${rootDir}/packages/app-desktop/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/app-cli/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/app-desktop/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/generator-joplin/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/server/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/plugin-repo-cli/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/htmlpack/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/lib/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/plugin-repo-cli/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/renderer/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/server/package.json`, majorMinorVersion, options);
|
||||
await updatePackageVersion(`${rootDir}/packages/tools/package.json`, majorMinorVersion, options);
|
||||
|
||||
if (options.updateVersion) {
|
||||
|
Loading…
Reference in New Issue
Block a user