import { useCallback } from 'react';
import { BlogOutlineSection } from '../services/blogWriterApi';
export const useMarkdownProcessor = (
outline: BlogOutlineSection[],
sections: Record$1
');
html = html.replace(/^## (.*$)/gim, '$1
');
html = html.replace(/^# (.*$)/gim, '$1
');
// Bold and Italic
html = html.replace(/\*\*(.+?)\*\*/g, '$1');
html = html.replace(/\*(.+?)\*/g, '$1');
// Links [text](url) - handle both http and data:image URLs
html = html.replace(/\[(.+?)\]\((.+?)\)/g, (match, text, url) => {
const safeUrl = url.replace(/"/g, '"');
if (url.startsWith('data:image') || url.startsWith('http')) {
return ``;
}
return `${text}`;
});
// Images  - explicit image syntax
html = html.replace(/!\[(.+?)\]\((.+?)\)/g, '
');
// Blockquotes
html = html.replace(/^> (.+)$/gm, '
$1
');
// Inline code
html = html.replace(/`(.+?)`/g, '$1');
// Horizontal rules
html = html.replace(/^-{3,}$/gm, '
');
// Unordered lists (- item or * item)
html = html.replace(/^[-*] (.+)$/gm, '
html = html.replace(/(
${match}
`;
});
// Ordered lists (1. item, 2. item, etc.)
html = html.replace(/^\d+\. (.+)$/gm, ' (simplified - assumes ordered lists come after unordered processing)
// Paragraphs (double newlines)
html = html.replace(/\n\n/g, '
'); html = `
${html}
`; // Clean up empty paragraphs html = html.replace(/<\/p>/g, ''); html = html.replace(/
( ( ( ( ( ()/g, '$1');
html = html.replace(/(<\/ul>)<\/p>/g, '$1');
html = html.replace(/
)/g, '$1');
html = html.replace(/(<\/ol>)<\/p>/g, '$1');
html = html.replace(/
)/g, '$1');
html = html.replace(/(<\/blockquote>)<\/p>/g, '$1');
html = html.replace(/
]*\/>)<\/p>/g, '$1');
html = html.replace(/ {
const fullMarkdown = buildFullMarkdown();
return fullMarkdown.split(/\s+/).filter(word => word.length > 0).length;
}, [buildFullMarkdown]);
const getSectionWordCount = useCallback((sectionId: string) => {
const content = sections[sectionId] || '';
return content.split(/\s+/).filter(word => word.length > 0).length;
}, [sections]);
const getOutlineStats = useCallback(() => {
const totalWords = getTotalWords();
const totalSections = outline.length;
const totalSubheadings = outline.reduce((sum, section) => sum + section.subheadings.length, 0);
const totalKeyPoints = outline.reduce((sum, section) => sum + section.key_points.length, 0);
return {
totalWords,
totalSections,
totalSubheadings,
totalKeyPoints,
averageWordsPerSection: totalSections > 0 ? Math.round(totalWords / totalSections) : 0
};
}, [outline, getTotalWords]);
return {
buildFullMarkdown,
convertMarkdownToHTML,
getTotalWords,
getSectionWordCount,
getOutlineStats
};
};