Skip to content

Commit e27841e

Browse files
refine content
1 parent cb9b39b commit e27841e

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

src/pages/docs/resources/markdown.md

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

77
# Markdown
88

9-
In this section we'll cover some of the Markdown related feature of **Greenwood**, which by default supports the [CommonMark](https://commonmark.org/help/) specification and [**unifiedjs**](https://unifiedjs.com/) as the markdown / content framework.
9+
In this section we'll cover some of the Markdown related features of **Greenwood**, which by default supports the [CommonMark](https://commonmark.org/help/) specification and [**unifiedjs**](https://unifiedjs.com/) as the markdown / content framework.
1010

1111
## Plugins
1212

@@ -254,3 +254,55 @@ With [`activeContent`](/docs/reference/configuration/#active-content) enabled, a
254254
</app-ctc-block>
255255

256256
<!-- prettier-ignore-end -->
257+
258+
## Web Components
259+
260+
Web Components work great with markdown, and can be used to mix markdown authored content as HTML to be "projected" into a custom element definition. We make extensive use of the [HTML Web Components pattern](/guides/getting-started/going-further/#light-dom) in this documentation site, which allows us to encapsulate styles and layout around generic, page specific content; for example to create our ["section headers"](https://raw.githubusercontent.com/ProjectEvergreen/www.greenwoodjs.dev/refs/heads/main/src/pages/docs/introduction/index.md).
261+
262+
Perfect for documentation sites when combined with [prerendering](/docs/reference/configuration/#prerender) and [static optimization](/docs/reference/configuration/#optimization) configuration options, to get zero runtime templating. Works great with syntax highlighting too! ✨
263+
264+
The example below mixes static content and attributes, leveraging our (optional) [CSS Modules plugin](/docs/plugins/css-modules/):
265+
266+
```js
267+
import styles from "./heading-box.module.css";
268+
269+
export default class HeadingBox extends HTMLElement {
270+
connectedCallback() {
271+
const heading = this.getAttribute("heading");
272+
273+
this.innerHTML = `
274+
<div class="${styles.container}">
275+
<h1 class="${styles.heading}" role="heading">${heading}</h1>
276+
<div class="${styles.slotted}" role="details">
277+
${this.innerHTML}
278+
</div>
279+
</div>
280+
`;
281+
}
282+
}
283+
284+
customElements.define("app-heading-box", HeadingBox);
285+
```
286+
287+
And then anywhere in our pages we can use it with any custom content:
288+
289+
```md
290+
<app-heading-box heading="Plugins">
291+
<p>Some content about plugins.</p>
292+
</app-heading-box>
293+
```
294+
295+
This would produce the following HTML output:
296+
297+
```html
298+
<app-heading-box heading="Plugins">
299+
<div class="heading-box-1843513151-container">
300+
<h1 class="heading-box-1843513151-heading" role="heading">Plugins</h1>
301+
<div class="heading-box-1843513151-slotted" role="details">
302+
<p>Some content about plugins.</p>
303+
</div>
304+
</div>
305+
</app-heading-box>
306+
```
307+
308+
> There are some known issues and conventions around mixing Web Components and markdown to be aware of that we cover in [this discussion](https://github.com/ProjectEvergreen/greenwood/discussions/1267).

0 commit comments

Comments
 (0)