From 3c0a01db9506408e906cf0c97f91dc9fac460076 Mon Sep 17 00:00:00 2001 From: NunoSempere Date: Wed, 11 Aug 2021 23:06:46 +0200 Subject: [PATCH] fix: Better markdown conversion for Hypermind questions --- src/platforms/hypermind-fetch.js | 2 +- src/utils/algolia.js | 2 +- src/utils/toMarkdown.js | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/platforms/hypermind-fetch.js b/src/platforms/hypermind-fetch.js index d5462ae..f867896 100644 --- a/src/platforms/hypermind-fetch.js +++ b/src/platforms/hypermind-fetch.js @@ -133,7 +133,7 @@ async function hypermind_inner(cookie) { let descriptionprocessed2 = descriptionprocessed1.replaceAll("![image] ()", "") let descriptionprocessed3 = descriptionprocessed2.replaceAll(" Forecasting Schedule ", "") let descriptionprocessed4 = descriptionprocessed3.replaceAll("\n", "") - let descriptionprocessed5 = descriptionprocessed4.replaceAll("Context: ", "") + let descriptionprocessed5 = descriptionprocessed4.replaceAll("Context:", "") let description = descriptionprocessed5 || toMarkdown(result.props.details) return ({ "title": result.props.title, diff --git a/src/utils/algolia.js b/src/utils/algolia.js index 7f86c78..9405400 100644 --- a/src/utils/algolia.js +++ b/src/utils/algolia.js @@ -35,4 +35,4 @@ export async function rebuildAlgoliaDatabaseTheEasyWay(){ } } -export const rebuildAlgoliaDatabase = rebuildAlgoliaDatabaseTheHardWay \ No newline at end of file +export const rebuildAlgoliaDatabase = rebuildAlgoliaDatabaseTheEasyWay//rebuildAlgoliaDatabaseTheHardWay \ No newline at end of file diff --git a/src/utils/toMarkdown.js b/src/utils/toMarkdown.js index 7493e53..86ffb67 100644 --- a/src/utils/toMarkdown.js +++ b/src/utils/toMarkdown.js @@ -2,6 +2,8 @@ import textVersion from "textversionjs" /* Definitions */ +String.prototype.replaceAll = function replaceAll(search, replace) { return this.split(search).join(replace); } + var styleConfig = { linkProcess: function(href, linkText){ let newHref = href ? href.replace(/\(/g, "%28").replace(/\)/g, "%29") : "" @@ -15,7 +17,9 @@ var styleConfig = { /* Body */ export default function toMarkdown(htmlText){ - return textVersion(htmlText, styleConfig); + let html2 = htmlText.replaceAll(`='`, `="`).replaceAll(`'>`, `">`) + return textVersion(html2, styleConfig); } -// toMarkdown() +// toMarkdown() +// console.log(toMarkdown("Context:Many intellectual endeavors require mathematical problem solving, but this skill remains beyond the capabilities of computers. To help advance the art, the MATH dataset offers..."))