@magic/transmute 0.0.57 → 0.0.59

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
@@ -339,7 +339,11 @@ update dependencies
339
339
 
340
340
  update dependencies
341
341
 
342
- ##### 0.0.58 - unreleased
342
+ ##### 0.0.58
343
+
344
+ - update dependencies
345
+
346
+ ##### 0.0.59 - unreleased
343
347
 
344
348
  ...
345
349
 
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@magic/transmute",
3
- "version": "0.0.57",
3
+ "version": "0.0.59",
4
4
  "author": "Wizards & Witches",
5
5
  "homepage": "https://magic.github.io/transmute",
6
6
  "license": "AGPL-3.0",
7
7
  "description": "convert markdown and html to magic function strings.",
8
- "main": "src/index.mjs",
8
+ "main": "src/index.js",
9
9
  "type": "module",
10
10
  "bin": {
11
- "magic-transmute": "src/bin.mjs"
11
+ "magic-transmute": "src/bin.js"
12
12
  },
13
13
  "files": [
14
14
  "src"
@@ -31,28 +31,28 @@
31
31
  "build": "NODE_ENV=production magic build",
32
32
  "prod": "NODE_ENV=production magic build serve",
33
33
  "dev": "magic dev",
34
- "dirty-cli-test": "src/bin/bin.js file --input test/.data/testing.md --output testing.mjs && echo 'contents: ' && cat testing.mjs && echo 'deleting testing.mjs' && rm testing.mjs",
34
+ "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
35
  "calls": "calls"
36
36
  },
37
37
  "dependencies": {
38
- "@magic/cases": "0.0.9",
39
- "@magic/cli": "0.0.44",
40
- "@magic/entities": "0.0.13",
41
- "@magic/log": "0.1.18",
42
- "@magic/types": "0.1.23",
43
- "marked": "4.2.12",
44
- "posthtml-parser": "0.11.0",
45
- "prettier": "2.8.4"
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"
46
46
  },
47
47
  "devDependencies": {
48
48
  "@magic-modules/git-badges": "0.0.12",
49
- "@magic-modules/light-switch": "0.0.11",
50
- "@magic-modules/no-spy": "0.0.8",
51
- "@magic-modules/pre": "0.0.11",
52
- "@magic-themes/docs": "0.0.14",
53
- "@magic/core": "0.0.149",
54
- "@magic/format": "0.0.51",
55
- "@magic/test": "0.2.15"
49
+ "@magic-modules/light-switch": "0.0.12",
50
+ "@magic-modules/no-spy": "0.0.9",
51
+ "@magic-modules/pre": "0.0.12",
52
+ "@magic-themes/docs": "0.0.15",
53
+ "@magic/core": "0.0.158",
54
+ "@magic/format": "0.0.74",
55
+ "@magic/test": "0.3.12"
56
56
  },
