Skip to content

Commit

Permalink
add edge-case handling logic
Browse files Browse the repository at this point in the history
  • Loading branch information
SebinSong committed Dec 14, 2024
1 parent 9db4641 commit 92e9798
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion frontend/views/utils/markdown-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ export function renderMarkdown (str: string): any {
.replace(/<br>\n(\s*)(>|\d+\.|-)/g, '\n\n$1$2') // [1] custom-handling the case where <br> is directly followed by the start of ordered/unordered lists
.replace(/(>|\d+\.|-)(\s.+)\n<br>/g, '$1$2\n\n') // [2] this is a custom-logic added so that the end of ordered/un-ordered lists are correctly detected by markedjs.
.replace(/(>)(\s.+)\n<br>/gs, '$1$2\n\n') // [3] this is a custom-logic added so that the end of blockquotes are correctly detected by markedjs. ('s' flag is needed to account for multi-line strings)

console.log('!@# entryText after all transformations: ', entryText)
entry.text = entryText
}
})

str = combineMarkdownSegmentListIntoString(strSplitByCodeMarkdown)
str = str.replace(/(\d+\.|-)(\s.+)\n<br>/g, '$1$2\n\n') // Check for [2] above once more to resolve edge-cases (reference: https://github.com/okTurtles/group-income/issues/2356)
str = str.replace(/(\d+\.|-)(\s.+)\n<br>/g, '$1$2\n\n')
.replace(/(>)(\s.+)\n<br>/gs, '$1$2\n\n') // Check for [2], [3] above once more to resolve edge-cases (reference: https://github.com/okTurtles/group-income/issues/2356)

// STEP 2. convert the markdown into html DOM string.
let converted = marked.parse(str, { gfm: true })
Expand Down

0 comments on commit 92e9798

Please sign in to comment.