@magic/transmute 0.0.60 → 0.0.62

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
@@ -363,5 +363,14 @@ update dependencies
363
363
  - add @magic/lint, add npm run tasks for tsc and lint, add oxlint.config and tsconfig files
364
364
  - update multiple dependencies
365
365
 
366
- [npm-image]: https://img.shields.io/npm/v/@magic/transmute.svg
366
+ ##### 0.0.61
367
+
368
+ - sort imports
369
+ - update dependencies
370
+
371
+ ##### 0.0.62
372
+
373
+ - markdown: escape html special characters in code and code span content. marked >= 5 no longer pre-escapes token text
374
+
375
+ [npm-image]: https://img.shields.io/npm/v/@magic/transmute.sv
367
376
  [npm-url]: https://www.npmjs.com/package/@magic/transmute
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@magic/transmute",
3
- "version": "0.0.60",
3
+ "version": "0.0.62",
4
4
  "description": "convert markdown and html to magic function strings.",
5
5
  "keywords": [
6
6
  "html",
@@ -51,8 +51,8 @@
51
51
  "@magic/entities": "0.0.19",
52
52
  "@magic/log": "0.1.26",
53
53
  "@magic/types": "0.1.42",
54
- "marked": "18.2.0",
55
- "oxfmt": "0.78.0",
54
+ "marked": "18.2.1",
55
+ "oxfmt": "0.79.0",
56
56
  "posthtml-parser": "0.13.0"
57
57
  },
58
58
  "devDependencies": {
@@ -61,16 +61,16 @@
61
61
  "@magic-modules/no-spy": "0.0.9",
62
62
  "@magic-modules/pre": "0.0.12",
63
63
  "@magic-themes/docs": "0.0.15",
64
- "@magic/core": "0.0.161",
65
- "@magic/format": "0.0.79",
66
- "@magic/lint": "0.0.5",
67
- "@magic/test": "0.3.57"
64
+ "@magic/core": "0.0.163",
65
+ "@magic/format": "0.0.82",
66
+ "@magic/lint": "0.0.6",
67
+ "@magic/test": "0.3.60"
68
68
  },
69
69
  "engines": {
70
70
  "node": ">=14.15.4"
71
71
  },
72
72
  "engineStrict": true,
73
73
  "allowScripts": {
74
- "@swc/core@1.15.47": true
74
+ "@swc/core@1.16.22": true
75
75
  }
76
76
  }
package/src/bin/runCli.js CHANGED
@@ -1,11 +1,10 @@
1
- import path from 'path'
2
1
  import fs from 'fs'
3
-
4
- import { format } from 'oxfmt'
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
10
  // oxfmt's format returns a promise, so the pretty path is async.
package/src/index.js CHANGED
@@ -1,10 +1,8 @@
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
 
10
8
  /**
package/src/lib/escape.js CHANGED
@@ -1,3 +1,9 @@
1
1
  // escape string delimiters in the string
2
2
  /** @param {string} str */
3
3
  export const escape = str => str.replace(/'/g, "\\'").replace(/`/g, '\\`').replace(/"/g, '\\"')
4
+
5
+ // escape html special characters in strings that are injected into html strings,
6
+ // so they render as text instead of being parsed as tags.
7
+ /** @param {string} str */
8
+ export const escapeHtml = str =>
9
+ str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;')
package/src/lib/index.js CHANGED
@@ -1,4 +1,4 @@
1
- export { escape } from './escape.js'
1
+ export { escape, escapeHtml } from './escape.js'
2
2
  export { findState } from './findState.js'
3
3
  export { implantState } from './implantState.js'
4
4
  export { stringDecode } from './stringDecode.js'
@@ -1,4 +1,5 @@
1
1
  import { Renderer } from 'marked'
2
+ import { escapeHtml } from '../lib/index.js'
2
3
 
3
4
  export const markdown = new Renderer()
4
5
 
@@ -22,16 +23,17 @@ const slugify = str => {
22
23
  markdown.code = (/** @type {import('marked').Tokens.Code} */ token) => {
23
24
  const { text, lang } = token
24
25
  const language = (lang || '').match(/\S*/)?.[0]
26
+ const escaped = escapeHtml(text)
25
27
 
26
28
  if (!language) {
27
- return `<Pre>${text}</Pre>\n`
29
+ return `<Pre>${escaped}</Pre>\n`
28
30
  }
29
31
 
30
- return `<Pre class="${language}">${text}</Pre>`
32
+ return `<Pre class="${language}">${escaped}</Pre>`
31
33
  }
32
34
 
33
35
  markdown.codespan = (/** @type {import('marked').Tokens.Codespan} */ token) =>
34
- `<Pre lines="false">${token.text}</Pre>`
36
+ `<Pre lines="false">${escapeHtml(token.text)}</Pre>`
35
37
 
36
38
  markdown.link = (/** @type {import('marked').Tokens.Link} */ token) => {
37
39
  const { href, title, text } = token
@@ -158,7 +160,7 @@ markdown.paragraph = (/** @type {import('marked').Tokens.Paragraph} */ token) =>
158
160
  return out + '/>\n'
159
161
  }
160
162
  if (t.type === 'codespan') {
161
- return `<Pre lines="false">${t.text}</Pre>\n`
163
+ return `<Pre lines="false">${escapeHtml(t.text)}</Pre>\n`
162
164
  }
163
165
  // Single html token that starts with block-level tag
164
166
  if (t.type === 'html') {
@@ -210,7 +212,7 @@ markdown.paragraph = (/** @type {import('marked').Tokens.Paragraph} */ token) =>
210
212
  return `<${tag}>${inner}</${tag}>`
211
213
  }
212
214
  if (t.type === 'codespan') {
213
- return `<Pre lines="false">${t.text}</Pre>`
215
+ return `<Pre lines="false">${escapeHtml(t.text)}</Pre>`
214
216
  }
215
217
  if (t.type === 'image') {
216
218
  let out = `<Img src="${t.href}"`