mirror of
https://github.com/docmost/docmost.git
synced 2026-05-21 09:14:07 +08:00
share html normalization between zip and single-file imports
This commit is contained in:
@@ -30,6 +30,8 @@ import { InjectQueue } from '@nestjs/bullmq';
|
|||||||
import { Queue } from 'bullmq';
|
import { Queue } from 'bullmq';
|
||||||
import { QueueJob, QueueName } from '../../queue/constants';
|
import { QueueJob, QueueName } from '../../queue/constants';
|
||||||
import { ModuleRef } from '@nestjs/core';
|
import { ModuleRef } from '@nestjs/core';
|
||||||
|
import { load } from 'cheerio';
|
||||||
|
import { normalizeImportHtml } from '../utils/import-formatter';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ImportService {
|
export class ImportService {
|
||||||
@@ -137,7 +139,9 @@ export class ImportService {
|
|||||||
|
|
||||||
async processHTML(htmlInput: string): Promise<any> {
|
async processHTML(htmlInput: string): Promise<any> {
|
||||||
try {
|
try {
|
||||||
return htmlToJson(htmlInput);
|
const $ = load(htmlInput);
|
||||||
|
normalizeImportHtml($, $.root());
|
||||||
|
return htmlToJson($.html() || '');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,9 +52,7 @@ export async function formatImportHtml(opts: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notionFormatter($, $root);
|
normalizeImportHtml($, $root);
|
||||||
xwikiFormatter($, $root);
|
|
||||||
defaultHtmlFormatter($, $root);
|
|
||||||
|
|
||||||
const backlinks = await rewriteInternalLinksToMentionHtml(
|
const backlinks = await rewriteInternalLinksToMentionHtml(
|
||||||
$,
|
$,
|
||||||
@@ -74,6 +72,23 @@ export async function formatImportHtml(opts: {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Contextless HTML cleanup shared by every import path.
|
||||||
|
* - notionFormatter: no-op on non-Notion HTML (class-selector-based).
|
||||||
|
* - xwikiFormatter: no-op on non-XWiki HTML (looks for #xwikicontent).
|
||||||
|
* - defaultHtmlFormatter: table column widths + provider auto-embeds.
|
||||||
|
*
|
||||||
|
* Does NOT run rewriteInternalLinksToMentionHtml — that requires zip context.
|
||||||
|
*/
|
||||||
|
export function normalizeImportHtml(
|
||||||
|
$: CheerioAPI,
|
||||||
|
$root: Cheerio<any>,
|
||||||
|
): void {
|
||||||
|
notionFormatter($, $root);
|
||||||
|
xwikiFormatter($, $root);
|
||||||
|
defaultHtmlFormatter($, $root);
|
||||||
|
}
|
||||||
|
|
||||||
export function xwikiFormatter($: CheerioAPI, $root: Cheerio<any>) {
|
export function xwikiFormatter($: CheerioAPI, $root: Cheerio<any>) {
|
||||||
const $content = $root.find('#xwikicontent');
|
const $content = $root.find('#xwikicontent');
|
||||||
if ($content.length) {
|
if ($content.length) {
|
||||||
|
|||||||
Reference in New Issue
Block a user