Skip to content

Commit 2b3a3cc

Browse files
docs(readme): fix server options
1 parent 5f7d786 commit 2b3a3cc

1 file changed

Lines changed: 51 additions & 23 deletions

File tree

README.md

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,62 @@ The client parser mimics the server parser by using the [DOM](https://developer.
171171

172172
## Options (server only)
173173

174-
Because the server parser is a wrapper of [htmlparser2](https://github.com/fb55/htmlparser2), which implements [domhandler](https://github.com/fb55/domhandler), you can alter how the server parser parses your code with the following options:
174+
Because the server parser is a wrapper of [htmlparser2](https://github.com/fb55/htmlparser2), which implements [domhandler](https://github.com/fb55/domhandler), you can alter how the server parser parses your code with the options:
175175

176-
```js
177-
/**
178-
* These are the default options being used if you omit the optional options object.
179-
* htmlparser2 will use the same options object for its domhandler so the options
180-
* should be combined into a single object like so:
181-
*/
182-
const options = {
176+
```ts
177+
export interface ParserOptions {
183178
/**
184-
* Options for the domhandler class.
185-
* https://github.com/fb55/domhandler/blob/master/src/index.ts#L16
179+
* Indicates whether special tags (`<script>`, `<style>`, and `<title>`) should get special treatment
180+
* and if "empty" tags (eg. `<br>`) can have children. If `false`, the content of special tags
181+
* will be text only. For feeds and other XML content (documents that don't consist of HTML),
182+
* set this to `true`.
183+
*
184+
* @default false
186185
*/
187-
withStartIndices: false,
188-
withEndIndices: false,
189-
xmlMode: false,
186+
xmlMode?: boolean;
187+
188+
/**
189+
* Decode entities within the document.
190+
*
191+
* @default true
192+
*/
193+
decodeEntities?: boolean;
194+
195+
/**
196+
* If set to true, all tags will be lowercased.
197+
*
198+
* @default !xmlMode
199+
*/
200+
lowerCaseTags?: boolean;
201+
202+
/**
203+
* If set to `true`, all attribute names will be lowercased. This has noticeable impact on speed.
204+
*
205+
* @default !xmlMode
206+
*/
207+
lowerCaseAttributeNames?: boolean;
208+
209+
/**
210+
* If set to true, CDATA sections will be recognized as text even if the xmlMode option is not enabled.
211+
* NOTE: If xmlMode is set to `true` then CDATA sections will always be recognized as text.
212+
*
213+
* @default xmlMode
214+
*/
215+
recognizeCDATA?: boolean;
216+
217+
/**
218+
* If set to `true`, self-closing tags will trigger the onclosetag event even if xmlMode is not set to `true`.
219+
* NOTE: If xmlMode is set to `true` then self-closing tags will always be recognized.
220+
*
221+
* @default xmlMode
222+
*/
223+
recognizeSelfClosing?: boolean;
224+
190225
/**
191-
* Options for the htmlparser2 class.
192-
* https://github.com/fb55/htmlparser2/blob/master/src/Parser.ts#L104
226+
* Allows the default tokenizer to be overwritten.
193227
*/
194-
xmlMode: false, // Will overwrite what is used for the domhandler, otherwise inherited.
195-
decodeEntities: true,
196-
lowerCaseTags: true, // !xmlMode by default
197-
lowerCaseAttributeNames: true, // !xmlMode by default
198-
recognizeCDATA: false, // xmlMode by default
199-
recognizeSelfClosing: false, // xmlMode by default
200-
Tokenizer: Tokenizer,
201-
};
228+
Tokenizer?: typeof Tokenizer;
229+
}
202230
```
203231

204232
If you're parsing SVG, you can set `lowerCaseTags` to `true` without having to enable `xmlMode`. This will return all tag names in camelCase and not the HTML standard of lowercase.

0 commit comments

Comments
 (0)