Skip to content

Commit f785e91

Browse files
committed
feat: add description section classes-mixins
1 parent 95d92f3 commit f785e91

File tree

9 files changed

+36
-2
lines changed

9 files changed

+36
-2
lines changed

packages/to-markdown/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ fs.writeFileSync('./custom-elements.md', markdown);
2727
| Option | Type | Default | Description |
2828
| ------------- | ---------------------------- | ------- | ----------- |
2929
| headingOffset | Integer | 0 | Offset the heading level by this number |
30+
| mainDescription | Boolean | true | Show description field for Class and Mixins |
3031
| private | `'all'\|'details'\|'hidden'` | `'all'` | See [Private Members](#private-members) |
3132
| omitDeclarations | `OptionalDeclarations[]` | [] | See [Omit Declarations](#omit-declarations) |
3233
| omitSections | `OptionalSections[]` | [] | See [Omit Sections](#omit-sections) |
@@ -62,6 +63,7 @@ customElementsManifestToMarkdown(manifest, {
6263
The `omitSections` option is a `string[]` that controls which sections of a declaration's full entry in the manifest.json should be rendered in the final markdown output. The section names are:
6364

6465
- mainHeading : "main-heading"
66+
- mainDescription : "main-description"
6567
- superClass : "super-class"
6668
- fields : "fields"
6769
- methods : "methods"
@@ -117,6 +119,7 @@ customElementsManifestToMarkdown(manifest, {
117119
"declarations": [
118120
{
119121
"kind": "class",
122+
"description": "My description",
120123
"name": "SuperClass",
121124
"events": [
122125
{
@@ -420,6 +423,8 @@ customElementsManifestToMarkdown(manifest, {
420423

421424
<details><summary>Result</summary>
422425

426+
My description
427+
423428
## `./fixtures/-TEST/package/my-element.js`:
424429

425430
### class: `SuperClass`

packages/to-markdown/fixtures/heading-offset-2/EXPECTED.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
Large description of ...
2+
13
### `my-element.js`:
24

35
#### class: `MyElement`, `my-element`

packages/to-markdown/fixtures/heading-offset-2/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
Large description of ...
2+
3+
14
### `my-element.js`:
25

36
#### class: `MyElement`, `my-element`

packages/to-markdown/fixtures/heading-offset-2/custom-elements.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
{
1010
"kind": "class",
1111
"name": "MyElement",
12+
"description": "Large description of ...",
1213
"cssProperties": [
1314
{
1415
"name": "--background-color",

packages/to-markdown/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ const DECLARATIONS = {
2222
};
2323

2424
const SECTIONS = {
25+
mainDescription : 'main-description',
2526
mainHeading: 'main-heading',
2627
superClass: 'super-class',
2728
fields: 'fields',
@@ -180,7 +181,20 @@ function makeModuleDoc(mod, options) {
180181
const variablesDecl = filteredDeclarations(declarations, omittedDeclarations, classNameFilter).filter(kindIs('variable'));
181182
const functionsDecl = filteredDeclarations(declarations, omittedDeclarations, classNameFilter).filter(kindIs('function'));
182183

184+
const mainDescription =
185+
optionEnabled(omittedSections.mainDescription)
186+
? declarations.map((decl) =>{
187+
if (['mixin', 'class'].includes(decl.kind) && decl.description) {
188+
return html(`${decl.description}\n`);
189+
} else {
190+
return '';
191+
}
192+
})
193+
: [];
194+
183195
return [
196+
...mainDescription,
197+
184198
optionEnabled(omittedSections.mainHeading) ? heading(1 + headingOffset, [inlineCode(mod.path), text(':')]) : null,
185199

186200
...(filteredDeclarations(declarations, omittedDeclarations, classNameFilter).flatMap(decl => {

packages/to-markdown/lib/cells.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@ function getExportKind(x, options) {
1616
return x.kind ? inlineCode(x.kind) : text('');
1717
}
1818

19+
const formatInline = x =>
20+
x?.replace(/\n/g, '');
21+
1922
export const DECLARATION = { heading: 'Declaration', get: x => x.declaration?.name ?? '' };
20-
export const DEFAULT = { heading: 'Default', get: x => x.default, cellType: inlineCode };
23+
export const DEFAULT = { heading: 'Default', get: x => formatInline(x.default), cellType: inlineCode };
2124
export const NAME = { heading: 'Name', get: x => x.name, cellType: inlineCode };
2225
export const ATTR_FIELD = { heading: 'Field', get: x => x.fieldName };
2326
export const INHERITANCE = { heading: 'Inherited From', get: x => x.inheritedFrom?.name ?? '' };

packages/to-markdown/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,5 +59,9 @@
5959
"remark-gfm": "^1.0.0",
6060
"remark-stringify": "^9.0.1",
6161
"unified": "^9.2.1"
62+
},
63+
"devDependencies": {
64+
"@asdgf/cli": "https://gitpkg.now.sh/thepassle/asdgf/packages/cli?master",
65+
"esbuild": "^0.19.2"
6266
}
6367
}

packages/to-markdown/test/to-markdown.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ const MAIN_TEST_CASE_OPTIONS = {
2727
};
2828

2929
const OUTPUT_OPTIONS_TESTS_OPTIONS = {
30-
'no-heading': { omitSections: ['main-heading'] },
30+
'no-heading': { omitSections: ['main-heading','main-description'] },
3131
'class-name-filter': { classNameFilter: 'My*' },
3232
'no-attributes': { omitSections: ['attributes'] },
3333
'no-cssparts': { omitSections: ['css-parts'] },

packages/to-markdown/types/main.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ enum Declarations {
99
}
1010

1111
enum Sections {
12+
mainDescription = 'main-description',
1213
mainHeading = 'main-heading',
1314
superClass = 'super-class',
1415
fields = 'fields',
@@ -29,6 +30,7 @@ type OptionalSections = `${Sections}`;
2930
export interface Options {
3031
private?: 'details'|'hidden'|'all';
3132
headingOffset?: number;
33+
mainDescription?: boolean;
3234
omitSections: OptionalSections[];
3335
omitDeclarations: OptionalDeclarations[];
3436
classNameFilter: string | (() => string);

0 commit comments

Comments
 (0)