1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-01 19:15:01 +02:00

Desktop: By default disable pasting colors in RTE, and added option to enable it

This commit is contained in:
Laurent Cozic 2024-11-09 23:58:15 +00:00
parent de83b42972
commit e16f452bdf
4 changed files with 16 additions and 4 deletions

View File

@ -1,11 +1,11 @@
import { FormNote } from './types'; import { FormNote } from './types';
import HtmlToMd from '@joplin/lib/HtmlToMd'; import HtmlToMd, { ParseOptions } from '@joplin/lib/HtmlToMd';
import Note from '@joplin/lib/models/Note'; import Note from '@joplin/lib/models/Note';
import { NoteEntity } from '@joplin/lib/services/database/types'; import { NoteEntity } from '@joplin/lib/services/database/types';
const { MarkupToHtml } = require('@joplin/renderer'); const { MarkupToHtml } = require('@joplin/renderer');
export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string): Promise<string> { export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string, parseOptions: ParseOptions = null): Promise<string> {
let newBody = ''; let newBody = '';
if (markupLanguage === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN) { if (markupLanguage === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN) {
@ -14,6 +14,7 @@ export async function htmlToMarkdown(markupLanguage: number, html: string, origi
preserveImageTagsWithSize: true, preserveImageTagsWithSize: true,
preserveNestedTables: true, preserveNestedTables: true,
preserveColorStyles: true, preserveColorStyles: true,
...parseOptions,
}); });
newBody = await Note.replaceResourceExternalToInternalLinks(newBody, { useAbsolutePaths: true }); newBody = await Note.replaceResourceExternalToInternalLinks(newBody, { useAbsolutePaths: true });
} else { } else {

View File

@ -180,7 +180,7 @@ export async function processPastedHtml(html: string, htmlToMd: HtmlToMarkdownHa
// TinyMCE, but lost once the note is saved. So here we convert the HTML to Markdown then back // TinyMCE, but lost once the note is saved. So here we convert the HTML to Markdown then back
// to HTML to ensure that the content we paste will be handled correctly by the app. // to HTML to ensure that the content we paste will be handled correctly by the app.
if (htmlToMd && mdToHtml) { if (htmlToMd && mdToHtml) {
const md = await htmlToMd(MarkupLanguage.Markdown, html, ''); const md = await htmlToMd(MarkupLanguage.Markdown, html, '', { preserveColorStyles: Setting.value('editor.pastePreserveColors') });
html = (await mdToHtml(MarkupLanguage.Markdown, md, markupRenderOptions({ bodyOnly: true }))).html; html = (await mdToHtml(MarkupLanguage.Markdown, md, markupRenderOptions({ bodyOnly: true }))).html;
// When plugins that add to the end of rendered content are installed, bodyOnly can // When plugins that add to the end of rendered content are installed, bodyOnly can

View File

@ -7,6 +7,7 @@ import { Dispatch } from 'redux';
import { ProcessResultsRow } from '@joplin/lib/services/search/SearchEngine'; import { ProcessResultsRow } from '@joplin/lib/services/search/SearchEngine';
import { DropHandler } from './useDropHandler'; import { DropHandler } from './useDropHandler';
import { SearchMarkers } from './useSearchMarkers'; import { SearchMarkers } from './useSearchMarkers';
import { ParseOptions } from '@joplin/lib/HtmlToMd';
export interface AllAssetsOptions { export interface AllAssetsOptions {
contentMaxWidthTarget?: string; contentMaxWidthTarget?: string;
@ -85,7 +86,7 @@ export interface MarkupToHtmlOptions {
} }
export type MarkupToHtmlHandler = (markupLanguage: MarkupLanguage, markup: string, options: MarkupToHtmlOptions)=> Promise<RenderResult>; export type MarkupToHtmlHandler = (markupLanguage: MarkupLanguage, markup: string, options: MarkupToHtmlOptions)=> Promise<RenderResult>;
export type HtmlToMarkdownHandler = (markupLanguage: number, html: string, originalCss: string)=> Promise<string>; export type HtmlToMarkdownHandler = (markupLanguage: number, html: string, originalCss: string, parseOptions?: ParseOptions)=> Promise<string>;
export interface NoteBodyEditorProps { export interface NoteBodyEditorProps {
// eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied // eslint-disable-next-line @typescript-eslint/no-explicit-any -- Old code before rule was applied

View File

@ -658,6 +658,16 @@ const builtInMetadata = (Setting: typeof SettingType) => {
storage: SettingStorage.File, storage: SettingStorage.File,
isGlobal: true, isGlobal: true,
}, },
'editor.pastePreserveColors': {
value: false,
type: SettingItemType.Bool,
public: true,
section: 'note',
appTypes: [AppType.Desktop],
label: () => _('Preserve colours when pasting text in Rich Text Editor'),
storage: SettingStorage.File,
isGlobal: true,
},
'notes.columns': { 'notes.columns': {
value: defaultListColumns(), value: defaultListColumns(),
public: false, public: false,