文件
mynode/packages/editor/CodeMirror/extensions/rendering/replaceFormatCharacters.ts
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

60 行
1.6 KiB
TypeScript

import { SyntaxNodeRef } from '@lezer/common';
import { EditorState } from '@codemirror/state';
import makeHideReplaceExtension from './utils/makeHideReplaceExtension';
const shouldFullReplace = (node: SyntaxNodeRef, state: EditorState) => {
const getNodeStartLine = () => state.doc.lineAt(node.from);
if (['HeaderMark', 'CodeMark', 'EmphasisMark', 'StrikethroughMark', 'HighlightMarker', 'InsertMarker'].includes(node.name)) {
return true;
}
if (node.name === 'QuoteMark' && node.from === getNodeStartLine().from) {
return true;
}
return false;
};
const replaceFormatCharacters = [
makeHideReplaceExtension({
getRevealStrategy: (node) => {
if (node.name === 'QuoteMark') {
return 'line';
}
if (node.name === 'CodeMark') {
if (node.node.parent?.name === 'FencedCode') {
return 'line';
}
}
return 'active';
},
shouldHide: (node, state) => {
return shouldFullReplace(node, state);
},
getDecorationRange: (node, state) => {
// Headers in the form "## Header" should have the "##"s and the
// space immediately after hidden
if (node.name === 'HeaderMark') {
const markerLine = state.doc.lineAt(node.from);
// Certain header styles DON'T have a space after the header mark:
const hasRoomForSpace = node.to + 1 >= markerLine.to;
if (hasRoomForSpace) {
return null;
}
// Include the space in the hidden region, if it's available
if (state.doc.sliceString(node.to, node.to + 1) === ' ') {
return [node.from, node.to + 1];
}
}
return null;
},
}),
];
export default replaceFormatCharacters;