npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

knowledge-html-converter

v0.7.2

Published

Converts html to the json format of genesys knowledge article content.

Downloads

161

Readme

knowledge-html-converter

Takes an html string as input and converts it to the json format of knowledge document variation content, which can be used in the Genesys Knowledge API: https://developer.genesys.cloud/devapps/api-explorer#post-api-v2-knowledge-knowledgebases--knowledgeBaseId--documents--documentId--variations

Please, note that this library is not stable yet and expect changes in how we translate html to the AST of the API. The code was extracted from the Knowledge Articles editor UI that converts the output of the html editor in the UI to the knowledge AST and we are still working on enhancing the code to better deal with html coming from an external source.

Installation

npm install knowledge-html-converter

Usage

import { convertHtmlToBlocks } from 'knowledge-html-converter';

const documentBodyBlocks = convertHtmlToBlocks('<html><body><p>Document content</p></body></html>');

This will convert html to blocks with default options, If needed you can customize the options

const documentBodyBlocks = convertHtmlToBlocks('<html><body><p>Document content</p></body></html>', { handleWidthWithUnits: true, baseFontSize: 32 });

NOTE: The package is now pure ESM. It cannot be require()'d from CommonJS.

The value of documentBodyBlocks will be:

[
  {
    "type": "Paragraph",
    "paragraph": {
      "blocks": [
        {
          "type": "Text",
          "text": {
            "text": "Document content"
          }
        }
      ],
      "properties": {
        "fontType": "Paragraph"
      }
    }
  }
]

The json array returned by convertHtmlToBlocks can be used as the value of the body.blocks property in document variation create and update requests. For example:

fetch('https://api.mypurecloud.com/api/v2/knowledge/knowledgeBases/<kb-id>/documents/<doc-id>/variations/<variation-id>', {
  method: 'PATCH',
  headers: new Headers({
    'Content-Type': 'application/json',
    'Authorization': 'Bearer <token>',
  }),
  body: JSON.stringify({
    body: {
      blocks: [
        {
          "type": "Paragraph",
          "paragraph": {
            "blocks": [
              {
                "type": "Text",
                "text": {
                  "text": "Document content"
                }
              }
            ],
            "properties": {
              "fontType": "Paragraph"
            }
          }
        }
      ]
    }
  }),
});

Default options

{
  handleWidthWithUnits: false,
  baseFontSize: 16
}

| SNO | OPTION | DEFAULT VALUE | USAGE | | --- | -------------------- | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | 1 | handleWidthWithUnits | false | If set true, handles the table width with unit. Sample output will be ' width: 100, widthUnit: "Percentage" '. | | 2 | baseFontSize | 16 | The default text size in a browser is 16px. So for the default size, 16px is converted to 1em. If you need to override the default font-size, use this option like 'baseFontSize : 32'. For the option 'baseFontSize : 32', the conversion will be 32px to 1em. |

Developer setup

Node v16, npm v8.

Git Pre-commit Hooks

npm run prepare

Installs husky to run precommit hooks: eslint, prettier. See .husky/pre-commit and "lint-staged" in package.json.

Tests

npm test

Filtering test cases: tests use Mocha, describe or it can be suffixed with .only. For example: describe.only('suite name', ...); or it.only('test name', ...);

Test coverage:

npm run coverage

The coverage report can be found at coverage/index.html.