@graphql-markdown/printer-legacy 1.1.5 → 1.1.7
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 +2 -2
- package/src/badge.js +63 -0
- package/src/code.js +39 -0
- package/src/common.js +37 -0
- package/src/const/strings.js +6 -0
- package/src/graphql/directive.js +45 -0
- package/src/graphql/enum.js +34 -0
- package/src/graphql/index.js +10 -0
- package/src/graphql/input.js +10 -0
- package/src/graphql/interface.js +10 -0
- package/src/graphql/object.js +43 -0
- package/src/graphql/operation.js +29 -0
- package/src/graphql/scalar.js +30 -0
- package/src/graphql/union.js +31 -0
- package/src/group.js +18 -0
- package/src/index.js +2 -612
- package/src/link.js +167 -0
- package/src/printer.js +211 -0
- package/src/relation.js +82 -0
- package/src/section.js +111 -0
package/src/link.js
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
const {
|
|
2
|
+
string: { toSlug },
|
|
3
|
+
url: { pathUrl },
|
|
4
|
+
object: { hasProperty },
|
|
5
|
+
graphql: {
|
|
6
|
+
isEnumType,
|
|
7
|
+
isUnionType,
|
|
8
|
+
isObjectType,
|
|
9
|
+
isScalarType,
|
|
10
|
+
isOperation,
|
|
11
|
+
isDirectiveType,
|
|
12
|
+
isInterfaceType,
|
|
13
|
+
getNamedType,
|
|
14
|
+
isInputType,
|
|
15
|
+
hasDirective,
|
|
16
|
+
getTypeName,
|
|
17
|
+
isListType,
|
|
18
|
+
isNonNullType,
|
|
19
|
+
isLeafType,
|
|
20
|
+
},
|
|
21
|
+
} = require("@graphql-markdown/utils");
|
|
22
|
+
|
|
23
|
+
const { getGroup } = require("./group");
|
|
24
|
+
const { ROOT_TYPE_LOCALE } = require("./const/strings");
|
|
25
|
+
|
|
26
|
+
class Link {
|
|
27
|
+
static getLinkCategory = (graphLQLNamedType) => {
|
|
28
|
+
switch (true) {
|
|
29
|
+
case isEnumType(graphLQLNamedType):
|
|
30
|
+
return ROOT_TYPE_LOCALE.ENUM;
|
|
31
|
+
case isUnionType(graphLQLNamedType):
|
|
32
|
+
return ROOT_TYPE_LOCALE.UNION;
|
|
33
|
+
case isInterfaceType(graphLQLNamedType):
|
|
34
|
+
return ROOT_TYPE_LOCALE.INTERFACE;
|
|
35
|
+
case isObjectType(graphLQLNamedType):
|
|
36
|
+
return ROOT_TYPE_LOCALE.TYPE;
|
|
37
|
+
case isInputType(graphLQLNamedType):
|
|
38
|
+
return ROOT_TYPE_LOCALE.INPUT;
|
|
39
|
+
case isScalarType(graphLQLNamedType):
|
|
40
|
+
return ROOT_TYPE_LOCALE.SCALAR;
|
|
41
|
+
case isDirectiveType(graphLQLNamedType):
|
|
42
|
+
return ROOT_TYPE_LOCALE.DIRECTIVE;
|
|
43
|
+
case isOperation(graphLQLNamedType):
|
|
44
|
+
return ROOT_TYPE_LOCALE.OPERATION;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
static toLink = (type, name, operation, options) => {
|
|
50
|
+
const fallback = {
|
|
51
|
+
text: name,
|
|
52
|
+
url: "#",
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
if (typeof type === "undefined") {
|
|
56
|
+
return fallback;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (hasProperty(options, "skipDocDirective")) {
|
|
60
|
+
if (hasDirective(type, options.skipDocDirective)) {
|
|
61
|
+
return fallback;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const graphLQLNamedType = getNamedType(type);
|
|
66
|
+
|
|
67
|
+
let category = Link.getLinkCategory(graphLQLNamedType);
|
|
68
|
+
|
|
69
|
+
if (
|
|
70
|
+
typeof category === "undefined" ||
|
|
71
|
+
typeof graphLQLNamedType === "undefined" ||
|
|
72
|
+
graphLQLNamedType === null
|
|
73
|
+
) {
|
|
74
|
+
return fallback;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// special case for support relation map
|
|
78
|
+
if (category === ROOT_TYPE_LOCALE.OPERATION) {
|
|
79
|
+
if (typeof operation === "undefined") {
|
|
80
|
+
return fallback;
|
|
81
|
+
}
|
|
82
|
+
category = operation;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const text = graphLQLNamedType.name || graphLQLNamedType;
|
|
86
|
+
const group = getGroup(type, options.groups);
|
|
87
|
+
const url = pathUrl.join(
|
|
88
|
+
options.basePath,
|
|
89
|
+
group,
|
|
90
|
+
category.plural,
|
|
91
|
+
toSlug(text),
|
|
92
|
+
);
|
|
93
|
+
|
|
94
|
+
return {
|
|
95
|
+
text: text,
|
|
96
|
+
url: url,
|
|
97
|
+
};
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
static getRelationLink = (category, type, options) => {
|
|
101
|
+
if (typeof category === "undefined") {
|
|
102
|
+
return "";
|
|
103
|
+
}
|
|
104
|
+
const link = Link.toLink(type, type.name, category, options);
|
|
105
|
+
return `[\`${link.text}\`](${link.url}) <Badge class="secondary" text="${category.singular}"/>`;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
static printParentLink = (type, options) => {
|
|
109
|
+
return hasProperty(type, "type")
|
|
110
|
+
? `<Bullet />${Link.printLink(type.type, {
|
|
111
|
+
withAttributes: true,
|
|
112
|
+
...options,
|
|
113
|
+
})}`
|
|
114
|
+
: "";
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
static hasOptionWithAttributes = (options) =>
|
|
118
|
+
hasProperty(options, "withAttributes") === true &&
|
|
119
|
+
options.withAttributes === true;
|
|
120
|
+
|
|
121
|
+
static hasOptionParentType = (options) =>
|
|
122
|
+
hasProperty(options, "parentTypePrefix") &&
|
|
123
|
+
options.parentTypePrefix === true &&
|
|
124
|
+
hasProperty(options, "parentType") &&
|
|
125
|
+
typeof options.parentType !== "undefined" &&
|
|
126
|
+
options.parentType !== null;
|
|
127
|
+
|
|
128
|
+
static printLink = (type, options) => {
|
|
129
|
+
let text;
|
|
130
|
+
|
|
131
|
+
const link = Link.toLink(type, getTypeName(type), undefined, options);
|
|
132
|
+
|
|
133
|
+
if (Link.hasOptionWithAttributes(options) === false) {
|
|
134
|
+
text =
|
|
135
|
+
Link.hasOptionParentType(options) === true
|
|
136
|
+
? `<code style={{ fontWeight: 'normal' }}>${options.parentType}.<b>${link.text}</b></code>`
|
|
137
|
+
: `\`${link.text}\``;
|
|
138
|
+
return `[${text}](${link.url})`;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
text = Link.printLinkAttributes(type, link.text);
|
|
142
|
+
|
|
143
|
+
return `[\`${text}\`](${link.url})`;
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
static printLinkAttributes = (type, text) => {
|
|
147
|
+
if (typeof type === "undefined" || type === null) {
|
|
148
|
+
return text ?? "";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (!isLeafType(type, text) && typeof type.ofType != "undefined") {
|
|
152
|
+
text = Link.printLinkAttributes(type.ofType, text);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
if (isListType(type)) {
|
|
156
|
+
return `[${text}]`;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
if (isNonNullType(type)) {
|
|
160
|
+
return `${text}!`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
return text;
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
module.exports = Link;
|
package/src/printer.js
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
const {
|
|
2
|
+
graphql: {
|
|
3
|
+
getTypeName,
|
|
4
|
+
isOperation,
|
|
5
|
+
isEnumType,
|
|
6
|
+
isUnionType,
|
|
7
|
+
isInterfaceType,
|
|
8
|
+
isObjectType,
|
|
9
|
+
isInputType,
|
|
10
|
+
isScalarType,
|
|
11
|
+
isDirectiveType,
|
|
12
|
+
hasDirective,
|
|
13
|
+
},
|
|
14
|
+
} = require("@graphql-markdown/utils");
|
|
15
|
+
|
|
16
|
+
const {
|
|
17
|
+
url: { pathUrl },
|
|
18
|
+
} = require("@graphql-markdown/utils");
|
|
19
|
+
|
|
20
|
+
const { printRelations } = require("./relation");
|
|
21
|
+
const { printDescription } = require("./common");
|
|
22
|
+
const {
|
|
23
|
+
printOperationMetadata,
|
|
24
|
+
printCodeOperation,
|
|
25
|
+
printCodeEnum,
|
|
26
|
+
printEnumMetadata,
|
|
27
|
+
printCodeUnion,
|
|
28
|
+
printUnionMetadata,
|
|
29
|
+
printCodeInterface,
|
|
30
|
+
printInterfaceMetadata,
|
|
31
|
+
printCodeObject,
|
|
32
|
+
printObjectMetadata,
|
|
33
|
+
printCodeInput,
|
|
34
|
+
printInputMetadata,
|
|
35
|
+
printCodeScalar,
|
|
36
|
+
printScalarMetadata,
|
|
37
|
+
printCodeDirective,
|
|
38
|
+
printDirectiveMetadata,
|
|
39
|
+
} = require("./graphql");
|
|
40
|
+
const {
|
|
41
|
+
MARKDOWN_EOP,
|
|
42
|
+
MARKDOWN_EOL,
|
|
43
|
+
MARKDOWN_SOC,
|
|
44
|
+
MARKDOWN_EOC,
|
|
45
|
+
FRONT_MATTER,
|
|
46
|
+
} = require("./const/strings");
|
|
47
|
+
const mdx = require("./const/mdx");
|
|
48
|
+
|
|
49
|
+
const DEFAULT_OPTIONS = {
|
|
50
|
+
schema: undefined,
|
|
51
|
+
basePath: "/",
|
|
52
|
+
groups: {},
|
|
53
|
+
parentTypePrefix: true,
|
|
54
|
+
relatedTypeSection: true,
|
|
55
|
+
typeBadges: true,
|
|
56
|
+
skipDocDirective: undefined,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
class Printer {
|
|
60
|
+
static options;
|
|
61
|
+
|
|
62
|
+
static init = (
|
|
63
|
+
schema,
|
|
64
|
+
baseURL,
|
|
65
|
+
linkRoot = "/",
|
|
66
|
+
{ groups, printTypeOptions, skipDocDirective } = {
|
|
67
|
+
groups: undefined,
|
|
68
|
+
printTypeOptions: undefined,
|
|
69
|
+
skipDocDirective: undefined,
|
|
70
|
+
},
|
|
71
|
+
) => {
|
|
72
|
+
if (typeof Printer.options !== "undefined" && Printer.options !== null) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
Printer.options = {
|
|
77
|
+
...DEFAULT_OPTIONS,
|
|
78
|
+
schema,
|
|
79
|
+
basePath: pathUrl.join(linkRoot, baseURL),
|
|
80
|
+
groups,
|
|
81
|
+
parentTypePrefix: printTypeOptions?.parentTypePrefix ?? true,
|
|
82
|
+
relatedTypeSection: printTypeOptions?.relatedTypeSection ?? true,
|
|
83
|
+
typeBadges: printTypeOptions?.typeBadges ?? true,
|
|
84
|
+
skipDocDirective: skipDocDirective ?? undefined,
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
static printHeader = (id, title, options) => {
|
|
89
|
+
const { toc, pagination } = {
|
|
90
|
+
toc: true,
|
|
91
|
+
pagination: true,
|
|
92
|
+
...(options.header ?? undefined),
|
|
93
|
+
};
|
|
94
|
+
const pagination_buttons = pagination
|
|
95
|
+
? []
|
|
96
|
+
: ["pagination_next: null", "pagination_prev: null"];
|
|
97
|
+
|
|
98
|
+
const header = [
|
|
99
|
+
FRONT_MATTER,
|
|
100
|
+
`id: ${id}`,
|
|
101
|
+
`title: ${title}`,
|
|
102
|
+
`hide_table_of_contents: ${!toc}`,
|
|
103
|
+
...pagination_buttons,
|
|
104
|
+
FRONT_MATTER,
|
|
105
|
+
];
|
|
106
|
+
|
|
107
|
+
return header.join(MARKDOWN_EOL);
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
static printDescription = printDescription;
|
|
111
|
+
|
|
112
|
+
static printCode = (type) => {
|
|
113
|
+
let code = "";
|
|
114
|
+
|
|
115
|
+
switch (true) {
|
|
116
|
+
case isOperation(type):
|
|
117
|
+
code += printCodeOperation(type);
|
|
118
|
+
break;
|
|
119
|
+
case isEnumType(type):
|
|
120
|
+
code += printCodeEnum(type);
|
|
121
|
+
break;
|
|
122
|
+
case isUnionType(type):
|
|
123
|
+
code += printCodeUnion(type);
|
|
124
|
+
break;
|
|
125
|
+
case isInterfaceType(type):
|
|
126
|
+
code += printCodeInterface(type);
|
|
127
|
+
break;
|
|
128
|
+
case isObjectType(type):
|
|
129
|
+
code += printCodeObject(type);
|
|
130
|
+
break;
|
|
131
|
+
case isInputType(type):
|
|
132
|
+
code += printCodeInput(type);
|
|
133
|
+
break;
|
|
134
|
+
case isScalarType(type):
|
|
135
|
+
code += printCodeScalar(type);
|
|
136
|
+
break;
|
|
137
|
+
case isDirectiveType(type):
|
|
138
|
+
code += printCodeDirective(type);
|
|
139
|
+
break;
|
|
140
|
+
default:
|
|
141
|
+
code += `"${getTypeName(type)}" not supported`;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return MARKDOWN_SOC + code.trim() + MARKDOWN_EOC;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
static printTypeMetadata = (type, options) => {
|
|
148
|
+
let metadata;
|
|
149
|
+
|
|
150
|
+
switch (true) {
|
|
151
|
+
case isScalarType(type):
|
|
152
|
+
return printScalarMetadata(type, options);
|
|
153
|
+
case isEnumType(type):
|
|
154
|
+
return printEnumMetadata(type, options);
|
|
155
|
+
case isUnionType(type):
|
|
156
|
+
return printUnionMetadata(type, options);
|
|
157
|
+
case isObjectType(type):
|
|
158
|
+
return printObjectMetadata(type, options);
|
|
159
|
+
case isInterfaceType(type):
|
|
160
|
+
return printInterfaceMetadata(type, options);
|
|
161
|
+
case isInputType(type):
|
|
162
|
+
return printInputMetadata(type, options);
|
|
163
|
+
case isDirectiveType(type):
|
|
164
|
+
return printDirectiveMetadata(type, options);
|
|
165
|
+
case isOperation(type):
|
|
166
|
+
return printOperationMetadata(type, options);
|
|
167
|
+
default:
|
|
168
|
+
return metadata;
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
static printRelations = (type, options) => {
|
|
173
|
+
if (Printer.options.relatedTypeSection !== true) {
|
|
174
|
+
return "";
|
|
175
|
+
}
|
|
176
|
+
return printRelations(type, options);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
static printType = (name, type, options) => {
|
|
180
|
+
if (
|
|
181
|
+
typeof type === "undefined" ||
|
|
182
|
+
type === null ||
|
|
183
|
+
typeof name === "undefined" ||
|
|
184
|
+
name === null ||
|
|
185
|
+
hasDirective(type, Printer.options.skipDocDirective)
|
|
186
|
+
) {
|
|
187
|
+
return undefined;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
const printTypeOptions = {
|
|
191
|
+
...DEFAULT_OPTIONS,
|
|
192
|
+
...Printer.options,
|
|
193
|
+
...options,
|
|
194
|
+
};
|
|
195
|
+
|
|
196
|
+
const header = Printer.printHeader(name, getTypeName(type), {
|
|
197
|
+
...printTypeOptions,
|
|
198
|
+
header: options,
|
|
199
|
+
});
|
|
200
|
+
const description = Printer.printDescription(type);
|
|
201
|
+
const code = Printer.printCode(type);
|
|
202
|
+
const metadata = Printer.printTypeMetadata(type, printTypeOptions);
|
|
203
|
+
const relations = Printer.printRelations(type, printTypeOptions);
|
|
204
|
+
|
|
205
|
+
return [header, mdx, description, code, metadata, relations].join(
|
|
206
|
+
MARKDOWN_EOP,
|
|
207
|
+
);
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
module.exports = { Printer, DEFAULT_OPTIONS };
|
package/src/relation.js
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
const {
|
|
2
|
+
graphql: {
|
|
3
|
+
isOperation,
|
|
4
|
+
getRelationOfReturn,
|
|
5
|
+
getRelationOfField,
|
|
6
|
+
getRelationOfImplementation,
|
|
7
|
+
},
|
|
8
|
+
} = require("@graphql-markdown/utils");
|
|
9
|
+
|
|
10
|
+
const { getRelationLink } = require("./link");
|
|
11
|
+
const {
|
|
12
|
+
ROOT_TYPE_LOCALE,
|
|
13
|
+
HEADER_SECTION_LEVEL,
|
|
14
|
+
MARKDOWN_EOP,
|
|
15
|
+
} = require("./const/strings");
|
|
16
|
+
|
|
17
|
+
const getRootTypeLocaleFromString = (text) => {
|
|
18
|
+
for (const [type, props] of Object.entries(ROOT_TYPE_LOCALE)) {
|
|
19
|
+
if (Object.values(props).includes(text)) {
|
|
20
|
+
return ROOT_TYPE_LOCALE[type];
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return undefined;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const printRelationOf = (type, section, getRelation, options) => {
|
|
27
|
+
if (
|
|
28
|
+
typeof type === "undefined" ||
|
|
29
|
+
typeof getRelation !== "function" ||
|
|
30
|
+
typeof options === "undefined" ||
|
|
31
|
+
isOperation(type)
|
|
32
|
+
) {
|
|
33
|
+
return "";
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const relations = getRelation(type, options.schema);
|
|
37
|
+
|
|
38
|
+
if (typeof relations === "undefined") {
|
|
39
|
+
return "";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
let data = [];
|
|
43
|
+
for (const [relation, types] of Object.entries(relations)) {
|
|
44
|
+
if (types.length === 0) {
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const category = getRootTypeLocaleFromString(relation);
|
|
49
|
+
data = data.concat(types.map((t) => getRelationLink(category, t, options)));
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (data.length === 0) {
|
|
53
|
+
return "";
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const content = [...data]
|
|
57
|
+
.sort((a, b) => a.localeCompare(b))
|
|
58
|
+
.join("<Bullet />");
|
|
59
|
+
|
|
60
|
+
return `${HEADER_SECTION_LEVEL} ${section}${MARKDOWN_EOP}${content}${MARKDOWN_EOP}`;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const printRelations = (type, options) => {
|
|
64
|
+
const relations = {
|
|
65
|
+
"Returned by": getRelationOfReturn,
|
|
66
|
+
"Member of": getRelationOfField,
|
|
67
|
+
"Implemented by": getRelationOfImplementation,
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
let data = "";
|
|
71
|
+
for (const [section, getRelation] of Object.entries(relations)) {
|
|
72
|
+
data += printRelationOf(type, section, getRelation, options);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
return data;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
module.exports = {
|
|
79
|
+
getRootTypeLocaleFromString,
|
|
80
|
+
printRelationOf,
|
|
81
|
+
printRelations,
|
|
82
|
+
};
|
package/src/section.js
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
const {
|
|
2
|
+
graphql: { isParametrizedField, hasDirective },
|
|
3
|
+
} = require("@graphql-markdown/utils");
|
|
4
|
+
const { hasProperty } = require("@graphql-markdown/utils/src/object");
|
|
5
|
+
|
|
6
|
+
const {
|
|
7
|
+
HEADER_SECTION_LEVEL,
|
|
8
|
+
HEADER_SECTION_SUB_LEVEL,
|
|
9
|
+
HEADER_SECTION_ITEM_LEVEL,
|
|
10
|
+
MARKDOWN_EOL,
|
|
11
|
+
MARKDOWN_EOP,
|
|
12
|
+
} = require("./const/strings");
|
|
13
|
+
const { printDescription } = require("./common");
|
|
14
|
+
const { printBadges } = require("./badge");
|
|
15
|
+
const { printLink, printParentLink } = require("./link");
|
|
16
|
+
|
|
17
|
+
const sectionLevels = [
|
|
18
|
+
HEADER_SECTION_LEVEL,
|
|
19
|
+
HEADER_SECTION_SUB_LEVEL,
|
|
20
|
+
HEADER_SECTION_ITEM_LEVEL,
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const printSection = (values, section, options) => {
|
|
24
|
+
const level =
|
|
25
|
+
hasProperty(options, "level") &&
|
|
26
|
+
typeof options.level !== "undefined" &&
|
|
27
|
+
options.level !== null
|
|
28
|
+
? options.level
|
|
29
|
+
: HEADER_SECTION_LEVEL;
|
|
30
|
+
|
|
31
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
32
|
+
return "";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const levelPosition = sectionLevels.indexOf(level);
|
|
36
|
+
let subLevel = undefined;
|
|
37
|
+
if (levelPosition > -1) {
|
|
38
|
+
subLevel = sectionLevels[levelPosition + 1];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return `${level} ${section}${MARKDOWN_EOP}${printSectionItems(values, {
|
|
42
|
+
...options,
|
|
43
|
+
level: subLevel,
|
|
44
|
+
})}${MARKDOWN_EOP}`;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const printSectionItems = (values, options) => {
|
|
48
|
+
const level =
|
|
49
|
+
hasProperty(options, "level") &&
|
|
50
|
+
typeof options.level !== "undefined" &&
|
|
51
|
+
options.level !== null
|
|
52
|
+
? options.level
|
|
53
|
+
: HEADER_SECTION_SUB_LEVEL;
|
|
54
|
+
|
|
55
|
+
if (!Array.isArray(values) || values.length === 0) {
|
|
56
|
+
return "";
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
return values
|
|
60
|
+
.map(
|
|
61
|
+
(v) =>
|
|
62
|
+
v &&
|
|
63
|
+
printSectionItem(v, {
|
|
64
|
+
...options,
|
|
65
|
+
level,
|
|
66
|
+
}),
|
|
67
|
+
)
|
|
68
|
+
.join(MARKDOWN_EOP);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const printSectionItem = (type, options) => {
|
|
72
|
+
const level =
|
|
73
|
+
hasProperty(options, "level") &&
|
|
74
|
+
typeof options.level !== "undefined" &&
|
|
75
|
+
options.level !== null
|
|
76
|
+
? options.level
|
|
77
|
+
: HEADER_SECTION_SUB_LEVEL;
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
typeof type === "undefined" ||
|
|
81
|
+
type === null ||
|
|
82
|
+
hasDirective(type, options.skipDocDirective)
|
|
83
|
+
) {
|
|
84
|
+
return "";
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
const typeNameLink = printLink(type, { ...options, withAttributes: false });
|
|
88
|
+
const description = printDescription(type, "");
|
|
89
|
+
const badges = printBadges(type, options);
|
|
90
|
+
const parentTypeLink = printParentLink(type, options);
|
|
91
|
+
|
|
92
|
+
let section = `${level} ${typeNameLink}${parentTypeLink} ${badges}${MARKDOWN_EOL}> ${description}${MARKDOWN_EOL}> `;
|
|
93
|
+
if (isParametrizedField(type)) {
|
|
94
|
+
section += printSectionItems(type.args, {
|
|
95
|
+
...options,
|
|
96
|
+
level: HEADER_SECTION_ITEM_LEVEL,
|
|
97
|
+
parentType:
|
|
98
|
+
typeof options.parentType === "undefined"
|
|
99
|
+
? type.name
|
|
100
|
+
: `${options.parentType}.${type.name}`,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return section;
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
module.exports = {
|
|
108
|
+
printSection,
|
|
109
|
+
printSectionItem,
|
|
110
|
+
printSectionItems,
|
|
111
|
+
};
|