@splendidlabz/utils 1.5.0-alpha.0 → 1.5.0-alpha.1

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
  # @splendidlabz/utils
2
2
 
3
+ ## 1.5.0-alpha.1
4
+
5
+ ### Patch Changes
6
+
7
+ - df4f2d6: Simplified Markdown — so utils now contain a markdown function
8
+
3
9
  ## 1.5.0-alpha.0
4
10
 
5
11
  ### Minor Changes
@@ -1,13 +1,26 @@
1
+ import { marked } from 'marked'
2
+ import { gfmHeadingId } from 'marked-gfm-heading-id'
3
+ import { mangle } from 'marked-mangle'
4
+
5
+ export function markdown(content, options = {}) {
6
+ const defaultOptions = { inline: false }
7
+ const opts = { ...defaultOptions, ...options }
8
+
9
+ // Prepare Marked
10
+ marked.use(mangle())
11
+ marked.use(gfmHeadingId())
12
+
13
+ const { content: treated } = treatMarkdownWhitespace(content, opts)
14
+ return marked.parse(treated)
15
+ }
16
+
1
17
  /**
2
18
  * Removes leading whitespaces from a Markdown content so they can be rendered appropriately.
3
19
  * @param {string} content - The content to treat
4
20
  * @param {Boolean} options.inline - Whether content is inline, not block
5
21
  * @returns
6
22
  */
7
- export function treatMarkdownWhitespace(
8
- content,
9
- { inline, isSlot = false } = {},
10
- ) {
23
+ export function treatMarkdownWhitespace(content, { inline } = {}) {
11
24
  if (!content) return { content: '', inline }
12
25
  const lines = content.split('\n')
13
26
 
@@ -19,9 +32,7 @@ export function treatMarkdownWhitespace(
19
32
  const firstLineWithLeadingSpacesIndex = lines.findIndex(line =>
20
33
  line.match(/^\s+/),
21
34
  )
22
-
23
35
  const firstLineWithLeadingSpaces = lines[firstLineWithLeadingSpacesIndex]
24
-
25
36
  const indentation =
26
37
  firstLineWithLeadingSpaces?.match(/^\s+/)?.[0]?.length ?? 0
27
38
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@splendidlabz/utils",
3
- "version": "1.5.0-alpha.0",
3
+ "version": "1.5.0-alpha.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -24,7 +24,10 @@
24
24
  "dompurify": "^3.2.4",
25
25
  "glob-promise": "^6.0.7",
26
26
  "pluralize": "^8.0.0",
27
- "statuses": "^2.0.1"
27
+ "statuses": "^2.0.1",
28
+ "marked": "^15.0.7",
29
+ "marked-gfm-heading-id": "^4.1.1",
30
+ "marked-mangle": "^1.1.10"
28
31
  },
29
32
  "devDependencies": {
30
33
  "@splendidlabz/eslint-config": "*",