(ns mf2clj.core (:require [clojure.java.io :as io] [clojure.walk :refer [keywordize-keys]] [cheshire.core :as json]) (:import [org.extism.sdk.chicory Manifest ManifestWasm Plugin] [java.nio.charset StandardCharsets])) (def plugin (let [^ManifestWasm wasm-manifest (-> "mf2go.wasm" io/resource io/input-stream .readAllBytes ManifestWasm/fromBytes .build) ^Manifest manifest (-> (into-array ManifestWasm [wasm-manifest]) Manifest/ofWasms .build)] (-> manifest Plugin/ofManifest .build))) (def charset StandardCharsets/UTF_8) (defn parse-bytes [html-bytes] {:pre [(bytes? html-bytes)]} (let [^bytes result (.call ^Plugin plugin "parse" html-bytes)] (-> (String. result charset) json/parse-string keywordize-keys))) (defn parse [^String html-string] {:pre [(string? html-string)]} (let [html-bytes (.getBytes html-string charset)] (parse-bytes html-bytes)))