@magic/transmute 0.0.59 → 0.0.61

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/README.md CHANGED
@@ -3,10 +3,6 @@
3
3
  transmutes html and markdown to @magic view fragments
4
4
 
5
5
  [![NPM version][npm-image]][npm-url]
6
- [![Linux Build Status][travis-image]][travis-url]
7
- [![Windows Build Status][appveyor-image]][appveyor-url]
8
- [![Coverage Status][coveralls-image]][coveralls-url]
9
- [![Known Vulnerabilities][snyk-image]][snyk-url]
10
6
 
11
7
  ### installation
12
8
 
@@ -40,7 +36,7 @@ npm i --save @magic/transmute
40
36
  #### flags:
41
37
 
42
38
  - --add-wrapper - add export default[] to the returned string. - alias: ["--addWrapper"]
43
- - --no-pretty - do not run prettier. - alias: ["--noPretty"]
39
+ - --no-pretty - do not run oxfmt. - alias: ["--noPretty"]
44
40
  - --markdown - force markdown parser to run. - alias: ["--mark", "-m"]
45
41
  - --output - output file path - alias: ["--out", "-o"]
46
42
  - --input - input file path - alias: ["--in", "-i"]
@@ -343,17 +339,35 @@ update dependencies
343
339
 
344
340
  - update dependencies
345
341
 
346
- ##### 0.0.59 - unreleased
342
+ ##### 0.0.59
343
+
344
+ - update dependencies
345
+
346
+ ##### 0.0.60
347
+
348
+ - replace prettier with oxfmt in runCli
349
+ - remove prettier dependency, add oxfmt 0.78.0
350
+ - update help text and docs to say 'do not run oxfmt'
351
+ - adjust test expectations for oxfmt
352
+ - exclude docs and example/pages/html.html from package
353
+ - add test coverage for state implantation through public API
354
+ - add unit tests for html and markdown renderers
355
+ - add tests for CLI argument handling, runCli and CLI itself
356
+ - add tests for implantState and stringDecode
357
+ - await oxfmt format in runCli
358
+ - make tsc and oxlint happy
359
+ - remove duplicate --output from CLI help
360
+ - format example files
361
+ - remove .travis and appveyor config files
362
+ - format package.json
363
+ - add @magic/lint, add npm run tasks for tsc and lint, add oxlint.config and tsconfig files
364
+ - update multiple dependencies
365
+
366
+ ##### 0.0.61
367
+
368
+ - sort imports
369
+ - update dependencies
347
370
 
348
- ...
349
371
 
350
- [npm-image]: https://img.shields.io/npm/v/@magic/transmute.svg
372
+ [npm-image]: https://img.shields.io/npm/v/@magic/transmute.sv
351
373
  [npm-url]: https://www.npmjs.com/package/@magic/transmute
