Skip to content

Commit 59f7eca

Browse files
committed
[docs] refactor api docs syntax highlighting
1 parent b91872b commit 59f7eca

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

site/src/api.njk

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -119,40 +119,40 @@ By default, calls to `prefetch()` are low priority.
119119

120120
* Includes a very small fallback for [requestIdleCallback](https://developer.mozilla.org/en-US/docs/Web/API/Window/requestIdleCallback)
121121
* Requires `IntersectionObserver` to be supported (see [CanIUse](https://caniuse.com/#feat=intersectionobserver)). We recommend conditionally polyfilling this feature with a service like Polyfill.io:
122-
123-
```html
122+
{% endmarkdownConvert %}
123+
{% highlight "html" %}
124124
<script src="https://polyfill.io/v3/polyfill.min.js?features=IntersectionObserver"></script>
125-
```
126-
125+
{% endhighlight %}
126+
{% markdownConvert %}
127127
Alternatively, see the [Intersection Observer polyfill](https://github.com/w3c/IntersectionObserver/tree/master/polyfill).
128128

129129
## Recipes
130130

131131
### Set a custom timeout for prefetching resources
132132

133133
Defaults to 2 seconds (via `requestIdleCallback`). Here we override it to 4 seconds:
134-
135-
```js
134+
{% endmarkdownConvert %}
135+
{% highlight "js" %}
136136
quicklink.listen({
137137
timeout: 4000
138138
});
139-
```
140-
139+
{% endhighlight %}
140+
{% markdownConvert %}
141141
### Set the DOM element to observe for in-viewport links
142142

143143
Defaults to `document` otherwise.
144-
145-
```js
144+
{% endmarkdownConvert %}
145+
{% highlight "js" %}
146146
quicklink.listen({
147147
el: document.getElementById('carousel')
148148
});
149-
```
150-
149+
{% endhighlight %}
150+
{% markdownConvert %}
151151
### Programmatically `prefetch()` URLs
152152

153153
If you would prefer to provide a static list of URLs to be prefetched, instead of detecting those in-viewport, customizing URLs is supported.
154-
155-
```js
154+
{% endmarkdownConvert %}
155+
{% highlight "js" %}
156156
// Single URL
157157
quicklink.prefetch('2.html');
158158

@@ -162,25 +162,25 @@ quicklink.prefetch(['2.html', '3.html', '4.js']);
162162
// Multiple URLs, with high priority
163163
// Note: Can also be use with single URL!
164164
quicklink.prefetch(['2.html', '3.html', '4.js'], true);
165-
```
166-
165+
{% endhighlight %}
166+
{% markdownConvert %}
167167
### Set the request priority for prefetches while scrolling
168168

169169
Defaults to low-priority (`rel=prefetch` or XHR). For high-priority (`priority: true`), attempts to use `fetch()` or falls back to XHR.
170170

171171
> **Note:** This runs `prefetch(..., true)` with URLs found within the `options.el` container.
172-
173-
```js
172+
{% endmarkdownConvert %}
173+
{% highlight "js" %}
174174
quicklink.listen({ priority: true });
175-
```
176-
175+
{% endhighlight %}
176+
{% markdownConvert %}
177177
### Specify a custom list of allowed origins
178178

179179
Provide a list of hostnames that should be prefetch-able. Only the same origin is allowed by default.
180180

181181
> **Important:** You must also include your own hostname!
182-
183-
```js
182+
{% endmarkdownConvert %}
183+
{% highlight "js" %}
184184
quicklink.listen({
185185
origins: [
186186
// add mine
@@ -192,27 +192,27 @@ quicklink.listen({
192192
// ...
193193
]
194194
});
195-
```
196-
195+
{% endhighlight %}
196+
{% markdownConvert %}
197197
### Allow all origins
198198

199199
Enables all cross-origin requests to be made.
200200

201201
> **Note:** You may run into [CORB](https://chromium.googlesource.com/chromium/src/+/master/services/network/cross_origin_read_blocking_explainer.md) and [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) issues!
202-
203-
```js
202+
{% endmarkdownConvert %}
203+
{% highlight "js" %}
204204
quicklink.listen({
205205
origins: true,
206206
// or
207207
origins: []
208208
});
209-
```
210-
209+
{% endhighlight %}
210+
{% markdownConvert %}
211211
### Custom Ignore Patterns
212212

213213
These filters run _after_ the `origins` matching has run. Ignores can be useful for avoiding large file downloads or for responding to DOM attributes dynamically.
214-
215-
```js
214+
{% endmarkdownConvert %}
215+
{% highlight "js" %}
216216
// Same-origin restraint is enabled by default.
217217
//
218218
// This example will ignore all requests to:
@@ -227,21 +227,23 @@ quicklink.listen({
227227
(uri, elem) => elem.hasAttribute('noprefetch')
228228
]
229229
});
230-
```
231-
230+
{% endhighlight %}
231+
{% markdownConvert %}
232232
You may also wish to ignore prefetches to URLs which contain a URL fragment (e.g. `index.html#top`). This can be useful if you (1) are using anchors to headings in a page or (2) have URL fragments setup for a single-page application, and which to avoid firing prefetches for similar URLs.
233233

234234
Using `ignores` this can be achieved as follows:
235235

236-
```js
236+
{% endmarkdownConvert %}
237+
{% highlight "js" %}
237238
quicklink.listen({
238239
ignores: [
239240
uri => uri.includes('#')
240241
// or RegExp: /#(.+)/
241242
// or element matching: (uri, elem) => !!elem.hash
242243
]
243244
});
244-
```
245+
{% endhighlight %}
246+
{% markdownConvert %}
245247

246248
## Browser Support
247249

@@ -262,15 +264,14 @@ A `prefetch` method can be individually imported for use in other projects.<br>
262264
This method includes the logic to respect Data Saver and 2G connections. It also issues requests thru `fetch()`, XHRs, or `link[rel=prefetch]` depending on (a) the `isPriority` value and (b) the current browser's support.
263265

264266
After installing `quicklink` as a dependency, you can use it as follows:
265-
266-
```html
267+
{% endmarkdownConvert %}
268+
{% highlight "html" %}
267269
<script type="module">
268270
import { prefetch } from 'quicklink';
269271
prefetch(['1.html', '2.html']).catch(err => {
270272
// Handle own errors
271273
});
272274
</script>
273-
```
275+
{% endhighlight %}
274276

275-
{% endmarkdownConvert %}
276277
{% endblock %}

0 commit comments

Comments
 (0)