一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
47 行
1.6 KiB
TypeScript
47 行
1.6 KiB
TypeScript
import { FormNote } from './types';
|
|
import cleanMarkdownNbsp from './cleanMarkdownNbsp';
|
|
|
|
export { cleanMarkdownNbsp };
|
|
|
|
import HtmlToMd, { ParseOptions } from '@joplin/lib/HtmlToMd';
|
|
import Note from '@joplin/lib/models/Note';
|
|
import { MarkupToHtml } from '@joplin/renderer';
|
|
|
|
export async function htmlToMarkdown(markupLanguage: number, html: string, originalCss: string, parseOptions: ParseOptions = null): Promise<string> {
|
|
let newBody = '';
|
|
|
|
if (markupLanguage === MarkupToHtml.MARKUP_LANGUAGE_MARKDOWN) {
|
|
const htmlToMd = new HtmlToMd();
|
|
newBody = htmlToMd.parse(html, {
|
|
preserveImageTagsWithSize: true,
|
|
preserveNestedTables: true,
|
|
preserveTableStyles: true,
|
|
preserveColorStyles: true,
|
|
...parseOptions,
|
|
});
|
|
newBody = cleanMarkdownNbsp(newBody);
|
|
newBody = await Note.replaceResourceExternalToInternalLinks(newBody, { useAbsolutePaths: true });
|
|
} else {
|
|
newBody = await Note.replaceResourceExternalToInternalLinks(html, { useAbsolutePaths: true });
|
|
if (originalCss) newBody = `<style>${originalCss}</style>\n${newBody}`;
|
|
}
|
|
|
|
return newBody;
|
|
}
|
|
|
|
export async function formNoteToNote(formNote: FormNote) {
|
|
return {
|
|
id: formNote.id,
|
|
// Should also include parent_id and deleted_time so that the reducer
|
|
// can know in which folder the note should go when saving.
|
|
// https://discourse.joplinapp.org/t/experimental-wysiwyg-editor-in-joplin/6915/57?u=laurent
|
|
parent_id: formNote.parent_id,
|
|
deleted_time: formNote.deleted_time,
|
|
is_conflict: formNote.is_conflict,
|
|
title: formNote.title,
|
|
body: formNote.body,
|
|
is_locked: formNote.is_locked,
|
|
isDecrypted: formNote.isDecrypted,
|
|
};
|
|
}
|