mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-04 19:15:33 +08:00
f4c20056a0
fix AI-191 #### PR Dependency Tree * **PR #12840** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal) <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Introduced the ability to convert rich text documents into Markdown, supporting a wide range of content types such as headings, lists, tables, images, code blocks, attachments, and embedded documents. - Added support for parsing collaborative document structures and rendering them as structured Markdown or parsed representations. - Enhanced handling of database and table blocks, including conversion to Markdown tables with headers and cell content. - **Documentation** - Added a README noting the use of a forked Markdown converter. - **Tests** - Added new test coverage for document parsing features. <!-- end of auto-generated comment: release notes by coderabbit.ai --> #### PR Dependency Tree * **PR #12840** 👈 This tree was auto-generated by [Charcoal](https://github.com/danerwilliams/charcoal)
67 lines
1.3 KiB
TypeScript
67 lines
1.3 KiB
TypeScript
// eslint-disable
|
|
// @ts-nocheck
|
|
let id = 0;
|
|
|
|
export class Node {
|
|
id = ++id;
|
|
children: Node[];
|
|
open: string;
|
|
close: string;
|
|
text: string;
|
|
|
|
_format: string;
|
|
_parent: Node;
|
|
|
|
constructor(data?: string[] | string) {
|
|
if (Array.isArray(data)) {
|
|
this.open = data[0];
|
|
this.close = data[1];
|
|
} else if (typeof data === 'string') {
|
|
this.text = data;
|
|
}
|
|
this.children = [];
|
|
}
|
|
|
|
append(e: Node) {
|
|
if (!(e instanceof Node)) {
|
|
e = new Node(e);
|
|
}
|
|
if (e._parent) {
|
|
const idx = e._parent.children.indexOf(e);
|
|
e._parent.children.splice(idx, 1);
|
|
}
|
|
e._parent = this;
|
|
this.children = this.children.concat(e);
|
|
}
|
|
|
|
render() {
|
|
const inner =
|
|
(this.text || '') + this.children.map(c => c.render()).join('');
|
|
|
|
if (
|
|
inner.trim() === '' &&
|
|
this.open === this.close &&
|
|
this.open &&
|
|
this.close
|
|
) {
|
|
return '';
|
|
}
|
|
|
|
const wrapped = this.open && this.close;
|
|
const emptyInner = inner.trim() === '';
|
|
const fragments = [
|
|
inner.startsWith(' ') && !emptyInner && wrapped ? ' ' : '',
|
|
this.open,
|
|
wrapped ? inner.trim() : inner,
|
|
this.close,
|
|
inner.endsWith(' ') && !emptyInner && wrapped ? ' ' : '',
|
|
].filter(f => f);
|
|
|
|
return fragments.join('');
|
|
}
|
|
|
|
parent() {
|
|
return this._parent;
|
|
}
|
|
}
|