Skip to content

Commit 951d359

Browse files
committed
docs: ✏️ about pug encoding attributes
1 parent d109a89 commit 951d359

File tree

1 file changed

+24
-14
lines changed

1 file changed

+24
-14
lines changed

Diff for: README.md

+24-14
Original file line numberDiff line numberDiff line change
@@ -227,14 +227,14 @@ export default {
227227
228228
```js
229229
// svelte.config.js
230-
const sveltePreprocess = require('svelte-preprocess')
230+
const sveltePreprocess = require('svelte-preprocess');
231231
232232
module.exports = {
233233
preprocess: sveltePreprocess({
234234
// ...svelte-preprocess options
235235
}),
236236
// ...other svelte options
237-
}
237+
};
238238
```
239239
240240
_Tip: this file can be imported in your bundle config instead of having multiple svelte configurations lying around._
@@ -289,15 +289,15 @@ In case you want to manually configure your preprocessing step, `svelte-preproce
289289
- `globalStyle` - transform `<style global>` into global styles.
290290
291291
```js
292-
import { scss, coffeescript, pug, globalStyle } from 'svelte-preprocess'
292+
import { scss, coffeescript, pug, globalStyle } from 'svelte-preprocess';
293293
294-
svelte.preprocess(input, [pug(), coffeescript(), scss(), globalStyle()])
294+
svelte.preprocess(input, [pug(), coffeescript(), scss(), globalStyle()]);
295295
```
296296
297297
Every processor accepts an option object which is passed to its respective underlying tool.
298298
299299
```js
300-
import { scss, postcss } from 'svelte-preprocess'
300+
import { scss, postcss } from 'svelte-preprocess';
301301
302302
svelte.preprocess(input, [
303303
scss(),
@@ -308,7 +308,7 @@ svelte.preprocess(input, [
308308
}),
309309
],
310310
}),
311-
])
311+
]);
312312
```
313313
314314
**Note**: there's no built-in support for \<template\> tag when using standalone processors.
@@ -318,8 +318,8 @@ svelte.preprocess(input, [
318318
`svelte-preprocess` in _auto-processing_ mode can receive an options object.
319319
320320
```js
321-
const svelte = require('svelte')
322-
const sveltePreprocess = require('svelte-preprocess')
321+
const svelte = require('svelte');
322+
const sveltePreprocess = require('svelte-preprocess');
323323
const options = {
324324
/**
325325
* Define which tag should `svelte-preprocess` look for markup content.
@@ -402,18 +402,18 @@ const options = {
402402
403403
/** Use a custom preprocess method by passing a function. */
404404
pug({ content, filename }) {
405-
const code = pug.render(content)
406-
return { code, map: null }
405+
const code = pug.render(content);
406+
return { code, map: null };
407407
},
408408
409409
/** Add a custom language preprocessor */
410410
customLanguage({ content, filename }) {
411-
const { code, map } = require('custom-language-compiler')(content)
412-
return { code, map }
411+
const { code, map } = require('custom-language-compiler')(content);
412+
return { code, map };
413413
},
414-
}
414+
};
415415
416-
svelte.preprocess(input, sveltePreprocess(options))
416+
svelte.preprocess(input, sveltePreprocess(options));
417417
```
418418
419419
## Limitations
@@ -424,6 +424,8 @@ Since `typescript` is not officially supported by `svelte` for its template lang
424424
425425
### `pug`
426426
427+
#### Template blocks
428+
427429
Some of Svelte's template syntax is invalid in `pug`. `svelte-preprocess` provides some pug mixins to represent svelte's `{#...}{/...}` blocks: `+if()`, `+else()`, `+elseif()`, `+each()`, `+await()`, `+then()`, `+catch()`, `+debug()`.
428430
429431
```pug
@@ -436,6 +438,14 @@ ul
436438
span No posts :c
437439
```
438440
441+
#### Element attributes
442+
443+
Pug encodes everything inside an element attribute to html entities, so `attr="{foo && bar}"` becomes `attr="foo &amp;&amp; bar"`. To prevent this from happening, instead of using the `=` operator use `!=` which won't encode your attribute value:
444+
445+
```pug
446+
button(disabled!="{foo && bar}")
447+
```
448+
439449
## FAQ
440450
441451
### My VS Code is displaying a lot of errors on my templates when I try to use `x`...

0 commit comments

Comments
 (0)