@paroicms/tiptap-editor-plugin 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- import { stripHtmlTags } from "@paroicms/public-server-lib";
1
+ import { escapeHtml, stripHtmlTags } from "@paroicms/public-server-lib";
2
2
  import { Mark } from "@tiptap/core";
3
3
  import Code from "@tiptap/extension-code";
4
4
  import CodeBlockLowlight from "@tiptap/extension-code-block-lowlight";
@@ -53,46 +53,14 @@ export async function convertTiptapJsonToHtml(service, json, options) {
53
53
  const processedJson = addTargetBlankToLinks(service, json);
54
54
  const mediaMap = await preloadMediaImages(service, processedJson, options);
55
55
  const documentMap = await preloadInternalLinkDocuments(service, processedJson, options);
56
- const hasCodeInConf = service.pluginService.configuration.adminUi?.code ?? false;
57
56
  const usedLanguages = collectCodeBlockLanguages(processedJson);
58
57
  if (usedLanguages.size > 0) {
59
58
  service.setRenderState("paTiptapEditor:languages", Array.from(usedLanguages));
60
59
  }
61
- const extensions = [
62
- StarterKit.configure({
63
- code: hasCodeInConf ? false : undefined,
64
- codeBlock: hasCodeInConf ? false : undefined,
65
- }),
66
- ...(hasCodeInConf ? [Code, CodeBlockLowlight] : []),
67
- TextAlign.configure({
68
- types: ["heading", "paragraph"],
69
- defaultAlignment: undefined,
70
- }),
71
- TextStyle,
72
- TextSize,
73
- Subscript,
74
- Superscript,
75
- createMediaNodeBackend(service, mediaMap),
76
- createHtmlSnippetNodeBackend(),
77
- createObfuscateMarkBackend(),
78
- createPlatformVideoNodeBackend(),
79
- createInternalLinkNodeBackend(service, documentMap, options),
80
- ];
81
- const html = renderToHTMLString({
82
- content: processedJson,
83
- extensions,
84
- options: {
85
- nodeMapping: {
86
- htmlSnippet: ({ node }) => {
87
- return node.attrs.html || "";
88
- },
89
- },
90
- markMapping: {
91
- obfuscate: createObfuscateMarkRenderer(),
92
- },
93
- },
60
+ return renderTiptapToHtml(processedJson, service, mediaMap, documentMap, {
61
+ includeObfuscateMarkMapping: true,
62
+ renderingOptions: options,
94
63
  });
95
- return html;
96
64
  }
97
65
  function addTargetBlankToLinks(service, json) {
98
66
  if (!json.content)
@@ -135,31 +103,10 @@ function addTargetBlankToLinks(service, json) {
135
103
  }
136
104
  export function convertTiptapJsonToPlainText(service, json) {
137
105
  const cleanedJson = removeObfuscatedText(json);
138
- const hasCodeInConf = service.pluginService.configuration.adminUi?.code ?? false;
139
106
  const emptyMediaMap = new Map();
140
107
  const emptyDocumentMap = new Map();
141
- const extensions = [
142
- StarterKit.configure({
143
- code: hasCodeInConf ? false : undefined,
144
- codeBlock: hasCodeInConf ? false : undefined,
145
- }),
146
- ...(hasCodeInConf ? [Code, CodeBlockLowlight] : []),
147
- TextAlign.configure({
148
- types: ["heading", "paragraph"],
149
- defaultAlignment: undefined,
150
- }),
151
- TextStyle,
152
- TextSize,
153
- Subscript,
154
- Superscript,
155
- createMediaNodeBackend(service, emptyMediaMap),
156
- createHtmlSnippetNodeBackend(),
157
- createPlatformVideoNodeBackend(),
158
- createInternalLinkNodeBackend(service, emptyDocumentMap),
159
- ];
160
- const html = renderToHTMLString({
161
- content: cleanedJson,
162
- extensions,
108
+ const html = renderTiptapToHtml(cleanedJson, service, emptyMediaMap, emptyDocumentMap, {
109
+ includeObfuscateMarkMapping: false,
163
110
  });
164
111
  return stripHtmlTags(html, { blockSeparator: " – " });
165
112
  }
@@ -209,3 +156,41 @@ function collectCodeBlockLanguages(json) {
209
156
  traverse(json.content);
210
157
  return languages;
211
158
  }
159
+ function renderTiptapToHtml(json, service, mediaMap, documentMap, options) {
160
+ const hasCodeInConf = service.pluginService.configuration.adminUi?.code ?? false;
161
+ const extensions = [
162
+ StarterKit.configure({
163
+ code: hasCodeInConf ? false : undefined,
164
+ codeBlock: hasCodeInConf ? false : undefined,
165
+ }),
166
+ ...(hasCodeInConf ? [Code, CodeBlockLowlight] : []),
167
+ TextAlign.configure({
168
+ types: ["heading", "paragraph"],
169
+ defaultAlignment: undefined,
170
+ }),
171
+ TextStyle,
172
+ TextSize,
173
+ Subscript,
174
+ Superscript,
175
+ createMediaNodeBackend(service, mediaMap),
176
+ createHtmlSnippetNodeBackend(),
177
+ createObfuscateMarkBackend(),
178
+ createPlatformVideoNodeBackend(),
179
+ createInternalLinkNodeBackend(service, documentMap, options.renderingOptions),
180
+ ];
181
+ return renderToHTMLString({
182
+ content: json,
183
+ extensions,
184
+ options: {
185
+ nodeMapping: {
186
+ htmlSnippet: ({ node }) => node.attrs?.html ?? "",
187
+ text: ({ node }) => escapeHtml(node.text ?? ""),
188
+ },
189
+ markMapping: options.includeObfuscateMarkMapping
190
+ ? {
191
+ obfuscate: createObfuscateMarkRenderer(),
192
+ }
193
+ : undefined,
194
+ },
195
+ });
196
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/tiptap-editor-plugin",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Tiptap editor plugin for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -47,7 +47,7 @@
47
47
  },
48
48
  "devDependencies": {
49
49
  "@paroicms/public-anywhere-lib": "0.37.1",
50
- "@paroicms/public-server-lib": "0.47.1",
50
+ "@paroicms/public-server-lib": "0.47.2",
51
51
  "@types/node": "~24.8.1",
52
52
  "rimraf": "~6.0.1",
53
53
  "sass": "~1.93.2",