57
57
  "keywords": [
58
58
  "magic",
@@ -0,0 +1,2 @@
1
+ export { handleArgv } from './handleArgv.js'
2
+ export { runCli } from './runCli.js'
@@ -6,7 +6,7 @@ import prettier from 'prettier'
6
6
  import log from '@magic/log'
7
7
  import is from '@magic/types'
8
8
 
9
- import transmute from '../index.mjs'
9
+ import transmute from '../index.js'
10
10
 
11
11
  export const runCli = (html, isMarkdown, res) => {
12
12
  let out
@@ -2,7 +2,7 @@
2
2
 
3
3
  import { cli } from '@magic/cli'
4
4
 
5
- import { handleArgv, runCli } from './bin/index.mjs'
5
+ import { handleArgv, runCli } from './bin/index.js'
6
6
 
7
7
  const args = {
8
8
  options: [
@@ -41,13 +41,13 @@ transpile markdown string:
41
41
  magic-transmute markdown --str '[a link](https://example.com)'',
42
42
 
43
43
  transpile html file:
44
- magic-transmute file --input input.html --output output.mjs
44
+ magic-transmute file --input input.html --output output.js
45
45
 
46
46
  transpile markdown file (.markdown and .md get recognized):
47
- magic-transmute file --input input.md --output output.mjs
47
+ magic-transmute file --input input.md --output output.js
48
48
 
49
49
  transpile file as markdown (arbitrary file extensions)
50
- magic-transmute file --input input.txt --output output.mjs --markdown
50
+ magic-transmute file --input input.txt --output output.js --markdown
51
51
  `,
52
52
  },
53
53
  }
@@ -3,9 +3,9 @@ import { parser } from 'posthtml-parser'
3
3
 
4
4
  import is from '@magic/types'
5
5
 
6
- import { findState, implantState } from './lib/index.mjs'
6
+ import { findState, implantState } from './lib/index.js'
7
7
 
8
- import * as renderers from './renderers/index.mjs'
8
+ import * as renderers from './renderers/index.js'
9
9
 
10
10
  export const markdown = (string, state = {}, originalState = {}) => {
11
11
  const { input, state: st = {} } = findState(string)
@@ -0,0 +1,4 @@
1
+ export { escape } from './escape.js'
2
+ export { findState } from './findState.js'
3
+ export { implantState } from './implantState.js'
4
+ export { stringDecode } from './stringDecode.js'
@@ -1,7 +1,7 @@
1
1
  import cases from '@magic/cases'
2
2
  import is from '@magic/types'
3
3
 
4
- import { stringDecode } from '../lib/index.mjs'
4
+ import { stringDecode } from '../lib/index.js'
5
5
 
6
6
  const handleContent = content => {
7
7
  if (is.empty(content)) {
@@ -0,0 +1,2 @@
1
+ export { markdown } from './markdown.js'
2
+ export { html } from './html.js'
@@ -0,0 +1,222 @@
1
+ import { Renderer } from 'marked'
2
+
3
+ export const markdown = new Renderer()
4
+
5
+ // Slugger implementation (removed from marked v5+)
6
+ // No deduplication - reset state for each slugify call
7
+ const slugify = str => {
8
+ let s = str
9
+ .toLowerCase()
10
+ .trim()
11
+ .replace(/[\s]+/g, '-')
12
+ .replace(/[^\w-]+/g, '')
13
+ .replace(/--+/g, '-')
14
+ .replace(/^-+/, '')
15
+ .replace(/-+$/, '')
16
+ return s
17
+ }
18
+
19
+ /* overwrite builtin markdown functions to use @magic modules */
20
+
21
+ markdown.code = token => {
22
+ const { text, lang } = token
23
+ const language = (lang || '').match(/\S*/)[0]
24
+
25
+ if (!language) {
26
+ return `<Pre>${text}</Pre>\n`
27
+ }
28
+
29
+ return `<Pre class="${language}">${text}</Pre>`
30
+ }
31
+
32
+ markdown.codespan = token => `<Pre lines="false">${token.text}</Pre>`
33
+
34
+ markdown.link = token => {
35
+ const { href, title, text } = token
36
+ if (href === null) {
37
+ return text
38
+ }
39
+
40
+ let out = `<Link to="${href}"`
41
+
42
+ if (title) {
43
+ out += ` title="${title}"`
44
+ }
45
+
46
+ if (text) {
47
+ out += ` text="${text}"`
48
+ }
49
+
50
+ out += '></Link>'
51
+
52
+ return out
53
+ }
54
+
55
+ markdown.image = token => {
56
+ const { href, title, text } = token
57
+ if (href === null) {
58
+ return text
59
+ }
60
+
61
+ let out = `<Img src="${href}"`
62
+
63
+ if (text) {
64
+ out += ` alt="${text}"`
65
+ }
66
+
67
+ if (title) {
68
+ out += ` title="${title}"`
69
+ }
70
+
71
+ out += '/>'
72
+
73
+ return out
74
+ }
75
+
76
+ markdown.heading = token => {
77
+ let { text, depth } = token
78
+ let id = slugify(text)
79
+ let cssClass = ''
80
+
81
+ if (text.startsWith('#')) {
82
+ let [setId, ...t] = text.split(' ')
83
+
84
+ text = t.join(' ')
85
+
86
+ if (setId.endsWith('-')) {
87
+ setId += text
88
+ }
89
+
90
+ id = slugify(setId.substr(1))
91
+ }
92
+
93
+ if (text.startsWith('.')) {
94
+ let [setClass, ...t] = text.split(' ')
95
+
96
+ text = t.join(' ')
97
+
98
+ if (setClass.endsWith('-')) {
99
+ setClass += text
100
+ }
101
+
102
+ cssClass = ` class="${slugify(setClass)}"`
103
+ }
104
+
105
+ return `<h${depth} id="${id}"${cssClass}>${text}</h${depth}>\n`
106
+ }
107
+
108
+ markdown.html = token => {
109
+ let html = token.text || token.raw
110
+ if (html.startsWith('<img')) {
111
+ html = html.replace('<img', '<Img')
112
+ }
113
+
114
+ if (html.startsWith('<a')) {
115
+ html = html.replace('<a', '<Link').replace('</a>', '</Link>')
116
+ }
117
+
118
+ if (html.startsWith('</a>')) {
119
+ html = html.replace('</a>', '</Link>')
120
+ }
121
+
122
+ return html
123
+ }
124
+
125
+ markdown.paragraph = token => {
126
+ const text = token.text || ''
127
+ const inlineTokens = token.tokens || []
128
+
129
+ // Check if single token that shouldn't be wrapped in <p>
130
+ if (inlineTokens.length === 1) {
131
+ const t = inlineTokens[0]
132
+ if (t.type === 'link') {
133
+ let out = `<Link to="${t.href}"`
134
+ if (t.title) out += ` title="${t.title}"`
135
+ out += ` text="${t.text}"></Link>`
136
+ return out + '\n'
137
+ }
138
+ if (t.type === 'image') {
139
+ let out = `<Img src="${t.href}"`
140
+ if (t.text) out += ` alt="${t.text}"`
141
+ if (t.title) out += ` title="${t.title}"`
142
+ return out + '/>\n'
143
+ }
144
+ if (t.type === 'codespan') {
145
+ return `<Pre lines="false">${t.text}</Pre>\n`
146
+ }
147
+ // Single html token that starts with block-level tag
148
+ if (t.type === 'html') {
149
+ const raw = t.raw || t.text || ''
150
+ if (
151
+ raw.startsWith('<a ') ||
152
+ raw.startsWith('<img') ||
153
+ raw.startsWith('<A ') ||
154
+ raw.startsWith('<IMG')
155
+ ) {
156
+ return raw + '\n'
157
+ }
158
+ }
159
+ }
160
+
161
+ // Check if paragraph is a standalone block element (link with text content)
162
+ // If tokens are [html, text, html] pattern representing a complete link, don't wrap
163
+ if (inlineTokens.length === 3) {
164
+ const [open, content, close] = inlineTokens
165
+ if (
166
+ open?.type === 'html' &&
167
+ close?.type === 'html' &&
168
+ content?.type === 'text' &&
169
+ open?.raw?.startsWith('<a ') &&
170
+ close?.raw === '</a>'
171
+ ) {
172
+ return text + '\n'
173
+ }
174
+ }
175
+
176
+ // Render inline tokens
177
+ const renderInline = tokens => {
178
+ return tokens
179
+ .map(t => {
180
+ if (t.type === 'link') {
181
+ let out = `<Link to="${t.href}"`
182
+ if (t.title) out += ` title="${t.title}"`
183
+ out += ` text="${t.text}"></Link>`
184
+ return out
185
+ }
186
+ if (t.type === 'strong' || t.type === 'em') {
187
+ const inner = t.tokens ? renderInline(t.tokens) : t.text
188
+ const tag = t.type === 'strong' ? 'b' : 'em'
189
+ return `<${tag}>${inner}</${tag}>`
190
+ }
191
+ if (t.type === 'codespan') {
192
+ return `<Pre lines="false">${t.text}</Pre>`
193
+ }
194
+ if (t.type === 'image') {
195
+ let out = `<Img src="${t.href}"`
196
+ if (t.text) out += ` alt="${t.text}"`
197
+ if (t.title) out += ` title="${t.title}"`
198
+ out += '/>'
199
+ return out
200
+ }
201
+ return t.text || ''
202
+ })
203
+ .join('')
204
+ }
205
+
206
+ if (text.startsWith('<')) {
207
+ const tagName = text.substr(1).split(' ')[0].split('>')[0]
208
+
209
+ const inlineTags = ['a', 'img', 'strong', 'b', 'i', 'em']
210
+
211
+ if (inlineTags.includes(tagName)) {
212
+ return `<p>${text}</p>\n`
213
+ } else {
214
+ return `${text}\n`
215
+ }
216
+ }
217
+
218
+ const rendered = inlineTokens.length ? renderInline(inlineTokens) : text
219
+ return `<p>${rendered}</p>\n`
220
+ }
221
+
222
+ markdown.strong = token => `<b>${token.text}</b>`
package/src/bin/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- export { handleArgv } from './handleArgv.mjs'
2
- export { runCli } from './runCli.mjs'
package/src/lib/index.mjs DELETED
@@ -1,4 +0,0 @@
1
- export { escape } from './escape.mjs'
2
- export { findState } from './findState.mjs'
3
- export { implantState } from './implantState.mjs'
4
- export { stringDecode } from './stringDecode.mjs'
@@ -1,2 +0,0 @@
1
- export { markdown } from './markdown.mjs'
2
- export { html } from './html.mjs'
@@ -1,122 +0,0 @@
1
- import { Renderer } from 'marked'
2
-
3
- export const markdown = new Renderer()
4
-
5
- /* overwrite builtin markdown functions to use @magic modules */
6
-
7
- markdown.code = (code, infostring) => {
8
- let lang = (infostring || '').match(/\S*/)[0]
9
-
10
- if (!lang) {
11
- return `<Pre>${code}</Pre>\n`
12
- }
13
-
14
- return `<Pre class="${lang}">${code}</Pre>`
15
- }
16
-
17
- markdown.codespan = text => `<Pre lines="false">${text}</Pre>`
18
-
19
- markdown.link = (href, title, text) => {
20
- if (href === null) {
21
- return text
22
- }
23
-
24
- let out = `<Link to="${href}"`
25
-
26
- if (title) {
27
- out += ` title="${title}"`
28
- }
29
-
30
- if (text) {
31
- out += ` text="${text}"`
32
- }
33
-
34
- out += '></Link>'
35
-
36
- return out
37
- }
38
-
39
- markdown.image = (href, title, text) => {
40
- if (href === null) {
41
- return text
42
- }
43
-
44
- let out = `<Img src="${href}"`
45
-
46
- if (text) {
47
- out += ` alt="${text}"`
48
- }
49
-
50
- if (title) {
51
- out += ` title="${title}"`
52
- }
53
-
54
- out += '/>'
55
-
56
- return out
57
- }
58
-
59
- markdown.heading = (text, level, raw, slugger) => {
60
- let id = slugger.slug(raw)
61
- let cssClass = ''
62
-
63
- if (raw.startsWith('#')) {
64
- let [setId, ...t] = raw.split(' ')
65
-
66
- text = t.join(' ')
67
-
68
- if (setId.endsWith('-')) {
69
- setId += text
70
- }
71
-
72
- id = slugger.slug(setId.substr(1))
73
- }
74
-
75
- if (text.startsWith('.')) {
76
- let [setClass, ...t] = raw.split(' ')
77
-
78
- text = t.join(' ')
79
-
80
- if (setClass.endsWith('-')) {
81
- setClass += text
82
- }
83
-
84
- cssClass = ` class="${slugger.slug(setClass)}"`
85
- }
86
-
87
- return `<h${level} id="${id}"${cssClass}>${text}</h${level}>\n`
88
- }
89
-
90
- markdown.html = html => {
91
- if (html.startsWith('<img')) {
92
- html = html.replace('<img', '<Img')
93
- }
94
-
95
- if (html.startsWith('<a')) {
96
- html = html.replace('<a', '<Link').replace('</a>', '</Link>')
97
- }
98
-
99
- if (html.startsWith('</a>')) {
100
- html = html.replace('</a>', '</Link>')
101
- }
102
-
103
- return html
104
- }
105
-
106
- markdown.paragraph = text => {
107
- if (text.startsWith('<')) {
108
- const tagName = text.substr(1).split(' ')[0].split('>')[0]
109
-
110
- const inlineTags = ['a', 'img', 'strong', 'b', 'i', 'em']
111
-
112
- if (inlineTags.includes(tagName)) {
113
- return `<p>${text}</p>\n`
114
- } else {
115
- return `${text}\n`
116
- }
117
- }
118
-
119
- return `<p>${text}</p>\n`
120
- }
121
-
122
- markdown.strong = text => `<b>${text}</b>`
File without changes
File without changes
File without changes
File without changes
File without changes