diff options
| author | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-06 16:17:14 +0100 | 
|---|---|---|
| committer | Raphael Kabo <raphaelkabo@hey.com> | 2023-10-06 16:19:06 +0100 | 
| commit | c64b6febe5298219858bdc7ad27c3dfa1117a4de (patch) | |
| tree | e3943d91e24f9df9175942394940768ca110901f | |
| parent | 44cd1d5b4ee6bfbccffbf6c2448b684a7afd31de (diff) | |
Add util files
| -rw-r--r-- | src/util/markdown.ts | 44 | 
1 files changed, 44 insertions, 0 deletions
diff --git a/src/util/markdown.ts b/src/util/markdown.ts new file mode 100644 index 0000000..b1577d9 --- /dev/null +++ b/src/util/markdown.ts @@ -0,0 +1,44 @@ +// Extra marked renderer (used to render plaintext event description for page metadata) +// Adapted from https://dustinpfister.github.io/2017/11/19/nodejs-marked/ + +import { marked } from "marked"; + +// ? to ? helper +function htmlEscapeToText(text: string) { +  return text.replace(/\&\#[0-9]*;|&/g, function (escapeCode) { +    if (escapeCode.match(/amp/)) { +      return "&"; +    } +    const code = escapeCode.match(/[0-9]+/); +    return String.fromCharCode(Number(code)); +  }); +} + +export const renderPlain = () => { +  var render = new marked.Renderer(); +  // render just the text of a link, strong, em +  render.link = function (href, title, text) { +    return text; +  }; +  render.strong = function (text) { +    return text; +  }; +  render.em = function (text) { +    return text; +  }; +  // render just the text of a paragraph +  render.paragraph = function (text) { +    return htmlEscapeToText(text) + "\r\n"; +  }; +  // render nothing for headings, images, and br +  render.heading = function (text, level) { +    return ""; +  }; +  render.image = function (href, title, text) { +    return ""; +  }; +  render.br = function () { +    return ""; +  }; +  return render; +};  | 
