Merge pull request #92 from quantified-uncertainty/better-cleantext

Fix cleanText for metaculus
This commit is contained in:
Vyacheslav Matyukhin 2022-06-05 00:42:04 +03:00 committed by GitHub
commit f98958f27e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,8 +14,8 @@ export const getBasePath = () => {
}; };
export const cleanText = (text: string): string => { export const cleanText = (text: string): string => {
// Note: should no longer be necessary? // TODO - move to GraphQL:
// Still needed for e.g. /questions/rootclaim-what-caused-the-disappearance-of-malaysia-airlines-flight-370 // { description(clean: true, truncate: 250) }
let textString = !!text ? text : ""; let textString = !!text ? text : "";
textString = textString textString = textString
.replaceAll("] (", "](") .replaceAll("] (", "](")
@ -23,12 +23,13 @@ export const cleanText = (text: string): string => {
.replaceAll("( [", "([") .replaceAll("( [", "([")
.replaceAll(") ,", "),") .replaceAll(") ,", "),")
.replaceAll("==", "") // Denotes a title in markdown .replaceAll("==", "") // Denotes a title in markdown
.replaceAll("Background\n", "") .replaceAll(/^#+\s+/gm, "")
.replaceAll("Context\n", "") .replaceAll(/^Background\n/gm, "")
.replaceAll(/^Context\n/gm, "")
.replaceAll("--- \n", "- ") .replaceAll("--- \n", "- ")
.replaceAll(/\[(.*?)\]\(.*?\)/g, "$1"); .replaceAll(/\[(.*?)\]\(.*?\)/g, "$1");
textString = textString.slice(0, 1) == "=" ? textString.slice(1) : textString; textString = textString.slice(0, 1) == "=" ? textString.slice(1) : textString;
//console.log(textString)
return textString; return textString;
}; };