You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-23 22:36:32 +02:00
Desktop: Fixes #8485: Note imported from Web Clipper is broken after being saved from the Rich Text editor
This commit is contained in:
@@ -1,10 +1,6 @@
|
||||
import htmlUtils from './htmlUtils';
|
||||
import linkReplacement from './MdToHtml/linkReplacement';
|
||||
import utils, { ItemIdToUrlHandler } from './utils';
|
||||
|
||||
// TODO: fix
|
||||
// import Setting from '@joplin/lib/models/Setting';
|
||||
// const { themeStyle } = require('@joplin/lib/theme');
|
||||
import InMemoryCache from './InMemoryCache';
|
||||
import { RenderResult } from './MarkupToHtml';
|
||||
const md5 = require('md5');
|
||||
@@ -14,6 +10,11 @@ const md5 = require('md5');
|
||||
// relatively small.
|
||||
const inMemoryCache = new InMemoryCache(10);
|
||||
|
||||
export interface SplittedHtml {
|
||||
html: string;
|
||||
css: string;
|
||||
}
|
||||
|
||||
interface FsDriver {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types -- Old code before rule was applied
|
||||
writeFile: Function;
|
||||
@@ -79,19 +80,6 @@ export default class HtmlToHtml {
|
||||
return this.fsDriver_;
|
||||
}
|
||||
|
||||
public splitHtml(html: string) {
|
||||
const trimmedHtml = trimStart(html);
|
||||
if (trimmedHtml.indexOf('<style>') !== 0) return { html: html, css: '' };
|
||||
|
||||
const closingIndex = trimmedHtml.indexOf('</style>');
|
||||
if (closingIndex < 0) return { html: html, css: '' };
|
||||
|
||||
return {
|
||||
html: trimmedHtml.substr(closingIndex + 8),
|
||||
css: trimmedHtml.substr(7, closingIndex),
|
||||
};
|
||||
}
|
||||
|
||||
public async allAssets(/* theme*/): Promise<any[]> {
|
||||
return []; // TODO
|
||||
}
|
||||
@@ -166,7 +154,7 @@ export default class HtmlToHtml {
|
||||
let cssStrings: string[] = [];
|
||||
|
||||
if (options.splitted) {
|
||||
const splitted = this.splitHtml(html);
|
||||
const splitted = splitHtml(html);
|
||||
cssStrings = [splitted.css].concat(cssStrings);
|
||||
|
||||
const output: RenderResult = {
|
||||
@@ -191,3 +179,16 @@ export default class HtmlToHtml {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
const splitHtmlRegex = /^<style>([\s\S]*)<\/style>([\s\S]*)$/i;
|
||||
|
||||
// This function is designed to handle the narrow case of HTML generated by the
|
||||
// HtmlToHtml class and used by the Rich Text editor, and that's with the STYLE
|
||||
// tag at the top, followed by the HTML code. If it's anything else, we don't
|
||||
// try to handle it and return the whole HTML code.
|
||||
export const splitHtml = (html: string): SplittedHtml => {
|
||||
const trimmedHtml = trimStart(html);
|
||||
const result = trimmedHtml.match(splitHtmlRegex);
|
||||
if (!result) return { html, css: '' };
|
||||
return { html: result[2], css: result[1] };
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user