All files / src/services/parsing markdown.parser.js

0% Statements 0/7
0% Branches 0/2
0% Functions 0/1
0% Lines 0/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46                                                                                           
/**
 * Markdown Parser
 *
 * This module handles the parsing of Markdown files using the 'marked' library.
 * For V2, the primary requirement is to make the raw_content available for
 * storage and AI summarization.
 */
 
import { marked } from "marked";
 
/**
 * Parse Markdown content
 *
 * @param {string} fileContentString - The raw Markdown text to parse
 * @returns {Object} An object containing the raw content and optionally parsed HTML
 */
export function parseMarkdownContent(fileContentString) {
  if (!fileContentString) {
    return { rawContent: "" };
  }
 
  try {
    // For V2, we primarily need the raw content for storage and AI summarization
    // The HTML rendition is optional but included for potential future use
    const htmlContent = marked.parse(fileContentString);
 
    return {
      rawContent: fileContentString,
      htmlContent: htmlContent,
    };
  } catch (error) {
    // Handle any errors from the marked.parse() call
    console.error("Error parsing markdown content:", error);
 
    // Even if HTML parsing fails, still return the raw content
    return {
      rawContent: fileContentString,
      error: error.message,
    };
  }
}
 
export default {
  parseMarkdownContent,
};