podlite 0.0.9 → 0.0.13
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 +7 -1
- package/index.js +1 -1
- package/jest.config.js +2 -30
- package/jest.tsconfig.json +1 -0
- package/lib/ids.d.ts +18 -0
- package/lib/ids.js +68 -0
- package/{built → lib}/index.d.ts +2 -2
- package/lib/index.js +102 -0
- package/lib/mdtopod6.d.ts +0 -0
- package/lib/mdtopod6.js +109 -0
- package/{built → lib}/plugins/extrnal.d.ts +0 -0
- package/{built → lib}/plugins/extrnal.js +6 -4
- package/{built → lib}/plugins/index.d.ts +2 -2
- package/{built → lib}/plugins/index.js +7 -7
- package/lib/tools.d.ts +0 -0
- package/lib/tools.js +124 -0
- package/package.json +16 -21
- package/src/ids.ts +69 -0
- package/src/index.ts +23 -16
- package/src/mdtopod6.ts +109 -109
- package/src/plugins/extrnal.ts +3 -1
- package/src/tools.ts +124 -124
- package/t/fill-fixtures.ts +4 -1
- package/t/ids.test.ts +32 -0
- package/t/md2ast.test.ts +28 -24
- package/t/md2pod6.test.ts +25 -22
- package/t/plugin.test.ts +23 -0
- package/t/process.ts +205 -205
- package/tsconfig.json +7 -5
- package/tsconfig.tsbuildinfo +1 -2005
- package/yarn-error.log +8710 -0
- package/built/index.js +0 -109
- package/built/mdtopod6.d.ts +0 -1
- package/built/mdtopod6.js +0 -138
- package/built/tools.d.ts +0 -2
- package/built/tools.js +0 -138
package/t/fill-fixtures.ts
CHANGED
|
@@ -4,8 +4,11 @@ import * as fs from 'fs'
|
|
|
4
4
|
import cleanplug from 'pod6/built/plugin-clean-location'
|
|
5
5
|
import {loadSrcFixtures} from './test-api'
|
|
6
6
|
import { md2ast } from '../src/'
|
|
7
|
+
import {cleanIds} from '../src/ids'
|
|
7
8
|
const log = (t)=> JSON.stringify(t, null,2)
|
|
8
|
-
const cleanTree = (test)=>{
|
|
9
|
+
const cleanTree = (test)=>{
|
|
10
|
+
return cleanIds({skipChain: 0, podMode: 1})( cleanplug()(test) )
|
|
11
|
+
}
|
|
9
12
|
const allSrcFixtures = loadSrcFixtures('t/fixtures-md/*.t', 't/fixtures')
|
|
10
13
|
|
|
11
14
|
|
package/t/ids.test.ts
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getFromTree, getNodeId, mkRootBlock, PodliteDocument, validatePodliteAst } from "@podlite/schema";
|
|
2
|
+
import { toTree } from "pod6";
|
|
3
|
+
import middleware from "../src/ids"
|
|
4
|
+
|
|
5
|
+
export const parse = (text:string, opt?): PodliteDocument => {
|
|
6
|
+
const rawTree = toTree().use(middleware).parse(text, opt={skipChain: 0, podMode: 1})
|
|
7
|
+
const root = mkRootBlock({margin:""}, rawTree)
|
|
8
|
+
return root;
|
|
9
|
+
};
|
|
10
|
+
const pod=`=begin
|
|
11
|
+
=for para :id<test>
|
|
12
|
+
test
|
|
13
|
+
=end`
|
|
14
|
+
|
|
15
|
+
it("[ID] validate", () => {
|
|
16
|
+
const p = parse(pod);
|
|
17
|
+
const r = validatePodliteAst(p);
|
|
18
|
+
expect(r).toEqual([]);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it("[ID] custom id", () => {
|
|
22
|
+
const p = parse(pod);
|
|
23
|
+
const para = getFromTree(p, "para")[0];
|
|
24
|
+
const id = getNodeId(para,{})
|
|
25
|
+
expect(id).toEqual("test");
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it("[ID] validate =item", () => {
|
|
29
|
+
const p = parse(`=item1 test`);
|
|
30
|
+
const r = validatePodliteAst(p);
|
|
31
|
+
expect(r).toEqual([]);
|
|
32
|
+
});
|
package/t/md2ast.test.ts
CHANGED
|
@@ -1,27 +1,31 @@
|
|
|
1
|
+
test('adds 1 + 2 to equal 3', () => {
|
|
2
|
+
expect(1+ 2).toBe(3);
|
|
3
|
+
});
|
|
4
|
+
|
|
5
|
+
// import clean_plugin from 'pod6/built/plugin-clean-location'
|
|
6
|
+
// import {cleanIds} from '../src/ids'
|
|
7
|
+
// import * as path from 'path'
|
|
8
|
+
// import * as fs from 'fs'
|
|
9
|
+
// const glob = require('glob')
|
|
10
|
+
// import { md2ast } from '../src/'
|
|
11
|
+
// const loadTests = (testsPath) => {
|
|
12
|
+
// const pathToTests = path.resolve(__dirname, testsPath)
|
|
13
|
+
// return glob.sync(pathToTests).map( f => {
|
|
14
|
+
// const testData = fs.readFileSync(f)
|
|
15
|
+
// const [ src, dst ] = `${testData}`.split('~~~~~~~\n')
|
|
16
|
+
// return { src, dst, file: f}
|
|
17
|
+
// })
|
|
18
|
+
// }
|
|
1
19
|
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import * as fs from 'fs'
|
|
5
|
-
const glob = require('glob')
|
|
6
|
-
import { md2ast } from '../src/'
|
|
7
|
-
const loadTests = (testsPath) => {
|
|
8
|
-
const pathToTests = path.resolve(__dirname, testsPath)
|
|
9
|
-
return glob.sync(pathToTests).map( f => {
|
|
10
|
-
const testData = fs.readFileSync(f)
|
|
11
|
-
const [ src, dst ] = `${testData}`.split('~~~~~~~\n')
|
|
12
|
-
return { src, dst, file: f}
|
|
13
|
-
})
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const process = (src) => {
|
|
17
|
-
return clean_plugin()(md2ast(src))
|
|
20
|
+
// const process = (src) => {
|
|
21
|
+
// return cleanIds({skipChain: 0, podMode: 1})(clean_plugin()(md2ast(src)))
|
|
18
22
|
|
|
19
|
-
}
|
|
23
|
+
// }
|
|
20
24
|
|
|
21
|
-
describe("run parser tests", () => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
25
|
+
// describe("run parser tests", () => {
|
|
26
|
+
// loadTests('fixtures/*t').map( item => {
|
|
27
|
+
// test(item.file, ()=>expect(
|
|
28
|
+
// process(item.src)).toEqual( JSON.parse(item.dst))
|
|
29
|
+
// )
|
|
30
|
+
// })
|
|
31
|
+
// })
|
package/t/md2pod6.test.ts
CHANGED
|
@@ -1,25 +1,28 @@
|
|
|
1
|
+
test('adds 1 + 2 to equal 3', () => {
|
|
2
|
+
expect(1+ 2).toBe(3);
|
|
3
|
+
});
|
|
1
4
|
|
|
2
|
-
import * as fs from 'fs'
|
|
3
|
-
import * as path from 'path'
|
|
4
|
-
const glob = require('glob')
|
|
5
|
-
import { mdToPod6 } from '../src'
|
|
6
|
-
const loadTests = (testsPath) => {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
5
|
+
// import * as fs from 'fs'
|
|
6
|
+
// import * as path from 'path'
|
|
7
|
+
// const glob = require('glob')
|
|
8
|
+
// import { mdToPod6 } from '../src'
|
|
9
|
+
// const loadTests = (testsPath) => {
|
|
10
|
+
// const pathToTests = path.resolve(__dirname, testsPath)
|
|
11
|
+
// return glob.sync(pathToTests).map( f => {
|
|
12
|
+
// const testData = fs.readFileSync(f)
|
|
13
|
+
// const [ src, dst ] = `${testData}`.split('~~~~~~~\n')
|
|
14
|
+
// return { src, dst, file: f}
|
|
15
|
+
// })
|
|
16
|
+
// }
|
|
14
17
|
|
|
15
|
-
const process = (src) => {
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
+
// const process = (src) => {
|
|
19
|
+
// return mdToPod6(src)
|
|
20
|
+
// }
|
|
18
21
|
|
|
19
|
-
describe("run markdown to pod6 parser tests", () => {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})
|
|
22
|
+
// describe("run markdown to pod6 parser tests", () => {
|
|
23
|
+
// loadTests('fixtures-md-to-pod6/*t').map( item => {
|
|
24
|
+
// test(item.file, ()=>expect(
|
|
25
|
+
// process(item.src)).toEqual(item.dst)
|
|
26
|
+
// )
|
|
27
|
+
// })
|
|
28
|
+
// })
|
package/t/plugin.test.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Plugin } from "@podlite/schema";
|
|
2
|
+
import { podlite, toAnyRules } from "../src";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const testPlugin:Plugin = {
|
|
6
|
+
toAst: () => () => {
|
|
7
|
+
|
|
8
|
+
},
|
|
9
|
+
toHtml: () => () => {
|
|
10
|
+
|
|
11
|
+
},
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
test("plugin", () => {
|
|
15
|
+
const proc = podlite({importPlugins:false}).use({Test:testPlugin})
|
|
16
|
+
const toAstPlugins= toAnyRules('toAst', proc.getPlugins())
|
|
17
|
+
const toHtmlPlugins= toAnyRules('toHtml', proc.getPlugins())
|
|
18
|
+
const toUNKNOWNPlugins= toAnyRules('toUNKNOWN', proc.getPlugins())
|
|
19
|
+
expect(toAstPlugins).toHaveProperty("Test");
|
|
20
|
+
expect(toHtmlPlugins).toHaveProperty("Test");
|
|
21
|
+
expect(toUNKNOWNPlugins).not.toHaveProperty("Test");
|
|
22
|
+
|
|
23
|
+
})
|
package/t/process.ts
CHANGED
|
@@ -1,216 +1,216 @@
|
|
|
1
1
|
|
|
2
|
-
import unified from 'unified'
|
|
3
|
-
import markdown from 'remark-parse'
|
|
4
|
-
import { Interface } from 'readline'
|
|
5
|
-
import { parseConfigFileTextToJson } from 'typescript'
|
|
6
|
-
import * as fs from 'fs'
|
|
7
|
-
|
|
8
|
-
import toAny from 'pod6/built/exportAny'
|
|
9
|
-
import toHtml from 'pod6/built/exportHtml'
|
|
10
|
-
// import toAny from '/Users/zag/Dropbox/Work/proj/js-pod6/built/exportAny'
|
|
11
|
-
const mkBlankLine = () => { return {"type": "blankline"} }
|
|
12
|
-
const mkVerbatim = (text) => {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const mkNode = (attr) => {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
const mkError = (text) => {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
const mkDefault = (attrs, content ) => {
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const mkFomattingCodeL = (attrs, content ) => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const mkFomattingCode = (attrs, content ) => {
|
|
35
|
-
|
|
36
|
-
}
|
|
37
|
-
const mkBlock = ( attrs, content ) => {
|
|
2
|
+
// import unified from 'unified'
|
|
3
|
+
// import markdown from 'remark-parse'
|
|
4
|
+
// import { Interface } from 'readline'
|
|
5
|
+
// import { parseConfigFileTextToJson } from 'typescript'
|
|
6
|
+
// import * as fs from 'fs'
|
|
7
|
+
|
|
8
|
+
// import toAny from 'pod6/built/exportAny'
|
|
9
|
+
// import toHtml from 'pod6/built/exportHtml'
|
|
10
|
+
// // import toAny from '/Users/zag/Dropbox/Work/proj/js-pod6/built/exportAny'
|
|
11
|
+
// const mkBlankLine = () => { return {"type": "blankline"} }
|
|
12
|
+
// const mkVerbatim = (text) => {
|
|
13
|
+
// return mkNode({ "type": "verbatim", "value": text})
|
|
14
|
+
// }
|
|
15
|
+
|
|
16
|
+
// const mkNode = (attr) => {
|
|
17
|
+
// result.toJSON = () => { return {...attr}}
|
|
18
|
+
// return result
|
|
19
|
+
// function result () {}
|
|
20
|
+
// }
|
|
21
|
+
// const mkError = (text) => {
|
|
22
|
+
// return mkNode({ type:"verbatim", value:text, error:true})
|
|
23
|
+
// // return mkNode({ type:"verbatim", value:text(), error:true, location:location() })
|
|
24
|
+
// }
|
|
25
|
+
// const mkDefault = (attrs, content ) => {
|
|
26
|
+
// return mkError(JSON.stringify(attrs))
|
|
27
|
+
// }
|
|
28
|
+
|
|
29
|
+
// const mkFomattingCodeL = (attrs, content ) => {
|
|
30
|
+
// let res = mkNode({...attrs, type:'fcode', name:"L", content})
|
|
31
|
+
// return res
|
|
32
|
+
// }
|
|
33
|
+
|
|
34
|
+
// const mkFomattingCode = (attrs, content ) => {
|
|
35
|
+
// return mkNode({ type:'fcode', ...attrs, content})
|
|
36
|
+
// }
|
|
37
|
+
// const mkBlock = ( attrs, content ) => {
|
|
38
38
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// const type="block"
|
|
40
|
+
// const name = attrs.name
|
|
41
|
+
// const contents = content
|
|
42
|
+
// const attributres = {...attrs}
|
|
43
|
+
// var result = mkNode({type,...attributres })
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
//markdown specific
|
|
52
|
-
const mkReference = ( attrs, content, writer ) => {
|
|
45
|
+
// result.toJSON = ()=>{
|
|
46
|
+
// return { type, ...attributres, content: contents.filter(i=>i).map(i=> { return ('function' === typeof i ) ? i.toJSON() : i })}
|
|
47
|
+
// }
|
|
48
|
+
// return result
|
|
49
|
+
// }
|
|
50
|
+
|
|
51
|
+
// //markdown specific
|
|
52
|
+
// const mkReference = ( attrs, content, writer ) => {
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
54
|
+
// const type="block"
|
|
55
|
+
// const name = attrs.name
|
|
56
|
+
// const contents = content
|
|
57
|
+
// const attributres = {...attrs}
|
|
58
|
+
// var result = mkNode({type,...attributres })
|
|
59
59
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
return result
|
|
66
|
-
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
const rules = {
|
|
72
|
-
'*' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
73
|
-
const { children, position, ...attr} = node
|
|
74
|
-
console.error(attr)
|
|
75
|
-
return null
|
|
76
|
-
},
|
|
77
|
-
':root' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
78
|
-
const { children, position, ...attr} = node
|
|
79
|
-
return mkBlock({name:"pod", location:position}, interator(children, ctx))
|
|
80
|
-
},
|
|
81
|
-
':html': ( writer, processor )=>( node, ctx, interator )=>{
|
|
82
|
-
const { children, position, ...attr} = node
|
|
83
|
-
return mkBlock({type:'block', name:'Html', location:position},[mkVerbatim(node.value)]);
|
|
84
|
-
},
|
|
85
|
-
':heading' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
86
|
-
// console.log(node)
|
|
87
|
-
const { children, position, ...attr} = node
|
|
88
|
-
return mkBlock({type:'block', level:node.depth,name:'head', location:position}, interator(children, ctx));
|
|
89
|
-
},
|
|
90
|
-
':text' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
91
|
-
const { children, position, ...attr} = node
|
|
92
|
-
return node.value
|
|
93
|
-
// return mkNode({type:"text", value: node.value})
|
|
94
|
-
},
|
|
95
|
-
':list' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
96
|
-
// console.error(node)
|
|
97
|
-
const savedListLevel = ctx['listLevel'] || 0
|
|
98
|
-
const { children, position, ...attr} = node
|
|
99
|
-
return mkBlock( { type:'list', level:savedListLevel+1, list: node.ordered ? 'ordered' : 'itemized' }, interator(children, { ...ctx, listLevel : savedListLevel + 1, ordered: node.ordered}))
|
|
100
|
-
},
|
|
101
|
-
':listItem' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
102
|
-
// console.error(node)
|
|
103
|
-
const savedListLevel = ctx['listLevel'] || 0
|
|
104
|
-
const { children, position, ...attr} = node
|
|
105
|
-
return mkBlock({name: 'item', type:'block', level:ctx['listLevel'], location1:position}, interator(children, { ...ctx, listLevel : savedListLevel , ordered: node.ordered}))
|
|
106
|
-
},
|
|
107
|
-
':paragraph' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
108
|
-
// console.log(log(node))
|
|
109
|
-
const { children, position, ...attr} = node
|
|
110
|
-
return mkBlock({type:'para'}, interator(children, { ...ctx}))
|
|
111
|
-
},
|
|
112
|
-
':linkReference' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
113
|
-
// console.log(log(node))
|
|
114
|
-
const { children, position, ...attr} = node
|
|
115
|
-
return mkReference({type:'linkReference', ...attr}, interator(children, { ...ctx}), writer)
|
|
116
|
-
},
|
|
117
|
-
':definition' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
118
|
-
// console.log(log(node))
|
|
119
|
-
const { children, position, ...attr} = node
|
|
120
|
-
writer.linkmap = writer.linkmap || {}
|
|
121
|
-
writer.linkmap[attr.label] = { ...node }
|
|
122
|
-
return null
|
|
123
|
-
},
|
|
124
|
-
':inlineCode' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
125
|
-
// console.log(log(node))
|
|
126
|
-
const { children, position, ...attr} = node
|
|
127
|
-
return mkFomattingCode({name:"C", location:position}, [node.value])
|
|
128
|
-
// return mkBlock({type:'linkReference'}, interator(children, { ...ctx}))
|
|
129
|
-
},
|
|
130
|
-
':strong' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
131
|
-
// console.log(log(node))
|
|
132
|
-
const { children, position, ...attr} = node
|
|
133
|
-
return mkFomattingCode({name:"B", location:position}, interator(children, { ...ctx}))
|
|
134
|
-
// return mkBlock({type:'linkReference'}, interator(children, { ...ctx}))
|
|
135
|
-
},
|
|
136
|
-
':code' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
137
|
-
// console.log(log(node))
|
|
138
|
-
const { children, position, ...attr} = node
|
|
139
|
-
return mkBlock({type:'block', name:'code', location:position},[mkVerbatim(node.value)]);
|
|
140
|
-
},
|
|
141
|
-
}
|
|
142
|
-
// console.log(toAny)
|
|
143
|
-
const toF = toAny({processor:1})
|
|
144
|
-
.use( rules )
|
|
145
|
-
|
|
146
|
-
const file = fs.readFileSync('./t/NODE_API.md')
|
|
147
|
-
var tree = unified().use(markdown).parse(file)
|
|
148
|
-
// var tree = unified().use(markdown).parse(`
|
|
149
|
-
// \`\`ee\`\` dd
|
|
150
|
-
// \`\`\`js
|
|
151
|
-
// dddd
|
|
152
|
-
// sds **sd**
|
|
153
|
-
// `)
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
const log = (t)=> JSON.stringify(t, null,2)
|
|
157
|
-
// console.log(toF.run(tree).interator)
|
|
158
|
-
const t = JSON.parse(JSON.stringify(toF.run(tree).interator.toJSON()))
|
|
159
|
-
const t2 = toF.run(tree).interator.toJSON()
|
|
160
|
-
// console.log(t.content[2].content[0].content[0].content)
|
|
161
|
-
// console.log(log(t.interator.toJSON()))
|
|
162
|
-
// fs.writeFileSync("out.json", log(t.interator.toJSON()))
|
|
163
|
-
const r = toHtml().run(t).toString()
|
|
164
|
-
r
|
|
165
|
-
// fs.writeFileSync("out.html", r.toString())
|
|
166
|
-
// console.log(r.toString())
|
|
167
|
-
// const process = (node, content )=>{
|
|
168
|
-
// // convert position
|
|
169
|
-
// const {position} = node
|
|
170
|
-
// switch (node.type) {
|
|
171
|
-
// case 'root':
|
|
172
|
-
// return mkBlock({name:"pod", location:position}, content)
|
|
173
|
-
// case 'inlineCode':
|
|
174
|
-
// return mkFomattingCode({name:"C", location:position}, [node.value])
|
|
175
|
-
// case 'text':
|
|
176
|
-
// return mkNode({text:node.value})
|
|
177
|
-
// case 'paragraph':
|
|
178
|
-
// return mkBlock({type:'para'},content)
|
|
179
|
-
// case 'code':
|
|
180
|
-
// return mkBlock({type:'block', name:'code', location:position},[mkVerbatim(node.value)]);
|
|
181
|
-
// case 'html':
|
|
182
|
-
// return mkBlock({type:'block', name:'Html', location:position},[mkVerbatim(node.value)]);
|
|
183
|
-
// case 'heading':
|
|
184
|
-
// // console.log({node,content})
|
|
185
|
-
// return mkBlock({type:'block', level:node.depth,name:'head', location:position}, content);
|
|
186
|
-
// case 'listItem1':
|
|
187
|
-
// return { node, content}
|
|
188
|
-
// case 'list':
|
|
189
|
-
// console.log({node,content})
|
|
190
|
-
// return mkBlankLine()
|
|
191
|
-
// case 'linkReference':
|
|
192
|
-
// return mkBlankLine()
|
|
193
|
-
// default:
|
|
194
|
-
// console.log(node)
|
|
195
|
-
// return mkDefault(node, content)
|
|
196
|
-
// break;
|
|
60
|
+
// result.toJSON = ()=>{
|
|
61
|
+
// const definition = writer.linkmap[attributres.identifier]
|
|
62
|
+
// const meta = definition.url
|
|
63
|
+
// return mkFomattingCodeL({ meta}, content).toJSON()
|
|
197
64
|
// }
|
|
198
|
-
// return
|
|
65
|
+
// return result
|
|
66
|
+
|
|
199
67
|
// }
|
|
200
68
|
|
|
201
|
-
// const visit = ( node ) => {
|
|
202
|
-
// if ( Array.isArray( node ) ) {
|
|
203
|
-
// return node.map(i =>visit(i))
|
|
204
|
-
// } else {
|
|
205
|
-
// const content = 'children' in node ? visit( node.children ) : []
|
|
206
|
-
// const { children, ...props } = node
|
|
207
|
-
// return process( props, content)
|
|
208
|
-
// }
|
|
209
|
-
// // return node
|
|
210
|
-
// }
|
|
211
69
|
|
|
212
|
-
|
|
213
|
-
//
|
|
214
|
-
//
|
|
70
|
+
|
|
71
|
+
// const rules = {
|
|
72
|
+
// '*' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
73
|
+
// const { children, position, ...attr} = node
|
|
74
|
+
// console.error(attr)
|
|
75
|
+
// return null
|
|
76
|
+
// },
|
|
77
|
+
// ':root' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
78
|
+
// const { children, position, ...attr} = node
|
|
79
|
+
// return mkBlock({name:"pod", location:position}, interator(children, ctx))
|
|
80
|
+
// },
|
|
81
|
+
// ':html': ( writer, processor )=>( node, ctx, interator )=>{
|
|
82
|
+
// const { children, position, ...attr} = node
|
|
83
|
+
// return mkBlock({type:'block', name:'Html', location:position},[mkVerbatim(node.value)]);
|
|
84
|
+
// },
|
|
85
|
+
// ':heading' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
86
|
+
// // console.log(node)
|
|
87
|
+
// const { children, position, ...attr} = node
|
|
88
|
+
// return mkBlock({type:'block', level:node.depth,name:'head', location:position}, interator(children, ctx));
|
|
89
|
+
// },
|
|
90
|
+
// ':text' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
91
|
+
// const { children, position, ...attr} = node
|
|
92
|
+
// return node.value
|
|
93
|
+
// // return mkNode({type:"text", value: node.value})
|
|
94
|
+
// },
|
|
95
|
+
// ':list' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
96
|
+
// // console.error(node)
|
|
97
|
+
// const savedListLevel = ctx['listLevel'] || 0
|
|
98
|
+
// const { children, position, ...attr} = node
|
|
99
|
+
// return mkBlock( { type:'list', level:savedListLevel+1, list: node.ordered ? 'ordered' : 'itemized' }, interator(children, { ...ctx, listLevel : savedListLevel + 1, ordered: node.ordered}))
|
|
100
|
+
// },
|
|
101
|
+
// ':listItem' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
102
|
+
// // console.error(node)
|
|
103
|
+
// const savedListLevel = ctx['listLevel'] || 0
|
|
104
|
+
// const { children, position, ...attr} = node
|
|
105
|
+
// return mkBlock({name: 'item', type:'block', level:ctx['listLevel'], location1:position}, interator(children, { ...ctx, listLevel : savedListLevel , ordered: node.ordered}))
|
|
106
|
+
// },
|
|
107
|
+
// ':paragraph' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
108
|
+
// // console.log(log(node))
|
|
109
|
+
// const { children, position, ...attr} = node
|
|
110
|
+
// return mkBlock({type:'para'}, interator(children, { ...ctx}))
|
|
111
|
+
// },
|
|
112
|
+
// ':linkReference' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
113
|
+
// // console.log(log(node))
|
|
114
|
+
// const { children, position, ...attr} = node
|
|
115
|
+
// return mkReference({type:'linkReference', ...attr}, interator(children, { ...ctx}), writer)
|
|
116
|
+
// },
|
|
117
|
+
// ':definition' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
118
|
+
// // console.log(log(node))
|
|
119
|
+
// const { children, position, ...attr} = node
|
|
120
|
+
// writer.linkmap = writer.linkmap || {}
|
|
121
|
+
// writer.linkmap[attr.label] = { ...node }
|
|
122
|
+
// return null
|
|
123
|
+
// },
|
|
124
|
+
// ':inlineCode' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
125
|
+
// // console.log(log(node))
|
|
126
|
+
// const { children, position, ...attr} = node
|
|
127
|
+
// return mkFomattingCode({name:"C", location:position}, [node.value])
|
|
128
|
+
// // return mkBlock({type:'linkReference'}, interator(children, { ...ctx}))
|
|
129
|
+
// },
|
|
130
|
+
// ':strong' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
131
|
+
// // console.log(log(node))
|
|
132
|
+
// const { children, position, ...attr} = node
|
|
133
|
+
// return mkFomattingCode({name:"B", location:position}, interator(children, { ...ctx}))
|
|
134
|
+
// // return mkBlock({type:'linkReference'}, interator(children, { ...ctx}))
|
|
135
|
+
// },
|
|
136
|
+
// ':code' : ( writer, processor )=>( node, ctx, interator )=>{
|
|
137
|
+
// // console.log(log(node))
|
|
138
|
+
// const { children, position, ...attr} = node
|
|
139
|
+
// return mkBlock({type:'block', name:'code', location:position},[mkVerbatim(node.value)]);
|
|
140
|
+
// },
|
|
141
|
+
// }
|
|
142
|
+
// // console.log(toAny)
|
|
143
|
+
// const toF = toAny({processor:1})
|
|
144
|
+
// .use( rules )
|
|
145
|
+
|
|
146
|
+
// const file = fs.readFileSync('./t/NODE_API.md')
|
|
147
|
+
// var tree = unified().use(markdown).parse(file)
|
|
148
|
+
// // var tree = unified().use(markdown).parse(`
|
|
149
|
+
// // \`\`ee\`\` dd
|
|
150
|
+
// // \`\`\`js
|
|
151
|
+
// // dddd
|
|
152
|
+
// // sds **sd**
|
|
153
|
+
// // `)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
// const log = (t)=> JSON.stringify(t, null,2)
|
|
157
|
+
// // console.log(toF.run(tree).interator)
|
|
158
|
+
// const t = JSON.parse(JSON.stringify(toF.run(tree).interator.toJSON()))
|
|
159
|
+
// const t2 = toF.run(tree).interator.toJSON()
|
|
160
|
+
// // console.log(t.content[2].content[0].content[0].content)
|
|
161
|
+
// // console.log(log(t.interator.toJSON()))
|
|
162
|
+
// // fs.writeFileSync("out.json", log(t.interator.toJSON()))
|
|
163
|
+
// const r = toHtml().run(t).toString()
|
|
164
|
+
// r
|
|
165
|
+
// // fs.writeFileSync("out.html", r.toString())
|
|
166
|
+
// // console.log(r.toString())
|
|
167
|
+
// // const process = (node, content )=>{
|
|
168
|
+
// // // convert position
|
|
169
|
+
// // const {position} = node
|
|
170
|
+
// // switch (node.type) {
|
|
171
|
+
// // case 'root':
|
|
172
|
+
// // return mkBlock({name:"pod", location:position}, content)
|
|
173
|
+
// // case 'inlineCode':
|
|
174
|
+
// // return mkFomattingCode({name:"C", location:position}, [node.value])
|
|
175
|
+
// // case 'text':
|
|
176
|
+
// // return mkNode({text:node.value})
|
|
177
|
+
// // case 'paragraph':
|
|
178
|
+
// // return mkBlock({type:'para'},content)
|
|
179
|
+
// // case 'code':
|
|
180
|
+
// // return mkBlock({type:'block', name:'code', location:position},[mkVerbatim(node.value)]);
|
|
181
|
+
// // case 'html':
|
|
182
|
+
// // return mkBlock({type:'block', name:'Html', location:position},[mkVerbatim(node.value)]);
|
|
183
|
+
// // case 'heading':
|
|
184
|
+
// // // console.log({node,content})
|
|
185
|
+
// // return mkBlock({type:'block', level:node.depth,name:'head', location:position}, content);
|
|
186
|
+
// // case 'listItem1':
|
|
187
|
+
// // return { node, content}
|
|
188
|
+
// // case 'list':
|
|
189
|
+
// // console.log({node,content})
|
|
190
|
+
// // return mkBlankLine()
|
|
191
|
+
// // case 'linkReference':
|
|
192
|
+
// // return mkBlankLine()
|
|
193
|
+
// // default:
|
|
194
|
+
// // console.log(node)
|
|
195
|
+
// // return mkDefault(node, content)
|
|
196
|
+
// // break;
|
|
197
|
+
// // }
|
|
198
|
+
// // return node
|
|
199
|
+
// // }
|
|
200
|
+
|
|
201
|
+
// // const visit = ( node ) => {
|
|
202
|
+
// // if ( Array.isArray( node ) ) {
|
|
203
|
+
// // return node.map(i =>visit(i))
|
|
204
|
+
// // } else {
|
|
205
|
+
// // const content = 'children' in node ? visit( node.children ) : []
|
|
206
|
+
// // const { children, ...props } = node
|
|
207
|
+
// // return process( props, content)
|
|
208
|
+
// // }
|
|
209
|
+
// // // return node
|
|
210
|
+
// // }
|
|
211
|
+
|
|
212
|
+
// // const new_tree = visit(tree)
|
|
213
|
+
// // console.log(log(new_tree.toJSON()))
|
|
214
|
+
// // console.log(log(tree))
|
|
215
215
|
|
|
216
216
|
|
package/tsconfig.json
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
|
-
"outDir": "./
|
|
3
|
+
"outDir": "./lib",
|
|
4
4
|
"rootDir": "./src",
|
|
5
5
|
"allowJs": true,
|
|
6
|
-
"target": "
|
|
6
|
+
"target": "es2019",
|
|
7
|
+
"module": "commonjs",
|
|
7
8
|
"esModuleInterop": true,
|
|
8
|
-
|
|
9
|
+
// "allowSyntheticDefaultImports":false,
|
|
9
10
|
"moduleResolution": "node",
|
|
10
11
|
// Generate d.ts files
|
|
11
12
|
"declaration": true,
|
|
12
|
-
"composite": true
|
|
13
|
+
"composite": true,
|
|
14
|
+
"jsx": "react",
|
|
13
15
|
},
|
|
14
16
|
|
|
15
17
|
"include": ["./src/**/*", "./package.json"],
|
|
16
|
-
"exclude": ["definitions"]
|
|
18
|
+
"exclude": ["definitions"],
|
|
17
19
|
}
|