commentRemoval()
Entfernt HTML-Kommentare aus der Ausgabe.
import { commentRemoval } from "@unifast/node";Signatur
function commentRemoval(): UnifastPluginParameter
Keine.
Verwendung
import { compile, commentRemoval } from "@unifast/node";
const md = `# Hello
<!-- This comment will be removed -->
Some content here.`;
const result = compile(md, {
plugins: [commentRemoval()],
});
// The HTML comment is stripped from the outputBeispiele
Einfaches Entfernen von Kommentaren
Alle HTML-Kommentarknoten (<!-- ... -->) werden aus dem Ausgabebaum entfernt, einschließlich Kommentaren, die in Blockelementen wie Blockquotes verschachtelt sind:
import { compile, commentRemoval } from "@unifast/node";
const md = `First paragraph.
<!-- TODO: add more content -->
Second paragraph.`;
const result = compile(md, { plugins: [commentRemoval()] });
console.log(result.output);
// <p>First paragraph.</p>
// <p>Second paragraph.</p>Nicht-Kommentar-HTML bleibt erhalten
Nur Kommentarknoten werden entfernt. Anderes Inline-HTML bleibt unberührt:
import { compile, commentRemoval } from "@unifast/node";
const md = `<!-- hidden -->
<div class="custom">Visible content</div>`;
const result = compile(md, { plugins: [commentRemoval()] });
console.log(result.output);
// <div class="custom">Visible content</div>