文件
chen 301194963b
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
feat: Initial clean release of CHM
2026-11-04 11:29:39 +08:00

43 行
1.3 KiB
TypeScript

// If renderedHtml is an HTMLElement, the content is modified in-place.
const postProcessRenderedHtml = <InputType extends string|HTMLElement> (renderedHtml: InputType, isInline: boolean): InputType => {
let rootElement;
if (typeof renderedHtml === 'string') {
const parser = new DOMParser();
const parsed = parser.parseFromString(
`<!DOCTYPE html><html><body>${renderedHtml}</body></html>`,
'text/html',
);
rootElement = parsed.body;
} else {
rootElement = renderedHtml;
}
const replaceChildMatching = (selector: string) => {
const toReplace = [...rootElement.children].find(
child => child.matches(selector),
);
toReplace?.replaceWith(...toReplace.childNodes);
};
// If the original HTML is from .renderToMarkup, it may have a <div> wrapper:
replaceChildMatching('#rendered-md');
if (rootElement.children.length === 1 && isInline) {
replaceChildMatching('p, div');
}
// Remove the 'joplin-editable' container if it's the only thing in the content
// (since this.dom is itself a joplin-editable)
if (rootElement.children.length === 1) {
replaceChildMatching('.joplin-editable');
}
// Match the input type
if (typeof renderedHtml === 'string') {
return rootElement.innerHTML as InputType;
} else {
return rootElement as InputType;
}
};
export default postProcessRenderedHtml;