package com.microservices.wiki.refactoring.utils;

import com.vladsch.flexmark.ast.Node;
import com.vladsch.flexmark.ext.tables.TablesExtension;
import com.vladsch.flexmark.html.HtmlRenderer;
import com.vladsch.flexmark.parser.Parser;
import org.springframework.stereotype.Component;

import java.util.Collections;

@Component
public class MarkdownUtil {

    public static String convertToHtml(String markdown) {

        // 创建解析器和渲染器
        Parser parser = Parser.builder()
                .extensions(Collections.singletonList(TablesExtension.create()))
                .build();
        HtmlRenderer renderer = HtmlRenderer.builder().build();

        // 解析 Markdown
        Node document = parser.parse(markdown);

        // 渲染为 HTML
        return renderer.render(document);
    }
}