Function serialize

  • Serializes an AST node to an HTML string.

    Type Parameters


    • node: T["parentNode"]

      Node to serialize.

    • Optional options: SerializerOptions<T>

      Serialization options.

    Returns string


    const parse5 = require('parse5');

    const document = parse5.parse('<!DOCTYPE html><html><head></head><body>Hi there!</body></html>');

    // Serializes a document.
    const html = parse5.serialize(document);

    // Serializes the <html> element content.
    const str = parse5.serialize(document.childNodes[1]);

    console.log(str); //> '<head></head><body>Hi there!</body>'

Generated using TypeDoc