From 2c5f111c564537a8330af2ca8a6ca2bf480bed0d Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Thu, 13 May 2021 14:07:56 +0700 Subject: [PATCH] #6 made better content stripping --- package.json | 3 ++- src/service/template/index.ts | 7 ++++--- yarn.lock | 5 +++++ 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4f4b57d..05f382d 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "remark-parse-frontmatter": "^1.0.3", "retext": "^7.0.1", "socks-proxy-agent": "^5.0.0", + "strip-markdown": "^4.0.0", "telegraf": "^4.3.0", "to-vfile": "^6.1.0", "typeorm": "^0.2.32", @@ -39,9 +40,9 @@ }, "devDependencies": { "@types/axios": "^0.14.0", - "@types/node": "^14.14.37", "@types/express": "^4.17.11", "@types/handlebars": "^4.1.0", + "@types/node": "^14.14.37", "@types/ramda": "^0.27.39", "@types/winston": "^2.4.4", "@types/yargs": "^16.0.1", diff --git a/src/service/template/index.ts b/src/service/template/index.ts index 2806213..52d743d 100644 --- a/src/service/template/index.ts +++ b/src/service/template/index.ts @@ -1,13 +1,13 @@ import extract from "remark-extract-frontmatter"; import frontmatter from "remark-frontmatter"; import stringify from "remark-stringify"; -import textStringify from "retext-stringify"; import parser from "remark-parse"; import unified from "unified"; import { parse } from "yaml"; import toVFile from "to-vfile"; import path from "path"; import hb from "handlebars"; +import strip from "strip-markdown"; const removeFrontmatter = () => (tree) => { tree.children = tree.children.filter((item) => item.type !== "yaml"); @@ -62,11 +62,12 @@ export class Template< public static cleanText(text: string) { const processor = unified() - .use(textStringify) + .use(stringify) .use(frontmatter) .use(extract, { yaml: parse }) .use(removeFrontmatter) - .use(parser); + .use(parser) + .use(strip); return processor.processSync(text).contents.toString(); } diff --git a/yarn.lock b/yarn.lock index e3044ba..2b4a347 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1686,6 +1686,11 @@ strip-ansi@^6.0.0: dependencies: ansi-regex "^5.0.0" +strip-markdown@^4.0.0: + version "4.0.0" + resolved "https://registry.yarnpkg.com/strip-markdown/-/strip-markdown-4.0.0.tgz#1f48aeb5ce81b646487d9f8fbdc18f8bf1416ba2" + integrity sha512-jwoS5zwHNFjergQjg4RFzmdS4n5WOd5DXDIwRY0jye9ALYMscLWfwZVBMt4P/va5aRmm7Dlj6O4NjMuaD7609Q== + supports-color@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/supports-color/-/supports-color-2.0.0.tgz#535d045ce6b6363fa40117084629995e9df324c7"