Skip to content

Commit 772d68a

Browse files
aomarksjustinfagnani
authored andcommitted
Render the element page description markdown as HTML
1 parent a713b95 commit 772d68a

File tree

4 files changed

+58
-6
lines changed

4 files changed

+58
-6
lines changed

package-lock.json

Lines changed: 17 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/site-client/src/components/wco-element-page.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
import {html, css} from 'lit';
88
import {customElement, property} from 'lit/decorators.js';
9+
import {unsafeHTML} from 'lit/directives/unsafe-html.js';
910
import {WCOPage} from './wco-page.js';
1011

1112
import type {Package, Reference} from 'custom-elements-manifest/schema.js';
@@ -22,6 +23,7 @@ export interface ElementData {
2223
declarationReference: string;
2324
customElementExport: string;
2425
manifest: Package;
26+
elementDescriptionHtml: string;
2527
}
2628

2729
@customElement('wco-element-page')
@@ -40,6 +42,10 @@ export class WCOElementPage extends WCOPage {
4042
align-items: center;
4143
justify-items: center;
4244
}
45+
46+
main {
47+
padding: 25px;
48+
}
4349
`,
4450
];
4551

@@ -56,6 +62,7 @@ export class WCOElementPage extends WCOPage {
5662
declarationReference,
5763
customElementExport,
5864
manifest,
65+
elementDescriptionHtml,
5966
} = this.elementData;
6067
const ceExportRef = parseReferenceString(customElementExport);
6168
const declarationRef = parseReferenceString(declarationReference);
@@ -81,7 +88,7 @@ export class WCOElementPage extends WCOPage {
8188
<h1>${packageName}/${elementName}</h1>
8289
<h3>${declaration.summary}</h3>
8390
84-
<p>${declaration.description}</p>
91+
<p>${unsafeHTML(elementDescriptionHtml)}</p>
8592
8693
<h2>Usage</h2>
8794
<pre><code>

packages/site-server/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,14 @@
103103
"@types/koa-conditional-get": "^2.0.0",
104104
"@types/koa-etag": "^3.0.0",
105105
"@types/koa-static": "^4.0.2",
106+
"@types/marked": "^4.0.8",
106107
"@web/dev-server": "^0.1.34",
107108
"@webcomponents/internal-site-content": "^0.0.0",
108109
"koa": "^2.13.4",
109110
"koa-conditional-get": "^3.0.0",
110111
"koa-etag": "^4.0.0",
111-
"koa-static": "^5.0.0"
112+
"koa-static": "^5.0.0",
113+
"marked": "^4.2.5"
112114
},
113115
"devDependencies": {
114116
"uvu": "^0.5.6"

packages/site-server/src/lib/catalog/routes/element/element-route.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,19 @@ import {DefaultContext, DefaultState, ParameterizedContext} from 'koa';
1111
import {Readable} from 'stream';
1212
import {gql} from '@apollo/client/core/index.js';
1313
import Router from '@koa/router';
14+
import {marked} from 'marked';
1415

1516
import {renderElementPage} from '@webcomponents/internal-site-client/lib/entrypoints/element.js';
1617
import {client} from '../../graphql.js';
1718

19+
import type {ElementData} from '@webcomponents/internal-site-client/lib/components/wco-element-page.js';
20+
21+
import {
22+
getModule,
23+
parseReferenceString,
24+
resolveReference,
25+
} from '@webcomponents/custom-elements-manifest-tools';
26+
1827
export const handleElementRoute = async (
1928
context: ParameterizedContext<
2029
DefaultState,
@@ -91,12 +100,32 @@ export const handleElementRoute = async (
91100
throw new Error('Internal error');
92101
}
93102

94-
const elementData = {
103+
const declarationRef = parseReferenceString(customElement.declaration);
104+
const module =
105+
declarationRef.module === undefined
106+
? undefined
107+
: getModule(customElementsManifest, declarationRef.module);
108+
const declaration =
109+
module === undefined
110+
? undefined
111+
: resolveReference(
112+
customElementsManifest,
113+
module,
114+
declarationRef,
115+
packageName,
116+
''
117+
);
118+
const elementDescriptionHtml = declaration?.description
119+
? marked(declaration?.description)
120+
: '';
121+
122+
const elementData: ElementData = {
95123
packageName: packageName,
96124
elementName: elementName,
97125
declarationReference: customElement.declaration,
98126
customElementExport: customElement.customElementExport,
99127
manifest: customElementsManifest,
128+
elementDescriptionHtml,
100129
};
101130

102131
// Set location because wco-nav-bar reads pathname from it. URL isn't

0 commit comments

Comments
 (0)