@markdoc/markdoc 0.1.0
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/LICENSE +21 -0
- package/README.md +75 -0
- package/dist/index.d.ts +120 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7961 -0
- package/dist/index.js.map +7 -0
- package/dist/index.mjs +7959 -0
- package/dist/index.mjs.map +7 -0
- package/dist/react.js +40 -0
- package/dist/react.js.map +7 -0
- package/dist/src/ast/base.d.ts +6 -0
- package/dist/src/ast/base.d.ts.map +1 -0
- package/dist/src/ast/function.d.ts +9 -0
- package/dist/src/ast/function.d.ts.map +1 -0
- package/dist/src/ast/index.d.ts +26 -0
- package/dist/src/ast/index.d.ts.map +1 -0
- package/dist/src/ast/node.d.ts +21 -0
- package/dist/src/ast/node.d.ts.map +1 -0
- package/dist/src/ast/tag.d.ts +9 -0
- package/dist/src/ast/tag.d.ts.map +1 -0
- package/dist/src/ast/variable.d.ts +8 -0
- package/dist/src/ast/variable.d.ts.map +1 -0
- package/dist/src/functions/index.d.ts +11 -0
- package/dist/src/functions/index.d.ts.map +1 -0
- package/dist/src/parser.d.ts +4 -0
- package/dist/src/parser.d.ts.map +1 -0
- package/dist/src/renderers/html.d.ts +3 -0
- package/dist/src/renderers/html.d.ts.map +1 -0
- package/dist/src/renderers/index.d.ts +10 -0
- package/dist/src/renderers/index.d.ts.map +1 -0
- package/dist/src/renderers/react/react.d.ts +11 -0
- package/dist/src/renderers/react/react.d.ts.map +1 -0
- package/dist/src/renderers/react/shared.d.ts +5 -0
- package/dist/src/renderers/react/shared.d.ts.map +1 -0
- package/dist/src/renderers/react/static.d.ts +3 -0
- package/dist/src/renderers/react/static.d.ts.map +1 -0
- package/dist/src/schema-types/class.d.ts +6 -0
- package/dist/src/schema-types/class.d.ts.map +1 -0
- package/dist/src/schema.d.ts +27 -0
- package/dist/src/schema.d.ts.map +1 -0
- package/dist/src/tags/conditional.d.ts +5 -0
- package/dist/src/tags/conditional.d.ts.map +1 -0
- package/dist/src/tags/index.d.ts +44 -0
- package/dist/src/tags/index.d.ts.map +1 -0
- package/dist/src/tags/partial.d.ts +3 -0
- package/dist/src/tags/partial.d.ts.map +1 -0
- package/dist/src/tags/table.d.ts +3 -0
- package/dist/src/tags/table.d.ts.map +1 -0
- package/dist/src/tokenizer/index.d.ts +10 -0
- package/dist/src/tokenizer/index.d.ts.map +1 -0
- package/dist/src/tokenizer/plugins/annotations.d.ts +3 -0
- package/dist/src/tokenizer/plugins/annotations.d.ts.map +1 -0
- package/dist/src/tokenizer/plugins/frontmatter.d.ts +3 -0
- package/dist/src/tokenizer/plugins/frontmatter.d.ts.map +1 -0
- package/dist/src/transformer.d.ts +12 -0
- package/dist/src/transformer.d.ts.map +1 -0
- package/dist/src/transforms/index.d.ts +4 -0
- package/dist/src/transforms/index.d.ts.map +1 -0
- package/dist/src/transforms/table.d.ts +3 -0
- package/dist/src/transforms/table.d.ts.map +1 -0
- package/dist/src/types.d.ts +88 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/utils.d.ts +6 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/validator.d.ts +6 -0
- package/dist/src/validator.d.ts.map +1 -0
- package/global.d.ts +11 -0
- package/index.ts +138 -0
- package/package.json +63 -0
- package/spec/support/matchers.d.ts +6 -0
- package/src/ast/base.ts +41 -0
- package/src/ast/function.ts +22 -0
- package/src/ast/index.ts +28 -0
- package/src/ast/node.test.ts +307 -0
- package/src/ast/node.ts +71 -0
- package/src/ast/tag.ts +19 -0
- package/src/ast/variable.test.ts +35 -0
- package/src/ast/variable.ts +17 -0
- package/src/functions/index.test.ts +34 -0
- package/src/functions/index.ts +45 -0
- package/src/grammar/tag.d.ts +23 -0
- package/src/grammar/tag.js +1836 -0
- package/src/grammar/tag.pegjs +170 -0
- package/src/grammar/tag.test.ts +364 -0
- package/src/parser.test.ts +597 -0
- package/src/parser.ts +158 -0
- package/src/renderers/html.test.ts +62 -0
- package/src/renderers/html.ts +46 -0
- package/src/renderers/index.ts +5 -0
- package/src/renderers/react/react.test.ts +204 -0
- package/src/renderers/react/react.ts +51 -0
- package/src/renderers/react/shared.ts +16 -0
- package/src/renderers/react/static.ts +52 -0
- package/src/schema-types/class.ts +23 -0
- package/src/schema.ts +233 -0
- package/src/tags/conditional.ts +45 -0
- package/src/tags/index.ts +10 -0
- package/src/tags/partial.ts +33 -0
- package/src/tags/table.ts +5 -0
- package/src/tokenizer/index.ts +21 -0
- package/src/tokenizer/plugins/annotations.test.ts +337 -0
- package/src/tokenizer/plugins/annotations.ts +133 -0
- package/src/tokenizer/plugins/frontmatter.test.ts +86 -0
- package/src/tokenizer/plugins/frontmatter.ts +39 -0
- package/src/transformer.ts +72 -0
- package/src/transforms/index.ts +2 -0
- package/src/transforms/table.ts +51 -0
- package/src/types.ts +142 -0
- package/src/utils.test.ts +173 -0
- package/src/utils.ts +116 -0
- package/src/validator.test.ts +298 -0
- package/src/validator.ts +233 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021- Stripe, Inc. (https://stripe.com)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
<h1 align="center">
|
|
2
|
+
<br>
|
|
3
|
+
<img src="https://user-images.githubusercontent.com/62121649/166497424-eed74185-92b8-48bf-9d54-493282df288b.png" alt="Markdoc" width="260">
|
|
4
|
+
<br>
|
|
5
|
+
<br>
|
|
6
|
+
</h1>
|
|
7
|
+
|
|
8
|
+
<h4 align="center">A powerful, flexible, Markdown-based authoring framework.</h4>
|
|
9
|
+
|
|
10
|
+
Markdoc is a [Markdown](https://commonmark.org)-based syntax and toolchain for creating custom documentation sites and experiences.
|
|
11
|
+
We designed Markdoc to power [Stripe's public docs](http://stripe.com/docs), our largest and most complex content site.
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
To get started with Markdoc, first install the library:
|
|
16
|
+
|
|
17
|
+
```shell
|
|
18
|
+
npm install @markdoc/markdoc
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
or
|
|
22
|
+
|
|
23
|
+
```shell
|
|
24
|
+
yarn add @markdoc/markdoc
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
and import it in your app:
|
|
28
|
+
|
|
29
|
+
```js
|
|
30
|
+
const Markdoc = require('@markdoc/markdoc');
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
or if you are using ESM
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
import Markdoc from '@markdoc/markdoc';
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
then use `Markdoc` in your app or tool:
|
|
40
|
+
|
|
41
|
+
```js
|
|
42
|
+
const doc = `
|
|
43
|
+
# Markdoc README
|
|
44
|
+
|
|
45
|
+
{% image src="/logo.svg" /%}
|
|
46
|
+
`;
|
|
47
|
+
|
|
48
|
+
const ast = Markdoc.parse(doc);
|
|
49
|
+
const content = Markdoc.transform(ast);
|
|
50
|
+
return Markdoc.renderers.react(content, React);
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Check out [our docs](https://markdoc.io/docs) for more guidance on how to use Markdoc.
|
|
54
|
+
|
|
55
|
+
## Contributing
|
|
56
|
+
|
|
57
|
+
Contributions and feedback are welcome and encouraged. Check out our [contributing guidelines](.github/CONTRIBUTING.md) on how to do so.
|
|
58
|
+
|
|
59
|
+
### Development
|
|
60
|
+
|
|
61
|
+
1. Run `npm install`
|
|
62
|
+
1. Run `npm build`
|
|
63
|
+
1. Run the tests using `npm test`
|
|
64
|
+
|
|
65
|
+
## Code of conduct
|
|
66
|
+
|
|
67
|
+
This project has adopted the Stripe [Code of conduct](.github/CODE_OF_CONDUCT.md).
|
|
68
|
+
|
|
69
|
+
## License
|
|
70
|
+
|
|
71
|
+
This project uses the [MIT license](LICENSE).
|
|
72
|
+
|
|
73
|
+
## Credits
|
|
74
|
+
|
|
75
|
+
Shout out to [@marcioAlmada](https://github.com/marcioAlmada) for providing us with the [@markdoc](https://github.com/markdoc) GitHub org.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import Tokenizer from './src/tokenizer';
|
|
2
|
+
import Node from './src/ast/node';
|
|
3
|
+
import Tag from './src/ast/tag';
|
|
4
|
+
import Ast from './src/ast/index';
|
|
5
|
+
import * as nodes from './src/schema';
|
|
6
|
+
import tags from './src/tags/index';
|
|
7
|
+
import functions from './src/functions/index';
|
|
8
|
+
import renderers from './src/renderers/index';
|
|
9
|
+
import transformer from './src/transformer';
|
|
10
|
+
import validator from './src/validator';
|
|
11
|
+
import { parseTags } from './src/utils';
|
|
12
|
+
import transforms from './src/transforms/index';
|
|
13
|
+
import type Token from 'markdown-it/lib/token';
|
|
14
|
+
import type { Config, RenderableTreeNode, ValidateError } from './src/types';
|
|
15
|
+
export * from './src/types';
|
|
16
|
+
export declare function parse(content: string | Token[], file?: string): Node;
|
|
17
|
+
export declare function resolve<C extends Config = Config>(content: Node, config: C): Node;
|
|
18
|
+
export declare function resolve<C extends Config = Config>(content: Node[], config: C): Node[];
|
|
19
|
+
export declare function transform<C extends Config = Config>(node: Node, config?: C): RenderableTreeNode;
|
|
20
|
+
export declare function transform<C extends Config = Config>(nodes: Node[], config?: C): RenderableTreeNode[];
|
|
21
|
+
export declare function validate<C extends Config = Config>(content: Node, options?: C): ValidateError[];
|
|
22
|
+
export declare function createElement(name: string | {
|
|
23
|
+
key?: string | number;
|
|
24
|
+
}, attributes?: {}, ...children: any[]): {
|
|
25
|
+
name: string | {
|
|
26
|
+
key?: string | number | undefined;
|
|
27
|
+
};
|
|
28
|
+
attributes: {};
|
|
29
|
+
children: any[];
|
|
30
|
+
};
|
|
31
|
+
declare const _default: {
|
|
32
|
+
nodes: typeof nodes;
|
|
33
|
+
tags: {
|
|
34
|
+
if: import("./src/types").Schema<Readonly<Partial<{
|
|
35
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
36
|
+
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
37
|
+
variables: Record<string, any>;
|
|
38
|
+
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
39
|
+
partials: Record<string, any>;
|
|
40
|
+
validation?: {
|
|
41
|
+
validateFunctions?: boolean | undefined;
|
|
42
|
+
} | undefined;
|
|
43
|
+
}>>, string>;
|
|
44
|
+
else: import("./src/types").Schema<Readonly<Partial<{
|
|
45
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
46
|
+
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
47
|
+
variables: Record<string, any>;
|
|
48
|
+
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
49
|
+
partials: Record<string, any>;
|
|
50
|
+
validation?: {
|
|
51
|
+
validateFunctions?: boolean | undefined;
|
|
52
|
+
} | undefined;
|
|
53
|
+
}>>, string>;
|
|
54
|
+
partial: import("./src/types").Schema<Readonly<Partial<{
|
|
55
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
56
|
+
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
57
|
+
variables: Record<string, any>;
|
|
58
|
+
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
59
|
+
partials: Record<string, any>;
|
|
60
|
+
validation?: {
|
|
61
|
+
validateFunctions?: boolean | undefined;
|
|
62
|
+
} | undefined;
|
|
63
|
+
}>>, string>;
|
|
64
|
+
table: import("./src/types").Schema<Readonly<Partial<{
|
|
65
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
66
|
+
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
67
|
+
variables: Record<string, any>;
|
|
68
|
+
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
69
|
+
partials: Record<string, any>;
|
|
70
|
+
validation?: {
|
|
71
|
+
validateFunctions?: boolean | undefined;
|
|
72
|
+
} | undefined;
|
|
73
|
+
}>>, string>;
|
|
74
|
+
};
|
|
75
|
+
functions: {
|
|
76
|
+
and: import("./src/types").ConfigFunction;
|
|
77
|
+
or: import("./src/types").ConfigFunction;
|
|
78
|
+
not: import("./src/types").ConfigFunction;
|
|
79
|
+
equals: import("./src/types").ConfigFunction;
|
|
80
|
+
default: import("./src/types").ConfigFunction;
|
|
81
|
+
debug: import("./src/types").ConfigFunction;
|
|
82
|
+
};
|
|
83
|
+
renderers: {
|
|
84
|
+
html: typeof import("./src/renderers/html").default;
|
|
85
|
+
react: typeof import("./src/renderers/react/react").default;
|
|
86
|
+
reactStatic: typeof import("./src/renderers/react/static").default;
|
|
87
|
+
};
|
|
88
|
+
transforms: typeof import("./src/transforms/table").default[];
|
|
89
|
+
Ast: {
|
|
90
|
+
fromJSON: (text: string) => Node | Node[];
|
|
91
|
+
isAst(value?: any): value is import("./src/types").AstType;
|
|
92
|
+
isFunction(value?: any): value is import("./src/types").Function;
|
|
93
|
+
getAstValues(value: any): Generator<import("./src/types").AstType, void, unknown>;
|
|
94
|
+
resolve(value: any, config?: Readonly<Partial<{
|
|
95
|
+
nodes: Partial<Record<import("./src/types").NodeType, import("./src/types").Schema<Readonly<Partial<any>>, string>>>;
|
|
96
|
+
tags: Record<string, import("./src/types").Schema<Readonly<Partial<any>>, string>>;
|
|
97
|
+
variables: Record<string, any>;
|
|
98
|
+
functions: Record<string, import("./src/types").ConfigFunction>;
|
|
99
|
+
partials: Record<string, any>;
|
|
100
|
+
validation?: {
|
|
101
|
+
validateFunctions?: boolean | undefined;
|
|
102
|
+
} | undefined;
|
|
103
|
+
}>>): any;
|
|
104
|
+
Function: typeof import("./src/types").Function;
|
|
105
|
+
Node: typeof Node;
|
|
106
|
+
Variable: typeof import("./src/ast/variable").default;
|
|
107
|
+
};
|
|
108
|
+
Tag: typeof Tag;
|
|
109
|
+
Tokenizer: typeof Tokenizer;
|
|
110
|
+
parseTags: typeof parseTags;
|
|
111
|
+
transformer: import("./src/transformer").Transformer;
|
|
112
|
+
validator: typeof validator;
|
|
113
|
+
parse: typeof parse;
|
|
114
|
+
transform: typeof transform;
|
|
115
|
+
validate: typeof validate;
|
|
116
|
+
createElement: typeof createElement;
|
|
117
|
+
};
|
|
118
|
+
export default _default;
|
|
119
|
+
export { nodes, tags, functions, transforms, renderers, Ast, Tag, Tokenizer, parseTags, transformer, validator, };
|
|
120
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+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