Skip to content

Commit

Permalink
More conservative strong/em markdown matcher (#352)
Browse files Browse the repository at this point in the history
Both matchers are now constrained so that they will only be transformed
if the left-hand characters are the start of the text or preceeded by
whitespace, and the right-hand characters are the end of the text or
followed by whitespace or a punctuation mark.

This misses some cases, e.g. emphasis inside of parantheticals, but has
better behavior with e.g. underscores in function names outside of code
blocks.

Fixes #317.
  • Loading branch information
mrdomino committed May 6, 2024
1 parent 7900294 commit eecbf89
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions llama.cpp/server/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1125,8 +1125,8 @@

// Headlines, emphasis and line breaks
.replace(/^#{1,6} (.*)$/gim, '<h3>$1</h3>')
.replace(/(__|\*\*)(.*?)\1/g, '<strong>$2</strong>')
.replace(/(_|\*)(.*?)\1/g, '<em>$2</em>')
.replace(/(^|\s)(__|\*\*)(.*?)\2($|\s|[.?!])/g, '$1<strong>$3</strong>$4')
.replace(/(^|\s)(_|\*)(.*?)\2($|\s|[.?!])/g, '$1<em>$3</em>$4')
.replace(/\n/gim, '<br />')

// Paste the extracted blocks back in again
Expand Down

0 comments on commit eecbf89

Please sign in to comment.