Skip to main content
Glama
normalizeBlock.ts1.31 kB
import type { Block, NormalizedBlock } from './types'; const removeMarkdownFormatting = (text: string): string => { return text .replace(/`{1,3}[^`]*`{1,3}/g, ' ') .replace(/\*\*([^*]+)\*\*/g, '$1') .replace(/\*([^*]+)\*/g, '$1') .replace(/_([^_]+)_/g, '$1') .replace(/~~([^~]+)~~/g, '$1') .replace(/!?\[[^\]]*\]\([^)]*\)/g, ' ') .replace(/^\s*#{1,6}\s+/gm, '') .replace(/^\s*>\s?/gm, '') .replace(/^\s*[-*+]\s+/gm, '') .replace(/^\s*\d+\.\s+/gm, ''); }; const collapseWhitespace = (text: string): string => text.replace(/\s+/g, ' ').trim(); const stripLettersKeepDigitsAndSymbols = (text: string): string => { // Keep digits and non-letter characters, remove all letters (including accents) return text.replace(/\p{L}+/gu, ''); }; export const normalizeBlock = (block: Block): NormalizedBlock => { const contentWithoutMarkdown = removeMarkdownFormatting(block.content); const semanticLowercased = contentWithoutMarkdown.toLowerCase(); const semanticCollapsed = collapseWhitespace(semanticLowercased); const anchorOnlySymbols = stripLettersKeepDigitsAndSymbols(block.content); const anchorCollapsed = collapseWhitespace(anchorOnlySymbols); return { ...block, semanticText: semanticCollapsed, anchorText: anchorCollapsed, }; };

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/aymericzip/intlayer'

If you have feedback or need assistance with the MCP directory API, please join our Discord server