Ghost Utils icon

Ghost Utils

A collection of utility nodes for Ghost

Actions2

Overview

This node provides utility functions for converting between HTML and Lexical formats, which are useful in content editing and publishing workflows. Specifically, the "HTML to Lexical" operation converts HTML input into a Lexical JSON structure, a format used by the Lexical editor framework to represent rich text content.

Common scenarios include:

  • Importing HTML content from external sources or legacy systems and converting it into Lexical format for further editing or processing.
  • Preparing HTML content for use in applications that rely on Lexical's structured document model.

For example, you might input an HTML snippet like <h1>Hello World</h1> and get back a Lexical JSON representation of that heading, optionally stringified as JSON text.

Properties

Name Meaning
HTML The HTML string to convert into Lexical format. Example: <h1>Hello World</h1>
JSON Stringify Whether to output the Lexical result as a JSON string (true) or as a JavaScript object (false).

Output

The node outputs a JSON object with the following fields:

  • lexical: Contains the Lexical representation of the input HTML. This is either a parsed JavaScript object representing the Lexical document or a JSON stringified version of it depending on the "JSON Stringify" property.
  • html: Echoes back the original HTML input string.

No binary data output is produced by this operation.

Dependencies

  • Uses the external package @tryghost/kg-html-to-lexical to perform the conversion from HTML to Lexical.
  • No additional API keys or external services are required.
  • Requires the node to be configured with appropriate input data containing valid HTML strings.

Troubleshooting

  • Invalid HTML Input: If the HTML provided is malformed or empty, the conversion may fail or produce unexpected results. Ensure the HTML is well-formed.
  • JSON Stringify Issues: If "JSON Stringify" is enabled but downstream nodes expect an object, parsing errors may occur. Adjust the property accordingly.
  • Error Handling: If an error occurs during conversion, the node will throw an error unless "Continue On Fail" is enabled, in which case it outputs the error alongside the input data for that item.
  • Performance: Large HTML inputs may increase processing time; consider chunking large documents if performance issues arise.

Links and References

Discussion