Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion — rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher — de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { remark } from 'remark';
|
|
import html from 'remark-html';
|
|
import remarkGfm from 'remark-gfm';
|
|
import { Compatible } from "vfile";
|
|
import DOMPurify from 'isomorphic-dompurify';
|
|
|
|
/**
|
|
* Adds target="_blank" and rel="noopener noreferrer" attributes to all links in HTML content
|
|
* @param htmlContent - The HTML content containing links
|
|
* @returns The processed HTML with target="_blank" added to all links
|
|
*/
|
|
export const addTargetBlankToLinks = (htmlContent: string): string => {
|
|
return htmlContent.replace(
|
|
/<a(.*?)href="(.*?)"(.*?)>/gi,
|
|
'<a$1href="$2"$3 target="_blank" rel="noopener noreferrer">'
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Fixes the list item paragraph issue in HTML content
|
|
* This specifically addresses the problem where numbered list items with bold text
|
|
* have an extra line break between the marker and content
|
|
* @param htmlContent - The HTML content with possible list formatting issues
|
|
* @returns The processed HTML with fixed list formatting
|
|
*/
|
|
export const fixListItemParagraphIssue = (htmlContent: string): string => {
|
|
// This regex looks for list items with a paragraph immediately inside
|
|
// and removes the paragraph tags while preserving the content
|
|
return htmlContent.replace(
|
|
/<li>\s*<p>([\s\S]*?)<\/p>/g,
|
|
'<li>$1'
|
|
);
|
|
};
|
|
|
|
/**
|
|
* Converts markdown to HTML with GitHub Flavored Markdown support and adds target="_blank" to links
|
|
* @param markdown - The markdown content to convert
|
|
* @returns Promise with the HTML content
|
|
*/
|
|
export const markdownToHtml = async (markdown: Compatible | string): Promise<string> => {
|
|
try {
|
|
const result = await remark()
|
|
.use(remarkGfm) // Add GitHub Flavored Markdown support (tables, strikethrough, etc.)
|
|
.use(html, { sanitize: false })
|
|
.process(markdown);
|
|
|
|
// Get the HTML string
|
|
let htmlString = result.toString();
|
|
|
|
// Apply fixes
|
|
htmlString = fixListItemParagraphIssue(htmlString);
|
|
htmlString = addTargetBlankToLinks(htmlString);
|
|
|
|
// Sanitize the final HTML to prevent XSS. Report content is derived from
|
|
// untrusted sources (scraped web pages and LLM output) and is rendered via
|
|
// dangerouslySetInnerHTML, so it must be sanitized before being returned.
|
|
htmlString = DOMPurify.sanitize(htmlString, { ADD_ATTR: ['target'] });
|
|
|
|
return htmlString;
|
|
} catch (error) {
|
|
console.error('Error converting Markdown to HTML:', error);
|
|
return ''; // Handle error gracefully, return empty string or default content
|
|
}
|
|
};
|