mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 10:15:52 +01:00
feat(text-snippets): basic integration
This commit is contained in:
@@ -7,13 +7,14 @@ import { ensureMimeTypesForHighlighting, isSyntaxHighlightEnabled } from "../../
|
||||
import utils from "../../../services/utils.js";
|
||||
import emojiDefinitionsUrl from "@triliumnext/ckeditor5/emoji_definitions/en.json?url";
|
||||
import { copyTextWithToast } from "../../../services/clipboard_ext.js";
|
||||
import getTemplates from "./snippets.js";
|
||||
|
||||
const TEXT_FORMATTING_GROUP = {
|
||||
label: "Text formatting",
|
||||
icon: "text"
|
||||
};
|
||||
|
||||
export function buildConfig(): EditorConfig {
|
||||
export async function buildConfig(): Promise<EditorConfig> {
|
||||
return {
|
||||
image: {
|
||||
styles: {
|
||||
@@ -126,6 +127,9 @@ export function buildConfig(): EditorConfig {
|
||||
dropdownLimit: Number.MAX_SAFE_INTEGER,
|
||||
extraCommands: buildExtraCommands()
|
||||
},
|
||||
template: {
|
||||
definitions: await getTemplates()
|
||||
},
|
||||
// This value must be kept in sync with the language defined in webpack.config.js.
|
||||
language: "en"
|
||||
};
|
||||
|
||||
19
apps/client/src/widgets/type_widgets/ckeditor/snippets.ts
Normal file
19
apps/client/src/widgets/type_widgets/ckeditor/snippets.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import search from "../../../services/search";
|
||||
import type { TemplateDefinition } from "@triliumnext/ckeditor5";
|
||||
|
||||
/**
|
||||
* Generates the list of snippets based on the user's notes to be passed down to the CKEditor configuration.
|
||||
*
|
||||
* @returns the list of templates.
|
||||
*/
|
||||
export default async function getTemplates() {
|
||||
const definitions: TemplateDefinition[] = [];
|
||||
const snippets = await search.searchForNotes("#textSnippet");
|
||||
for (const snippet of snippets) {
|
||||
definitions.push({
|
||||
title: snippet.title,
|
||||
data: await snippet.getContent() ?? ""
|
||||
})
|
||||
}
|
||||
return definitions;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ export default class EditableTextTypeWidget extends AbstractTextTypeWidget {
|
||||
|
||||
const finalConfig = {
|
||||
...editorConfig,
|
||||
...buildConfig(),
|
||||
...(await buildConfig()),
|
||||
...buildToolbarConfig(isClassicEditor),
|
||||
htmlSupport: {
|
||||
allow: JSON.parse(options.get("allowedHtmlTags")),
|
||||
|
||||
Reference in New Issue
Block a user