@podlite/markdown 0.0.4 → 0.0.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/package.json CHANGED
@@ -1,38 +1,44 @@
1
1
  {
2
2
  "name": "@podlite/markdown",
3
- "version": "0.0.4",
3
+ "version": "0.0.6",
4
4
  "description": "=Markdown - markdown text block",
5
- "main": "index.js",
5
+ "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
7
- "module": "esm/index.js",
7
+ "module": "lib/index.esm.js",
8
8
  "license": "MIT",
9
9
  "scripts": {
10
10
  "clean": "rm -rf dist lib esm tsconfig.tsbuildinfo",
11
11
  "test": "yarn g:jest --passWithNoTests",
12
12
  "build": "run-p build:cjs build:esm",
13
13
  "build:cjs": "ts-node ./scripts/build.ts && tsc --declaration --emitDeclarationOnly",
14
- "build:esm": "ts-node ./scripts/build_esm.ts && tsc --declaration --emitDeclarationOnly --outDir esm"
14
+ "build:esm": "ts-node ./scripts/build_esm.ts"
15
15
  },
16
16
  "publishConfig": {
17
17
  "access": "public",
18
- "main": "index.js",
18
+ "main": "./lib/index.js",
19
19
  "types": "./lib/index.d.ts"
20
20
  },
21
21
  "peerDependencies": {
22
- "react": "^16.0.0 || ^17.0.0",
22
+ "react": "^16.0.0 || ^17.0.0 ",
23
23
  "react-dom": "^16.0.0 || ^17.0.0"
24
24
  },
25
+ "keywords": [
26
+ "markdown",
27
+ "podlite",
28
+ "markup",
29
+ "markup-language"
30
+ ],
25
31
  "dependencies": {
26
- "@podlite/schema": "0.0.11",
27
- "pod6": "^0.0.48",
28
- "react": "^16.0.0 || ^17.0.0",
32
+ "@podlite/schema": "0.0.13",
33
+ "react": "^16.0.0 || ^17.0.0 ",
29
34
  "react-dom": "^16.0.0 || ^17.0.0",
30
- "react-is": "^17.0.2",
35
+ "react-is": "^17.0.0",
31
36
  "remark-gfm": "^3.0.1",
32
37
  "remark-parse": "^10.0.1",
33
38
  "unified": "^10.1.2"
34
39
  },
35
40
  "devDependencies": {
36
- "esbuild": "^0.15.16"
41
+ "esbuild": "^0.15.16",
42
+ "npm-run-all": "^4.1.5"
37
43
  }
38
44
  }
package/scripts/build.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { build } from 'esbuild';
1
+ import { build } from 'esbuild'
2
2
 
