mirror of
https://github.com/muerwre/vk-tg-bot.git
synced 2025-04-25 06:56:40 +07:00
added links trimmer
This commit is contained in:
parent
31af4e11b1
commit
2d2c959925
3 changed files with 29 additions and 14 deletions
|
@ -9,6 +9,7 @@ import path from "path";
|
|||
import hb from "handlebars";
|
||||
import strip from "strip-markdown";
|
||||
import { VFileCompatible } from "vfile";
|
||||
import transformMDLinks from "../../utils/transformMDLinks";
|
||||
|
||||
const removeFrontmatter = () => (tree) => {
|
||||
tree.children = tree.children.filter((item) => item.type !== "yaml");
|
||||
|
@ -50,7 +51,8 @@ export class Template<
|
|||
}
|
||||
|
||||
/**
|
||||
* Themes the template with values
|
||||
* Themes the template with values, removes markdown from template.
|
||||
* NOTE: text, that we'll insert into template, won't be used here
|
||||
*/
|
||||
public theme = (values: V, markdown?: boolean) => {
|
||||
const processor = unified()
|
||||
|
@ -81,13 +83,17 @@ export class Template<
|
|||
});
|
||||
}
|
||||
|
||||
public static cleanText(text: string) {
|
||||
return unified()
|
||||
.use(stringify)
|
||||
.use(parser)
|
||||
.use(strip)
|
||||
.processSync(text)
|
||||
.contents.toString();
|
||||
/** Cleans text from markdown, but transforms links to MD if needed */
|
||||
public static cleanText(text: string, markdown?: boolean) {
|
||||
const processor = unified().use(stringify).use(parser).use(strip);
|
||||
|
||||
const output = processor.processSync(text).contents.toString();
|
||||
|
||||
if (markdown) {
|
||||
return transformMDLinks(output);
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue