Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/forum.nim
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,15 @@ proc updateProfile(
$rank, email, username
)

proc escapeMDCharacters(s: string): string =
## Escapes problematic Markdown characters:
## `# ` as it gets interpreted as headline
## `[` as it gets interpreted as startingpoint for a hyperlink
const headlineHash = ("# ", "\\# ")
const linkBracket = ("[", "\\[")
result = s.multireplace(@[headlineHash, linkBracket])


include "main.tmpl"

initialise()
Expand Down Expand Up @@ -1607,19 +1616,22 @@ routes:

get "/search.json":
cond "q" in request.params
let q = @"q"
cond q.len > 0
let searchTerm: string = @"q"
cond searchTerm.len > 0

var results: seq[SearchResult] = @[]

const queryFT = "fts.sql".slurp.sql
const count = 40
const count: string = $40
const offset: string = $0
let data = [
q, q, $count, $0, q,
q, $count, $0, q
searchTerm, searchTerm, count, offset, searchTerm,
searchTerm, count, offset, searchTerm
]
for rowFT in fastRows(db, queryFT, data):
var content = rowFT[3]
content = content.escapeMDCharacters()

try: content = content.rstToHtml() except EParseError: discard
results.add(
SearchResult(
Expand Down
2 changes: 1 addition & 1 deletion src/fts.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ SELECT
thread.name AS thread,
post.id AS post_id,
CASE what WHEN 1
THEN snippet(post_fts, '**', '**', '...', what, -45)
THEN snippet(post_fts, ' **', '** ', '...', what, -45)
ELSE SUBSTR(post_fts.content, 1, 200) END AS content,
cdate,
person.id,
Expand Down