Typescript - How to transform any HTML to ADF

Any working real example on how to transform any HTML to ADF in Typescript?

  1. So using adf-schema package throws an error
    Module ‘“@atlaskit/adf-schema”’ has no exported member ‘defaultSchema’
    no matter what I do. Using the cjs package and pointing directly to the JS file with ts ignores fixes it.
    // @ts-ignore
    import { defaultSchema } from “@atlaskit/adf-schema/dist/cjs/schema/default-schema.js”;
  2. Even when I get the great atlaskit package to work, it does not work all the time. Sometimes the ADF is invalid
  3. Tried using wouterken/htmltoadf: An HTML to Atlassian Document Format (ADF) converter, written in Rust (github.com) but same issue. Sometimes it replaces “<br>” at the first level with hardbreaks which are, according to the schema, invalid at the top level (direclty in the content)

Has anyone successfully implemented HTML to ADF conversion?
Included a sample HTML of some text with our company signature (replaced urls). It’s pretty complex for a signature but it’s an example of what I am unable to convert.
test.txt (10.3 KB)

Any help would be appreciated

1 Like

@vojtechvesely,

Thanks for the pointer to wouterken/htmltoadf. I read over the code to see why it mishandles the <br>. For the narrow case, it’s a pretty trivial fix. There’s already some similar code for handling unwrapped text nodes that could be squeezed into where <br> is handled. However, that is just a narrow case of a wider problem where the “permitted children” aren’t checked for most nodes. Right now, I would consider this library “permissive”; it handles the happy path well, but, as you already discovered, doesn’t guard against invalid ADF well.

The adf-schema lib isn’t documented on Atlaskit making it effectively unsupported. And having a look at the (internal) code for that, I can see why it would be hard to use and/or error prone. That said, I could look at a more specific case, if there were more details. Or, maybe someone else in the community has had success?

Also, don’t forget to watch, vote, and comment on this “root cause” issue: https://jira.atlassian.com/browse/JRACLOUD-77436

2 Likes