一些检查失败了
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
109 行
2.6 KiB
TypeScript
109 行
2.6 KiB
TypeScript
import { cleanMarkdownNbsp } from './cleanMarkdownNbsp';
|
|
|
|
describe('cleanMarkdownNbsp', () => {
|
|
it('should return unchanged text if no is present', () => {
|
|
const input = '# Heading\n\nSome paragraph\n\n- [ ] Todo item';
|
|
expect(cleanMarkdownNbsp(input)).toBe(input);
|
|
});
|
|
|
|
it('should clean standalone lines between paragraphs and items', () => {
|
|
const input = [
|
|
'jjjj',
|
|
'',
|
|
' ',
|
|
'',
|
|
'jjj',
|
|
'',
|
|
'',
|
|
'',
|
|
' ',
|
|
'',
|
|
'- [x] 2026/11/01 16:24',
|
|
].join('\n');
|
|
|
|
const expected = [
|
|
'jjjj',
|
|
'',
|
|
'jjj',
|
|
'',
|
|
'',
|
|
'',
|
|
'- [x] 2026/11/01 16:24',
|
|
].join('\n');
|
|
|
|
expect(cleanMarkdownNbsp(input)).toBe(expected);
|
|
});
|
|
|
|
it('should clean multiple contiguous or spaced entities and variants ( ,  )', () => {
|
|
const input = [
|
|
'Section 1',
|
|
' ',
|
|
'Section 2',
|
|
' ',
|
|
'Section 3',
|
|
' ',
|
|
'Section 4',
|
|
' ',
|
|
'Section 5',
|
|
].join('\n');
|
|
|
|
const expected = [
|
|
'Section 1',
|
|
'',
|
|
'Section 2',
|
|
'',
|
|
'Section 3',
|
|
'',
|
|
'Section 4',
|
|
'',
|
|
'Section 5',
|
|
].join('\n');
|
|
|
|
expect(cleanMarkdownNbsp(input)).toBe(expected);
|
|
});
|
|
|
|
it('should preserve inline inside text and table cells', () => {
|
|
const text = 'Hello world with inline nonbreaking space.';
|
|
expect(cleanMarkdownNbsp(text)).toBe(text);
|
|
|
|
const table = '| Header 1 | Header 2 |\n| --- | --- |\n| | Value |';
|
|
expect(cleanMarkdownNbsp(table)).toBe(table);
|
|
});
|
|
|
|
it('should preserve inline backtick code spans like ` `', () => {
|
|
const text = 'Use ` ` for non-breaking space in HTML.';
|
|
expect(cleanMarkdownNbsp(text)).toBe(text);
|
|
});
|
|
|
|
it('should preserve inside fenced code blocks', () => {
|
|
const codeBlock = [
|
|
'```html',
|
|
' ',
|
|
'<div> </div>',
|
|
'```',
|
|
].join('\n');
|
|
|
|
expect(cleanMarkdownNbsp(codeBlock)).toBe(codeBlock);
|
|
|
|
const tildeCodeBlock = [
|
|
'~~~html',
|
|
' ',
|
|
'~~~',
|
|
].join('\n');
|
|
|
|
expect(cleanMarkdownNbsp(tildeCodeBlock)).toBe(tildeCodeBlock);
|
|
});
|
|
|
|
it('should handle consecutive lines cleanly', () => {
|
|
const input = 'Paragraph 1\n\n \n\n \n\nParagraph 2';
|
|
const expected = 'Paragraph 1\n\nParagraph 2';
|
|
expect(cleanMarkdownNbsp(input)).toBe(expected);
|
|
});
|
|
|
|
it('should support Windows CRLF line endings', () => {
|
|
const input = 'Line 1\r\n\r\n \r\n\r\nLine 2';
|
|
const expected = 'Line 1\r\n\r\nLine 2';
|
|
expect(cleanMarkdownNbsp(input)).toBe(expected);
|
|
});
|
|
});
|