lightnet 3.4.5 → 3.4.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # lightnet
2
2
 
3
+ ## 3.4.6
4
+
5
+ ### Patch Changes
6
+
7
+ - [#271](https://github.com/LightNetDev/LightNet/pull/271) [`1ad0515`](https://github.com/LightNetDev/LightNet/commit/1ad051587cdf68c34a919f414ad2b5c15ffd273e) Thanks [@smn-cds](https://github.com/smn-cds)! - Fix markdown sanitation for search result descriptions.
8
+
3
9
  ## 3.4.5
4
10
 
5
11
  ### Patch Changes
@@ -2,6 +2,27 @@ import { expect, test } from "vitest"
2
2
 
3
3
  import { markdownToText } from "../../src/utils/markdown"
4
4
 
5
+ test("Should remove '\\' to force new lines", () => {
6
+ expect(markdownToText("a\\\nb\\ \nc")).toBe("a\nb \nc")
7
+ })
8
+
9
+ test("Should remove <br> to force new lines", () => {
10
+ expect(markdownToText("a <br> b<br>\nc")).toBe("a b \nc")
11
+ })
12
+
13
+ test("Should remove double white space", () => {
14
+ expect(markdownToText("a b")).toBe("a b")
15
+ })
16
+
17
+ test("Should remove triple white space", () => {
18
+ expect(markdownToText("a b")).toBe("a b")
19
+ })
20
+
21
+ test("Should remove escape character '\\'", () => {
22
+ // eslint-disable-next-line no-useless-escape
23
+ expect(markdownToText("a \\\* \\\# b")).toBe("a * # b")
24
+ })
25
+
5
26
  test("Should remove headers", () => {
6
27
  expect(markdownToText("# H1\n## H2 words#")).toBe("H1\nH2 words#")
7
28
  })
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "lightnet",
3
3
  "type": "module",
4
4
  "license": "MIT",
5
- "version": "3.4.5",
5
+ "version": "3.4.6",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/LightNetDev/lightnet",
@@ -6,12 +6,15 @@ import { marked } from "marked"
6
6
  * @param markdown string
7
7
  * @returns plain text
8
8
  */
9
+
9
10
  export function markdownToText(markdown?: string) {
10
11
  if (!markdown) {
11
12
  return markdown
12
13
  }
13
14
  return (
14
15
  markdown
16
+ // line breaks
17
+ .replaceAll(/<br>/g, " ")
15
18
  //headers
16
19
  .replaceAll(/^#+ ?/gm, "")
17
20
  // lists
@@ -19,11 +22,15 @@ export function markdownToText(markdown?: string) {
19
22
  // block quotes
20
23
  .replaceAll(/^>+ ?/gm, "")
21
24
  // bold and italics
22
- .replaceAll(/[*_]/g, "")
25
+ .replaceAll(/(?<!\\)[*_]/g, "")
23
26
  // images
24
27
  .replaceAll(/!\[(.*?)\]\(.*?\)/g, (_, imgAlt) => imgAlt)
25
28
  // links
26
29
  .replaceAll(/\[(.*?)\]\(.*?\)/g, (_, linkLabel) => linkLabel)
30
+ // escape character '\'
31
+ .replaceAll(/\\/g, "")
32
+ // multi white spaces
33
+ .replaceAll(/ +/g, " ")
27
34
  )
28
35
  }
29
36