mirror of
https://github.com/rowboatlabs/rowboat.git
synced 2026-04-25 00:16:29 +02:00
fix \n repitition in markdown editor
This commit is contained in:
parent
1306b7f442
commit
e8a7cd59c1
1 changed files with 10 additions and 5 deletions
|
|
@ -58,17 +58,22 @@ function preprocessMarkdown(markdown: string): string {
|
||||||
// line until a blank line terminates it, and markdown inline rules (bold,
|
// line until a blank line terminates it, and markdown inline rules (bold,
|
||||||
// italics, links) don't apply inside the block. Without surrounding blank
|
// italics, links) don't apply inside the block. Without surrounding blank
|
||||||
// lines, the line right after our placeholder div gets absorbed as HTML and
|
// lines, the line right after our placeholder div gets absorbed as HTML and
|
||||||
// its markdown is not parsed. We consume any adjacent newlines in the match
|
// its markdown is not parsed.
|
||||||
// and emit exactly `\n\n<div></div>\n\n` so the HTML block starts and ends on
|
//
|
||||||
// its own line.
|
// Consume ALL adjacent newlines (\n*, not \n?) so the emitted `\n\n…\n\n`
|
||||||
|
// is load/save stable. serializeBlocksToMarkdown emits `\n\n` between blocks
|
||||||
|
// on save; a `\n?` regex on reload would only consume one of those two
|
||||||
|
// newlines, so every cycle would add a net newline on each side of every
|
||||||
|
// marker — causing tracks running on an open note to steadily inflate the
|
||||||
|
// file with blank lines around target regions.
|
||||||
function preprocessTrackTargets(md: string): string {
|
function preprocessTrackTargets(md: string): string {
|
||||||
return md
|
return md
|
||||||
.replace(
|
.replace(
|
||||||
/\n?<!--track-target:([^\s>]+)-->\n?/g,
|
/\n*<!--track-target:([^\s>]+)-->\n*/g,
|
||||||
(_m, id: string) => `\n\n<div data-type="track-target-open" data-track-id="${id}"></div>\n\n`,
|
(_m, id: string) => `\n\n<div data-type="track-target-open" data-track-id="${id}"></div>\n\n`,
|
||||||
)
|
)
|
||||||
.replace(
|
.replace(
|
||||||
/\n?<!--\/track-target:([^\s>]+)-->\n?/g,
|
/\n*<!--\/track-target:([^\s>]+)-->\n*/g,
|
||||||
(_m, id: string) => `\n\n<div data-type="track-target-close" data-track-id="${id}"></div>\n\n`,
|
(_m, id: string) => `\n\n<div data-type="track-target-close" data-track-id="${id}"></div>\n\n`,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue