Syntax colored TypeScript source code:

import { parseHtml } from "@thi.ng/hiccup-html-parse";
import { serialize } from "@thi.ng/hiccup-markdown";
import { arrayZipper, type Location } from "@thi.ng/zipper";

// load a Mastodon status via API
const res = await (
	await fetch("https://mastodon.thi.ng/api/v1/statuses/115464108396925195")
).json();

// parse HTML content into thing/hiccup format (nested JS arrays)
const parsed = parseHtml(res.content, {
	whitespace: true,
	ignoreAttribs: ["class"],
}).result!;

// structure of parsed example:
// [["p", {}, "text"], ["p", {}, ...], ...]

// recursively traverse result document/array using thi.ng/zipper
// and replace all <span> elements with their raw text body
let loc: Location<any> | undefined = arrayZipper(parsed);
while (loc) {
	loc = loc.next;
	if (Array.isArray(loc?.node) && loc?.node[0] == "span")
		loc = loc.replace(loc.node[2]);
	if (loc?.next == null) break;
}

// serialize hiccup to markdown
console. log(serialize(loc?.root, null));

/*
Result (in markdown format), omitted here due to alt text limits
*/
Syntax colored TypeScript source code: import { parseHtml } from "@thi.ng/hiccup-html-parse"; import { serialize } from "@thi.ng/hiccup-markdown"; import { arrayZipper, type Location } from "@thi.ng/zipper"; // load a Mastodon status via API const res = await ( await fetch("https://mastodon.thi.ng/api/v1/statuses/115464108396925195") ).json(); // parse HTML content into thing/hiccup format (nested JS arrays) const parsed = parseHtml(res.content, { whitespace: true, ignoreAttribs: ["class"], }).result!; // structure of parsed example: // [["p", {}, "text"], ["p", {}, ...], ...] // recursively traverse result document/array using thi.ng/zipper // and replace all <span> elements with their raw text body let loc: Location<any> | undefined = arrayZipper(parsed); while (loc) { loc = loc.next; if (Array.isArray(loc?.node) && loc?.node[0] == "span") loc = loc.replace(loc.node[2]); if (loc?.next == null) break; } // serialize hiccup to markdown console. log(serialize(loc?.root, null)); /* Result (in markdown format), omitted here due to alt text limits */