Skip to content

Commit

Permalink
feat: add JSDocs for cdn ESM & UDM users
Browse files Browse the repository at this point in the history
  • Loading branch information
mcqua007 committed Jan 15, 2025
1 parent 1f029f3 commit dfcc1c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
9 changes: 4 additions & 5 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
declare module '@thebeyondgroup/shopify-rich-text-renderer' {

/** Shopify rich text schema */
/** Shopify richtext schema */
export interface Schema {
type: string
children?: Schema[]
Expand All @@ -14,7 +13,7 @@ declare module '@thebeyondgroup/shopify-rich-text-renderer' {
value?: string
}

/** Optional options for rendering Shopify rich text to HTML */
/** Optional options for rendering Shopify richtext to HTML */
export interface Options {
/** allows for the rich text HTML to be easily styled */
scoped?: boolean | string
Expand Down Expand Up @@ -50,6 +49,6 @@ declare module '@thebeyondgroup/shopify-rich-text-renderer' {
}
}

/** Converts Shopify rich text to HTML */
/** Converts Shopify richtext schema to HTML */
export function convertSchemaToHtml(schema: string | Schema | Schema[], options?: Options | string | boolean): string
}
}
22 changes: 16 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/* Shopify Metafield & Metaobject Rich Text Editor Schema to HTML Converter */

/**
* Converts Shopify Richtext Schema to HTML.
*
* @param {Object|string} schema - The schema object or JSON string to convert.
* @param {Object} [options={}] - The conversion options.
* @param {string|boolean} [options.scoped] - The scoped class name or a boolean value indicating whether to use the default scoped class name.
* @returns {string} The converted HTML string.
*/
export function convertSchemaToHtml(schema, options = {}) {
let { scoped } = options
let html = ''
Expand Down Expand Up @@ -73,29 +83,29 @@ function createElement(tag, classes, content, attributes = {}) {
return `<${tag}${outputAttributes(attributes)}>${content}</${tag}>`
}

export function buildParagraph(el, options) {
function buildParagraph(el, options) {
const { classes } = options
return createElement('p', classes, convertSchemaToHtml(el?.children, options))
}

export function buildHeading(el, options) {
function buildHeading(el, options) {
const { classes } = options
const tag = `h${el?.level}`
return createElement(tag, classes, convertSchemaToHtml(el?.children, options))
}

export function buildList(el, options) {
function buildList(el, options) {
const { classes } = options
const tag = el?.listType === 'ordered' ? 'ol' : 'ul'
return createElement(tag, classes, convertSchemaToHtml(el?.children, options))
}

export function buildListItem(el, options) {
function buildListItem(el, options) {
const { classes } = options
return createElement('li', classes, convertSchemaToHtml(el?.children, options))
}

export function buildLink(el, options) {
function buildLink(el, options) {
const { classes } = options
const attributes = {
href: el?.url,
Expand All @@ -105,7 +115,7 @@ export function buildLink(el, options) {
return createElement('a', classes, convertSchemaToHtml(el?.children, options), attributes)
}

export function buildText(el, options) {
function buildText(el, options) {
const { classes, newLineToBreak } = options
if (el?.bold) {
return createElement('strong', classes, el?.value)
Expand Down

0 comments on commit dfcc1c4

Please sign in to comment.