Skip to content

Commit

Permalink
📝 add some docs
Browse files Browse the repository at this point in the history
  • Loading branch information
nabeelvalley committed Mar 26, 2024
1 parent eec54ee commit a8dd085
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ While designed around the [EditorJS](https://github.com/codex-team/editor.js) AP
The conversion from HTML can be done as follows:

```ts
import { convertHtmlToBlocks } from "@sftsrv/structured-html";
import { convertHtmlToStructuredContents } from "@sftsrv/structured-html";

// get some RAW HTML
const htmlText = "<p>hello world</p>";

// use the DOM to parse it from a string
const html = new DOMParser().parseFromString(htmlText, "text/html").body;

// the convertHtmlToBlocks function takes an HTML ELement and returns the structured HTML content
const blocks = convertHtmlToBlocks(html);
// the convertHtmlToStructuredContents function takes an HTML ELement and returns the structured HTML content
const blocks = convertHtmlToStructuredContents(html);
```
7 changes: 5 additions & 2 deletions jsr.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "@sftsrv/structured-html",
"version": "0.0.1",
"exports": "./src/index.ts"
"version": "0.0.2",
"exports": {
".": "./src/index.ts",
"blocks": "./src/blocks.ts"
}
}
10 changes: 9 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,15 @@ const tagHandlers: TagHandlerMap = {
H6: headingHandler(6),
};

export const convertHtmlToBlocks = (html: Element): EditorContent => {
/**
* Converts HTML to structured content
*
* @param html input HTML
* @returns the restructured and simplified HTML
*/
export const convertHtmlToStructuredContents = (
html: Element
): EditorContent => {
const transformed = transform(html);

const baseHandler = tagHandlers[transformed.tagName];
Expand Down

0 comments on commit a8dd085

Please sign in to comment.