How to Dynamically Convert HTML to Figma Nodes Without Hardcoding?

Hello Figma Community,

I’m developing a Figma plugin where the UI sends arbitrary HTML content to the plugin’s main code using parent.postMessage. The main code is then responsible for dynamically converting the HTML structure into Figma nodes on the canvas.

Goals:

  1. Parse any valid HTML provided by the user (e.g., <div><strong>Hello World</strong></div>).
  2. Dynamically generate equivalent Figma nodes (like Frame, Text, Group, etc.) that mirror the HTML structure and styles.
  3. Avoid hardcoding specific tag types (e.g., <div> or <span>) so that the plugin works with any HTML.

Questions for the Community:

  1. Are there best practices or libraries for dynamically converting HTML to Figma nodes?
  2. How can I efficiently handle styles and attributes (e.g., inline style or class) from HTML in Figma?
  3. Are there any limitations or pitfalls I should be aware of when replicating HTML structures in Figma?