update textConverter, close issue #7

This commit is contained in:
somrat sorkar
2023-08-02 09:05:45 +06:00
parent 692dde74d6
commit a08c950a4c
2 changed files with 12 additions and 11 deletions
+5 -5
View File
@@ -19,7 +19,7 @@
"@astrojs/rss": "^2.4.3",
"@astrojs/sitemap": "^2.0.1",
"@astrojs/tailwind": "^4.0.0",
"astro": "^2.9.6",
"astro": "^2.9.7",
"astro-auto-import": "^0.3.0",
"date-fns": "^2.30.0",
"date-fns-tz": "^2.0.0",
@@ -27,7 +27,7 @@
"fuse.js": "^6.6.2",
"github-slugger": "^2.0.0",
"gray-matter": "^4.0.3",
"marked": "^5.1.2",
"marked": "^6.0.0",
"prettier-plugin-astro": "^0.11.0",
"prettier-plugin-tailwindcss": "^0.4.1",
"prop-types": "^15.8.1",
@@ -38,14 +38,14 @@
"remark-collapse": "^0.1.2",
"remark-toc": "^8.0.1",
"sharp": "^0.32.4",
"swiper": "^10.0.4"
"swiper": "^10.1.0"
},
"devDependencies": {
"@tailwindcss/forms": "^0.5.4",
"@tailwindcss/typography": "^0.5.9",
"@types/marked": "^5.0.1",
"@types/node": "20.4.5",
"@types/react": "18.2.17",
"@types/react": "18.2.18",
"@types/react-dom": "18.2.7",
"autoprefixer": "^10.4.14",
"eslint": "^8.46.0",
@@ -53,7 +53,7 @@
"prettier": "^3.0.0",
"prettier-plugin-astro": "^0.11.0",
"prettier-plugin-tailwindcss": "^0.4.1",
"sass": "^1.64.1",
"sass": "^1.64.2",
"tailwindcss": "^3.3.3",
"tailwind-bootstrap-grid": "^5.0.1",
"typescript": "5.1.6"
+7 -6
View File
@@ -7,17 +7,17 @@ marked.use({
});
// slugify
export const slugify = (content: string): string => {
export const slugify = (content: string) => {
return slug(content);
};
// markdownify
export const markdownify = (content: string, div?: boolean): string => {
export const markdownify = (content: string, div?: boolean) => {
return div ? marked.parse(content) : marked.parseInline(content);
};
// humanize
export const humanize = (content: string): string => {
export const humanize = (content: string) => {
return content
.replace(/^[\s_]+|[\s_]+$/g, "")
.replace(/[_\s]+/g, " ")
@@ -27,15 +27,16 @@ export const humanize = (content: string): string => {
};
// plainify
export const plainify = (content: string): string => {
const filterBrackets = content.replace(/<\/?[^>]+(>|$)/gm, "");
export const plainify = (content: string) => {
const parseMarkdown = marked.parse(content);
const filterBrackets = parseMarkdown.replace(/<\/?[^>]+(>|$)/gm, "");
const filterSpaces = filterBrackets.replace(/[\r\n]\s*[\r\n]/gm, "");
const stripHTML = htmlEntityDecoder(filterSpaces);
return stripHTML;
};
// strip entities for plainify
const htmlEntityDecoder = (htmlWithEntities: string): string => {
const htmlEntityDecoder = (htmlWithEntities: string) => {
let entityList: { [key: string]: string } = {
"&nbsp;": " ",
"&lt;": "<",