function replaceArtifactTags(input) {
const regex = /<antArtifact[^>]*>/g;
function extractAttributes(tag) {
const attributes = {};
const attrRegex = /(\w+)=("([^"]*)"|'([^']*)')/g;
let match;
while ((match = attrRegex.exec(tag)) !== null) {
const key = match[1];
const value = match[3] || match[4];
attributes[key] = value;
}
return attributes;
}
return input.replace(regex, (match) => {
const attributes = extractAttributes(match);
const typeLookup = {
"application/vnd.ant.react": "jsx",
"text/html": "html"
};
const lang = attributes.language || typeLookup[attributes.type] || "";
return `### ${attributes.title || "Untitled"}\n\n\`\`\`${lang}`;
});
}