Skip to content

Commit 8c8387b

Browse files
committed
Changed regexp for fences
1 parent 814f3e8 commit 8c8387b

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

src/cmem/markdown/truncateMarkdown.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ interface ListItemRange {
2424

2525
const getFenceRanges = (content: string): FenceRange[] => {
2626
const fenceRanges: FenceRange[] = [];
27-
const fenceRegex = /^([`~]{3,})[^\n]*(?:\n|$)/gm;
27+
const fenceRegex = /^[ ]{0,3}([`~]{3,})[^\n]*(?:\n|$)/gm;
2828
let fenceMatch = fenceRegex.exec(content);
2929

3030
while (fenceMatch !== null) {
3131
// Keep the original marker so a truncated fence is closed with the same marker style.
3232
const marker = fenceMatch[1];
3333
const start = fenceMatch.index;
3434
const contentStart = fenceRegex.lastIndex;
35-
const closeRegex = new RegExp(`^${marker}\\s*$`, "gm");
35+
const closeRegex = new RegExp(`^[ ]{0,3}${marker[0]}{${marker.length},}\\s*$`, "gm");
3636
closeRegex.lastIndex = contentStart;
3737
const closeMatch = closeRegex.exec(content);
3838
const contentEnd = closeMatch ? closeMatch.index : content.length;
@@ -218,7 +218,7 @@ export const truncateMarkdown = (content: string, cutOff: number, suffix?: strin
218218
if (activeFence) {
219219
const cutBeforeFence = activeFence.start > 0 && content.slice(0, activeFence.start).trim().length > 0;
220220
if (cutPoint !== -1 || cutBeforeFence) {
221-
return appendSuffix(content.slice(0, cutPoint !== -1 ? cutPoint : activeFence.start));
221+
return appendSuffix(content.slice(0, cutBeforeFence ? activeFence.start : cutPoint));
222222
}
223223

224224
return appendSuffix(truncateActiveFence(content, safeCutOff, activeFence));

0 commit comments

Comments
 (0)