aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utility/markdown.ts
blob: 3d086f0b2bed66798bc32003741651546f423c3b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*** EXPORT ------------------------------------------- ***/

export default (input: string): string => {
  return input
    .replace(/(\*\*|__)(.*?)\1/g, `<strong>$2</strong>`) /*** bold ***/
    .replace(/(\*|_)(.*?)\1/g, "<em>$2</em>") /*** italic ***/
    .replace(/(\~~)(.*?)\1/g, "<del>$2</del>") /*** strikethrough ***/
    .replace(/'/g, "’")             /*** fancy apostrophe ***/
    .replace(/(:nbhyp:)/g, "‑")     /*** non‑breaking hyphen ***/
    .replace(/(:nbsp:)/g, " ")      /*** non‑breaking space ***/
    .replace(/(\.\.\.)/g, "…")      /*** ellipsis ***/
    // .replace(/---/g, "<hr/>")
    .replace(/\[([^\]]+)\]\(([^)]+)\)/g, `<a href="$2" target="_blank">$1</a>`); /*** link ***/

  // TODO
  // : check if link is local and if not, add `target="_blank"`
}