mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-27 18:12:29 +08:00
fix(export/markdown): math expressions not working due to string escaping
This commit is contained in:
parent
4bb767f8ee
commit
7293f59a80
@ -11,6 +11,6 @@ When notes are exported, their note ID is kept in the metadata of the export. Ho
|
|||||||
|
|
||||||
Since the Note ID is a fixed-width randomly generated number, due to the [pigeonhole principle](https://en.wikipedia.org/wiki/Pigeonhole_principle), there is a possibility that a newly created note will have the same ID as an existing note.
|
Since the Note ID is a fixed-width randomly generated number, due to the [pigeonhole principle](https://en.wikipedia.org/wiki/Pigeonhole_principle), there is a possibility that a newly created note will have the same ID as an existing note.
|
||||||
|
|
||||||
Since the note ID is alphanumeric and the length is 12 we have \\(62^{12}\\) unique IDs. However since we are generating them randomly, we can use a collision calculator such as the one for [Nano ID](https://alex7kom.github.io/nano-nanoid-cc/?alphabet=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&size=12&speed=1000&speedUnit=hour) to determine that we'd need to create 1000 notes per hour every hour for 9 centuries in order to have at least 1% probability of a note collision.
|
Since the note ID is alphanumeric and the length is 12 we have $62^{12}$ unique IDs. However since we are generating them randomly, we can use a collision calculator such as the one for [Nano ID](https://alex7kom.github.io/nano-nanoid-cc/?alphabet=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz&size=12&speed=1000&speedUnit=hour) to determine that we'd need to create 1000 notes per hour every hour for 9 centuries in order to have at least 1% probability of a note collision.
|
||||||
|
|
||||||
As such, Trilium does not take any explicit action against potential note collisions, similar to other software that makes uses of unique hashes such as [Git](https://stackoverflow.com/questions/10434326/hash-collision-in-git). If one would theoretically occur, what would most likely happen is that the existing note will be replaced by the new one.
|
As such, Trilium does not take any explicit action against potential note collisions, similar to other software that makes uses of unique hashes such as [Git](https://stackoverflow.com/questions/10434326/hash-collision-in-git). If one would theoretically occur, what would most likely happen is that the existing note will be replaced by the new one.
|
@ -280,13 +280,13 @@ describe("Markdown export", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("converts inline math expressions into proper Markdown syntax", () => {
|
it("converts inline math expressions into proper Markdown syntax", () => {
|
||||||
const html = /*html*/`<p>The equation is <span class="math-tex">\(e=mc^{2}\)</span>.</p>`;
|
const html = /*html*/`<p>The equation is <span class="math-tex">\\(e=mc^{2}\\)</span>.</p>`;
|
||||||
const expected = `The equation is\u00a0$e=mc^{2}$.`;
|
const expected = `The equation is\u00a0$e=mc^{2}$.`;
|
||||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("converts display math expressions into proper Markdown syntax", () => {
|
it("converts display math expressions into proper Markdown syntax", () => {
|
||||||
const html = /*html*/`<span class="math-tex">\[\sqrt{x^{2}+1}\]</span>`;
|
const html = /*html*/`<span class="math-tex">\\[\sqrt{x^{2}+1}\\]</span>`;
|
||||||
const expected = `$$\sqrt{x^{2}+1}$$`;
|
const expected = `$$\sqrt{x^{2}+1}$$`;
|
||||||
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
expect(markdownExportService.toMarkdown(html)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
@ -215,13 +215,13 @@ function buildMathFilter(): Rule {
|
|||||||
},
|
},
|
||||||
replacement(content) {
|
replacement(content) {
|
||||||
// Inline math
|
// Inline math
|
||||||
if (content.startsWith("(") && content.endsWith(")")) {
|
if (content.startsWith("\\\\(") && content.endsWith("\\\\)")) {
|
||||||
return `$${content.substring(1, content.length - 1)}$`;
|
return `$${content.substring(3, content.length - 3)}$`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display math
|
// Display math
|
||||||
if (content.startsWith("\\[") && content.endsWith("\\]")) {
|
if (content.startsWith(String.raw`\\\[`) && content.endsWith(String.raw`\\\]`)) {
|
||||||
return `$$${content.substring(2, content.length - 2)}$$`;
|
return `$$${content.substring(4, content.length - 4)}$$`;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unknown.
|
// Unknown.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user