Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Transform <br/> into element #31

Merged
merged 2 commits into from
Mar 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 81 additions & 75 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -15036,6 +15036,81 @@ function createAdjustMap(values) {

const h = lib_core_core(property_information_html, 'div')

;// CONCATENATED MODULE: ./node_modules/hast-util-to-string/index.js
/**
* @fileoverview
* Get the plain-text value of a hast node.
* @longdescription
* ## Use
*
* ```js
* import {h} from 'hastscript'
* import {toString} from 'hast-util-to-string'
*
* toString(h('p', 'Alpha'))
* //=> 'Alpha'
* toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']))
* //=> 'Bold and italic.'
* ```
*
* ## API
*
* ### `toString(node)`
*
* Transform a node to a string.
*/

/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast').Element} Element
* @typedef {Root|Root['children'][number]} Node
*/

/**
* Get the plain-text value of a hast node.
*
* @param {Node} node
* @returns {string}
*/
function hast_util_to_string_toString(node) {
// “The concatenation of data of all the Text node descendants of the context
// object, in tree order.”
if ('children' in node) {
return hast_util_to_string_all(node)
}

// “Context object’s data.”
return 'value' in node ? node.value : ''
}

/**
* @param {Node} node
* @returns {string}
*/
function hast_util_to_string_one(node) {
if (node.type === 'text') {
return node.value
}

return 'children' in node ? hast_util_to_string_all(node) : ''
}

/**
* @param {Root|Element} node
* @returns {string}
*/
function hast_util_to_string_all(node) {
let index = -1
/** @type {string[]} */
const result = []

while (++index < node.children.length) {
result[index] = hast_util_to_string_one(node.children[index])
}

return result.join('')
}

;// CONCATENATED MODULE: ./node_modules/hast-util-from-html/node_modules/parse5/dist/common/unicode.js
const UNDEFINED_CODE_POINTS = new Set([
65534, 65535, 131070, 131071, 196606, 196607, 262142, 262143, 327678, 327679, 393214,
@@ -25594,6 +25669,7 @@ function lib_camelcase(value) {




/**
* @param {NotionRichText} richText
* @param {{allowHtml: boolean, wrapUnderlineBlank: boolean}} options
@@ -25648,6 +25724,11 @@ function transformRichText(richText, options = {}) {
node = h('a', { href }, [node]);
}

// transform code styled <br /> into a br element
if (node.tagName === 'code' && /^<br\s*\/?>$/.test(hast_util_to_string_toString(node))) {
node = h('br', []);
}

return node;

case 'equation':
@@ -26567,81 +26648,6 @@ async function importImages({ hast, slug }) {
);
}

;// CONCATENATED MODULE: ./node_modules/hast-util-to-string/index.js
/**
* @fileoverview
* Get the plain-text value of a hast node.
* @longdescription
* ## Use
*
* ```js
* import {h} from 'hastscript'
* import {toString} from 'hast-util-to-string'
*
* toString(h('p', 'Alpha'))
* //=> 'Alpha'
* toString(h('div', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.']))
* //=> 'Bold and italic.'
* ```
*
* ## API
*
* ### `toString(node)`
*
* Transform a node to a string.
*/

/**
* @typedef {import('hast').Root} Root
* @typedef {import('hast').Element} Element
* @typedef {Root|Root['children'][number]} Node
*/

/**
* Get the plain-text value of a hast node.
*
* @param {Node} node
* @returns {string}
*/
function hast_util_to_string_toString(node) {
// “The concatenation of data of all the Text node descendants of the context
// object, in tree order.”
if ('children' in node) {
return hast_util_to_string_all(node)
}

// “Context object’s data.”
return 'value' in node ? node.value : ''
}

/**
* @param {Node} node
* @returns {string}
*/
function hast_util_to_string_one(node) {
if (node.type === 'text') {
return node.value
}

return 'children' in node ? hast_util_to_string_all(node) : ''
}

/**
* @param {Root|Element} node
* @returns {string}
*/
function hast_util_to_string_all(node) {
let index = -1
/** @type {string[]} */
const result = []

while (++index < node.children.length) {
result[index] = hast_util_to_string_one(node.children[index])
}

return result.join('')
}

;// CONCATENATED MODULE: ./node_modules/hast-util-heading-rank/lib/index.js
/**
* @typedef {import('hast').Root} Root
6 changes: 6 additions & 0 deletions src/handlers/rich-text.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { h } from 'hastscript';
import { toString } from 'hast-util-to-string';
import { fromHtml } from 'hast-util-from-html';

/**
@@ -55,6 +56,11 @@ export function transformRichText(richText, options = {}) {
node = h('a', { href }, [node]);
}

// transform code styled <br /> into a br element
if (node.tagName === 'code' && /^<br\s*\/?>$/.test(toString(node))) {
node = h('br', []);
}

return node;

case 'equation':