UNPKG

8.82 kBMarkdownView Raw
1# Markdown Features in Project Helix
2
3Project Helix uses [GitHub Flavored Markdown](https://github.github.com/gfm/) (GFM) with following extensions:
4
5## Sections
6
7Use the section marker `---` followed and preceeded by a blank line to create a section break. This is a change from GFM, where `---` denotes a [thematic break](https://github.github.com/gfm/#thematic-breaks).
8
9```markdown
10
11This is one section.
12
13---
14
15This is another section.
16
17---
18
19And this is a third section.
20
21```
22
23You can still create thematic breaks in Markdown by using any of the alternative syntaxes:
24
25> A line consisting of 0-3 spaces of indentation, followed by a sequence of three or more matching `_` or `*` characters, each followed optionally by any number of spaces or tabs, forms a thematic break.
26
27## Section Metadata (or Midmatter)
28
29GitHub allows (although not part of the GFM spec) adding metadata to a document by adding a YAML block, enclosed by pairs of `---` to the beginning of the document. This is known as Markdown frontmatter.
30
31```markdown
32---
33key:value
34---
35
36This is my document.
37```
38
39Helix extends this notion by allowing to create YAML blocks at the beginning of a section.
40
41```markdown
42
43This is one section.
44
45---
46key:value
47---
48
49This is another section. It has some meta data.
50
51---
52
53And this is a third section.
54
55```
56
57Because it looks like Markdown "frontmatter", but is allowed in the middle of the document, we call it "midmatter".
58
59## External Embeds
60
61Embedding external content in a Markdown document is supported in Helix Markdown. We support a number of embedding syntaxes that were originally introduced for other software and allow a certain degree of interoperability:
62
63**Note: Helix Pipeline will only process embeds if the URL matches a known whitelist. This is for reasons of security and to guard against accidential embeds.**
64
65
66### IA Writer-Style Embeds
67
68The [IA Writer Markdown editing app](https://ia.net/writer) for desktop and mobile operating systems [introduced a system called content blocks](https://ia.net/writer/support/general/content-blocks) and this embed style is inspired by the system.
69
70An embed is:
71
72- a whitelisted URL
73- in a separate paragraph
74- that's all.
75
76```markdown
77
78https://www.youtube.com/watch?v=KOxbO0EI4MA
79
80```
81
82IA Writer-Style Embeds are the simplest and recommended way of creating embeds.
83
84### Gatsby-Style Embeds
85
86This embed style is also supported by a number of Gatsby-plugins like [gatsby-remark-embed-video](https://github.com/borgfriend/gatsby-remark-embed-video). The implementation in Helix shares no code with these plugins.
87
88An embed is:
89
90- an inline code block
91- in a separate paragraph
92- containing a keyword, a colon `:`, and a whitelisted URL
93
94```markdown
95
96`video: https://www.youtube.com/embed/2Xc9gXyf2G4`
97
98```
99
100In the example above, the keyword is `video`, but any keyword like `embed`, `external`, `link`, `media` is allowed.
101
102### Image-Style Embeds
103
104The only notion Markdown has of external content embedded in the document are images. This embed syntax extends that idea by allowing embeds using the image syntax.
105
106An embed is:
107
108- an image `![]()`
109- with a whitelisted URL
110- in a separate paragraph
111
112```markdown
113
114![](https://www.youtube.com/watch?v=KOxbO0EI4MA)
115
116```
117
118### Link + Image-Style Embeds
119
120The downside of the three embed approaches above is that they do not work on GitHub and don't have a preview. This is solved by Link + Image-Style embeds, albeit at the cost of a more convoluted syntax.
121
122An embed is:
123
124- a link to a whitelisted URL
125- in a separate paragraph
126- with a preview image as the only child
127
128```markdown
129
130[![Audi R8](http://img.youtube.com/vi/KOxbO0EI4MA/0.jpg)](https://www.youtube.com/watch?v=KOxbO0EI4MA "Audi R8")
131
132```
133
134## Internal Embeds
135
136Helix also supports internal embeds, similar to [IA Writer's content blocks](https://ia.net/writer/support/general/content-blocks), with following changes:
137
138- any of the external embed syntaxes are supported, not just IA-Writer-Style embeds
139- whitelisted URLs must be relative and end with `.md` or `.html`
140
141## Data Embeds and Markdown Templates
142
143Helix also supports the embedding of tabular or list data. This is useful for embedding data from external sources such as:
144
145- Google Sheets (not yet supported)
146- Microsoft Excel Online (not yet supported)
147- Google Calendar (not yet supported)
148- RSS Feeds (not yet supported)
149
150Instead of just dumping the data as a Markdown table, Helix will fetch the data, and find placeholders in the current Markdown document (or section, if the document has sections) and fill the placeholders with the data from the data source.
151
152If the data source has more than one entry, e.g. multiple rows in a spreadsheet, multiple events in a calendar, or multiple posts in an RSS feed, then the content of the document (or section) will be replicated for each entry.
153
154Helix maintains a separate whitelist of URLs that indicate embeddable data sources, so any of the embed syntaxes describe above can be used. In the following examples, we will use the IA Writer-style syntax.
155
156### Example
157
158Consider a fictional list of used cars, maintained in a spreadsheet:
159
160| Make | Model | Year | Image | Mileage (from) | Mileage (to) |
161| ------- | ------ | ---- | ----------- | -------------- | ------------ |
162| Nissan | Sunny | 1992 | nissan.jpg | 100000 | 150000 |
163| Renault | Scenic | 2000 | renault.jpg | 75000 | 100000 |
164| Honda | FR-V | 2005 | honda.png | 50000 | 150000 |
165
166This list would be represented as a JSON document like this:
167
168```json
169[
170 {
171 "make": "Nissan",
172 "model": "Sunny",
173 "year": 1992,
174 "image": "nissan.jpg",
175 "mileage": {
176 "from": 100000,
177 "to": 150000
178 }
179 },
180 {
181 "make": "Renault",
182 "model": "Scenic",
183 "year": 2000,
184 "image": "renault.jpg",
185 "mileage": {
186 "from": 75000,
187 "to": 100000
188 }
189 },
190 {
191 "make": "Honda",
192 "model": "FR-V",
193 "year": 2005,
194 "image": "honda.png",
195 "mileage": {
196 "from": 50000,
197 "to": 150000
198 }
199 }
200]
201```
202
203The following examples use the above data.
204
205#### Placeholders
206
207To create a data embed, add an embeddable URL to the document and use placeholders like `{{make}}` or `{{model}}` in the document.
208
209```markdown
210
211
212https://docs.google.com/spreadsheets/d/e/2PACX-1vQ78BeYUV4gFee4bSxjN8u86aV853LGYZlwv1jAUMZFnPn5TnIZteDJwjGr2GNu--zgnpTY1E_KHXcF/pubhtml
213
2141. My car: [![{{make}} {{model}}]({{image}})](cars-{{year}}.md)
215
216```
217
218This will create following HTML (boilerplate omitted):
219
220```html
221<ol>
222 <li>My car:<a href="cars-1992.html"><img src="nissan.jpg" alt="Nissan Sunny"></a></li>
223 <li>My car:<a href="cars-2000.html"><img src="renault.jpg" alt="Renault Scenic"></a></li>
224 <li>My car:<a href="cars-2005.html"><img src="honda.png" alt="Honda FR-V"></a></li>
225</ol>
226```
227
228Each of the placeholders have been replaced with entries from the table above.
229
230#### Dot Notation
231
232If you want to address nested properties (this will only be useful for some data sources), use a dot notation like `{{mileage.from}}`:
233
234```markdown
235
236https://docs.google.com/spreadsheets/d/e/2PACX-1vQ78BeYUV4gFee4bSxjN8u86aV853LGYZlwv1jAUMZFnPn5TnIZteDJwjGr2GNu--zgnpTY1E_KHXcF/pubhtml
237
238# My {{make}} {{model}}
239
240![{{make}} {{model}}]({{image}})
241
242Built in {{year}}. Driven from {{mileage.from}} km to {{mileage.to}} km.
243```
244
245to generate following HTML:
246
247```html
248<h1 id="my-nissan-sunny">My Nissan Sunny</h1>
249<p><img src="nissan.jpg" alt="Nissan Sunny"></p>
250<p>Built in 1992. Driven from 100000 km to 150000 km.</p>
251
252<h1 id="my-renault-scenic">My Renault Scenic</h1>
253<p><img src="renault.jpg" alt="Renault Scenic"></p>
254<p>Built in 2000. Driven from 75000 km to 100000 km.</p>
255
256<h1 id="my-honda-fr-v">My Honda FR-V</h1>
257<p><img src="honda.png" alt="Honda FR-V"></p>
258<p>Built in 2005. Driven from 50000 km to 150000 km.</p>
259```
260
261#### Sections
262
263If you have content that you don't want to see repeated for each data element, break it out in separate sections like this:
264
265```markdown
266
267## My Cars
268
269---
270
271https://docs.google.com/spreadsheets/d/e/2PACX-1vQ78BeYUV4gFee4bSxjN8u86aV853LGYZlwv1jAUMZFnPn5TnIZteDJwjGr2GNu--zgnpTY1E_KHXcF/pubhtml
272
273- [![{{make}} {{model}}]({{image}})](cars-{{year}}.md)
274
275```
276
277The first section, containing the "My Cars" headline won't be repeated in the generated HTML:
278
279```html
280<div>
281 <h2 id="my-cars">My Cars</h2>
282</div>
283<div>
284 <ul>
285 <li><a href="cars-1992.html"><img src="nissan.jpg" alt="Nissan Sunny"></a></li>
286 <li><a href="cars-2000.html"><img src="renault.jpg" alt="Renault Scenic"></a></li>
287 <li><a href="cars-2005.html"><img src="honda.png" alt="Honda FR-V"></a></li>
288 </ul>
289</div>
290```
291
292# Notes for Developers
293
294The new node types are documented in the [MDAST schema documentation](mdast.md). The types mentioned in this document are:
295
296- `section`
297- `embed`
298- `dataEmbed`
299