PartnerUI evidence, notification, indicators and actuals fixes

This commit is contained in:
2026-10-26 08:53:05 +02:00
parent 5ac317cbe3
commit bb77a4dc9a
10 changed files with 1290 additions and 302 deletions
@@ -149,3 +149,79 @@ export function parseMarkdownToHtml(markdown: string): string {
return html;
}
/**
* Converts formatted HTML from WYSIWYG composition into clean, semantic Markdown.
* Preserves headings, bold, italic, blockquotes, lists, dividers, and links.
*/
export function htmlToMarkdown(html: string): string {
if (!html) return '';
let md = html
.replace(/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi, '')
.replace(/<style\b[^<]*(?:(?!<\/style>)<[^<]*)*<\/style>/gi, '');
// Line breaks & paragraph breaks
md = md.replace(/<br\s*\/?>/gi, '\n');
md = md.replace(/<\/p>/gi, '\n\n');
md = md.replace(/<p[^>]*>/gi, '');
// Headers
md = md.replace(/<h1[^>]*>(.*?)<\/h1>/gis, '# $1\n\n');
md = md.replace(/<h2[^>]*>(.*?)<\/h2>/gis, '## $1\n\n');
md = md.replace(/<h3[^>]*>(.*?)<\/h3>/gis, '### $1\n\n');
md = md.replace(/<h4[^>]*>(.*?)<\/h4>/gis, '#### $1\n\n');
// Bold / Italic / Underline
md = md.replace(/<(strong|b)[^>]*>(.*?)<\/\1>/gis, '**$2**');
md = md.replace(/<(em|i)[^>]*>(.*?)<\/\1>/gis, '*$2*');
md = md.replace(/<u[^>]*>(.*?)<\/u>/gis, '$1');
// Blockquote
md = md.replace(/<blockquote[^>]*>(.*?)<\/blockquote>/gis, (_match, p1) => {
return (
p1
.trim()
.split('\n')
.map((l: string) => `> ${l.trim()}`)
.join('\n') + '\n\n'
);
});
// Unordered Lists
md = md.replace(/<ul[^>]*>(.*?)<\/ul>/gis, (_match, p1) => {
return p1.replace(/<li[^>]*>(.*?)<\/li>/gis, '- $1\n') + '\n';
});
// Ordered Lists
md = md.replace(/<ol[^>]*>(.*?)<\/ol>/gis, (_match, p1) => {
let index = 1;
return p1.replace(/<li[^>]*>(.*?)<\/li>/gis, () => `${index++}. $1\n`) + '\n';
});
// Horizontal Rules
md = md.replace(/<hr\s*\/?>/gi, '\n---\n\n');
// Links
md = md.replace(/<a\b[^>]*href=["']([^"']*)["'][^>]*>(.*?)<\/a>/gis, '[$2]($1)');
// Divs
md = md.replace(/<\/div>/gi, '\n');
md = md.replace(/<div[^>]*>/gi, '');
// Strip any remaining HTML tags
md = md.replace(/<[^>]+>/g, '');
// Unescape standard HTML entities
md = md
.replace(/&nbsp;/g, ' ')
.replace(/&amp;/g, '&')
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&quot;/g, '"')
.replace(/&#39;/g, "'");
// Collapse 3+ newlines into 2
return md.replace(/\n{3,}/g, '\n\n').trim();
}