Skip to content

Commit

Permalink
refine content
Browse files Browse the repository at this point in the history
  • Loading branch information
thescientist13 committed Dec 29, 2024
1 parent 0547162 commit 5314e02
Showing 1 changed file with 53 additions and 1 deletion.
54 changes: 53 additions & 1 deletion src/pages/docs/resources/markdown.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tocHeading: 2

# Markdown

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.
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.

## Plugins

Expand Down Expand Up @@ -179,3 +179,55 @@ author: Project Evergreen

Authored By: ${globalThis.page.data.author}
```

## Web Components

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).

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! ✨

The example below mixes static content and attributes, leveraging our (optional) [CSS Modules plugin](/docs/plugins/css-modules/):

```js
import styles from "./heading-box.module.css";

export default class HeadingBox extends HTMLElement {
connectedCallback() {
const heading = this.getAttribute("heading");

this.innerHTML = `
<div class="${styles.container}">
<h1 class="${styles.heading}" role="heading">${heading}</h1>
<div class="${styles.slotted}" role="details">
${this.innerHTML}
</div>
</div>
`;
}
}

customElements.define("app-heading-box", HeadingBox);
```

And then anywhere in our pages we can use it with any custom content:

```md
<app-heading-box heading="Plugins">
<p>Some content about plugins.</p>
</app-heading-box>
```

This would produce the following HTML output:

```html
<app-heading-box heading="Plugins">
<div class="heading-box-1843513151-container">
<h1 class="heading-box-1843513151-heading" role="heading">Plugins</h1>
<div class="heading-box-1843513151-slotted" role="details">
<p>Some content about plugins.</p>
</div>
</div>
</app-heading-box>
```

> 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 comments on commit 5314e02

Please sign in to comment.