mirror of
https://github.com/SableClient/Sable.git
synced 2026-12-05 16:22:26 -08:00
Fix fenced code block newline expansion
This commit is contained in:
1 parent
7a31298f39
commit
b8343ce72f
2 files changed
+21
-10
No files matched your search
@@ -33,6 +33,11 @@ describe('expandBlockBoundariesAfterSingleNewlines', () => {
|
||||
it('still expands before the first top-level list item after prose', () => {
|
||||
expect(expandBlockBoundariesAfterSingleNewlines('intro\n- item')).toBe('intro\n\n- item');
|
||||
});
|
||||
|
||||
it('does not expand block-like lines inside a fenced code block with an info string', () => {
|
||||
const md = '```text\n# heading\n- item\n+ item\n-# subheading\n1. item\n```';
|
||||
expect(expandBlockBoundariesAfterSingleNewlines(md)).toBe(md);
|
||||
});
|
||||
});
|
||||
|
||||
describe('consecutive blockquotes', () => {
|
||||
|
||||
@@ -50,7 +50,7 @@ function trySkipFenceEnd(md: string, i: number): number | null {
|
||||
if (!atLineStart) return null;
|
||||
|
||||
const rest = md.slice(i);
|
||||
const open = /^(\s{0,3})(`{3,}|~{3,})/.exec(rest);
|
||||
const open = /^( {0,3})(`{3,}|~{3,})/.exec(rest);
|
||||
if (!open?.[2]) return null;
|
||||
|
||||
const fenceStr = open[2];
|
||||
@@ -58,20 +58,26 @@ function trySkipFenceEnd(md: string, i: number): number | null {
|
||||
const openLen = fenceStr.length;
|
||||
const afterOpen = i + open[0].length;
|
||||
|
||||
if (afterOpen < md.length && md[afterOpen] === '\n') {
|
||||
const contentStart = afterOpen + 1;
|
||||
const lineEnd = md.indexOf('\n', afterOpen);
|
||||
const closeIdx = findSameLineFenceClose(md, afterOpen, tick, openLen);
|
||||
if (closeIdx >= 0) {
|
||||
let closeRun = 0;
|
||||
while (closeIdx + closeRun < md.length && md[closeIdx + closeRun] === tick) closeRun++;
|
||||
|
||||
return closeIdx + closeRun;
|
||||
}
|
||||
|
||||
if (lineEnd >= 0) {
|
||||
const info = md.slice(afterOpen, lineEnd);
|
||||
if (tick === '`' && info.includes('`')) return null;
|
||||
|
||||
const contentStart = lineEnd + 1;
|
||||
const close = findMultilineFenceEnd(md, contentStart, tick, openLen);
|
||||
if (!close) return md.length;
|
||||
return close.blockEnd;
|
||||
}
|
||||
|
||||
const closeIdx = findSameLineFenceClose(md, afterOpen, tick, openLen);
|
||||
if (closeIdx < 0) return null;
|
||||
|
||||
let closeRun = 0;
|
||||
while (closeIdx + closeRun < md.length && md[closeIdx + closeRun] === tick) closeRun++;
|
||||
|
||||
return closeIdx + closeRun;
|
||||
return null;
|
||||
}
|
||||
|
||||
function afterLeadingIndent(line: string): string {
|
||||
|
||||
Reference in new issue
Block a user