{"version":3,"file":"normalizeBlock.mjs","names":[],"sources":["../../../src/docReview/normalizeBlock.ts"],"sourcesContent":["import type { Block, NormalizedBlock } from './types';\n\nconst removeMarkdownFormatting = (text: string): string => {\n  return text\n    .replace(/`{1,3}[^`]*`{1,3}/g, ' ')\n    .replace(/\\*\\*([^*]+)\\*\\*/g, '$1')\n    .replace(/\\*([^*]+)\\*/g, '$1')\n    .replace(/_([^_]+)_/g, '$1')\n    .replace(/~~([^~]+)~~/g, '$1')\n    .replace(/!?\\[[^\\]]*\\]\\([^)]*\\)/g, ' ')\n    .replace(/^\\s*#{1,6}\\s+/gm, '')\n    .replace(/^\\s*>\\s?/gm, '')\n    .replace(/^\\s*[-*+]\\s+/gm, '')\n    .replace(/^\\s*\\d+\\.\\s+/gm, '');\n};\n\nconst collapseWhitespace = (text: string): string =>\n  text.replace(/\\s+/g, ' ').trim();\n\nconst stripLettersKeepDigitsAndSymbols = (text: string): string => {\n  // Keep digits and non-letter characters, remove all letters (including accents)\n  return text.replace(/\\p{L}+/gu, '');\n};\n\n/**\n * Derive the normalized representations of a block used for matching.\n *\n * - `semanticText`: markdown-stripped, lower-cased text (used to detect identical\n *   content across versions of the same language).\n * - `anchorText`: only digits/symbols (used to align blocks across languages, as\n *   prose differs but structure such as numbers and punctuation is preserved).\n *\n * @param block - The block to normalize.\n * @returns The block enriched with its normalized texts.\n */\nexport const normalizeBlock = (block: Block): NormalizedBlock => {\n  const contentWithoutMarkdown = removeMarkdownFormatting(block.content);\n  const semanticLowercased = contentWithoutMarkdown.toLowerCase();\n  const semanticCollapsed = collapseWhitespace(semanticLowercased);\n\n  const anchorOnlySymbols = stripLettersKeepDigitsAndSymbols(block.content);\n  const anchorCollapsed = collapseWhitespace(anchorOnlySymbols);\n\n  return {\n    ...block,\n    semanticText: semanticCollapsed,\n    anchorText: anchorCollapsed,\n  };\n};\n"],"mappings":";AAEA,MAAM,4BAA4B,SAAyB;CACzD,OAAO,KACJ,QAAQ,sBAAsB,GAAG,CAAC,CAClC,QAAQ,oBAAoB,IAAI,CAAC,CACjC,QAAQ,gBAAgB,IAAI,CAAC,CAC7B,QAAQ,cAAc,IAAI,CAAC,CAC3B,QAAQ,gBAAgB,IAAI,CAAC,CAC7B,QAAQ,0BAA0B,GAAG,CAAC,CACtC,QAAQ,mBAAmB,EAAE,CAAC,CAC9B,QAAQ,cAAc,EAAE,CAAC,CACzB,QAAQ,kBAAkB,EAAE,CAAC,CAC7B,QAAQ,kBAAkB,EAAE;AACjC;AAEA,MAAM,sBAAsB,SAC1B,KAAK,QAAQ,QAAQ,GAAG,CAAC,CAAC,KAAK;AAEjC,MAAM,oCAAoC,SAAyB;CAEjE,OAAO,KAAK,QAAQ,YAAY,EAAE;AACpC;;;;;;;;;;;;AAaA,MAAa,kBAAkB,UAAkC;CAE/D,MAAM,qBADyB,yBAAyB,MAAM,OACd,CAAC,CAAC,YAAY;CAC9D,MAAM,oBAAoB,mBAAmB,kBAAkB;CAE/D,MAAM,oBAAoB,iCAAiC,MAAM,OAAO;CACxE,MAAM,kBAAkB,mBAAmB,iBAAiB;CAE5D,OAAO;EACL,GAAG;EACH,cAAc;EACd,YAAY;CACd;AACF"}