diff --git a/chrome-extension/content.js b/chrome-extension/content.js index 19141e7..8c93294 100644 --- a/chrome-extension/content.js +++ b/chrome-extension/content.js @@ -67,6 +67,29 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => { } }); +// Convert a small subset of Markdown to HTML. +// Handles bold, italic, headings, inline code, unordered lists, and code fences. +function markdownToHtml(text) { + return text + // Strip wrapping code fences (```html ... ``` or ``` ... ```) + .replace(/^```(?:html)?\n?/gi, '').replace(/\n?```$/g, '') + // Headings + .replace(/^### (.*$)/gim, '

$1

') + .replace(/^## (.*$)/gim, '

$1

') + .replace(/^# (.*$)/gim, '

$1

') + // Bold and italic + .replace(/\*\*(.*?)\*\*/g, '$1') + .replace(/\*(.*?)\*/g, '$1') + // Inline code + .replace(/`([^`]+)`/g, '$1') + // Unordered list items (lines starting with "* " or "- ") + .replace(/^[*-] (.+)$/gim, '
  • $1
  • ') + // Wrap consecutive
  • elements in a