package com.clevertree.md2ast

import android.util.Log

object MarkdownParser {
    init {
        try {
            System.loadLibrary("md2ast")
        } catch (e: Exception) {
            Log.e("MarkdownParser", "Failed to load native library md2ast", e)
        }
    }

    fun parse(markdown: String, allowedTags: List<String> = emptyList()): String {
        val allowedTagsJson = if (allowedTags.isEmpty()) "[]" else {
            "[\"" + allowedTags.joinToString("\",\"") + "\"]"
        }
        return nativeParse(markdown, allowedTagsJson)
    }

    private external fun nativeParse(markdown: String, allowedTagsJson: String): String
}