3
3
  build({
4
4
  bundle: true,
@@ -9,8 +9,8 @@ build({
9
9
  target: 'node14',
10
10
  platform: 'node',
11
11
  sourcemap: true,
12
- outfile: 'lib/index.js',
13
- }).catch((e) => {
14
- console.log('Build not successful', e.message);
15
- process.exit(1);
16
- });
12
+ outfile: 'lib/index.cjs',
13
+ }).catch(e => {
14
+ console.log('Build not successful', e.message)
15
+ process.exit(1)
16
+ })
@@ -1,15 +1,18 @@
1
- import { build } from 'esbuild';
2
-
1
+ import { build, BuildOptions } from 'esbuild'
2
+ const opt: BuildOptions = {
3
+ tsconfig: 'tsconfig-esm.json',
4
+ }
3
5
  build({
4
6
  bundle: true,
5
7
  entryPoints: ['src/index.tsx'],
6
8
  external: ['react', 'react-dom'],
7
- minify: true,
9
+ minify: false,
8
10
  format: 'esm',
9
- target: 'node14',
11
+ target: 'es2019',
10
12
  sourcemap: true,
11
- outfile: 'esm/index.js',
12
- }).catch((e) => {
13
- console.log('Build not successful', e.message);
14
- process.exit(1);
15
- });
13
+ outfile: 'lib/index.esm.js',
14
+ ...opt,
15
+ }).catch(e => {
16
+ console.log('Build not successful', e.message)
17
+ process.exit(1)
18
+ })
package/src/index.tsx CHANGED
@@ -1,30 +1,25 @@
1
- import { Plugins } from '@podlite/schema';
2
- import {Plugin} from '@podlite/schema'
3
- import { md2ast } from './tools';
4
- import { content as nodeContent } from 'pod6/built/helpers/handlers'
5
-
6
- export const plugin:Plugin =({
7
- toAst: (_, processor) => (node, ctx) => {
8
- if (typeof node !== "string" && 'type' in node && 'content' in node && node.type === 'block') {
9
- const content = node.content[0]
10
- if (content && typeof content !== "string" && 'location' in node && 'value' in content) {
11
- const lineOffset = node.location.start.line
12
- return { ...node, content: md2ast(content, {lineOffset}) }
13
- }
14
- return node
15
- }
1
+ import { content as nodeContent, Plugins } from '@podlite/schema'
2
+ import { Plugin } from '@podlite/schema'
3
+ import { md2ast } from './tools'
16
4
 
17
- },
18
- toJSX: (helper) => {
19
- return nodeContent
20
- }
21
-
22
- })
23
- export const PluginRegister:Plugins = {
24
- Markdown: plugin
5
+ export const plugin: Plugin = {
6
+ toAst: (_, processor) => (node, ctx) => {
7
+ if (typeof node !== 'string' && 'type' in node && 'content' in node && node.type === 'block') {
8
+ const content = node.content[0]
9
+ if (content && typeof content !== 'string' && 'location' in node && 'value' in content) {
10
+ const lineOffset = node.location.start.line
11
+ return { ...node, content: md2ast(content, { lineOffset }) }
12
+ }
13
+ return node
14
+ }
15
+ },
16
+ toJSX: helper => {
17
+ return nodeContent
18
+ },
19
+ }
20
+ export const PluginRegister: Plugins = {
21
+ Markdown: plugin,
25
22
  }
26
23
 
27
24
  export { md2ast as parseMd } from './tools'
28
25
  export default plugin
29
-
30
-
package/src/tools.ts CHANGED
@@ -1,147 +1,191 @@
1
- import {unified} from 'unified'
2
- import markdown from 'remark-parse'
1
+ import { unified } from 'unified'
2
+ import markdown from 'remark-parse'
3
3
  import remarkGfm from 'remark-gfm'
4
- import toAny from 'pod6/built/exportAny'
5
- import { AstTree, BlockImage, mkBlock, mkFomattingCode, mkFomattingCodeL, mkVerbatim, Location } from '@podlite/schema'
4
+ import {
5
+ toAny,
6
+ AstTree,
7
+ BlockImage,
8
+ mkBlock,
9
+ mkFomattingCode,
10
+ mkFomattingCodeL,
11
+ mkVerbatim,
12
+ Location,
13
+ } from '@podlite/schema'
6
14
  import { mkRootBlock } from '@podlite/schema'
7
15
  import { mkImage } from '@podlite/schema'
8
16
  import { mkCaption } from '@podlite/schema'
9
17
  import { mkFomattingCodeDelete } from '@podlite/schema'
10
18
 
11
- type Md2astArgs = { lineOffset?: number};
12
- export const md2ast = ( src:string, {lineOffset }:Md2astArgs = {lineOffset:0} ) :AstTree => {
13
- // first convert mardown to ast
14
- const md_tree = unified().use(markdown).use(remarkGfm).parse(src)
15
- // first pass : collect linkRefs
16
- let definitionMap = {}
17
- const applyLineOffset = ((offset:number)=>(location:Location):Location=>{
18
- const { start, end } = location
19
- return {
20
- "start": {
21
- ...start,
22
- "line": start.line + offset,
23
- },
24
- "end": {
25
- ...end,
26
- "line": end.line + offset,
27
- }
19
+ type Md2astArgs = { lineOffset?: number }
20
+ export const md2ast = (src: string, { lineOffset }: Md2astArgs = { lineOffset: 0 }): AstTree => {
21
+ // first convert mardown to ast
22
+ const md_tree = unified().use(markdown).use(remarkGfm).parse(src)
23
+ // first pass : collect linkRefs
24
+ let definitionMap = {}
25
+ const applyLineOffset = (
26
+ (offset: number) =>
27
+ (location: Location): Location => {
28
+ const { start, end } = location
29
+ return {
30
+ start: {
31
+ ...start,
32
+ line: start.line + offset,
33
+ },
34
+ end: {
35
+ ...end,
36
+ line: end.line + offset,
37
+ },
38
+ }
28
39
  }
29
- })(lineOffset);
30
- toAny({processor:1})
31
- .use({'*:*':( writer, processor )=>( node, ctx, interator )=>{
32
- if (node.children) interator(node.children, { ...ctx})
33
- }})
34
- .use({':definition' : ( writer, processor )=>( node, ctx, interator )=>{
40
+ )(lineOffset)
41
+ toAny({ processor: 1 })
42
+ .use({
43
+ '*:*': (writer, processor) => (node, ctx, interator) => {
44
+ if (node.children) interator(node.children, { ...ctx })
45
+ },
46
+ })
47
+ .use({
48
+ ':definition': (writer, processor) => (node, ctx, interator) => {
35
49
  definitionMap[node.identifier] = node
36
- }}).run(md_tree)
50
+ },
51
+ })
52
+ .run(md_tree)
37
53
 
38
- // second stage - make Universal AST nodes
39
- const uast = []
40
- const res = toAny({processor:1})
41
- .use({'*:*':( writer, processor )=>( node, ctx, interator )=>{
54
+ // second stage - make Universal AST nodes
55
+ const uast = []
56
+ const res = toAny({ processor: 1 })
57
+ .use({
58
+ '*:*': (writer, processor) => (node, ctx, interator) => {
42
59
  console.warn('[Podlite:md2ast]- unhandled MD node')
43
- console.warn(JSON.stringify(node,null,2))
44
- if (node.children) interator(node.children, { ...ctx})
45
- }})
60
+ console.warn(JSON.stringify(node, null, 2))
61
+ if (node.children) interator(node.children, { ...ctx })
62
+ },
63
+ })
46
64
  .use({
47
- ':root' : ( writer, processor )=>( node, ctx, interator )=>{
48
- const { children, position, ...attr} = node
49
- return mkRootBlock({}, interator(children, ctx))
50
- },
51
- ':heading' : ( writer, processor )=>( node, ctx, interator )=>{
52
- const { children, position, ...attr} = node
53
- return mkBlock({type:'block', level:node.depth,name:'head', location:applyLineOffset(position)}, interator(children, ctx));
54
- },
55
- ':text' : ( writer, processor )=>( node, ctx, interator )=>{
56
- const { children, position, ...attr} = node
57
- return node.value
58
- // return mkNode({type:"text", value: node.value})
59
- },
60
- ':list' : ( writer, processor )=>( node, ctx, interator )=>{
61
- const savedListLevel = ctx['listLevel'] || 0
62
- const { children, position, ...attr} = node
63
- return mkBlock( { type:'list', level:savedListLevel+1, list: node.ordered ? 'ordered' : 'itemized' }, interator(children, { ...ctx, listLevel : savedListLevel + 1, ordered: node.ordered}))
64
- },
65
- ':listItem' : ( writer, processor )=>( node, ctx, interator )=>{
66
- const savedListLevel = ctx['listLevel'] || 0
67
- const { children, position, ...attr} = node
68
- return mkBlock({name: 'item', type:'block', level:ctx['listLevel'], location:applyLineOffset(position)}, interator(children, { ...ctx, listLevel : savedListLevel , ordered: node.ordered}))
69
- },
70
- ':paragraph' : ( writer, processor )=>( node, ctx, interator )=>{
71
- const { children, position, ...attr} = node
72
- return mkBlock({type:'para', location:applyLineOffset(position), text: 'text', margin:"",}, interator(children, { ...ctx}))
73
- },
74
- ':linkReference' : ( writer, processor )=>( node, ctx, interator )=>{
75
- const { children, position, ...attr} = node
76
- const definition = definitionMap[attr.identifier]
77
- const meta = definition?.url || ''
78
- return mkFomattingCodeL({ meta}, interator(children, { ...ctx}))
79
- },
80
- ':definition' : ( writer, processor )=>( node, ctx, interator )=>{
81
- return null
82
- },
83
- ':inlineCode' : ( writer, processor )=>( node, ctx, interator )=>{
84
- const { children, position, ...attr} = node
85
- return mkFomattingCode({name:"C"}, [node.value])
86
- },
87
- ':strong' : ( writer, processor )=>( node, ctx, interator )=>{
88
- const { children, position, ...attr} = node
89
- return mkFomattingCode({name:"B"}, interator(children, { ...ctx}))
90
- },
91
- ':emphasis' : ( writer, processor )=>( node, ctx, interator )=>{
92
- const { children, position, ...attr} = node
93
- return mkFomattingCode({name:"I"}, interator(children, { ...ctx}))
94
- },
95
- ':link': ( writer, processor )=>( node, ctx, interator )=>{
96
- const { children, position, ...attr} = node
97
- return mkFomattingCodeL({ meta:node.url}, interator(children, { ...ctx}))
98
- },
99
- ':html': ( writer, processor )=>( node, ctx, interator )=>{
100
- const { children, position, ...attr} = node
101
- return mkBlock({type:'block', name:'Html', location:applyLineOffset(position)},[mkVerbatim(node.value)]);
102
- },
103
- ':code' : ( writer, processor )=>( node, ctx, interator )=>{
104
- const { children, position, lang, meta, ...attr} = node
105
- if (lang === 'mermaid' || lang === 'diagram') {
106
- return mkBlock({type:'block', name:'Diagram', config:[], location:applyLineOffset(position)},[mkVerbatim(node.value)]);
107
- }
108
- let config = []
109
- if (lang) { config.push({ name: 'lang', value:lang, type:"string"})}
110
- if (meta) { config.push({ name: 'meta', value:meta, type:"string"})} // filled as is from markdown
111
- return mkBlock({type:'block', name:'code', config, location:applyLineOffset(position)},[mkVerbatim(node.value)]);
112
- },
113
- ':image': ( writer, processor )=>( node, ctx, interator ):BlockImage=>{
114
- const { title, alt, url, position, ...attr} = node
115
- let config = []
116
- return mkBlock({type:'block', name:'Image', config, location:applyLineOffset(position)},[mkImage(url,alt),mkCaption([title])]);
117
- },
118
- ':thematicBreak': ( writer, processor )=>( node, ctx, interator )=>{
119
- return null // TODO: add support for "thematic break"
120
- },
121
- ':blockquote' : ( writer, processor )=>( node, ctx, interator )=>{
122
- const { children, position, ...attr} = node
123
- return mkBlock({name:'nested', location:applyLineOffset(position)}, interator(children, { ...ctx}))
124
- },
125
- //table section
126
- ':table' : ( writer, processor )=>( node, ctx, interator )=>{
127
- const { children, position, ...attr} = node
128
- return mkBlock({name:'table', location:applyLineOffset(position)}, interator(children, { ...ctx}))
129
- },
130
- ':tableRow' : ( writer, processor )=>( node, ctx, interator )=>{
131
- const { children, position, ...attr} = node
132
- return mkBlock({name:'table_row', location:applyLineOffset(position)}, interator(children, { ...ctx}))
133
- },
134
- ':tableCell' : ( writer, processor )=>( node, ctx, interator )=>{
135
- const { children, position, ...attr} = node
136
- return mkBlock({name:'table_cell', location:applyLineOffset(position)}, interator(children, { ...ctx}))
137
- },
138
- ':delete': ( writer, processor )=>( node, ctx, interator )=>{
139
- const { children, position, ...attr} = node
140
- return mkFomattingCodeDelete( interator(children, { ...ctx}))
141
- },
142
- ':break': ( writer, processor )=>( node, ctx, interator )=>{
143
- return null
144
- },
145
- }).run(md_tree)
146
- return res.interator
147
- }
65
+ ':root': (writer, processor) => (node, ctx, interator) => {
66
+ const { children, position, ...attr } = node
67
+ return mkRootBlock({}, interator(children, ctx))
68
+ },
69
+ ':heading': (writer, processor) => (node, ctx, interator) => {
70
+ const { children, position, ...attr } = node
71
+ return mkBlock(
72
+ { type: 'block', level: node.depth, name: 'head', location: applyLineOffset(position) },
73
+ interator(children, ctx),
74
+ )
75
+ },
76
+ ':text': (writer, processor) => (node, ctx, interator) => {
77
+ const { children, position, ...attr } = node
78
+ return node.value
79
+ // return mkNode({type:"text", value: node.value})
80
+ },
81
+ ':list': (writer, processor) => (node, ctx, interator) => {
82
+ const savedListLevel = ctx['listLevel'] || 0
83
+ const { children, position, ...attr } = node
84
+ return mkBlock(
85
+ { type: 'list', level: savedListLevel + 1, list: node.ordered ? 'ordered' : 'itemized' },
86
+ interator(children, { ...ctx, listLevel: savedListLevel + 1, ordered: node.ordered }),
87
+ )
88
+ },
89
+ ':listItem': (writer, processor) => (node, ctx, interator) => {
90
+ const savedListLevel = ctx['listLevel'] || 0
91
+ const { children, position, ...attr } = node
92
+ return mkBlock(
93
+ { name: 'item', type: 'block', level: ctx['listLevel'], location: applyLineOffset(position) },
94
+ interator(children, { ...ctx, listLevel: savedListLevel, ordered: node.ordered }),
95
+ )
96
+ },
97
+ ':paragraph': (writer, processor) => (node, ctx, interator) => {
98
+ const { children, position, ...attr } = node
99
+ return mkBlock(
100
+ { type: 'para', location: applyLineOffset(position), text: 'text', margin: '' },
101
+ interator(children, { ...ctx }),
102
+ )
103
+ },
104
+ ':linkReference': (writer, processor) => (node, ctx, interator) => {
105
+ const { children, position, ...attr } = node
106
+ const definition = definitionMap[attr.identifier]
107
+ const meta = definition?.url || ''
108
+ return mkFomattingCodeL({ meta }, interator(children, { ...ctx }))
109
+ },
110
+ ':definition': (writer, processor) => (node, ctx, interator) => {
111
+ return null
112
+ },
113
+ ':inlineCode': (writer, processor) => (node, ctx, interator) => {
114
+ const { children, position, ...attr } = node
115
+ return mkFomattingCode({ name: 'C' }, [node.value])
116
+ },
117
+ ':strong': (writer, processor) => (node, ctx, interator) => {
118
+ const { children, position, ...attr } = node
119
+ return mkFomattingCode({ name: 'B' }, interator(children, { ...ctx }))
120
+ },
121
+ ':emphasis': (writer, processor) => (node, ctx, interator) => {
122
+ const { children, position, ...attr } = node
123
+ return mkFomattingCode({ name: 'I' }, interator(children, { ...ctx }))
124
+ },
125
+ ':link': (writer, processor) => (node, ctx, interator) => {
126
+ const { children, position, ...attr } = node
127
+ return mkFomattingCodeL({ meta: node.url }, interator(children, { ...ctx }))
128
+ },
129
+ ':html': (writer, processor) => (node, ctx, interator) => {
130
+ const { children, position, ...attr } = node
131
+ return mkBlock({ type: 'block', name: 'Html', location: applyLineOffset(position) }, [mkVerbatim(node.value)])
132
+ },
133
+ ':code': (writer, processor) => (node, ctx, interator) => {
134
+ const { children, position, lang, meta, ...attr } = node
135
+ if (lang === 'mermaid' || lang === 'diagram') {
136
+ return mkBlock({ type: 'block', name: 'Diagram', config: [], location: applyLineOffset(position) }, [
137
+ mkVerbatim(node.value),
138
+ ])
139
+ }
140
+ let config = []
141
+ if (lang) {
142
+ config.push({ name: 'lang', value: lang, type: 'string' })
143
+ }
144
+ if (meta) {
145
+ config.push({ name: 'meta', value: meta, type: 'string' })
146
+ } // filled as is from markdown
147
+ return mkBlock({ type: 'block', name: 'code', config, location: applyLineOffset(position) }, [
148
+ mkVerbatim(node.value),
149
+ ])
150
+ },
151
+ ':image':
152
+ (writer, processor) =>
153
+ (node, ctx, interator): BlockImage => {
154
+ const { title, alt, url, position, ...attr } = node
155
+ let config = []
156
+ return mkBlock({ type: 'block', name: 'Image', config, location: applyLineOffset(position) }, [
157
+ mkImage(url, alt),
158
+ mkCaption([title]),
159
+ ])
160
+ },
161
+ ':thematicBreak': (writer, processor) => (node, ctx, interator) => {
162
+ return null // TODO: add support for "thematic break"
163
+ },
164
+ ':blockquote': (writer, processor) => (node, ctx, interator) => {
165
+ const { children, position, ...attr } = node
166
+ return mkBlock({ name: 'nested', location: applyLineOffset(position) }, interator(children, { ...ctx }))
167
+ },
168
+ //table section
169
+ ':table': (writer, processor) => (node, ctx, interator) => {
170
+ const { children, position, ...attr } = node
171
+ return mkBlock({ name: 'table', location: applyLineOffset(position) }, interator(children, { ...ctx }))
172
+ },
173
+ ':tableRow': (writer, processor) => (node, ctx, interator) => {
174
+ const { children, position, ...attr } = node
175
+ return mkBlock({ name: 'table_row', location: applyLineOffset(position) }, interator(children, { ...ctx }))
176
+ },
177
+ ':tableCell': (writer, processor) => (node, ctx, interator) => {
178
+ const { children, position, ...attr } = node
179
+ return mkBlock({ name: 'table_cell', location: applyLineOffset(position) }, interator(children, { ...ctx }))
180
+ },
181
+ ':delete': (writer, processor) => (node, ctx, interator) => {
182
+ const { children, position, ...attr } = node
183
+ return mkFomattingCodeDelete(interator(children, { ...ctx }))
184
+ },
185
+ ':break': (writer, processor) => (node, ctx, interator) => {
186
+ return null
187
+ },
188
+ })
189
+ .run(md_tree)
190
+ return res.interator
191
+ }