@ -1,6 +1,8 @@
|
||||
import { URL } from 'node:url';
|
||||
import * as parse5 from 'parse5';
|
||||
import treeAdapter from 'parse5/lib/tree-adapters/default.js';
|
||||
import * as TreeAdapter from '../../node_modules/parse5/dist/tree-adapters/default.js';
|
||||
|
||||
const treeAdapter = TreeAdapter.defaultTreeAdapter;
|
||||
|
||||
const urlRegex = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+/;
|
||||
const urlRegexFull = /^https?:\/\/[\w\/:%#@$&?!()\[\]~.,=+\-]+$/;
|
||||
@ -19,7 +21,7 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
|
||||
return text.trim();
|
||||
|
||||
function getText(node: parse5.Node): string {
|
||||
function getText(node: TreeAdapter.Node): string {
|
||||
if (treeAdapter.isTextNode(node)) return node.value;
|
||||
if (!treeAdapter.isElementNode(node)) return '';
|
||||
if (node.nodeName === 'br') return '\n';
|
||||
@ -31,7 +33,7 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
return '';
|
||||
}
|
||||
|
||||
function appendChildren(childNodes: parse5.ChildNode[]): void {
|
||||
function appendChildren(childNodes: TreeAdapter.ChildNode[]): void {
|
||||
if (childNodes) {
|
||||
for (const n of childNodes) {
|
||||
analyze(n);
|
||||
@ -39,7 +41,7 @@ export function fromHtml(html: string, hashtagNames?: string[]): string {
|
||||
}
|
||||
}
|
||||
|
||||
function analyze(node: parse5.Node) {
|
||||
function analyze(node: TreeAdapter.Node) {
|
||||
if (treeAdapter.isTextNode(node)) {
|
||||
text += node.value;
|
||||
return;
|
||||
|
Reference in New Issue
Block a user