-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (36 loc) · 1.3 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { marked } from "marked";
import { PlainTextRenderer } from "./PlainTextRenderer.js";
let defaultOptions = {
sanitize: false,
mangle: false,
headerIds: false
}
function convertMarkdownToPlainText(markdownText, markedOptions = defaultOptions) {
const renderer = new PlainTextRenderer();
marked.setOptions(markedOptions);
return marked(markdownText, { renderer })
}
function __convertASCIINamesToText(str) {
// convert HTML Names (eg. "&" => "&")
/* every HTMLName replacement needs to be a
separate statement, because string.replace()
can only replace one value at a time.*/
let replaceAmp = str.replaceAll(""", '"');
let replaceQuot = replaceAmp.replaceAll("&", "&");
let convertedHTMLNames = replaceQuot;
return convertedHTMLNames
}
function __convertASCIINumbersToText(str) {
// convert HTML Numbers (eg. "$" => $)
return str.replace(/&#(\d+);/g, (match, code) => {
let convertedHTMLNumbers = String.fromCharCode(Number(code));
return convertedHTMLNumbers
});
}
function convertASCIICharsToText(str) {
let conversion1 = __convertASCIINamesToText(str);
let conversion2 = __convertASCIINumbersToText(conversion1);
let processedString = conversion2;
return processedString
}
export { convertMarkdownToPlainText, convertASCIICharsToText }