diff --git a/lib/routes/gcores/parser.ts b/lib/routes/gcores/parser.ts index c30715462..815ba9bb0 100644 --- a/lib/routes/gcores/parser.ts +++ b/lib/routes/gcores/parser.ts @@ -3,14 +3,14 @@ import { getCurrentPath } from '@/utils/helpers'; import path from 'node:path'; -export const __dirname = getCurrentPath(import.meta.url); +const __dirname = getCurrentPath(import.meta.url); interface Style { [key: string]: string; } interface BlockType { - element: string; + element: string | undefined; parentElement?: string; aliasedElements?: string[]; } @@ -68,59 +68,31 @@ const BLOCK_TYPES: Readonly> = { 'unordered-list-item': { element: 'li', parentElement: 'ul' }, 'ordered-list-item': { element: 'li', parentElement: 'ol' }, blockquote: { element: 'blockquote' }, - atomic: { element: 'figure' }, + atomic: { element: undefined }, 'code-block': { element: 'pre' }, - unstyled: { element: 'div', aliasedElements: ['p'] }, + unstyled: { element: 'p' }, }; /** * Creates a styled HTML fragment for a given text and style object. - * @param text The text content of the fragment. - * @param style An object containing CSS styles (key-value pairs). - * @returns An HTML string representing the styled fragment. + * @param text - The text content. + * @param style - CSS styles as key-value pairs. + * @returns HTML string with applied styles. */ -const createStyledFragment = (text: string, style: Record): string => - `${text}`; - -/** - * Applies inline styles to a text string. - * @param text The text to style. - * @param inlineStyleRanges An array of inline style ranges. - * @returns The styled text. - */ -const applyStyles = (text: string, inlineStyleRanges: readonly InlineStyleRange[]): string => { - if (!inlineStyleRanges || inlineStyleRanges.length === 0) { - return text; - } - - const sortedRanges = [...inlineStyleRanges].sort((a, b) => a.offset - b.offset); - - let lastOffset = 0; - const styledFragments = sortedRanges.map((range) => { - const style = STYLES[range.style]; - if (!style) { - return text.substring(lastOffset, range.offset); - } - - const styledText = createStyledFragment(text.substring(range.offset, range.offset + range.length), style); - const preText = text.substring(lastOffset, range.offset); - lastOffset = range.offset + range.length; - return preText + styledText; - }); - let result = styledFragments.join(''); - result += text.substring(lastOffset); - return result; +const createStyledFragment = (text: string, style: Readonly