11// @ts -expect-error
22import isJSON from 'is-json' ;
33import { Attributes , NodeText , NodeTag } from 'posthtml-parser' ;
4- import { closingSingleTagOptionEnum , closingSingleTagTypeEnum , Options , quoteStyleEnum } from '../types/index.d' ;
54
6- type Node = NodeText | NodeTag & {
5+ export enum quoteStyleEnum {
6+ Smart ,
7+ Single ,
8+ Double
9+ }
10+
11+ export enum closingSingleTagOptionEnum {
12+ tag = 'tag' ,
13+ slash = 'slash' ,
14+ default = 'default' ,
15+ closeAs = 'closeAs'
16+ }
17+
18+ export enum closingSingleTagTypeEnum {
19+ tag = 'tag' ,
20+ slash = 'slash' ,
21+ default = 'default'
22+ }
23+
24+ export type Node = NodeText | NodeTag & {
725 closeAs ?: closingSingleTagTypeEnum ;
826} ;
927
28+ export type Options = {
29+ /**
30+ * Custom single tags (selfClosing).
31+ *
32+ * @default []
33+ */
34+ singleTags ?: Array < string | RegExp > ;
35+
36+ /**
37+ * Closing format for single tag.
38+ *
39+ * Formats:
40+ *
41+ * tag: `<br></br>`, slash: `<br />`, default: `<br>`
42+ *
43+ */
44+ closingSingleTag ?: closingSingleTagOptionEnum ;
45+
46+ /**
47+ * If all attributes should be quoted.
48+ * Otherwise attributes will be unquoted when allowed.
49+ *
50+ * @default true
51+ */
52+ quoteAllAttributes ?: boolean ;
53+
54+ /**
55+ * Replaces quotes in attribute values with `"e;`.
56+ *
57+ * @default true
58+ */
59+ replaceQuote ?: boolean ;
60+
61+ /**
62+ * Quote style
63+ *
64+ * 0 - Smart quotes
65+ * <img src="https://example.com/example.png" onload='testFunc("test")'>
66+ * 1 - Single quotes
67+ * <img src='https://example.com/example.png' onload='testFunc("test")'>
68+ * 2 - double quotes
69+ * <img src="https://example.com/example.png" onload="testFunc("test")">
70+ *
71+ * @default 2
72+ */
73+ quoteStyle ?: quoteStyleEnum ;
74+ } ;
75+
1076const SINGLE_TAGS : Array < string | RegExp > = [
1177 'area' ,
1278 'base' ,
@@ -229,4 +295,4 @@ function render(tree?: Node | Node[], options: Options = {}): string {
229295 }
230296}
231297
232- export default render ;
298+ export default render ;
0 commit comments