Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/to-markdown/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ customElementsManifestToMarkdown(manifest, {
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:

- mainHeading : "main-heading"
- description : "description"
- superClass : "super-class"
- fields : "fields"
- methods : "methods"
Expand Down Expand Up @@ -118,6 +119,7 @@ customElementsManifestToMarkdown(manifest, {
{
"kind": "class",
"name": "SuperClass",
"description" : "Description of the *class*.",
"events": [
{
"name": "custom-event",
Expand Down Expand Up @@ -424,6 +426,8 @@ customElementsManifestToMarkdown(manifest, {

### class: `SuperClass`

Description of the *class*.

#### Superclass

| Name | Module | Package |
Expand Down
4 changes: 4 additions & 0 deletions packages/to-markdown/fixtures/kitchen-sink/EXPECTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## class: `SuperClass`

This is a *super* class

See [Custom Elements Manifest](https://custom-elements-manifest.open-wc.org/)

### Superclass

| Name | Module | Package |
Expand Down
4 changes: 4 additions & 0 deletions packages/to-markdown/fixtures/kitchen-sink/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## class: `SuperClass`

This is a *super* class

See [Custom Elements Manifest](https://custom-elements-manifest.open-wc.org/)

### Superclass

| Name | Module | Package |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{
"kind": "class",
"name": "SuperClass",
"description": "This is a *super* class\n\nSee [Custom Elements Manifest](https://custom-elements-manifest.open-wc.org/)",
"events": [
{
"name": "custom-event",
Expand Down
25 changes: 24 additions & 1 deletion packages/to-markdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
isDefined
} from './lib/fp.js';
import * as CELLS from './lib/cells.js';
import { serialize } from './lib/serialize.js';
import { serialize, parse } from './lib/serialize.js';

const line = html('<hr/>');

Expand All @@ -23,6 +23,7 @@ const DECLARATIONS = {

const SECTIONS = {
mainHeading: 'main-heading',
description: 'description',
superClass: 'super-class',
fields: 'fields',
methods: 'methods',
Expand Down Expand Up @@ -51,6 +52,26 @@ const declarationHeading = options =>
]
);

/** Options -> Declaration -> [Content] */
const declarationDescription = options =>
({ description }) => {
const headingOffset = 1 + (options?.headingOffset ?? 0);

try {
const contentNodes = parse(description).children || [];

contentNodes.forEach((node) => {
if (node.type === 'heading' && typeof node.depth === "number") {
node.depth = Math.min(node.depth + headingOffset, 6);
}
})

return contentNodes;
} catch {
return [];
}
}

/** String -> Descriptor */
const defaultDescriptor = name =>
({ heading: capital(name), get: x => x?.[name] });
Expand Down Expand Up @@ -177,6 +198,7 @@ function makeModuleDoc(mod, options) {

const makeTable = tableWithTitle(options);
const makeHeading = declarationHeading(options);
const makeDescription = declarationDescription(options);
const variablesDecl = filteredDeclarations(declarations, omittedDeclarations, classNameFilter).filter(kindIs('variable'));
const functionsDecl = filteredDeclarations(declarations, omittedDeclarations, classNameFilter).filter(kindIs('function'));

Expand All @@ -193,6 +215,7 @@ function makeModuleDoc(mod, options) {

const nodes = [
!['mixin', 'class'].includes(kind) ? null : makeHeading(decl),
...['mixin', 'class'].includes(kind) && optionEnabled(omittedSections.description) ? makeDescription(decl) : [],
...optionEnabled(omittedSections.superClass) ? makeTable('Superclass', [CELLS.NAME, 'module', 'package'], [decl.superclass]) : [],
...optionEnabled(omittedSections.mixins) ? makeTable('Mixins', [CELLS.NAME, 'module', 'package'], decl.mixins) : [],
...kind === 'mixin' && optionEnabled(omittedSections.mixins) ? makeTable('Parameters', [CELLS.NAME, CELLS.TYPE, CELLS.DEFAULT, 'description'], decl.parameters) : [],
Expand Down
1 change: 1 addition & 0 deletions packages/to-markdown/types/main.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ enum Declarations {

enum Sections {
mainHeading = 'main-heading',
description = 'description',
superClass = 'super-class',
fields = 'fields',
methods = 'methods',
Expand Down