n8n-nodes-notion-advanced 1.2.21-beta → 1.2.22-beta

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.
@@ -43,12 +43,13 @@ export declare class NotionAITool implements INodeType {
43
43
  }[]): string;
44
44
  static getUtf8BytePosition(str: string, charIndex: number): number;
45
45
  static buildXMLTree(content: string, tagProcessors: any[]): XMLNode[];
46
- static processXMLTreeDepthFirst(nodes: XMLNode[], blocks: IDataObject[], placeholderPrefix: string, placeholderCounter: {
46
+ static processXMLTreeDepthFirst(nodes: XMLNode[], blocks: IDataObject[], placeholderCounter: {
47
47
  value: number;
48
48
  }): Map<string, string>;
49
49
  static applyHierarchicalReplacements(content: string, nodes: XMLNode[], replacements: Map<string, string>): string;
50
50
  static getAllNodesFromTree(nodes: XMLNode[]): XMLNode[];
51
51
  static processXmlTags(content: string, blocks: IDataObject[]): string;
52
+ static decodeHtmlEntities(content: string): string;
52
53
  static cleanupRemainingHtml(content: string, placeholderPrefix?: string): string;
53
54
  static processNestedHtmlInListItem(content: string): string;
54
55
  static convertInlineHtmlToMarkdown(content: string): string;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NotionAITool = void 0;
4
4
  const n8n_workflow_1 = require("n8n-workflow");
5
- const crypto_1 = require("crypto");
6
5
  const NotionUtils_1 = require("./NotionUtils");
7
6
  class NotionAITool {
8
7
  constructor() {
@@ -480,8 +479,8 @@ class NotionAITool {
480
479
  for (let i = 0; i < lines.length; i++) {
481
480
  const line = lines[i];
482
481
  const trimmedLine = line.trim();
483
- // Skip completely empty lines and XML placeholders (consistent format check)
484
- if (!trimmedLine || /__XML_[a-f0-9]{8}_\d+__/.test(trimmedLine))
482
+ // Skip completely empty lines and placeholder artifacts
483
+ if (!trimmedLine || /__BLOCK_\d+__/.test(trimmedLine) || /^\d+__$/.test(trimmedLine))
485
484
  continue;
486
485
  // Skip lines that contain XML tag patterns (to prevent double processing)
487
486
  const xmlTagPatterns = [
@@ -789,7 +788,7 @@ class NotionAITool {
789
788
  return rootNodes;
790
789
  }
791
790
  // Process XML tree depth-first (children before parents)
792
- static processXMLTreeDepthFirst(nodes, blocks, placeholderPrefix, placeholderCounter) {
791
+ static processXMLTreeDepthFirst(nodes, blocks, placeholderCounter) {
793
792
  const replacements = new Map();
794
793
  const processNode = (node) => {
795
794
  // First, process all children depth-first
@@ -834,14 +833,14 @@ class NotionAITool {
834
833
  // Handle special list processors
835
834
  if (node.listProcessor && (node.tagName === 'ul' || node.tagName === 'ol')) {
836
835
  node.listProcessor(innerContent, blocks);
837
- return `${placeholderPrefix}${placeholderCounter.value++}__`;
836
+ return `__BLOCK_${placeholderCounter.value++}__`;
838
837
  }
839
838
  // Use blockCreator to create the block
840
839
  const block = node.processor(...node.groups);
841
840
  if (block) {
842
841
  blocks.push(block);
843
842
  }
844
- return `${placeholderPrefix}${placeholderCounter.value++}__`;
843
+ return `__BLOCK_${placeholderCounter.value++}__`;
845
844
  }
846
845
  catch (error) {
847
846
  console.warn(`Error processing XML node ${node.tagName}:`, error);
@@ -887,10 +886,10 @@ class NotionAITool {
887
886
  // New hierarchical XML-like tag processing function
888
887
  static processXmlTags(content, blocks) {
889
888
  let processedContent = content;
890
- // Generate consistent placeholder format: __XML_{uuid8}_{counter}__
891
- const placeholderUuid = (0, crypto_1.randomUUID)().slice(0, 8);
892
- const placeholderPrefix = `__XML_${placeholderUuid}_`;
893
- let placeholderCounter = 0;
889
+ // First, decode HTML entities to proper XML tags
890
+ processedContent = NotionAITool.decodeHtmlEntities(processedContent);
891
+ // Use simple sequential placeholder format: __BLOCK_N__
892
+ let placeholderCounter = 1; // Start from 1 for cleaner numbering
894
893
  // Debug mode for development
895
894
  const DEBUG_ORDERING = process.env.NODE_ENV === 'development';
896
895
  // Define all tag processors
@@ -1154,12 +1153,12 @@ class NotionAITool {
1154
1153
  })));
1155
1154
  }
1156
1155
  // Step 2: Process tree depth-first (children before parents)
1157
- const counterRef = { value: 0 };
1158
- const replacements = NotionAITool.processXMLTreeDepthFirst(xmlTree, blocks, placeholderPrefix, counterRef);
1156
+ const counterRef = { value: 1 };
1157
+ const replacements = NotionAITool.processXMLTreeDepthFirst(xmlTree, blocks, counterRef);
1159
1158
  // Step 3: Apply hierarchical replacements to content
1160
1159
  processedContent = NotionAITool.applyHierarchicalReplacements(processedContent, xmlTree, replacements);
1161
1160
  // Step 4: Clean up any remaining HTML tags
1162
- processedContent = NotionAITool.cleanupRemainingHtml(processedContent, placeholderPrefix);
1161
+ processedContent = NotionAITool.cleanupRemainingHtml(processedContent);
1163
1162
  if (DEBUG_ORDERING) {
1164
1163
  console.log(`Processed ${xmlTree.length} root XML nodes hierarchically, created ${blocks.length} blocks`);
1165
1164
  }
@@ -1182,7 +1181,7 @@ class NotionAITool {
1182
1181
  if (block) {
1183
1182
  blocks.push(block);
1184
1183
  }
1185
- return `${placeholderPrefix}${placeholderCounter++}__`;
1184
+ return `__BLOCK_${placeholderCounter++}__`;
1186
1185
  }
1187
1186
  catch (error) {
1188
1187
  console.warn('Error in fallback processor:', error);
@@ -1207,10 +1206,27 @@ class NotionAITool {
1207
1206
  if (processedMatches.length > 0) {
1208
1207
  processedContent = NotionAITool.optimizedReplace(processedContent, processedMatches);
1209
1208
  }
1210
- processedContent = NotionAITool.cleanupRemainingHtml(processedContent, placeholderPrefix);
1209
+ processedContent = NotionAITool.cleanupRemainingHtml(processedContent);
1211
1210
  }
1212
1211
  return processedContent;
1213
1212
  }
1213
+ // Helper function to decode HTML entities
1214
+ static decodeHtmlEntities(content) {
1215
+ const entityMap = {
1216
+ '&lt;': '<',
1217
+ '&gt;': '>',
1218
+ '&amp;': '&',
1219
+ '&quot;': '"',
1220
+ '&apos;': "'",
1221
+ '&#39;': "'",
1222
+ '&nbsp;': ' ',
1223
+ };
1224
+ let decoded = content;
1225
+ Object.entries(entityMap).forEach(([entity, char]) => {
1226
+ decoded = decoded.replace(new RegExp(entity, 'g'), char);
1227
+ });
1228
+ return decoded;
1229
+ }
1214
1230
  // Cleanup function to remove remaining HTML tags and XML_BLOCK artifacts
1215
1231
  static cleanupRemainingHtml(content, placeholderPrefix) {
1216
1232
  let cleaned = content;
@@ -1221,9 +1237,17 @@ class NotionAITool {
1221
1237
  const placeholderPattern = new RegExp(`${escapedPrefix}\\d+__`, 'g');
1222
1238
  cleaned = cleaned.replace(placeholderPattern, '');
1223
1239
  }
1224
- // Single fallback cleanup for the standard format only
1225
- const standardPlaceholderPattern = /__XML_[a-f0-9]{8}_\d+__/g;
1226
- cleaned = cleaned.replace(standardPlaceholderPattern, '');
1240
+ // Comprehensive fallback cleanup for all possible placeholder formats
1241
+ const placeholderPatterns = [
1242
+ /__XML_[a-f0-9]{8}_\d+__/g, // Standard format: __XML_abc12345_1__
1243
+ /\b[A-Z]{2}[a-z0-9]{8,12}_+\b/g, // Variations like "MLb82d670450__"
1244
+ /\b[A-Za-z]{2,4}[a-f0-9]{6,12}_+\b/g, // More flexible pattern matching
1245
+ /_[a-f0-9]{8,12}_\d+_*/g, // Underscore variations
1246
+ /[a-f0-9]{8,12}_\d+__/g, // Without prefix
1247
+ ];
1248
+ placeholderPatterns.forEach(pattern => {
1249
+ cleaned = cleaned.replace(pattern, '');
1250
+ });
1227
1251
  // Remove entire lines containing XML content to prevent double processing
1228
1252
  const xmlContentLines = [
1229
1253
  /^.*<[^>]+>.*$/gm, // Any line with XML/HTML tags
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "n8n-nodes-notion-advanced",
3
- "version": "1.2.21-beta",
3
+ "version": "1.2.22-beta",
4
4
  "description": "Advanced n8n Notion nodes: Full-featured workflow node + AI Agent Tool for intelligent Notion automation with 25+ block types (BETA)",
5
5
  "scripts": {},
6
6
  "files": [