mirror of
				https://github.com/TriliumNext/Notes.git
				synced 2025-10-31 21:11:30 +08:00 
			
		
		
		
	feat(import/markdown): normalize non-breaking spaces
This commit is contained in:
		
							parent
							
								
									99461dbf7e
								
							
						
					
					
						commit
						32db26684d
					
				| @ -226,4 +226,16 @@ describe("Markdown export", () => { | ||||
|         expect(markdownExportService.toMarkdown(html)).toBe(expected); | ||||
|     }); | ||||
| 
 | ||||
|     it("converts   to character", () => { | ||||
|         const html = /*html*/`<p>Hello world.</p>`; | ||||
|         const expected = `Hello\u00a0world.`; | ||||
|         expect(markdownExportService.toMarkdown(html)).toBe(expected); | ||||
|     }); | ||||
| 
 | ||||
|     it("preserves non-breaking space character", () => { | ||||
|         const html = /*html*/`<p>Hello\u00adworld.</p>`; | ||||
|         const expected = `Hello\u00adworld.`; | ||||
|         expect(markdownExportService.toMarkdown(html)).toBe(expected); | ||||
|     }); | ||||
| 
 | ||||
| }); | ||||
|  | ||||
| @ -133,4 +133,16 @@ second line 2</code></pre><ul><li>Hello</li><li>world</li></ul><ol><li>Hello</li | ||||
|         expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); | ||||
|     }); | ||||
| 
 | ||||
|     it("preserves  ", () => { | ||||
|         const input = `Hello world.`; | ||||
|         const expected = /*html*/`<p>Hello world.</p>`; | ||||
|         expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); | ||||
|     }); | ||||
| 
 | ||||
|     it("converts non-breaking space character to  ", () => { | ||||
|         const input = `Hello\u00a0world.`; | ||||
|         const expected = /*html*/`<p>Hello world.</p>`; | ||||
|         expect(markdownService.renderToHtml(input, "Title")).toStrictEqual(expected); | ||||
|     }); | ||||
| 
 | ||||
| }); | ||||
|  | ||||
| @ -87,6 +87,9 @@ function renderToHtml(content: string, title: string) { | ||||
|     // Remove slash for self-closing tags to match CKEditor's approach.
 | ||||
|     html = html.replace(/<(\w+)([^>]*)\s+\/>/g, "<$1$2>"); | ||||
| 
 | ||||
|     // Normalize non-breaking spaces to entity.
 | ||||
|     html = html.replaceAll("\u00a0", " "); | ||||
| 
 | ||||
|     return html; | ||||
| } | ||||
| 
 | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user
	 Elian Doran
						Elian Doran