352
- [travis-image]: https://img.shields.io/travis/com/magic/transmute/master
353
- [travis-url]: https://travis-ci.com/magic/transmute
354
- [appveyor-image]: https://img.shields.io/appveyor/ci/magic/transmute/master.svg
355
- [appveyor-url]: https://ci.appveyor.com/project/magic/transmute/branch/master
356
- [coveralls-image]: https://coveralls.io/repos/github/magic/transmute/badge.svg
357
- [coveralls-url]: https://coveralls.io/github/magic/transmute
358
- [snyk-image]: https://snyk.io/test/github/magic/transmute/badge.svg
359
- [snyk-url]: https://snyk.io/test/github/magic/transmute
package/package.json CHANGED
@@ -1,48 +1,59 @@
1
1
  {
2
2
  "name": "@magic/transmute",
3
- "version": "0.0.59",
4
- "author": "Wizards & Witches",
5
- "homepage": "https://magic.github.io/transmute",
6
- "license": "AGPL-3.0",
3
+ "version": "0.0.61",
7
4
  "description": "convert markdown and html to magic function strings.",
8
- "main": "src/index.js",
9
- "type": "module",
10
- "bin": {
11
- "magic-transmute": "src/bin.js"
12
- },
13
- "files": [
14
- "src"
5
+ "keywords": [
6
+ "html",
7
+ "magic",
8
+ "markdown",
9
+ "transmute"
15
10
  ],
16
- "engines": {
17
- "node": ">=14.15.4"
11
+ "homepage": "https://magic.github.io/transmute",
12
+ "bugs": {
13
+ "url": "https://github.com/magic/transmute/issues"
18
14
  },
19
- "engineStrict": true,
15
+ "license": "AGPL-3.0",
16
+ "author": "Wizards & Witches",
17
+ "contributors": [
18
+ {
19
+ "name": "jascha ehrenreich",
20
+ "github": "jaeh"
21
+ }
22
+ ],
20
23
  "repository": {
21
24
  "type": "git",
22
25
  "url": "git+https://github.com/magic/transmute.git"
23
26
  },
24
- "bugs": {
25
- "url": "https://github.com/magic/transmute/issues"
27
+ "bin": {
28
+ "magic-transmute": "src/bin.js"
26
29
  },
30
+ "files": [
31
+ "src"
32
+ ],
33
+ "type": "module",
34
+ "main": "src/index.js",
27
35
  "scripts": {
28
36
  "start": "t -p",
29
37
  "test": "t",
30
- "format": "f -w --exclude docs",
38
+ "format": "f -w '!docs' '!example/pages/html.html'",
31
39
  "build": "NODE_ENV=production magic build",
32
40
  "prod": "NODE_ENV=production magic build serve",
33
41
  "dev": "magic dev",
34
42
  "dirty-cli-test": "src/bin/bin.js file --input test/.data/testing.md --output testing.js && echo 'contents: ' && cat testing.js && echo 'deleting testing.js' && rm testing.js",
35
- "calls": "calls"
43
+ "lint": "lint",
44
+ "tsc": "tsc --noEmit",
45
+ "tsc:test": "tsc --noEmit -p tsconfig.test.json",
46
+ "check": "npm run tsc && npm run tsc:test && npm run lint"
36
47
  },
37
48
  "dependencies": {
38
- "@magic/cases": "0.0.13",
39
- "@magic/cli": "0.0.54",
40
- "@magic/entities": "0.0.17",
41
- "@magic/log": "0.1.22",
42
- "@magic/types": "0.1.37",
43
- "marked": "18.0.5",
44
- "posthtml-parser": "0.12.1",
45
- "prettier": "3.8.5"
49
+ "@magic/cases": "0.0.15",
50
+ "@magic/cli": "0.0.56",
51
+ "@magic/entities": "0.0.19",
52
+ "@magic/log": "0.1.26",
53
+ "@magic/types": "0.1.42",
54
+ "marked": "18.2.1",
55
+ "oxfmt": "0.79.0",
56
+ "posthtml-parser": "0.13.0"
46
57
  },
47
58
  "devDependencies": {
48
59
  "@magic-modules/git-badges": "0.0.12",
@@ -50,20 +61,16 @@
50
61
  "@magic-modules/no-spy": "0.0.9",
51
62
  "@magic-modules/pre": "0.0.12",
52
63
  "@magic-themes/docs": "0.0.15",
53
- "@magic/core": "0.0.158",
54
- "@magic/format": "0.0.74",
55
- "@magic/test": "0.3.12"
64
+ "@magic/core": "0.0.161",
65
+ "@magic/format": "0.0.82",
66
+ "@magic/lint": "0.0.6",
67
+ "@magic/test": "0.3.59"
56
68
  },
57
- "keywords": [
58
- "magic",
59
- "transmute",
60
- "html",
61
- "markdown"
62
- ],
63
- "contributors": [
64
- {
65
- "name": "jascha ehrenreich",
66
- "github": "jaeh"
67
- }
68
- ]
69
+ "engines": {
70
+ "node": ">=14.15.4"
71
+ },
72
+ "engineStrict": true,
73
+ "allowScripts": {
74
+ "@swc/core@1.15.47": true
75
+ }
69
76
  }
@@ -3,6 +3,10 @@ import path from 'path'
3
3
 
4
4
  import log from '@magic/log'
5
5
 
6
+ /**
7
+ * @param {import('@magic/cli').ParsedCLI} sr
8
+ * @returns {[string, boolean]}
9
+ */
6
10
  export const handleArgv = sr => {
7
11
  const { commands, args, argv } = sr
8
12
 
package/src/bin/runCli.js CHANGED
@@ -1,40 +1,54 @@
1
- import path from 'path'
2
1
  import fs from 'fs'
3
-
4
- import prettier from 'prettier'
2
+ import path from 'path'
5
3
 
6
4
  import log from '@magic/log'
7
5
  import is from '@magic/types'
8
6
 
7
+ import { format } from 'oxfmt'
9
8
  import transmute from '../index.js'
10
9
 
11
- export const runCli = (html, isMarkdown, res) => {
12
- let out
13
- if (isMarkdown) {
14
- out = transmute.markdown(html)
15
- } else {
16
- out = transmute.html(html)
17
- }
10
+ // oxfmt's format returns a promise, so the pretty path is async.
11
+ /**
12
+ * @param {string} source
13
+ * @returns {Promise<string>}
14
+ */
15
+ const formatCode = async source => {
16
+ const result = await format('script.js', source, {
17
+ semi: false,
18
+ singleQuote: true,
19
+ trailingComma: 'es5',
20
+ })
18
21
 
19
- if (is.array(out.rendered)) {
20
- if (out.rendered.length === 1) {
21
- out.rendered = out.rendered[0]
22
+ return result.code
23
+ }
24
+
25
+ /**
26
+ * @param {string} html
27
+ * @param {boolean} isMarkdown
28
+ * @param {import('@magic/cli').ParsedCLI} res
29
+ */
30
+ export const runCli = async (html, isMarkdown, res) => {
31
+ const out = isMarkdown ? transmute.markdown(html) : transmute.html(html)
32
+
33
+ let rendered = out.rendered
34
+
35
+ if (is.array(rendered)) {
36
+ if (rendered.length === 1) {
37
+ rendered = rendered[0]
22
38
  } else {
23
- out.rendered = `[${out.rendered.join(',')}]`
39
+ rendered = `[${rendered.join(',')}]`
24
40
  }
25
41
  }
26
42
 
43
+ /** @type {string} */
44
+ let outString = rendered
45
+
27
46
  if (res.args.addWrapper) {
28
- out.rendered = `export default [\n${out.rendered},\n]`
47
+ outString = `export default [\n${outString},\n]`
29
48
  }
30
49
 
31
50
  if (!res.args.noPretty) {
32
- out.rendered = prettier.format(out.rendered, {
33
- semi: false,
34
- parser: 'babel',
35
- singleQuote: true,
36
- trailingComma: 'es5',
37
- })
51
+ outString = await formatCode(outString)
38
52
  }
39
53
 
40
54
  if (res.args.output) {
@@ -42,12 +56,12 @@ export const runCli = (html, isMarkdown, res) => {
42
56
  const dir = path.dirname(outputFile)
43
57
  if (!fs.existsSync(dir)) {
44
58
  log.info('output dir does not exist, creating it.', dir)
45
- mkdirp(dir)
59
+ fs.mkdirSync(dir, { recursive: true })
46
60
  }
47
61
 
48
62
  log.info('writing to:', { outputFile })
49
- fs.writeFileSync(outputFile, out.rendered)
63
+ fs.writeFileSync(outputFile, outString)
50
64
  } else {
51
- log(out.rendered)
65
+ log(outString)
52
66
  }
53
67
  }
package/src/bin.js CHANGED
@@ -26,10 +26,9 @@ const args = {
26
26
  options: {
27
27
  '--output': 'output file to write to',
28
28
  '--add-wrapper': 'add export default[] to the returned string.',
29
- '--no-pretty': 'do not run prettier.',
29
+ '--no-pretty': 'do not run oxfmt.',
30
30
  '--markdown': 'force markdown parser to run.',
31
31
  '--input': 'input file path',
32
- '--output': 'output file path',
33
32
  '--help': 'this help text',
34
33
  '--str': 'an input string of either html or markdown, depending on running command',
35
34
  },
@@ -56,4 +55,4 @@ const res = cli(args)
56
55
 
57
56
  const [html, isMarkdown] = handleArgv(res)
58
57
 
59
- runCli(html, isMarkdown, res)
58
+ await runCli(html, isMarkdown, res)
package/src/index.js CHANGED
@@ -1,12 +1,19 @@
1
- import { marked } from 'marked'
2
- import { parser } from 'posthtml-parser'
3
-
4
1
  import is from '@magic/types'
5
2
 
3
+ import { marked } from 'marked'
4
+ import { parser } from 'posthtml-parser'
6
5
  import { findState, implantState } from './lib/index.js'
7
-
8
6
  import * as renderers from './renderers/index.js'
9
7
 
8
+ /**
9
+ * @typedef {Record<string, unknown>} State
10
+ */
11
+
12
+ /**
13
+ * @param {string} string
14
+ * @param {State} [state]
15
+ * @param {object} [originalState]
16
+ */
10
17
  export const markdown = (string, state = {}, originalState = {}) => {
11
18
  const { input, state: st = {} } = findState(string)
12
19
 
@@ -21,13 +28,18 @@ export const markdown = (string, state = {}, originalState = {}) => {
21
28
  }
22
29
 
23
30
  const implanted = implantState({ input: string, state })
24
- let md = marked(implanted, { renderer: renderers.markdown })
31
+ const md = marked(implanted, { renderer: renderers.markdown, async: false })
25
32
 
26
33
  const out = html(md, state, originalState)
27
34
 
28
35
  return out
29
36
  }
30
37
 
38
+ /**
39
+ * @param {string} string
40
+ * @param {State} [state]
41
+ * @param {object} [originalState]
42
+ */
31
43
  export const html = (string, state = {}, originalState = {}) => {
32
44
  const { input, state: st = {} } = findState(string)
33
45
 
package/src/lib/escape.js CHANGED
@@ -1,2 +1,3 @@
1
1
  // escape string delimiters in the string
2
+ /** @param {string} str */
2
3
  export const escape = str => str.replace(/'/g, "\\'").replace(/`/g, '\\`').replace(/"/g, '\\"')
@@ -1,4 +1,8 @@
1
1
  // find and extract the page state from both markdown and html vars.
2
+ /**
3
+ * @param {string} input
4
+ * @returns {{ input: string, state?: Record<string, unknown> }}
5
+ */
2
6
  export const findState = input => {
3
7
  if (input.trim().startsWith('---')) {
4
8
  const splinters = input.split('---')
@@ -2,6 +2,10 @@ import is from '@magic/types'
2
2
 
3
3
  const bracketRegExp = /(\${|{{).*(}|}})/gim
4
4
 
5
+ /**
6
+ * @param {{ input: string, state: Record<string, unknown> }} params
7
+ * @returns {string}
8
+ */
5
9
  export const implantState = ({ input, state }) => {
6
10
  const matches = input.match(bracketRegExp)
7
11
 
@@ -26,7 +30,9 @@ export const implantState = ({ input, state }) => {
26
30
 
27
31
  subMatches.forEach(subM => {
28
32
  if (is.undefined(curState[subM])) {
29
- curState = curState[subM]
33
+ curState = /** @type {Record<string, unknown>} */ (
34
+ /** @type {unknown} */ (curState[subM])
35
+ )
30
36
  val = curState
31
37
  } else {
32
38
  val = undefined
@@ -46,7 +52,7 @@ export const implantState = ({ input, state }) => {
46
52
  val = val.join(' ')
47
53
  }
48
54
 
49
- input = input.replace(match, val)
55
+ input = input.replace(match, /** @type {string} */ (val))
50
56
  })
51
57
  }
52
58
 
@@ -1,5 +1,6 @@
1
1
  import entities from '@magic/entities'
2
2
 
3
+ /** @param {string} str */
3
4
  export const stringDecode = str => {
4
5
  entities.forEach(([num, symbol, name]) => {
5
6
  if (symbol) {
@@ -3,16 +3,26 @@ import is from '@magic/types'
3
3
 
4
4
  import { stringDecode } from '../lib/index.js'
5
5
 
6
+ /**
7
+ * @typedef {import('posthtml-parser').NodeTag} NodeTag
8
+ * @typedef {string | number | NodeTag} NodeValue
9
+ */
10
+
11
+ /**
12
+ * @param {Array<NodeValue>} content
13
+ * @returns {string | Array<string>}
14
+ */
6
15
  const handleContent = content => {
7
16
  if (is.empty(content)) {
8
17
  return ''
9
18
  }
10
19
 
11
- content = content.filter(a => (!is.string(a) ? a : a.trim()))
20
+ /** @type {Array<NodeValue> | string} */
21
+ let out = content.filter(a => (!is.string(a) ? a : a.trim()))
12
22
 
13
- if (is.array(content)) {
14
- if (content.length === 1) {
15
- let cnt = content[0]
23
+ if (is.array(out)) {
24
+ if (out.length === 1) {
25
+ let cnt = out[0]
16
26
  if (is.string(cnt)) {
17
27
  cnt = stringDecode(cnt)
18
28
  }
@@ -20,55 +30,55 @@ const handleContent = content => {
20
30
  return html(cnt)
21
31
  }
22
32
 
23
- content = `[${content.map(html).filter(a => a)}]`
33
+ out = `[${out.map(html).filter(a => a)}]`
24
34
  }
25
35
 
26
- if (!content) {
27
- content = ''
28
- }
29
-
30
- if (is.string(content)) {
31
- return stringDecode(content)
32
- }
33
-
34
- return content
36
+ return stringDecode(out)
35
37
  }
36
38
 
39
+ /**
40
+ * @param {Record<string, string | number | boolean> | undefined} attrs
41
+ * @param {string | boolean | undefined} tag
42
+ * @returns {string}
43
+ */
37
44
  const handleAttrs = (attrs, tag) => {
38
- if (attrs) {
39
- attrs = Object.entries(attrs)
40
- .map(([key, val]) => {
41
- val = val.trim()
42
-
43
- if (tag === 'a' || tag === 'Link') {
44
- if (key === 'href') {
45
- key = 'to'
46
- }
47
- }
48
-
49
- key = cases.camel(key)
50
-
51
- if (!val) {
52
- return key
53
- }
54
-
55
- if (val.startsWith('[') || val.startsWith('{')) {
56
- return `${key}: ${val}`
57
- }
58
-
59
- return `${key}: '${val}'`
60
- })
61
- .filter(a => a)
62
- .join(', ')
63
-
64
- attrs = `{ ${attrs} }`
65
- } else {
66
- attrs = ''
45
+ if (!attrs) {
46
+ return ''
67
47
  }
68
48
 
69
- return attrs
49
+ const out = Object.entries(attrs)
50
+ .map(([key, rawVal]) => {
51
+ const val = /** @type {string} */ (rawVal)
52
+ const trimmed = val.trim()
53
+
54
+ let outKey = key
55
+
56
+ if ((tag === 'a' || tag === 'Link') && outKey === 'href') {
57
+ outKey = 'to'
58
+ }
59
+
60
+ outKey = cases.camel(outKey)
61
+
62
+ if (!trimmed) {
63
+ return outKey
64
+ }
65
+
66
+ if (trimmed.startsWith('[') || trimmed.startsWith('{')) {
67
+ return `${outKey}: ${trimmed}`
68
+ }
69
+
70
+ return `${outKey}: '${trimmed}'`
71
+ })
72
+ .filter(a => a)
73
+ .join(', ')
74
+
75
+ return `{ ${out} }`
70
76
  }
71
77
 
78
+ /**
79
+ * @param {NodeValue | Array<NodeValue>} ast
80
+ * @returns {string | Array<string>}
81
+ */
72
82
  export const html = ast => {
73
83
  if (is.string(ast)) {
74
84
  if (!ast.trim()) {
@@ -98,11 +108,13 @@ export const html = ast => {
98
108
  }
99
109
 
100
110
  if (is.objectNative(ast)) {
101
- let { tag, attrs, content } = ast
111
+ const node = /** @type {NodeTag} */ (ast)
112
+ let { tag } = node
113
+ const rawContent = node.content
102
114
 
103
- content = handleContent(content)
115
+ let content = handleContent(/** @type {Array<NodeValue>} */ (rawContent))
104
116
 
105
- attrs = handleAttrs(attrs, tag)
117
+ let attrs = handleAttrs(node.attrs, tag)
106
118
 
107
119
  if (attrs && !is.empty(content)) {
108
120
  attrs += ', '
@@ -135,5 +147,8 @@ export const html = ast => {
135
147
  return `${tag}(${attrs}${content})`
136
148
  }
137
149
 
138
- return ast.map(html).filter(a => a)
150
+ const nodes = /** @type {Array<NodeValue>} */ (ast)
151
+ const out = /** @type {Array<string>} */ (nodes.map(html))
152
+
153
+ return out.filter(a => a)
139
154
  }
@@ -4,8 +4,9 @@ export const markdown = new Renderer()
4
4
 
5
5
  // Slugger implementation (removed from marked v5+)
6
6
  // No deduplication - reset state for each slugify call
7
+ /** @param {string} str */
7
8
  const slugify = str => {
8
- let s = str
9
+ const s = str
9
10
  .toLowerCase()
10
11
  .trim()
11
12
  .replace(/[\s]+/g, '-')
@@ -18,9 +19,9 @@ const slugify = str => {
18
19
 
19
20
  /* overwrite builtin markdown functions to use @magic modules */
20
21
 
21
- markdown.code = token => {
22
+ markdown.code = (/** @type {import('marked').Tokens.Code} */ token) => {
22
23
  const { text, lang } = token
23
- const language = (lang || '').match(/\S*/)[0]
24
+ const language = (lang || '').match(/\S*/)?.[0]
24
25
 
25
26
  if (!language) {
26
27
  return `<Pre>${text}</Pre>\n`
@@ -29,9 +30,10 @@ markdown.code = token => {
29
30
  return `<Pre class="${language}">${text}</Pre>`
30
31
  }
31
32
 
32
- markdown.codespan = token => `<Pre lines="false">${token.text}</Pre>`
33
+ markdown.codespan = (/** @type {import('marked').Tokens.Codespan} */ token) =>
34
+ `<Pre lines="false">${token.text}</Pre>`
33
35
 
34
- markdown.link = token => {
36
+ markdown.link = (/** @type {import('marked').Tokens.Link} */ token) => {
35
37
  const { href, title, text } = token
36
38
  if (href === null) {
37
39
  return text
@@ -52,7 +54,7 @@ markdown.link = token => {
52
54
  return out
53
55
  }
54
56
 
55
- markdown.image = token => {
57
+ markdown.image = (/** @type {import('marked').Tokens.Image} */ token) => {
56
58
  const { href, title, text } = token
57
59
  if (href === null) {
58
60
  return text
@@ -73,13 +75,16 @@ markdown.image = token => {
73
75
  return out
74
76
  }
75
77
 
76
- markdown.heading = token => {
77
- let { text, depth } = token
78
+ markdown.heading = (/** @type {import('marked').Tokens.Heading} */ token) => {
79
+ let { text } = token
80
+ const depth = token.depth
78
81
  let id = slugify(text)
79
82
  let cssClass = ''
80
83
 
81
84
  if (text.startsWith('#')) {
82
- let [setId, ...t] = text.split(' ')
85
+ const parts = text.split(' ')
86
+ let setId = parts[0]
87
+ const t = parts.slice(1)
83
88
 
84
89
  text = t.join(' ')
85
90
 
@@ -91,7 +96,9 @@ markdown.heading = token => {
91
96
  }
92
97
 
93
98
  if (text.startsWith('.')) {
94
- let [setClass, ...t] = text.split(' ')
99
+ const parts = text.split(' ')
100
+ let setClass = parts[0]
101
+ const t = parts.slice(1)
95
102
 
96
103
  text = t.join(' ')
97
104
 
@@ -105,7 +112,9 @@ markdown.heading = token => {
105
112
  return `<h${depth} id="${id}"${cssClass}>${text}</h${depth}>\n`
106
113
  }
107
114
 
108
- markdown.html = token => {
115
+ markdown.html = (
116
+ /** @type {import('marked').Tokens.HTML | import('marked').Tokens.Tag} */ token,
117
+ ) => {
109
118
  let html = token.text || token.raw
110
119
  if (html.startsWith('<img')) {
111
120
  html = html.replace('<img', '<Img')
@@ -122,8 +131,9 @@ markdown.html = token => {
122
131
  return html
123
132
  }
124
133
 
125
- markdown.paragraph = token => {
134
+ markdown.paragraph = (/** @type {import('marked').Tokens.Paragraph} */ token) => {
126
135
  const text = token.text || ''
136
+ /** @type {import('marked').Tokens.Generic[]} */
127
137
  const inlineTokens = token.tokens || []
128
138
 
129
139
  // Check if single token that shouldn't be wrapped in <p>
@@ -131,14 +141,20 @@ markdown.paragraph = token => {
131
141
  const t = inlineTokens[0]
132
142
  if (t.type === 'link') {
133
143
  let out = `<Link to="${t.href}"`
134
- if (t.title) out += ` title="${t.title}"`
144
+ if (t.title) {
145
+ out += ` title="${t.title}"`
146
+ }
135
147
  out += ` text="${t.text}"></Link>`
136
148
  return out + '\n'
137
149
  }
138
150
  if (t.type === 'image') {
139
151
  let out = `<Img src="${t.href}"`
140
- if (t.text) out += ` alt="${t.text}"`
141
- if (t.title) out += ` title="${t.title}"`
152
+ if (t.text) {
153
+ out += ` alt="${t.text}"`
154
+ }
155
+ if (t.title) {
156
+ out += ` title="${t.title}"`
157
+ }
142
158
  return out + '/>\n'
143
159
  }
144
160
  if (t.type === 'codespan') {
@@ -174,17 +190,22 @@ markdown.paragraph = token => {
174
190
  }
175
191
 
176
192
  // Render inline tokens
177
- const renderInline = tokens => {
193
+ /** @returns {string} */
194
+ const renderInline = (/** @type {import('marked').Tokens.Generic[]} */ tokens) => {
178
195
  return tokens
179
196
  .map(t => {
180
197
  if (t.type === 'link') {
181
198
  let out = `<Link to="${t.href}"`
182
- if (t.title) out += ` title="${t.title}"`
199
+ if (t.title) {
200
+ out += ` title="${t.title}"`
201
+ }
183
202
  out += ` text="${t.text}"></Link>`
184
203
  return out
185
204
  }
186
205
  if (t.type === 'strong' || t.type === 'em') {
187
- const inner = t.tokens ? renderInline(t.tokens) : t.text
206
+ const inner = t.tokens
207
+ ? renderInline(/** @type {import('marked').Tokens.Generic[]} */ t.tokens)
208
+ : t.text
188
209
  const tag = t.type === 'strong' ? 'b' : 'em'
189
210
  return `<${tag}>${inner}</${tag}>`
190
211
  }
@@ -193,8 +214,12 @@ markdown.paragraph = token => {
193
214
  }
194
215
  if (t.type === 'image') {
195
216
  let out = `<Img src="${t.href}"`
196
- if (t.text) out += ` alt="${t.text}"`
197
- if (t.title) out += ` title="${t.title}"`
217
+ if (t.text) {
218
+ out += ` alt="${t.text}"`
219
+ }
220
+ if (t.title) {
221
+ out += ` title="${t.title}"`
222
+ }
198
223
  out += '/>'
199
224
  return out
200
225
  }
@@ -219,4 +244,4 @@ markdown.paragraph = token => {
219
244
  return `<p>${rendered}</p>\n`
220
245
  }
221
246
 
222
- markdown.strong = token => `<b>${token.text}</b>`
247
+ markdown.strong = (/** @type {import('marked').Tokens.Strong} */ token) => `<b>${token.text}</b>`