(http://www.starptech.de)",
26 | "license": "MIT",
27 | "bugs": {
28 | "url": "https://github.com/StarpTech/prettyhtml/issues"
29 | },
30 | "homepage": "https://github.com/StarpTech/prettyhtml#readme",
31 | "dependencies": {
32 | "@starptech/expression-parser": "^0.10.0",
33 | "@starptech/prettyhtml-hast-to-html": "^0.10.0",
34 | "@starptech/rehype-minify-whitespace": "^0.10.0",
35 | "@starptech/rehype-webparser": "^0.10.0",
36 | "@starptech/webparser": "^0.10.0",
37 | "hast-util-is-element": "^1.0.3",
38 | "hast-util-to-string": "^1.0.2",
39 | "html-void-elements": "^1.0.4",
40 | "html-whitespace-sensitive-tag-names": "^1.0.1",
41 | "is-hidden": "^1.1.2",
42 | "prettier": "^1.18.2",
43 | "repeat-string": "^1.6.1",
44 | "to-vfile": "^6.0.0",
45 | "unified": "^7.1.0",
46 | "unist-util-find": "^1.0.1",
47 | "unist-util-is": "^2.1.3",
48 | "unist-util-visit-parents": "^2.1.2",
49 | "xtend": "^4.0.1"
50 | },
51 | "devDependencies": {
52 | "ava": "^2.1.0",
53 | "bail": "^1.0.4",
54 | "is-hidden": "^1.1.2",
55 | "negate": "^1.0.0",
56 | "nyc": "^14.1.1",
57 | "rehype": "^8.0.0",
58 | "to-vfile": "^6.0.0"
59 | },
60 | "nyc": {
61 | "check-coverage": true,
62 | "lines": 90,
63 | "functions": 90,
64 | "branches": 85
65 | },
66 | "publishConfig": {
67 | "access": "public"
68 | },
69 | "gitHead": "c7bfe5fdd9ef240ddf235e50a81be52b30828c8f"
70 | }
71 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/stringify.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const xtend = require('xtend')
4 | const toHTML = require('@starptech/prettyhtml-hast-to-html')
5 |
6 | module.exports = stringify
7 |
8 | function stringify(config) {
9 | const settings = xtend(config, this.data('settings'))
10 |
11 | this.Compiler = compiler
12 |
13 | function compiler(tree) {
14 | return toHTML(tree, settings)
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-boolean/input.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 | This is valid.
3 | This is valid.
4 | This is valid.
5 | This is valid. This will be disabled.
6 | This is valid. This will be disabled.
7 | This is valid. This will be disabled.
8 | This is valid. This will be disabled.
9 | This is valid. This will be disabled.
10 | This is valid. This will be disabled.
11 | This is valid. This will be disabled.
12 | This is valid. This will be disabled.
13 | This is valid. This will be disabled.
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-boolean/output.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 | This is valid.
3 | This is valid.
4 | This is valid.
5 | This is valid. This will be disabled.
6 | This is valid. This will be disabled.
7 | This is valid. This will be disabled.
8 | This is valid. This will be disabled.
9 | This is valid. This will be disabled.
10 | This is valid. This will be disabled.
11 | This is valid. This will be disabled.
12 | This is valid. This will be disabled.
13 | This is valid. This will be disabled.
14 |
15 |
16 |
17 |
18 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-casesensitive/input.html:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-casesensitive/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-character-references/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-character-references/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-encoding/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | help
6 |
7 | Special
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-encoding/output.html:
--------------------------------------------------------------------------------
1 |
7 |
8 |
9 |
10 | help
11 |
14 | Special
15 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-known-incasesensitive/input.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-known-incasesensitive/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-no-quotes/input.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-no-quotes/output.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-quoting/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-quoting/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-single-quotes/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "singleQuote": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-single-quotes/input.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 | This is valid.
3 | This is valid.
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/attribute-single-quotes/output.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 | This is valid.
3 | This is valid.
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/auto-close-tags/input.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/auto-close-tags/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/camelCase-tags/input.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/camelCase-tags/output.html:
--------------------------------------------------------------------------------
1 | This is valid.
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/case-sensitive-void-elements/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/case-sensitive-void-elements/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/comments-conditional/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
foo
11 |
12 |
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/comments-conditional/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
foo
11 |
12 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/comments-elements/input.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/comments-elements/output.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/comments/input.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 | foo
12 |
13 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/comments/output.html:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 | foo
14 |
15 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/custom-void-elements/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/custom-void-elements/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/doctype/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/doctype/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/entity-encoding/input.html:
--------------------------------------------------------------------------------
1 | &
2 | foo > bar
3 | foo < bar
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/entity-encoding/output.html:
--------------------------------------------------------------------------------
1 | &
2 | foo > bar
3 | foo < bar
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/example/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 | {{ item.label }}
8 |
11 |
12 | {{ item.label }}
13 |
14 |
15 |
16 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/example/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
12 | {{ item.label }}
13 |
17 |
18 | {{ item.label }}
23 |
24 |
25 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/force-attribute-wrapping/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "wrapAttributes": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/force-attribute-wrapping/input.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/force-attribute-wrapping/output.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/gaps-preservation/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 | Content
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/gaps-preservation/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/html5-boilerplate/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
22 |
23 |
24 | Hello world! This is HTML5 Boilerplate.
25 |
26 |
27 |
28 |
29 |
30 |
31 |
39 |
40 |
41 |
45 |
46 |
47 |
48 |
49 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/html5-boilerplate/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
25 |
26 |
27 |
28 | Hello world! This is HTML5 Boilerplate.
29 |
30 |
35 |
39 |
40 |
41 |
42 |
50 |
51 |
52 |
61 |
62 |
63 |
64 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/ignore-flag/input.html:
--------------------------------------------------------------------------------
1 |
2 | Check me out
3 | Check me out
4 |
5 |
9 |
13 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/ignore-flag/output.html:
--------------------------------------------------------------------------------
1 |
2 | Check me out
3 |
4 |
5 | Check me out
6 |
7 |
8 |
9 |
13 |
20 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/image-tag/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | foo
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/image-tag/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | foo
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-default/input.html:
--------------------------------------------------------------------------------
1 | Foo
2 | bar
3 |
4 | Foo
5 | bar
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-default/output.html:
--------------------------------------------------------------------------------
1 |
2 | Foo
3 | bar
4 |
5 |
6 | Foo
7 | bar
8 |
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-initial-default/input.html:
--------------------------------------------------------------------------------
1 |
4 |
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-initial-default/output.html:
--------------------------------------------------------------------------------
1 |
4 |
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-initial-false/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "indentInitial": false
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-initial-false/input.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-initial-false/output.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-multiline-text/input.html:
--------------------------------------------------------------------------------
1 |
2 | my text
3 | on multiple
4 | lines
5 |
6 |
7 | my text
8 | on multiple
9 | lines
10 | fooBar
11 |
12 |
13 | my text
14 | on multiple
15 | lines
16 |
17 |
18 | my text
19 | on multiple
20 | lines
21 | dedwedwed
22 | dwedwedwe
23 |
24 |
25 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-multiline-text/output.html:
--------------------------------------------------------------------------------
1 |
2 | my text
3 | on multiple
4 | lines
5 |
6 |
7 | my text
8 | on multiple
9 | lines
10 | fooBar
11 |
12 |
13 | my text
14 | on multiple
15 | lines
16 |
17 |
18 |
19 | my text
20 | on multiple
21 | lines
22 |
23 | dedwedwed
24 | dwedwedwe
25 |
26 |
27 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-number/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "tabWidth": 4
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-number/input.html:
--------------------------------------------------------------------------------
1 | Foo
2 | bar
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-number/output.html:
--------------------------------------------------------------------------------
1 |
2 | Foo
3 | bar
4 |
5 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-tabs/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "useTabs": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-tabs/input.html:
--------------------------------------------------------------------------------
1 | Foo
2 | bar
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/indent-tabs/output.html:
--------------------------------------------------------------------------------
1 |
2 | Foo
3 | bar
4 |
5 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/issue-65-white-space/input.html:
--------------------------------------------------------------------------------
1 | I am writing to tell you that I am extremely excited about this new HTML formatter. It promises to be as far as I can tell both flexible and resilient in the face of many new ways of writing HTML
2 |
3 | Check me out
4 |
5 |
6 |
7 | I am writing to tell you that I am
8 | extremely excited about this new
9 | HTML formatter. It promises to be
10 | as far as I can tell both
11 | flexible and
12 | resilient in the face of many new ways of writing
13 | HTML
14 |
15 |
16 | Check me out
17 |
18 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/issue-65-white-space/output.html:
--------------------------------------------------------------------------------
1 |
2 | I am writing to tell you that I am
3 | extremely excited about this new
4 | HTML formatter. It promises to be
5 | as far as I can tell both
6 | flexible and
7 | resilient in the face of many new ways of writing
8 | HTML
9 |
10 |
11 | Check me out
12 |
13 |
14 |
15 |
16 | I am writing to tell you that I am
17 | extremely excited about this new
18 | HTML formatter. It promises to be
19 | as far as I can tell both
20 | flexible and
21 | resilient in the face of many new ways of writing
22 | HTML
23 |
24 |
25 | Check me out
26 |
27 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/issue-74-white-space/input.html:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/issue-74-white-space/output.html:
--------------------------------------------------------------------------------
1 |
12 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/issue-79-gaps-preservation/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/issue-79-gaps-preservation/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
10 |
11 |
12 |
13 |
14 |
19 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/mixed-documents/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Document 1
5 |
6 |
7 | foo1
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Document 2
16 |
17 |
18 | foo2
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/mixed-documents/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Document 1
5 |
6 |
7 |
8 | foo1
9 |
10 |
11 |
12 |
13 |
14 |
15 | Document 2
16 |
17 |
18 |
19 | foo2
20 |
21 |
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/nested-templates/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{getChipString(data.item)}} {{data.item.name}}
5 |
6 | {{getChipString(data.item)}} {{data.item.name}}
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/nested-templates/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | {{getChipString(data.item)}}
5 | {{data.item.name}}
6 |
7 |
8 | {{getChipString(data.item)}}
9 | {{data.item.name}}
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/parent-insertion/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
11 |
12 |
13 |
14 |
15 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/parent-insertion/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-attribute-wrapping-flag/input.html:
--------------------------------------------------------------------------------
1 |
2 | Check me out
3 | Check me out
4 |
5 |
9 |
16 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-attribute-wrapping-flag/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Check me out
5 |
6 |
7 |
16 |
17 | Check me out
18 |
19 |
20 |
21 |
22 |
24 | First
25 |
27 | Second
28 |
30 |
31 |
47 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-boolean-attributes/input.html:
--------------------------------------------------------------------------------
1 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-boolean-attributes/output.html:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-explicit-namespace/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-explicit-namespace/output.html:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-whitespace-flag/input.html:
--------------------------------------------------------------------------------
1 |
2 | Check me out
3 | foo
4 |
5 |
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/preserve-whitespace-flag/output.html:
--------------------------------------------------------------------------------
1 |
2 | Check me out
3 | foo
4 |
5 |
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/prettier-embedded/input.html:
--------------------------------------------------------------------------------
1 |
5 |
6 |
16 |
25 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/prettier-embedded/output.html:
--------------------------------------------------------------------------------
1 |
10 |
11 |
21 |
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-custom/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "printWidth": 120
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-custom/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-custom/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-nested-tabs/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "useTabs": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-nested-tabs/input.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-nested-tabs/output.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-nested/input.html:
--------------------------------------------------------------------------------
1 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-nested/output.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-self-closing/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-self-closing/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-tabs/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "useTabs": true
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-tabs/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-tabs/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-void/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-void/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-with-inner-text/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
7 |
8 |
12 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width-with-inner-text/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
7 |
8 |
12 |
13 |
17 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/print-width/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/script-nested/input.html:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/script-nested/output.html:
--------------------------------------------------------------------------------
1 |
2 |
10 |
11 |
21 |
22 |
38 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/script-no-prettier/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "usePrettier": false
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/script-no-prettier/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
11 |
12 |
13 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/script-no-prettier/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/self-closing-elements/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/self-closing-elements/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/soft-table-handling/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Month
5 | Savings
6 |
7 |
8 |
9 |
10 | Council budgets (in £) 2018
11 |
12 |
13 |
14 | Items
15 | Yorkshire
16 | Lancashire
17 |
18 |
19 |
20 |
21 |
22 |
23 | Donuts
24 | 3,000
25 | 5,000
26 |
27 |
28 | Stationary
29 | 18,000
30 | 17,000
31 |
32 |
33 |
34 |
35 |
36 |
37 | Totals
38 | 21,000
39 | 22,000
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/soft-table-handling/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Month
5 | Savings
6 |
7 |
8 |
9 |
10 | Council budgets (in £) 2018
11 |
12 |
13 |
14 | Items
15 | Yorkshire
16 | Lancashire
17 |
18 |
19 |
20 |
21 |
22 |
23 | Donuts
24 | 3,000
25 | 5,000
26 |
27 |
28 | Stationary
29 | 18,000
30 | 17,000
31 |
32 |
33 |
34 |
35 |
36 |
37 | Totals
38 | 21,000
39 | 22,000
40 |
41 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/structural-directives-angular/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | 404
4 |
5 | the {{ resource }} was
6 |
7 | not found
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/structural-directives-angular/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | 404
4 | the {{ resource }} was
5 | not found
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/structural-directives-vue/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | 404
4 |
5 | the {{ resource }} was
6 |
7 | not found
8 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/structural-directives-vue/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 | 404
4 | the {{ resource }} was
5 | not found
6 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style-different-type/input.html:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style-different-type/output.html:
--------------------------------------------------------------------------------
1 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style-no-prettier/config.json:
--------------------------------------------------------------------------------
1 | {
2 | "usePrettier": false
3 | }
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style-no-prettier/input.html:
--------------------------------------------------------------------------------
1 |
3 |
11 |
19 |
20 |
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style-no-prettier/output.html:
--------------------------------------------------------------------------------
1 |
2 |
10 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style/input.html:
--------------------------------------------------------------------------------
1 |
3 |
9 |
10 |
12 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/style/output.html:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/table-foster-parenting/input.html:
--------------------------------------------------------------------------------
1 |
5 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/table-foster-parenting/output.html:
--------------------------------------------------------------------------------
1 |
7 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/tag-casesensitive/input.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/tag-casesensitive/output.html:
--------------------------------------------------------------------------------
1 | foo
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/template-expressions-angular/input.html:
--------------------------------------------------------------------------------
1 |
2 | {{ message | translate }}
3 | Hello world
4 | {{ title }}
5 | foo bar
6 | {{ name }} {{ footer }}
7 |
8 |
9 | {{ message | translate }}Hello world {{ title }}{{ name }} {{ footer }}
10 |
11 | {{
12 | name
13 | }}
14 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/template-expressions-angular/output.html:
--------------------------------------------------------------------------------
1 |
2 | {{ message | translate }}
3 | Hello world
4 | {{ title }}
5 | foo bar
6 | {{ name }}
7 | {{ footer }}
8 |
9 |
10 |
11 | {{ message | translate }}
12 | Hello world
13 | {{ title }}
14 | {{ name }}
15 | {{ footer }}
16 |
17 |
18 |
19 | {{
20 | name
21 | }}
22 |
23 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/template-expressions-svelte/input.html:
--------------------------------------------------------------------------------
1 | Cats of YouTube
2 |
3 |
4 | {#each cats as cat}
5 | {cat.name}
6 | {/each}
7 |
8 |
9 |
10 | {#each rows as row, y}
11 |
12 | {#each columns as column, x}
13 |
14 | {x + 1},{y + 1}:
15 | {row[column]}
16 |
17 | {/each}
18 |
19 | {/each}
20 |
21 |
22 | {
23 | y + 1
24 | }
25 |
26 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/template-expressions-svelte/output.html:
--------------------------------------------------------------------------------
1 | Cats of YouTube
2 |
3 |
4 | {#each cats as cat}
5 |
6 | {cat.name}
7 |
8 | {/each}
9 |
10 |
11 |
12 | {#each rows as row, y}
13 |
14 | {#each columns as column, x}
15 |
16 | {x + 1},{y + 1}:
17 | {row[column]}
18 |
19 | {/each}
20 |
21 | {/each}
22 |
23 |
24 | {
25 | y + 1
26 | }
27 |
28 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/template-expressions-vue/input.html:
--------------------------------------------------------------------------------
1 |
2 | {{ message.split('').reverse().join('') }}
3 | Hello world
4 | {{ ok ? 'YES' : 'NO' }}
5 | foo bar
6 | {{ name }}
7 | {{ footer }}
8 |
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/template-expressions-vue/output.html:
--------------------------------------------------------------------------------
1 |
2 | {{ message.split('').reverse().join('') }}
3 | Hello world
4 | {{ ok ? 'YES' : 'NO' }}
5 | foo bar
6 | {{ name }}
7 | {{ footer }}
8 |
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/void/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/void/output.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/vue/input.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
15 |
16 |
17 |
18 |
19 |
20 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/vue/output.html:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
14 |
15 |
16 |
17 |
18 |
25 |
26 |
27 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/white-space-void/input.html:
--------------------------------------------------------------------------------
1 | Some code
, emphasis , and more importance
2 | .
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/white-space-void/output.html:
--------------------------------------------------------------------------------
1 |
2 | Some
3 | code
,
4 | emphasis , and
5 | more
6 | importance
7 | .
8 |
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/white-space/input.html:
--------------------------------------------------------------------------------
1 | Some code
, emphasis , and importance
2 | .
3 |
4 |
5 | Lorem ipsum dolor sit amet,
6 | consectetur adipisicing elit,
7 | sed do eiusmod tempor incididunt
8 | ut labore et dolore magna aliqua.
9 | Ut enim ad minim veniam, quis
10 | nostrud exercitation ullamco
11 | laboris nisi ut aliquip ex ea
12 | commodo consequat. Duis aute
13 | irure dolor in reprehenderit in
14 | voluptate velit esse cillum dolore
15 | eu fugiat nulla pariatur.
16 | Lorem ipsum dolor sit amet,
17 | consectetur adipisicing elit,
18 | sed do eiusmod tempor incididunt
19 | ut labore et dolore magna aliqua.
20 | Ut enim ad minim veniam, quis
21 | nostrud exercitation ullamco
22 | laboris nisi ut aliquip ex ea
23 | commodo consequat. Duis aute
24 | irure dolor in reprehenderit in
25 | voluptate velit esse cillum dolore
26 | eu fugiat nulla pariatur.
27 |
28 |
29 |
30 |
31 | foo
32 |
33 |
34 | bar
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 | hello there!
45 | this is great
46 |
47 |
48 |
49 |
50 | foo
51 |
52 |
53 | bar
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/white-space/output.html:
--------------------------------------------------------------------------------
1 |
2 | Some
3 | code
,
4 | emphasis , and
5 |
6 | importance
7 | .
8 |
9 |
10 |
11 | Lorem ipsum dolor sit amet,
12 | consectetur adipisicing elit,
13 | sed do eiusmod tempor incididunt
14 | ut labore et dolore magna aliqua.
15 | Ut enim ad minim veniam, quis
16 | nostrud exercitation ullamco
17 | laboris nisi ut aliquip ex ea
18 | commodo consequat. Duis aute
19 | irure dolor in reprehenderit in
20 | voluptate velit esse cillum dolore
21 | eu fugiat nulla pariatur.
22 | Lorem ipsum dolor sit amet,
23 | consectetur adipisicing elit,
24 | sed do eiusmod tempor incididunt
25 | ut labore et dolore magna aliqua.
26 | Ut enim ad minim veniam, quis
27 | nostrud exercitation ullamco
28 | laboris nisi ut aliquip ex ea
29 | commodo consequat. Duis aute
30 | irure dolor in reprehenderit in
31 | voluptate velit esse cillum dolore
32 | eu fugiat nulla pariatur.
33 |
34 |
35 |
36 |
37 | foo
38 |
39 |
40 | bar
41 |
42 |
43 |
44 |
45 |
46 |
47 | hello there!
48 | this is great
49 |
50 |
51 |
52 |
53 |
54 |
55 | foo
56 |
57 |
58 | bar
59 |
60 |
61 |
62 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/whitespace-leading-text/input.html:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
7 | Some code
,
8 | emphasis , and
9 |
10 | importance
11 | .
12 |
13 |
14 | Some
15 | code
,
16 | emphasis , and
17 |
18 | importance
19 | .
20 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/fixtures/whitespace-leading-text/output.html:
--------------------------------------------------------------------------------
1 |
2 |
9 |
10 |
11 |
12 | Some
13 | code
,
14 | emphasis , and
15 |
16 | importance
17 | .
18 |
19 |
20 |
21 | Some
22 | code
,
23 | emphasis , and
24 |
25 | importance
26 | .
27 |
28 |
--------------------------------------------------------------------------------
/packages/prettyhtml-formatter/test/index.js:
--------------------------------------------------------------------------------
1 | /* eslint-disable import/no-extraneous-dependencies */
2 |
3 | 'use strict'
4 |
5 | const fs = require('fs')
6 | const path = require('path')
7 | const test = require('ava')
8 | const vfile = require('to-vfile')
9 | const hidden = require('is-hidden')
10 | const negate = require('negate')
11 |
12 | const unified = require('unified')
13 | const parse = require('@starptech/rehype-webparser')
14 | const stringify = require('../stringify')
15 | const format = require('..')
16 |
17 | const root = path.join(__dirname, 'fixtures')
18 |
19 | fs.readdirSync(root)
20 | .filter(negate(hidden))
21 | .forEach(each)
22 |
23 | function each(fixture) {
24 | test.cb(fixture, function eachFixture(t) {
25 | const base = path.join(root, fixture)
26 | const opts = {
27 | base,
28 | input: vfile.readSync(path.join(base, 'input.html')),
29 | output: vfile.readSync(path.join(base, 'output.html'))
30 | }
31 |
32 | t.plan(3)
33 |
34 | check(t, fixture, opts)
35 | })
36 | }
37 |
38 | function check(t, fixture, options) {
39 | let config
40 |
41 | try {
42 | config = JSON.parse(fs.readFileSync(path.join(options.base, 'config.json')))
43 | // eslint-disable-next-line no-empty
44 | } catch (err) {}
45 |
46 | const proc = unified()
47 | .use(parse, {
48 | ignoreFirstLf: false,
49 | decodeEntities: false,
50 | selfClosingCustomElements: true,
51 | selfClosingElements: true
52 | })
53 | .use(format, config)
54 | .use(
55 | stringify,
56 | Object.assign(
57 | {
58 | closeSelfClosing: true,
59 | closeEmptyElements: true
60 | },
61 | config
62 | )
63 | )
64 |
65 | proc.process(options.input, function process(err /* ,vFile */) {
66 | t.falsy(err, 'shouldn’t throw')
67 | t.is(options.input.messages.length, 0, 'shouldn’t warn')
68 | t.is(String(options.input), String(options.output), 'should match')
69 | // fs.writeFileSync(path.join(options.base, 'output.html'), vFile.contents)
70 | t.end()
71 | })
72 | }
73 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dustin Deus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/prettyhtml-hast-to-html
2 |
3 | [**Hast**](https://github.com/syntax-tree/hast) to HTML converter
4 |
5 | ## Installation
6 |
7 | ```
8 | npm install --save @starptech/prettyhtml-hast-to-html
9 | ```
10 |
11 | ## Api
12 |
13 | ###### `node.data.ignore`
14 |
15 | When this property `true` the node is skipped for attribute collapsing.
16 |
17 | ###### `node.data.preserveAttrWrapping`
18 |
19 | When this property `true` the node is skipped for attribute collapsing.
20 |
21 | ## Caveats
22 |
23 | The implementation is a modified version of [hast-util-to-html](https://github.com/syntax-tree/hast-util-to-html).
24 |
25 | - Known html attributes aren't handled case-sensitively
26 | - Consider `printWidth`
27 | - Don't encode attribute values
28 | - Don't escape special characters in text
29 | - Don't omit value behind boolean attributes
30 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | module.exports = require('./lib')
3 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/all.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var one = require('./one')
4 | var sensitive = require('html-whitespace-sensitive-tag-names')
5 |
6 | module.exports = all
7 |
8 | /* Stringify all children of `parent`. */
9 | function all(ctx, parent) {
10 | var children = parent && parent.children
11 | var length = children && children.length
12 | var index = -1
13 | var results = []
14 |
15 | let printWidthOffset = 0
16 | let innerTextLength = 0
17 | while (++index < length) {
18 | innerTextLength = getInnerTextLength(children[index])
19 | results[index] = one(ctx, children[index], index, parent, printWidthOffset, innerTextLength)
20 | printWidthOffset = results[index].replace(/\n+/g, '').length
21 | }
22 |
23 | return results.join('')
24 | }
25 |
26 | /**
27 | * Returns the text lenght of the first line of the first child.
28 | * Whitespace sensitive elements are ignored.
29 | * @param {*} node
30 | */
31 | function getInnerTextLength(node) {
32 | // ignore style, script, pre, textarea elements
33 | if (sensitive.indexOf(node.tagName) !== -1) {
34 | return 0
35 | }
36 |
37 | if (!node.children || !node.children.length) {
38 | return 0
39 | }
40 |
41 | var child = node.children[0]
42 |
43 | if (child.type === 'text' || child.type === 'comment') {
44 | return child.value.split('\n')[0].length
45 | }
46 |
47 | return 0
48 | }
49 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/comment.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = comment
4 |
5 | /* Stringify a comment `node`. */
6 | function comment(ctx, node) {
7 | return ''
8 | }
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/constants.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | // Characters.
4 | var NULL = '\0'
5 | var AMP = '&'
6 | var SP = ' '
7 | var TB = '\t'
8 | var GR = '`'
9 | var DQ = '"'
10 | var SQ = "'"
11 | var EQ = '='
12 | var LT = '<'
13 | var GT = '>'
14 | var SO = '/'
15 | var LF = '\n'
16 | var CR = '\r'
17 | var FF = '\f'
18 |
19 | var whitespace = [SP, TB, LF, CR, FF]
20 | // https://html.spec.whatwg.org/#attribute-name-state
21 | var name = whitespace.concat(AMP, SO, GT, EQ)
22 | // https://html.spec.whatwg.org/#attribute-value-(unquoted)-state
23 | var unquoted = whitespace.concat(AMP, GT)
24 | var unquotedSafe = unquoted.concat(NULL, DQ, SQ, LT, EQ, GR)
25 | // https://html.spec.whatwg.org/#attribute-value-(single-quoted)-state
26 | var singleQuoted = [AMP, SQ]
27 | // https://html.spec.whatwg.org/#attribute-value-(double-quoted)-state
28 | var doubleQuoted = [AMP, DQ]
29 |
30 | // Maps of subsets. Each value is a matrix of tuples.
31 | // The first value causes parse errors, the second is valid.
32 | // Of both values, the first value is unsafe, and the second is safe.
33 | module.exports = {
34 | name: [[name, name.concat(DQ, SQ, GR)], [name.concat(NULL, DQ, SQ, LT), name.concat(NULL, DQ, SQ, LT, GR)]],
35 | unquoted: [[unquoted, unquotedSafe], [unquotedSafe, unquotedSafe]],
36 | single: [
37 | [singleQuoted, singleQuoted.concat(DQ, GR)],
38 | [singleQuoted.concat(NULL), singleQuoted.concat(NULL, DQ, GR)]
39 | ],
40 | double: [
41 | [doubleQuoted, doubleQuoted.concat(SQ, GR)],
42 | [doubleQuoted.concat(NULL), doubleQuoted.concat(NULL, SQ, GR)]
43 | ]
44 | }
45 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/doctype.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = doctype
4 |
5 | /* Stringify a doctype `node`. */
6 | function doctype(ctx, node) {
7 | var sep = ctx.tightDoctype ? '' : ' '
8 | var name = node.name
9 | var pub = node.public
10 | var sys = node.system
11 | var val = [''
28 | }
29 |
30 | function smart(value) {
31 | var quote = value.indexOf('"') === -1 ? '"' : "'"
32 | return quote + value + quote
33 | }
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var html = require('property-information/html')
4 | var svg = require('property-information/svg')
5 | var voids = require('html-void-elements')
6 | var omission = require('./omission')
7 | var one = require('./one')
8 | const repeat = require('repeat-string')
9 |
10 | module.exports = toHTML
11 |
12 | /* Characters. */
13 | var DQ = '"'
14 | var SQ = "'"
15 |
16 | /* Stringify the given HAST node. */
17 | function toHTML(node, options) {
18 | var settings = options || {}
19 | var quote = settings.singleQuote ? SQ : DQ
20 | var printWidth = settings.printWidth === undefined ? 80 : settings.printWidth
21 | var useTabs = settings.useTabs
22 | var tabWidth = settings.tabWidth || 2
23 | var wrapAttributes = settings.wrapAttributes
24 |
25 | if (useTabs) {
26 | tabWidth = '\t'
27 | } else if (typeof tabWidth === 'number') {
28 | tabWidth = repeat(' ', tabWidth)
29 | }
30 |
31 | return one(
32 | {
33 | valid: settings.allowParseErrors ? 0 : 1,
34 | safe: settings.allowDangerousCharacters ? 0 : 1,
35 | schema: settings.space === 'svg' ? svg : html,
36 | omit: settings.omitOptionalTags && omission,
37 | quote: quote,
38 | printWidth: printWidth,
39 | tabWidth: tabWidth,
40 | wrapAttributes: wrapAttributes,
41 | tightDoctype: Boolean(settings.tightDoctype),
42 | tightLists: settings.tightCommaSeparatedLists,
43 | voids: settings.voids || voids.concat(),
44 | entities: settings.entities || {},
45 | close: settings.closeSelfClosing,
46 | tightClose: settings.tightSelfClosing,
47 | closeEmpty: settings.closeEmptyElements
48 | },
49 | node
50 | )
51 | }
52 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 | exports.opening = require('./opening')
3 | exports.closing = require('./closing')
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/omission.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = omission
4 |
5 | var own = {}.hasOwnProperty
6 |
7 | /* Factory to check if a given node can have a tag omitted. */
8 | function omission(handlers) {
9 | return omit
10 |
11 | /* Check if a given node can have a tag omitted. */
12 | function omit(node, index, parent) {
13 | var name = node.tagName
14 | var fn = own.call(handlers, name) ? handlers[name] : false
15 |
16 | return fn ? fn(node, index, parent) : false
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/opening.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var is = require('unist-util-is')
4 | var element = require('hast-util-is-element')
5 | var before = require('./util/siblings').before
6 | var first = require('./util/first')
7 | var place = require('./util/place')
8 | var whiteSpaceLeft = require('./util/white-space-left')
9 | var closing = require('./closing')
10 | var omission = require('./omission')
11 |
12 | var own = {}.hasOwnProperty
13 |
14 | var uniqueHeadMetadata = ['title', 'base']
15 | var meta = ['meta', 'link', 'script', 'style', 'template']
16 | var tableContainers = ['thead', 'tbody']
17 | var tableRow = 'tr'
18 |
19 | module.exports = omission({
20 | html: html,
21 | head: head,
22 | body: body,
23 | colgroup: colgroup,
24 | tbody: tbody
25 | })
26 |
27 | /* Whether to omit ``. */
28 | function html(node) {
29 | var head = first(node)
30 | return !head || !is('comment', head)
31 | }
32 |
33 | /* Whether to omit ``. */
34 | function head(node) {
35 | var children = node.children
36 | var length = children.length
37 | var map = {}
38 | var index = -1
39 | var child
40 | var name
41 |
42 | while (++index < length) {
43 | child = children[index]
44 | name = child.tagName
45 |
46 | if (element(child, uniqueHeadMetadata)) {
47 | if (own.call(map, name)) {
48 | return false
49 | }
50 |
51 | map[name] = true
52 | }
53 | }
54 |
55 | return Boolean(length)
56 | }
57 |
58 | /* Whether to omit ``. */
59 | function body(node) {
60 | var head = first(node, true)
61 |
62 | return !head || (!is('comment', head) && !whiteSpaceLeft(head) && !element(head, meta))
63 | }
64 |
65 | /* Whether to omit ``.
66 | * The spec describes some logic for the opening tag,
67 | * but it’s easier to implement in the closing tag, to
68 | * the same effect, so we handle it there instead. */
69 | function colgroup(node, index, parent) {
70 | var prev = before(parent, index)
71 | var head = first(node, true)
72 |
73 | /* Previous colgroup was already omitted. */
74 | if (element(prev, 'colgroup') && closing(prev, place(parent, prev), parent)) {
75 | return false
76 | }
77 |
78 | return head && element(head, 'col')
79 | }
80 |
81 | /* Whether to omit ` `. */
82 | function tbody(node, index, parent) {
83 | var prev = before(parent, index)
84 | var head = first(node)
85 |
86 | /* Previous table section was already omitted. */
87 | if (element(prev, tableContainers) && closing(prev, place(parent, prev), parent)) {
88 | return false
89 | }
90 |
91 | return head && element(head, tableRow)
92 | }
93 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/util/first.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var after = require('./siblings').after
4 |
5 | module.exports = first
6 |
7 | /* Get the first child in `parent`. */
8 | function first(parent, includeWhiteSpace) {
9 | return after(parent, -1, includeWhiteSpace)
10 | }
11 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/util/place.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = place
4 |
5 | /* Get the position of `node` in `parent`. */
6 | function place(parent, child) {
7 | return parent && parent.children && parent.children.indexOf(child)
8 | }
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/util/siblings.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var whiteSpace = require('hast-util-whitespace')
4 |
5 | exports.before = siblings(-1)
6 | exports.after = siblings(1)
7 |
8 | /* Factory to check siblings in a direction. */
9 | function siblings(increment) {
10 | return sibling
11 |
12 | /* Find applicable siblings in a direction. */
13 | function sibling(parent, index, includeWhiteSpace) {
14 | var siblings = parent && parent.children
15 | var next
16 |
17 | index += increment
18 | next = siblings && siblings[index]
19 |
20 | if (!includeWhiteSpace) {
21 | while (next && whiteSpace(next)) {
22 | index += increment
23 | next = siblings[index]
24 | }
25 | }
26 |
27 | return next
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/omission/util/white-space-left.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var is = require('unist-util-is')
4 | var whiteSpace = require('hast-util-whitespace')
5 |
6 | module.exports = whiteSpaceLeft
7 |
8 | /* Check if `node` starts with white-space. */
9 | function whiteSpaceLeft(node) {
10 | return is('text', node) && whiteSpace(node.value.charAt(0))
11 | }
12 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/one.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = one
4 |
5 | var own = {}.hasOwnProperty
6 |
7 | var handlers = {}
8 |
9 | handlers.root = require('./all')
10 | handlers.text = require('./text')
11 | handlers.element = require('./element')
12 | handlers.doctype = require('./doctype')
13 | handlers.comment = require('./comment')
14 | handlers.raw = require('./raw')
15 |
16 | /* Stringify `node`. */
17 | function one(ctx, node, index, parent, printWidthOffset, innerTextLength) {
18 | var type = node && node.type
19 |
20 | if (!type) {
21 | throw new Error('Expected node, not `' + node + '`')
22 | }
23 |
24 | if (!own.call(handlers, type)) {
25 | throw new Error('Cannot compile unknown node `' + type + '`')
26 | }
27 |
28 | return handlers[type](ctx, node, index, parent, printWidthOffset, innerTextLength)
29 | }
30 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/raw.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = raw
4 |
5 | /* Stringify `raw`. */
6 | function raw(ctx, node) {
7 | return node.value
8 | }
9 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/lib/text.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = text
4 |
5 | /* Stringify `text`. */
6 | function text(ctx, node, index, parent) {
7 | var value = node.value
8 |
9 | return value
10 | }
11 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/prettyhtml-hast-to-html",
3 | "version": "0.10.0",
4 | "description": "Hast to html converter",
5 | "main": "index.js",
6 | "repository": {
7 | "type": "git",
8 | "url": "git+https://github.com/StarpTech/prettyhtml.git"
9 | },
10 | "scripts": {
11 | "test": "ava",
12 | "test-coverage": "nyc --reporter lcov ava"
13 | },
14 | "files": [
15 | "index.js",
16 | "lib"
17 | ],
18 | "keywords": [
19 | "prettyhtml",
20 | "formatter",
21 | "html5",
22 | "stringify"
23 | ],
24 | "author": "Dustin Deus (http://www.starptech.de)",
25 | "license": "MIT",
26 | "bugs": {
27 | "url": "https://github.com/StarpTech/prettyhtml/issues"
28 | },
29 | "homepage": "https://github.com/StarpTech/prettyhtml#readme",
30 | "dependencies": {
31 | "ccount": "^1.0.4",
32 | "comma-separated-tokens": "^1.0.7",
33 | "hast-util-is-element": "^1.0.3",
34 | "hast-util-whitespace": "^1.0.3",
35 | "html-void-elements": "^1.0.4",
36 | "html-whitespace-sensitive-tag-names": "^1.0.1",
37 | "property-information": "^5.1.0",
38 | "repeat-string": "^1.6.1",
39 | "space-separated-tokens": "^1.1.4",
40 | "stringify-entities": "^2.0.0",
41 | "unist-util-is": "^2.1.3",
42 | "xtend": "^4.0.1"
43 | },
44 | "devDependencies": {
45 | "@starptech/prettyhtml-hastscript": "^0.10.0",
46 | "ava": "^2.1.0",
47 | "nyc": "^14.1.1",
48 | "unist-builder": "^1.0.4"
49 | },
50 | "publishConfig": {
51 | "access": "public"
52 | },
53 | "gitHead": "c7bfe5fdd9ef240ddf235e50a81be52b30828c8f"
54 | }
55 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/comment.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var u = require('unist-builder')
5 | var to = require('..')
6 |
7 | test('`comment`', function(t) {
8 | t.deepEqual(to(u('comment', 'alpha')), '', 'should stringify `comment`s')
9 |
10 | t.deepEqual(to(u('comment', 'AT&T')), '', 'should not encode `comment`s (#1)')
11 |
12 | /* No way to get around this. */
13 | t.deepEqual(to(u('comment', '-->')), '-->', 'should not encode `comment`s (#2)')
14 | })
15 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/core.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var u = require('unist-builder')
5 | var to = require('..')
6 |
7 | test('toHTML()', function(t) {
8 | t.throws(
9 | function() {
10 | to(true)
11 | },
12 | /Expected node, not `true`/,
13 | 'should throw on non-nodes'
14 | )
15 |
16 | t.throws(
17 | function() {
18 | to(u('foo', []))
19 | },
20 | /Cannot compile unknown node `foo`/,
21 | 'should throw on unknown nodes'
22 | )
23 | })
24 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/element.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`element`', function(t) {
8 | t.deepEqual(to(h('i', 'bravo')), 'bravo ', 'should stringify `element`s')
9 |
10 | t.deepEqual(to(h('foo')), ' ', 'should stringify unknown `element`s')
11 |
12 | t.deepEqual(to(h('img')), ' ', 'should stringify void `element`s')
13 |
14 | t.deepEqual(to(h('foo'), { voids: ['foo'] }), '', 'should stringify given void `element`s')
15 |
16 | t.deepEqual(
17 | to({
18 | type: 'element',
19 | tagName: 'template',
20 | properties: {},
21 | children: [h('p', [h('b', 'Bold'), ' and ', h('i', 'italic'), '.'])]
22 | }),
23 | 'Bold and italic .
',
24 | 'should support ``s content'
25 | )
26 |
27 | t.deepEqual(
28 | to(h('img'), { closeSelfClosing: true, tightSelfClosing: true }),
29 | ' ',
30 | 'should stringify voids with `/` in `closeSelfClosing` and `tightSelfClosing` mode'
31 | )
32 | })
33 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | /* eslint-disable import/no-unassigned-import */
4 |
5 | require('./core')
6 | require('./root')
7 | require('./comment')
8 | require('./doctype')
9 | require('./text')
10 | require('./raw')
11 | require('./element')
12 | require('./attribute')
13 | require('./omission')
14 | require('./omission-opening')
15 | require('./omission-closing')
16 | require('./svg')
17 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-body.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`body` (closing)', function(t) {
9 | t.deepEqual(to(h('body'), { omitOptionalTags: true }), '', 'should omit tag without following')
10 |
11 | t.deepEqual(
12 | to(h('html', [h('body'), u('comment', 'alpha')]), {
13 | omitOptionalTags: true
14 | }),
15 | '',
16 | 'should not omit tag if followed by `comment`'
17 | )
18 |
19 | t.deepEqual(
20 | to(h('html', [h('body'), u('text', 'alpha')]), { omitOptionalTags: true }),
21 | 'alpha',
22 | 'should omit tag if not followed by `comment`'
23 | )
24 | })
25 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-caption.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`caption` (closing)', function(t) {
9 | t.deepEqual(
10 | to(h('caption'), { omitOptionalTags: true }),
11 | '',
12 | 'should not omit tag without children'
13 | )
14 |
15 | t.deepEqual(
16 | to(h('table', h('caption')), { omitOptionalTags: true }),
17 | '',
18 | 'should omit tag without following'
19 | )
20 |
21 | t.deepEqual(
22 | to(h('table', [h('caption'), u('comment', 'alpha')]), {
23 | omitOptionalTags: true
24 | }),
25 | '',
26 | 'should not omit tag followed by `comment`'
27 | )
28 |
29 | t.deepEqual(
30 | to(h('table', [h('caption'), ' alpha']), { omitOptionalTags: true }),
31 | '',
32 | 'should not omit tag followed by white-space'
33 | )
34 |
35 | t.deepEqual(
36 | to(h('table', [h('caption'), h('tr')]), { omitOptionalTags: true }),
37 | '',
38 | 'should omit tag followed by others'
39 | )
40 | })
41 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-colgroup.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`colgroup` (closing)', function(t) {
9 | t.deepEqual(
10 | to(h('colgroup'), { omitOptionalTags: true }),
11 | ' ',
12 | 'should not omit tag without children'
13 | )
14 |
15 | t.deepEqual(
16 | to(h('colgroup', h('col', { span: 2 })), { omitOptionalTags: true }),
17 | ' ',
18 | 'should omit tag if head is `col`'
19 | )
20 |
21 | t.deepEqual(
22 | to(h('colgroup', [u('comment', 'alpha')]), { omitOptionalTags: true }),
23 | ' ',
24 | 'should not omit tag if head is not `col`'
25 | )
26 |
27 | t.deepEqual(
28 | to(h('table', [h('colgroup', [h('col', { span: 2 })]), h('colgroup', [h('col', { span: 3 })])]), {
29 | omitOptionalTags: true
30 | }),
31 | '',
32 | 'should not omit tag if previous is `colgroup` whose closing tag is omitted'
33 | )
34 | })
35 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-dd.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`dd` (closing)', function(t) {
8 | t.deepEqual(to(h('dd'), { omitOptionalTags: true }), '', 'should omit tag without parent')
9 |
10 | t.deepEqual(
11 | to(h('dl', h('dd')), { omitOptionalTags: true }),
12 | ' ',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('dl', [h('dd'), h('dd')]), { omitOptionalTags: true }),
18 | ' ',
19 | 'should omit tag followed by `dd`'
20 | )
21 |
22 | t.deepEqual(
23 | to(h('dl', [h('dd'), h('dt')]), { omitOptionalTags: true }),
24 | ' ',
25 | 'should omit tag followed by `dt`'
26 | )
27 |
28 | t.deepEqual(
29 | to(h('dl', [h('dd'), h('p')]), { omitOptionalTags: true }),
30 | '
',
31 | 'should not omit tag followed by others'
32 | )
33 | })
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-dt.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`dt` (closing)', function(t) {
8 | t.deepEqual(to(h('dt'), { omitOptionalTags: true }), ' ', 'should not omit tag without parent')
9 |
10 | t.deepEqual(
11 | to(h('dl', h('dt')), { omitOptionalTags: true }),
12 | ' ',
13 | 'should not omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('dl', [h('dt'), h('dt')]), { omitOptionalTags: true }),
18 | ' ',
19 | 'should omit tag followed by `dt`'
20 | )
21 |
22 | t.deepEqual(
23 | to(h('dl', [h('dt'), h('dd')]), { omitOptionalTags: true }),
24 | ' ',
25 | 'should omit tag followed by `dd`'
26 | )
27 |
28 | t.deepEqual(
29 | to(h('dl', [h('dt'), h('p')]), { omitOptionalTags: true }),
30 | '
',
31 | 'should not omit tag followed by others'
32 | )
33 | })
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-head.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`head` (closing)', function(t) {
9 | t.deepEqual(to(h('head'), { omitOptionalTags: true }), '', 'should omit tag without following')
10 |
11 | t.deepEqual(
12 | to(h('html', [h('head'), u('comment', 'alpha')]), {
13 | omitOptionalTags: true
14 | }),
15 | '',
16 | 'should not omit tag if followed by `comment`'
17 | )
18 |
19 | t.deepEqual(
20 | to(h('html', [h('head'), ' alpha']), { omitOptionalTags: true }),
21 | ' alpha',
22 | 'should not omit tag if the next sibling starts with white-space'
23 | )
24 |
25 | t.deepEqual(
26 | to(h('html', [h('head'), u('text', 'alpha')]), { omitOptionalTags: true }),
27 | 'alpha',
28 | 'should omit tag if not followed by `comment`'
29 | )
30 | })
31 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-html.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`html` (closing)', function(t) {
9 | t.deepEqual(to(h('html'), { omitOptionalTags: true }), '', 'should omit tag without following')
10 |
11 | t.deepEqual(
12 | to(u('root', [h('html'), u('comment', 'alpha')]), {
13 | omitOptionalTags: true
14 | }),
15 | '',
16 | 'should not omit tag if followed by `comment`'
17 | )
18 |
19 | t.deepEqual(
20 | to(u('root', [h('html'), u('text', 'alpha')]), { omitOptionalTags: true }),
21 | 'alpha',
22 | 'should omit tag if not followed by `comment`'
23 | )
24 | })
25 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-li.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`li` (closing)', function(t) {
8 | t.deepEqual(to(h('li'), { omitOptionalTags: true }), '', 'should omit tag without parent')
9 |
10 | t.deepEqual(
11 | to(h('ol', h('li')), { omitOptionalTags: true }),
12 | ' ',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('ol', [h('li'), h('li')]), { omitOptionalTags: true }),
18 | ' ',
19 | 'should omit tag followed by `li`'
20 | )
21 |
22 | t.deepEqual(
23 | to(h('ol', [h('li'), h('p')]), { omitOptionalTags: true }),
24 | '
',
25 | 'should not omit tag followed by others'
26 | )
27 | })
28 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-menuitem.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`menuitem` (closing)', function(t) {
8 | t.deepEqual(
9 | to(h('menuitem', 'alpha'), { omitOptionalTags: true }),
10 | 'alpha',
11 | 'should omit tag without parent'
12 | )
13 |
14 | t.deepEqual(
15 | to(h('menu', [h('menuitem', 'alpha')]), { omitOptionalTags: true }),
16 | 'alpha ',
17 | 'should omit tag without following'
18 | )
19 |
20 | t.deepEqual(
21 | to(h('menu', [h('menuitem'), h('menuitem')]), { omitOptionalTags: true }),
22 | ' ',
23 | 'should omit tag followed by `menuitem`'
24 | )
25 |
26 | t.deepEqual(
27 | to(h('menu', [h('menuitem', 'alpha'), h('hr')]), {
28 | omitOptionalTags: true
29 | }),
30 | 'alpha ',
31 | 'should omit tag followed by `hr`'
32 | )
33 |
34 | t.deepEqual(
35 | to(h('menu', [h('menuitem', 'alpha'), h('menu')]), {
36 | omitOptionalTags: true
37 | }),
38 | 'alpha ',
39 | 'should omit tag followed by `menu`'
40 | )
41 |
42 | t.deepEqual(
43 | to(h('menu', [h('menuitem', 'alpha'), h('p')]), { omitOptionalTags: true }),
44 | 'alpha
',
45 | 'should not omit tag followed by others'
46 | )
47 |
48 | /* This actually tests an edge case where `menuitems`,
49 | * which can have children in WHATWG HTML, but not in
50 | * W3C HTML, here do not have children. */
51 | t.deepEqual(
52 | to(h('menu', [h('menuitem'), h('p')]), { omitOptionalTags: true }),
53 | '
',
54 | 'should omit tag when without children'
55 | )
56 | })
57 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-optgroup.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`optgroup` (closing)', function(t) {
8 | t.deepEqual(to(h('optgroup'), { omitOptionalTags: true }), '', 'should omit tag without parent')
9 |
10 | t.deepEqual(
11 | to(h('select', h('optgroup')), { omitOptionalTags: true }),
12 | ' ',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('select', [h('optgroup'), h('optgroup')]), { omitOptionalTags: true }),
18 | ' ',
19 | 'should omit tag followed by `optgroup`'
20 | )
21 |
22 | t.deepEqual(
23 | to(h('select', [h('optgroup'), h('p')]), { omitOptionalTags: true }),
24 | '
',
25 | 'should not omit tag followed by others'
26 | )
27 | })
28 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-option.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`option` (closing)', function(t) {
8 | t.deepEqual(to(h('option'), { omitOptionalTags: true }), '', 'should omit tag without parent')
9 |
10 | t.deepEqual(
11 | to(h('select', h('option')), { omitOptionalTags: true }),
12 | ' ',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('select', [h('option'), h('option')]), { omitOptionalTags: true }),
18 | ' ',
19 | 'should omit tag followed by `option`'
20 | )
21 |
22 | t.deepEqual(
23 | to(h('select', [h('option'), h('optgroup')]), { omitOptionalTags: true }),
24 | ' ',
25 | 'should omit tag followed by `optgroup`'
26 | )
27 |
28 | t.deepEqual(
29 | to(h('select', [h('option'), h('p')]), { omitOptionalTags: true }),
30 | '
',
31 | 'should not omit tag followed by others'
32 | )
33 | })
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-p.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`p` (closing)', function(t) {
9 | t.deepEqual(to(u('root', [h('p')]), { omitOptionalTags: true }), '', 'should omit tag without following')
10 |
11 | t.deepEqual(
12 | to(u('root', [h('p'), h('address')]), { omitOptionalTags: true }),
13 | '
',
14 | 'should omit tag if followed by `address`'
15 | )
16 |
17 | t.deepEqual(
18 | to(u('root', [h('p'), h('ul')]), { omitOptionalTags: true }),
19 | '
',
20 | 'should omit tag if followed by `ul`'
21 | )
22 |
23 | t.deepEqual(
24 | to(u('root', [h('p'), h('a')]), { omitOptionalTags: true }),
25 | '
',
26 | 'should not omit tag if followed by `a`'
27 | )
28 |
29 | t.deepEqual(
30 | to(u('root', [h('p'), h('xmp')]), { omitOptionalTags: true }),
31 | '
',
32 | 'should not omit tag if followed by `xmp`'
33 | )
34 |
35 | t.deepEqual(to(h('p'), { omitOptionalTags: true }), '', 'should omit tag without parent')
36 |
37 | t.deepEqual(
38 | to(h('a', [h('p')]), { omitOptionalTags: true }),
39 | '
',
40 | 'should not omit tag if parent is `a`'
41 | )
42 |
43 | t.deepEqual(
44 | to(h('video', [h('p')]), { omitOptionalTags: true }),
45 | '
',
46 | 'should not omit tag if parented by `video`'
47 | )
48 |
49 | t.deepEqual(
50 | to(h('article', [h('p')]), { omitOptionalTags: true }),
51 | '
',
52 | 'should not omit tag if parent is `article`'
53 | )
54 |
55 | t.deepEqual(
56 | to(h('section', [h('p')]), { omitOptionalTags: true }),
57 | '',
58 | 'should not omit tag if parented by `section`'
59 | )
60 | })
61 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-rp-rt.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | 'rp,rt'.split(',').forEach(function(tagName, index, values) {
8 | test('`' + tagName + '` (closing)', function(t) {
9 | var other = values[index ? 0 : 1]
10 |
11 | t.deepEqual(
12 | to(h(tagName), { omitOptionalTags: true }),
13 | '<' + tagName + '>',
14 | 'should omit tag without parent'
15 | )
16 |
17 | t.deepEqual(
18 | to(h('ruby', h(tagName)), { omitOptionalTags: true }),
19 | '<' + tagName + '> ',
20 | 'should omit tag without following'
21 | )
22 |
23 | t.deepEqual(
24 | to(h('ruby', [h(tagName), h(tagName)]), { omitOptionalTags: true }),
25 | '<' + tagName + '><' + tagName + '> ',
26 | 'should omit tag followed by `' + tagName + '`'
27 | )
28 |
29 | t.deepEqual(
30 | to(h('ruby', [h(tagName), h(other)]), { omitOptionalTags: true }),
31 | '<' + tagName + '><' + other + '> ',
32 | 'should omit tag followed by `' + other + '`'
33 | )
34 |
35 | t.deepEqual(
36 | to(h('ruby', [h(tagName), h('p')]), { omitOptionalTags: true }),
37 | '<' + tagName + '>' + tagName + '>
',
38 | 'should not omit tag followed by others'
39 | )
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-tbody.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`tbody` (closing)', function(t) {
8 | t.deepEqual(to(h('tbody'), { omitOptionalTags: true }), '
', 'should omit tag without siblings')
9 |
10 | t.deepEqual(
11 | to(h('table', h('tbody')), { omitOptionalTags: true }),
12 | '',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('table', [h('tbody'), h('tbody')]), { omitOptionalTags: true }),
18 | '',
19 | 'should omit tag followed by `tbody`'
20 | )
21 |
22 | t.deepEqual(
23 | to(h('table', [h('tbody'), h('tfoot')]), { omitOptionalTags: true }),
24 | '',
25 | 'should omit tag followed by `tfoot`'
26 | )
27 |
28 | t.deepEqual(
29 | to(h('table', [h('tbody'), h('tr')]), { omitOptionalTags: true }),
30 | '',
31 | 'should not omit tag followed by others'
32 | )
33 | })
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-td-th.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | 'td,th'.split(',').forEach(function(tagName, index, values) {
8 | test('`' + tagName + '` (closing)', function(t) {
9 | var other = values[index ? 0 : 1]
10 |
11 | t.deepEqual(
12 | to(h(tagName), { omitOptionalTags: true }),
13 | '<' + tagName + '>',
14 | 'should omit tag without parent'
15 | )
16 |
17 | t.deepEqual(
18 | to(h('tr', h(tagName)), { omitOptionalTags: true }),
19 | '<' + tagName + '>',
20 | 'should omit tag without following'
21 | )
22 |
23 | t.deepEqual(
24 | to(h('tr', [h(tagName), h(tagName)]), { omitOptionalTags: true }),
25 | ' <' + tagName + '><' + tagName + '>',
26 | 'should omit tag followed by `' + tagName + '`'
27 | )
28 |
29 | t.deepEqual(
30 | to(h('tr', [h(tagName), h(other)]), { omitOptionalTags: true }),
31 | ' <' + tagName + '><' + other + '>',
32 | 'should omit tag followed by `' + other + '`'
33 | )
34 |
35 | t.deepEqual(
36 | to(h('tr', [h(tagName), h('p')]), { omitOptionalTags: true }),
37 | ' <' + tagName + '>' + tagName + '>',
38 | 'should not omit tag followed by others'
39 | )
40 | })
41 | })
42 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-tfoot.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`tfoot` (closing)', function(t) {
8 | t.deepEqual(to(h('tfoot'), { omitOptionalTags: true }), '
', 'should omit tag without siblings')
9 |
10 | t.deepEqual(
11 | to(h('table', h('tfoot')), { omitOptionalTags: true }),
12 | '',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('table', [h('tfoot'), h('tr')]), { omitOptionalTags: true }),
18 | '',
19 | 'should not omit tag followed by others'
20 | )
21 | })
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-thead.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`thead` (closing)', function(t) {
8 | t.deepEqual(
9 | to(h('thead'), { omitOptionalTags: true }),
10 | ' ',
11 | 'should not omit tag without siblings'
12 | )
13 |
14 | t.deepEqual(
15 | to(h('table', h('thead')), { omitOptionalTags: true }),
16 | '',
17 | 'should not omit tag without following'
18 | )
19 |
20 | t.deepEqual(
21 | to(h('table', [h('thead'), h('tbody')]), { omitOptionalTags: true }),
22 | '',
23 | 'should omit tag followed by `tbody`'
24 | )
25 |
26 | t.deepEqual(
27 | to(h('table', [h('thead'), h('tfoot')]), { omitOptionalTags: true }),
28 | '',
29 | 'should omit tag followed by `tfoot`'
30 | )
31 |
32 | t.deepEqual(
33 | to(h('table', [h('thead'), h('tr')]), { omitOptionalTags: true }),
34 | '',
35 | 'should not omit tag followed by others'
36 | )
37 | })
38 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing-tr.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`tr` (closing)', function(t) {
8 | t.deepEqual(to(h('tr'), { omitOptionalTags: true }), '', 'should omit tag without siblings')
9 |
10 | t.deepEqual(
11 | to(h('table', h('tr')), { omitOptionalTags: true }),
12 | '',
13 | 'should omit tag without following'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('table', [h('tr'), h('tbody')]), { omitOptionalTags: true }),
18 | '',
19 | 'should not omit tag followed by others'
20 | )
21 | })
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-closing.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | /* eslint-disable import/no-unassigned-import */
4 |
5 | require('./omission-closing-body')
6 | require('./omission-closing-caption')
7 | require('./omission-closing-colgroup')
8 | require('./omission-closing-dd')
9 | require('./omission-closing-dt')
10 | require('./omission-closing-head')
11 | require('./omission-closing-html')
12 | require('./omission-closing-li')
13 | require('./omission-closing-menuitem')
14 | require('./omission-closing-optgroup')
15 | require('./omission-closing-option')
16 | require('./omission-closing-p')
17 | require('./omission-closing-rp-rt')
18 | require('./omission-closing-tbody')
19 | require('./omission-closing-td-th')
20 | require('./omission-closing-tfoot')
21 | require('./omission-closing-thead')
22 | require('./omission-closing-tr')
23 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-opening-body.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var u = require('unist-builder')
5 | var h = require('@starptech/prettyhtml-hastscript')
6 | var to = require('..')
7 |
8 | test('`body` (opening)', function(t) {
9 | t.deepEqual(to(h('body'), { omitOptionalTags: true }), '', 'should omit tag without children')
10 |
11 | t.deepEqual(
12 | to(h('body', u('comment', 'alpha')), { omitOptionalTags: true }),
13 | '',
14 | 'should not omit tag if the head is a `comment`'
15 | )
16 |
17 | t.deepEqual(
18 | to(h('body', ' alpha'), { omitOptionalTags: true }),
19 | ' alpha',
20 | 'should not omit tag if the head starts with white-space'
21 | )
22 |
23 | t.deepEqual(
24 | to(h('body', [h('meta')]), { omitOptionalTags: true }),
25 | ' ',
26 | 'should not omit tag if head is `meta`'
27 | )
28 |
29 | t.deepEqual(
30 | to(h('body', [h('link')]), { omitOptionalTags: true }),
31 | ' ',
32 | 'should not omit tag if head is `link`'
33 | )
34 |
35 | t.deepEqual(
36 | to(h('body', [h('script')]), { omitOptionalTags: true }),
37 | '',
38 | 'should not omit tag if head is `script`'
39 | )
40 |
41 | t.deepEqual(
42 | to(h('body', [h('style')]), { omitOptionalTags: true }),
43 | '',
44 | 'should not omit tag if head is `style`'
45 | )
46 |
47 | t.deepEqual(
48 | to(h('body', [h('template')]), { omitOptionalTags: true }),
49 | ' ',
50 | 'should not omit tag if head is `template`'
51 | )
52 |
53 | t.deepEqual(
54 | to(h('body', [h('div')]), { omitOptionalTags: true }),
55 | '
',
56 | 'should omit tag if head is something else'
57 | )
58 | })
59 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-opening-colgroup.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var u = require('unist-builder')
5 | var h = require('@starptech/prettyhtml-hastscript')
6 | var to = require('..')
7 |
8 | test('`colgroup` (opening)', function(t) {
9 | t.deepEqual(
10 | to(h('colgroup'), { omitOptionalTags: true }),
11 | '',
12 | 'should not omit tag without children'
13 | )
14 |
15 | t.deepEqual(to(h('colgroup'), { omitOptionalTags: true }), ' ', 'should omit tag with `col` child')
16 |
17 | t.deepEqual(
18 | to(h('table', h('colgroup')), { omitOptionalTags: true }),
19 | '',
20 | 'should omit tag without following'
21 | )
22 |
23 | t.deepEqual(
24 | to(h('table', [h('colgroup'), u('comment', 'alpha')]), {
25 | omitOptionalTags: true
26 | }),
27 | '',
28 | 'should not omit tag followed by `comment`'
29 | )
30 |
31 | t.deepEqual(
32 | to(h('table', [h('colgroup'), ' alpha']), { omitOptionalTags: true }),
33 | '',
34 | 'should not omit tag followed by white-space'
35 | )
36 |
37 | t.deepEqual(
38 | to(h('table', [h('colgroup'), h('tr')]), { omitOptionalTags: true }),
39 | '',
40 | 'should omit tag followed by others'
41 | )
42 | })
43 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-opening-head.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`head` (opening)', function(t) {
8 | t.deepEqual(
9 | to(h('head', h('meta', { charSet: 'utf8' })), { omitOptionalTags: true }),
10 | ' ',
11 | 'should omit tag with children'
12 | )
13 |
14 | t.deepEqual(to(h('head'), { omitOptionalTags: true }), '', 'should not omit tag without children')
15 |
16 | t.deepEqual(
17 | to(h('head', h('title', 'alpha')), { omitOptionalTags: true }),
18 | 'alpha ',
19 | 'should omit tag with `title`'
20 | )
21 |
22 | t.deepEqual(to(h('head', h('base')), { omitOptionalTags: true }), ' ', 'should omit tag with `base`')
23 |
24 | t.deepEqual(
25 | to(h('head', [h('title'), h('title')]), { omitOptionalTags: true }),
26 | ' ',
27 | 'should not omit tag with multiple `title`s'
28 | )
29 |
30 | t.deepEqual(
31 | to(h('head', [h('base'), h('base')]), { omitOptionalTags: true }),
32 | ' ',
33 | 'should not omit tag with multiple `base`s'
34 | )
35 | })
36 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-opening-html.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`html` (opening)', function(t) {
9 | t.deepEqual(to(h('html'), { omitOptionalTags: true }), '', 'should omit tag without first child')
10 |
11 | t.deepEqual(
12 | to(h('html', [u('comment', 'alpha'), 'bravo']), { omitOptionalTags: true }),
13 | 'bravo',
14 | 'should not omit tag if head is `comment`'
15 | )
16 |
17 | t.deepEqual(
18 | to(h('html', 'bravo'), { omitOptionalTags: true }),
19 | 'bravo',
20 | 'should omit tag if head is not `comment`'
21 | )
22 | })
23 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-opening-tbody.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`tbody` (opening)', function(t) {
8 | t.deepEqual(to(h('tbody'), { omitOptionalTags: true }), ' ', 'should not omit tag without children')
9 |
10 | t.deepEqual(to(h('tbody', h('tr')), { omitOptionalTags: true }), '', 'should omit tag if head is `tr`')
11 |
12 | t.deepEqual(
13 | to(h('table', [h('thead', h('tr')), h('tbody', h('tr'))]), {
14 | omitOptionalTags: true
15 | }),
16 | '',
17 | 'should not omit tag preceded by an omitted `thead` closing tag'
18 | )
19 |
20 | t.deepEqual(
21 | to(h('table', [h('tbody', h('tr')), h('tbody', h('tr'))]), {
22 | omitOptionalTags: true
23 | }),
24 | '',
25 | 'should not omit tag preceded by an omitted `tbody` closing tag'
26 | )
27 | })
28 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission-opening.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | /* eslint-disable import/no-unassigned-import */
4 |
5 | require('./omission-opening-body')
6 | require('./omission-opening-colgroup')
7 | require('./omission-opening-head')
8 | require('./omission-opening-html')
9 | require('./omission-opening-tbody')
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/omission.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var to = require('..')
6 |
7 | test('`omitOptionalTags` mode', function(t) {
8 | t.deepEqual(to(h('html'), { omitOptionalTags: true }), '', 'should omit opening and closing tags')
9 |
10 | t.deepEqual(
11 | to(h('html', { lang: 'en' }), { omitOptionalTags: true }),
12 | '',
13 | 'should not omit opening tags with attributes'
14 | )
15 |
16 | t.deepEqual(
17 | to(h('ol', [h('li', 'alpha'), h('li', 'bravo')]), {
18 | omitOptionalTags: true
19 | }),
20 | 'alpha bravo ',
21 | 'should ignore white-space when determining whether tags can be omitted (#1)'
22 | )
23 |
24 | t.deepEqual(
25 | to(h('ol', [h('li', 'alpha'), ' ', h('li', 'bravo'), '\t']), {
26 | omitOptionalTags: true
27 | }),
28 | 'alpha bravo\t ',
29 | 'should ignore white-space when determining whether tags can be omitted (#2)'
30 | )
31 | })
32 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/raw.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var u = require('unist-builder')
5 | var to = require('..')
6 |
7 | test('`element/raw`', function(t) {
8 | t.deepEqual(
9 | to(u('raw', '')),
10 | '',
11 | 'should not encode `raw`s'
12 | )
13 |
14 | t.deepEqual(
15 | to(u('raw', '')),
16 | '',
17 | 'should not encode `raw`s'
18 | )
19 | })
20 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/root.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`root`', function(t) {
9 | t.deepEqual(
10 | to(u('root', [u('text', 'alpha '), h('i', 'bravo'), u('text', ' charlie')])),
11 | 'alpha bravo charlie',
12 | 'should stringify `root`s'
13 | )
14 | })
15 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hast-to-html/test/text.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var test = require('ava')
4 | var h = require('@starptech/prettyhtml-hastscript')
5 | var u = require('unist-builder')
6 | var to = require('..')
7 |
8 | test('`text`', function(t) {
9 | t.deepEqual(to(u('text', 'alpha')), 'alpha', 'should stringify `text`s')
10 |
11 | t.deepEqual(to(u('text', '3 < 5 & 7')), '3 < 5 & 7', 'should not encode `text`s')
12 |
13 | t.deepEqual(
14 | to(h('style', u('text', '*:before {content: "3 < 5"}'))),
15 | '',
16 | 'should not encode `text`s in `style`'
17 | )
18 |
19 | t.deepEqual(
20 | to(h('script', u('text', 'alert("3 < 5")'))),
21 | '',
22 | 'should not encode `text`s in `script`'
23 | )
24 |
25 | t.deepEqual(to(h('b', u('text', '3 < 5'))), '3 < 5 ', 'should not encode `text`s in other nodes')
26 | })
27 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/.editorconfig:
--------------------------------------------------------------------------------
1 | root = true
2 |
3 | [*]
4 | indent_style = space
5 | indent_size = 2
6 | end_of_line = lf
7 | charset = utf-8
8 | trim_trailing_whitespace = true
9 | insert_final_newline = true
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/LICENSE:
--------------------------------------------------------------------------------
1 | (The MIT License)
2 |
3 | Copyright (c) 2016 Titus Wormer
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining
6 | a copy of this software and associated documentation files (the
7 | 'Software'), to deal in the Software without restriction, including
8 | without limitation the rights to use, copy, modify, merge, publish,
9 | distribute, sublicense, and/or sell copies of the Software, and to
10 | permit persons to whom the Software is furnished to do so, subject to
11 | the following conditions:
12 |
13 | The above copyright notice and this permission notice shall be
14 | included in all copies or substantial portions of the Software.
15 |
16 | THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/prettyhtml-hastscript
2 |
3 | Hyperscript compatible DSL for creating virtual HAST trees
4 |
5 | ## Installation
6 |
7 | ```
8 | npm install --save @starptech/prettyhtml-hastscript
9 | ```
10 |
11 | ## Caveats
12 |
13 | The implementation is a modified version of [**Hastscript Version 4.0.0**](https://github.com/syntax-tree/hastscript)
14 |
15 | - Known html attributes aren't handled case-sensitively
16 | - Don't coerce or optimize attribute values
17 | - Don't house `` node through `content` property. Handle it like any other element.
18 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/html.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var schema = require('property-information/html')
4 | var factory = require('./factory')
5 |
6 | var html = factory(schema, 'div')
7 | html.displayName = 'html'
8 |
9 | module.exports = html
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = require('./html')
4 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/prettyhtml-hastscript",
3 | "version": "0.10.0",
4 | "description": "Hyperscript compatible DSL for creating virtual HAST trees",
5 | "keywords": [
6 | "hast",
7 | "prettyhtml",
8 | "vdom",
9 | "virtual",
10 | "dom",
11 | "hyperscript",
12 | "dsl",
13 | "html"
14 | ],
15 | "repository": {
16 | "type": "git",
17 | "url": "git+https://github.com/StarpTech/prettyhtml.git"
18 | },
19 | "author": "Dustin Deus (http://www.starptech.de)",
20 | "license": "MIT",
21 | "bugs": {
22 | "url": "https://github.com/StarpTech/prettyhtml/issues"
23 | },
24 | "files": [
25 | "index.js",
26 | "factory.js",
27 | "html.js",
28 | "svg.js"
29 | ],
30 | "dependencies": {
31 | "comma-separated-tokens": "^1.0.7",
32 | "hast-util-parse-selector": "^2.2.2",
33 | "property-information": "^5.1.0",
34 | "space-separated-tokens": "^1.1.4"
35 | },
36 | "devDependencies": {
37 | "ava": "^1.4.1",
38 | "nyc": "^13.3.0"
39 | },
40 | "scripts": {
41 | "test": "ava",
42 | "test-coverage": "nyc --reporter lcov ava"
43 | },
44 | "nyc": {
45 | "check-coverage": true,
46 | "lines": 100,
47 | "functions": 100,
48 | "branches": 100
49 | },
50 | "publishConfig": {
51 | "access": "public"
52 | },
53 | "gitHead": "c7bfe5fdd9ef240ddf235e50a81be52b30828c8f"
54 | }
55 |
--------------------------------------------------------------------------------
/packages/prettyhtml-hastscript/svg.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var schema = require('property-information/svg')
4 | var factory = require('./factory')
5 |
6 | var svg = factory(schema, 'g')
7 | svg.displayName = 'svg'
8 |
9 | module.exports = svg
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-quick/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dustin Deus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml-quick/README.md:
--------------------------------------------------------------------------------
1 | # prettyhtml-quick
2 |
3 | Runs [Prettyhtml](https://github.com/Prettyhtml/prettyhtml) on your changed (based on Git) files.
4 |
5 | Example:
6 |
7 | ```
8 | prettyhtml-quick
9 | 🔍 Finding changed files since git revision 2eb4337.
10 | 🎯 Found 1 changed file.
11 | ☝ printWidth: 80, tabWidth: 2
12 | ✍️ Fixing up test.html.
13 | ✅ Everything is awesome!
14 | ```
15 |
16 | ## Install
17 |
18 | ```shellsession
19 | npm install --save-dev @starptech/prettyhtml-quick
20 | ```
21 |
22 | ## Usage
23 |
24 | With [`npx`](https://npm.im/npx): (No install required)
25 |
26 | ```shellsession
27 | npx @starptech/prettyhtml-quick
28 | ```
29 |
30 | ## Pre-Commit Hook
31 |
32 | You can run `prettyhtml-quick` as a pre-commit hook using [`husky`](https://github.com/typicode/husky).
33 |
34 | ```shellstream
35 | yarn add --dev husky
36 | ```
37 |
38 | In `package.json`'s `"scripts"` section, add:
39 |
40 | ```
41 | "precommit": "prettyhtml-quick"
42 | ```
43 |
44 | ## CLI Flags
45 |
46 | ### `-s --staged`
47 |
48 | Only staged files will be formatted, and they will be re-staged after formatting.
49 |
50 | ## Formatter options
51 |
52 | We use prettier [`resolveConfig`](https://prettier.io/docs/en/api.html#prettierresolveconfigfilepath-options) to indentify your tabWidth and printWidth. It will fallback to `.editorconfig`.
53 |
--------------------------------------------------------------------------------
/packages/prettyhtml-quick/bin/cli.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | 'use strict'
4 |
5 | const program = require('commander')
6 | const prettyhtml = require('@starptech/prettyhtml')
7 | const path = require('path')
8 | const fs = require('fs')
9 | const chalk = require('chalk')
10 | const prettier = require('prettier')
11 | const git = require('./../lib/git')
12 | const packageJSON = require('./../package.json')
13 |
14 | program
15 | .version(packageJSON.version)
16 | .option('-s, --staged', 'Only staged files will be formatted, and they will be re-staged after formatting')
17 | .parse(process.argv)
18 |
19 | const cwd = process.cwd()
20 | const prettierConfig = prettier.resolveConfig.sync(cwd)
21 | const root = git.detect(cwd)
22 | const revision = git.getSinceRevision(root, { staged: program.staged })
23 | const changedFiles = program.staged ? git.getStagedChangedFiles(root) : git.getUnstagedChangedFiles(root)
24 |
25 | // only html files
26 | const htmlFiles = changedFiles.filter(filename => /.+\.html|.htm$/.test(filename))
27 |
28 | // same prettyhtml defaults
29 | const prettyhtmlCfg = {
30 | printWidth: prettierConfig.printWidth,
31 | tabWidth: prettierConfig.tabWidth,
32 | prettier: prettierConfig,
33 | wrapAttributes: prettierConfig.wrapAttributes,
34 | sortAttributes: prettierConfig.sortAttributes
35 | }
36 |
37 | if (htmlFiles.length) {
38 | console.log(`🔍 Finding changed files since ${chalk.bold('git')} revision ${chalk.bold(revision)}.`)
39 | }
40 |
41 | console.log(
42 | `🎯 Found ${chalk.bold(htmlFiles.length)} changed ${htmlFiles.length === 1 ? 'file' : 'files'}.
43 | ☝ printWidth: ${prettyhtmlCfg.printWidth || 80}, tabWidth: ${prettyhtmlCfg.tabWidth || 2}`
44 | )
45 |
46 | htmlFiles.forEach(file => {
47 | const filePath = path.join(root, file)
48 | const input = fs.readFileSync(filePath, 'utf8')
49 | try {
50 | const vFile = prettyhtml(input, prettyhtmlCfg)
51 | fs.writeFileSync(filePath, vFile.contents, 'utf8')
52 | git.stageFile(root, file)
53 | console.log(`✍️ Fixing up ${chalk.bold(file)}.`)
54 | } catch (error) {
55 | console.log(`❌ Error: ${chalk.bold(error.message)}.`)
56 | }
57 | })
58 |
59 | console.log('✅ Everything is awesome!')
60 |
--------------------------------------------------------------------------------
/packages/prettyhtml-quick/lib/git.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const execa = require('execa')
4 | const path = require('path')
5 | const findUp = require('find-up')
6 |
7 | module.exports.detect = directory => {
8 | const gitDirectory = findUp.sync('.git', {cwd: directory, type: 'directory'})
9 | if (gitDirectory) {
10 | return path.dirname(gitDirectory)
11 | } else {
12 | throw new Error('Could not find git repository');
13 | }
14 | }
15 |
16 | const runGit = (directory, args) =>
17 | execa.sync('git', args, {
18 | cwd: directory
19 | })
20 |
21 | const getLines = execaResult => execaResult.stdout.split('\n')
22 |
23 | module.exports.getSinceRevision = (directory, opts) => {
24 | try {
25 | const revision = opts.staged
26 | ? 'HEAD'
27 | : runGit(directory, ['merge-base', 'HEAD', opts.branch || 'master']).stdout.trim()
28 | return runGit(directory, ['rev-parse', '--short', revision]).stdout.trim()
29 | } catch (error) {
30 | if (/HEAD/.test(error.message) || (opts.staged && /Needed a single revision/.test(error.message))) {
31 | return null
32 | }
33 | throw error
34 | }
35 | }
36 |
37 | module.exports.getChangedFiles = (directory, revision, staged) => {
38 | const a = getLines(
39 | runGit(
40 | directory,
41 | ['diff', '--name-only', staged ? '--cached' : null, '--diff-filter=ACMRTUB', revision].filter(Boolean)
42 | )
43 | )
44 |
45 | const b = staged ? [] : getLines(runGit(directory, ['ls-files', '--others', '--exclude-standard']))
46 |
47 | return a.concat(b).filter(Boolean)
48 | }
49 |
50 | module.exports.getUnstagedChangedFiles = directory => {
51 | return module.exports.getChangedFiles(directory, null, false)
52 | }
53 |
54 | module.exports.getStagedChangedFiles = directory => {
55 | return module.exports.getChangedFiles(directory, null, true)
56 | }
57 |
58 | module.exports.stageFile = (directory, file) => {
59 | runGit(directory, ['add', file])
60 | }
61 |
--------------------------------------------------------------------------------
/packages/prettyhtml-quick/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/prettyhtml-quick",
3 | "version": "0.10.1",
4 | "description": "",
5 | "main": "./bin/cli.js",
6 | "scripts": {
7 | "test": "echo 'no tests defined'"
8 | },
9 | "bin": {
10 | "prettyhtml-quick": "./bin/cli.js"
11 | },
12 | "files": [
13 | "lib",
14 | "bin"
15 | ],
16 | "keywords": [
17 | "prettyhtml",
18 | "git",
19 | "formatter",
20 | "html5"
21 | ],
22 | "author": "Dustin Deus (http://www.starptech.de)",
23 | "license": "MIT",
24 | "dependencies": {
25 | "@starptech/prettyhtml": "^0.10.0",
26 | "chalk": "^2.4.2",
27 | "commander": "^2.20.0",
28 | "execa": "^1.0.0",
29 | "find-up": "^4.1.0",
30 | "prettier": "^1.18.2"
31 | },
32 | "publishConfig": {
33 | "access": "public"
34 | },
35 | "gitHead": "878bd4ae77583429002b938671aab22fbfa4e622"
36 | }
37 |
--------------------------------------------------------------------------------
/packages/prettyhtml-sort-attributes/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/prettyhtml-sort-attributes
2 |
3 | Sort attributes alphabetically
4 |
5 | ## Installation
6 |
7 | ```
8 | npm install --save @starptech/prettyhtml-sort-attributes
9 | ```
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml-sort-attributes/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | var visit = require('unist-util-visit')
4 | var has = require('hast-util-has-property')
5 |
6 | module.exports = sort
7 |
8 | function sort() {
9 | return transform
10 | }
11 |
12 | function transform(tree) {
13 | visit(tree, 'element', reorder)
14 |
15 | function reorder(node) {
16 | var props = node.properties
17 | var index = -1
18 | var result = {}
19 | var prop
20 |
21 | var all = Object.keys(props).sort((left, right) => left.localeCompare(right))
22 |
23 | while (++index < all.length) {
24 | prop = all[index]
25 |
26 | if (has(node, prop)) {
27 | result[prop] = props[prop]
28 | }
29 | }
30 |
31 | node.properties = result
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml-sort-attributes/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/prettyhtml-sort-attributes",
3 | "version": "0.10.0",
4 | "description": "Sort attributes alphabetically",
5 | "main": "index.js",
6 | "scripts": {
7 | "test": "ava",
8 | "test-coverage": "nyc --reporter lcov ava"
9 | },
10 | "devDependencies": {
11 | "@starptech/prettyhtml-hastscript": "^0.10.0",
12 | "ava": "^2.1.0",
13 | "nyc": "^14.1.1",
14 | "rehype": "^8.0.0"
15 | },
16 | "dependencies": {
17 | "hast-util-has-property": "^1.0.3",
18 | "unist-util-visit": "^1.4.1"
19 | },
20 | "files": [
21 | "index.js"
22 | ],
23 | "nyc": {
24 | "check-coverage": true,
25 | "lines": 100,
26 | "functions": 100,
27 | "branches": 100
28 | },
29 | "keywords": [
30 | "prettyhtml",
31 | "rehype",
32 | "sort",
33 | "attributes"
34 | ],
35 | "author": "Dustin Deus (http://www.starptech.de)",
36 | "license": "MIT",
37 | "publishConfig": {
38 | "access": "public"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/packages/prettyhtml-sort-attributes/test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const test = require('ava')
4 | const rehype = require('rehype')
5 | const h = require('@starptech/prettyhtml-hastscript')
6 | const min = require('.')
7 |
8 | test('rehype-sort-attributes', function(t) {
9 | t.deepEqual(
10 | rehype().stringify(
11 | rehype()
12 | .use(min)
13 | .runSync(
14 | h(
15 | 'p',
16 | {
17 | z: 'foo',
18 | d: ['bar'],
19 | c: 'foo',
20 | b: 1,
21 | a: 'foo',
22 | 2: 2,
23 | 1: 1,
24 | '[foo]': 'foo'
25 | },
26 | [h('strong', { id: 'baz', className: ['qux'] }), h('em', { hidden: false, className: ['quux'] })]
27 | )
28 | )
29 | ),
30 | rehype().stringify(
31 | h(
32 | 'p',
33 | {
34 | 1: 1,
35 | 2: 2,
36 | '[foo]': 'foo',
37 | a: 'foo',
38 | b: 1,
39 | c: 'foo',
40 | d: ['bar'],
41 | z: 'foo'
42 | },
43 | [h('strong', { className: ['qux'], id: 'baz' }), h('em', { hidden: false, className: ['quux'] })]
44 | )
45 | )
46 | )
47 | })
48 |
--------------------------------------------------------------------------------
/packages/prettyhtml/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dustin Deus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/prettyhtml
2 |
3 | This is the primary tool to interact with the formatter. We provide cli and api.
4 |
5 | ## Installation
6 |
7 | ```
8 | npm install --save @starptech/prettyhtml
9 | ```
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml/cli/args.js:
--------------------------------------------------------------------------------
1 | const meow = require('meow')
2 |
3 | function args(prettierConfig = {}) {
4 | return meow(
5 | `
6 | Usage: prettyhtml [ ...] [options ...],
7 |
8 | Options:
9 |
10 | --tab-width Specify the number of spaces per indentation-level
11 | --print-width Specify the maximum line length
12 | --use-tabs Use tabs for indentation
13 | --single-quote Use single instead of double quotes
14 | --use-prettier Use prettier to format embedded content
15 | --wrapAttributes Force to wrap attributes (when it has multiple)
16 | --sortAttributes Sort attributes alphabetically
17 | --stdin Specify the standard stream as source (for pipe mode)
18 | --quiet Do not output anything for a file which has no warnings or errors
19 | --silent Do not output messages without fatal set to true
20 |
21 | Examples
22 | $ prettyhtml *.html
23 | $ prettyhtml *.html !example.html
24 | $ echo " " | prettyhtml --stdin
25 | $ echo " " --stdin ./test.html
26 | `,
27 | {
28 | autoHelp: true,
29 | autoVersion: true,
30 | flags: {
31 | tabWidth: {
32 | type: 'number',
33 | default: prettierConfig.tabWidth || 2
34 | },
35 | printWidth: {
36 | type: 'number',
37 | default: prettierConfig.printWidth || 80
38 | },
39 | useTabs: {
40 | type: 'boolean',
41 | default: prettierConfig.useTabs || false
42 | },
43 | singleQuote: {
44 | type: 'boolean',
45 | default: false
46 | },
47 | usePrettier: {
48 | type: 'boolean',
49 | default: true
50 | },
51 | wrapAttributes: {
52 | type: 'boolean',
53 | default: false
54 | },
55 | sortAttributes: {
56 | type: 'boolean',
57 | default: false
58 | },
59 | stdin: {
60 | type: 'boolean',
61 | default: false
62 | },
63 | quiet: {
64 | type: 'boolean',
65 | default: false
66 | },
67 | silent: {
68 | type: 'boolean',
69 | default: false
70 | }
71 | }
72 | }
73 | )
74 | }
75 |
76 | module.exports = args
77 |
--------------------------------------------------------------------------------
/packages/prettyhtml/cli/index.js:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env node
2 |
3 | 'use strict'
4 |
5 | const { PassThrough } = require('stream')
6 | const { basename } = require('path')
7 | const prettier = require('prettier')
8 | const engine = require('unified-engine')
9 | const unified = require('unified')
10 | const updateNotifier = require('update-notifier')
11 | const { configTransform, processResult } = require('./processor')
12 | const args = require('./args')
13 | const pkg = require('./../package')
14 |
15 | function getDefaultSettings() {
16 | const settings = {
17 | extensions: ['html'],
18 | streamError: new PassThrough(), // sink errors
19 | rcName: '.prettyhtmlrc',
20 | packageField: 'prettyhtml',
21 | ignoreName: '.prettyhtmlignore',
22 | frail: false
23 | }
24 | return settings
25 | }
26 |
27 | module.exports = { getDefaultSettings }
28 |
29 | // this was run directly from the command line
30 | if (require.main === module) {
31 | const notifier = updateNotifier({
32 | pkg: {
33 | name: 'prettyhtml',
34 | version: pkg.version
35 | },
36 | updateCheckInterval: 1000 * 60 * 60 * 24 * 7 // 1 week
37 | })
38 |
39 | notifier.notify({
40 | isGlobal: false,
41 | defer: false
42 | })
43 |
44 | const prettierConfig = prettier.resolveConfig.sync(process.cwd()) || {}
45 | const cli = args(prettierConfig)
46 | const settings = getDefaultSettings()
47 | settings.configTransform = configTransform
48 | settings.defaultConfig = configTransform({ prettierConfig, cli })
49 | settings.processor = unified()
50 |
51 | if (cli.flags.stdin === false) {
52 | if (cli.input.length === 0) {
53 | cli.showHelp()
54 | } else {
55 | settings.files = cli.input
56 | settings.output = true // Whether to overwrite the input files
57 | settings.out = false // Whether to write the processed file to streamOut
58 |
59 | engine(settings, processResult({ cli }))
60 | }
61 | } else {
62 | if (cli.input.length !== 0) {
63 | settings.output = basename(cli.input[0])
64 | }
65 | engine(settings, processResult({ cli }))
66 | }
67 | }
68 |
--------------------------------------------------------------------------------
/packages/prettyhtml/cli/processor.js:
--------------------------------------------------------------------------------
1 | const parse = require('@starptech/rehype-webparser')
2 | const stringify = require('@starptech/prettyhtml-formatter/stringify')
3 | const sortAttributes = require('@starptech/prettyhtml-sort-attributes')
4 | const format = require('@starptech/prettyhtml-formatter')
5 | const report = require('vfile-reporter')
6 |
7 | function processResult({ cli }) {
8 | return (err, code, result) => {
9 | const out = report(err || result.files, {
10 | quiet: cli.flags.quiet,
11 | silent: cli.flags.silent
12 | })
13 |
14 | if (out) {
15 | console.error(out)
16 | }
17 |
18 | // eslint-disable-next-line no-process-exit
19 | process.exit(code)
20 | }
21 | }
22 |
23 | function configTransform({ prettierConfig, cli }) {
24 | const plugins = [
25 | [
26 | parse,
27 | {
28 | ignoreFirstLf: false,
29 | decodeEntities: false,
30 | selfClosingCustomElements: true,
31 | selfClosingElements: true
32 | }
33 | ],
34 | [
35 | format,
36 | {
37 | tabWidth: cli.flags.tabWidth,
38 | useTabs: cli.flags.useTabs,
39 | singleQuote: cli.flags.singleQuote,
40 | usePrettier: cli.flags.usePrettier,
41 | prettier: prettierConfig
42 | }
43 | ]
44 | ]
45 |
46 | if (cli.flags.sortAttributes || prettierConfig.sortAttributes) {
47 | plugins.push([sortAttributes, {}])
48 | }
49 |
50 | plugins.push([
51 | stringify,
52 | {
53 | tabWidth: cli.flags.tabWidth,
54 | printWidth: cli.flags.printWidth,
55 | singleQuote: cli.flags.singleQuote,
56 | wrapAttributes: cli.flags.wrapAttributes
57 | }
58 | ])
59 |
60 | return { plugins }
61 | }
62 |
63 | module.exports = { configTransform, processResult }
64 |
--------------------------------------------------------------------------------
/packages/prettyhtml/index.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const VFile = require('vfile')
4 | const unified = require('unified')
5 | const parse = require('@starptech/rehype-webparser')
6 | const stringify = require('@starptech/prettyhtml-formatter/stringify')
7 | const format = require('@starptech/prettyhtml-formatter')
8 | const sortAttributes = require('@starptech/prettyhtml-sort-attributes')
9 |
10 | module.exports = prettyhtml
11 |
12 | function core(value, processor, options) {
13 | const file = new VFile(value)
14 | let proc = processor().use(format, {
15 | tabWidth: options.tabWidth,
16 | useTabs: options.useTabs,
17 | usePrettier: options.usePrettier,
18 | prettier: options.prettier
19 | })
20 |
21 | if (options.sortAttributes) {
22 | proc = proc.use(sortAttributes)
23 | }
24 |
25 | return proc
26 | .use(stringify, {
27 | wrapAttributes: options.wrapAttributes,
28 | printWidth: options.printWidth,
29 | tabWidth: options.tabWidth,
30 | useTabs: options.useTabs,
31 | singleQuote: options.singleQuote,
32 | closeSelfClosing: true,
33 | closeEmptyElements: true
34 | })
35 | .processSync(file)
36 | }
37 |
38 | function prettyhtml(value, options) {
39 | const opt = Object.assign({}, options)
40 | return core(
41 | value,
42 | unified()
43 | .use(parse, {
44 | ignoreFirstLf: false,
45 | decodeEntities: false,
46 | selfClosingCustomElements: true,
47 | selfClosingElements: true
48 | })
49 | .freeze(),
50 | opt
51 | )
52 | }
53 |
--------------------------------------------------------------------------------
/packages/prettyhtml/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/prettyhtml",
3 | "version": "0.10.0",
4 | "description": "Opinionated Web Component HTML formatter",
5 | "main": "index.js",
6 | "repository": {
7 | "type": "git",
8 | "url": "git+https://github.com/StarpTech/prettyhtml.git"
9 | },
10 | "bin": "cli/index.js",
11 | "types": "./index.d.ts",
12 | "scripts": {
13 | "test-coverage": "nyc --reporter lcov ava",
14 | "test": "ava"
15 | },
16 | "files": [
17 | "index.js",
18 | "cli",
19 | "index.d.ts"
20 | ],
21 | "keywords": [
22 | "formatter",
23 | "prettyhtml",
24 | "html5"
25 | ],
26 | "ava": {
27 | "files": [
28 | "test/**/*",
29 | "!test/test-helpers"
30 | ]
31 | },
32 | "author": "Dustin Deus (http://www.starptech.de)",
33 | "license": "MIT",
34 | "bugs": {
35 | "url": "https://github.com/StarpTech/prettyhtml/issues"
36 | },
37 | "homepage": "https://github.com/StarpTech/prettyhtml#readme",
38 | "dependencies": {
39 | "@starptech/prettyhtml-formatter": "^0.10.0",
40 | "@starptech/prettyhtml-sort-attributes": "^0.10.0",
41 | "@starptech/rehype-webparser": "^0.10.0",
42 | "@starptech/webparser": "^0.10.0",
43 | "meow": "^5.0.0",
44 | "prettier": "^1.18.2",
45 | "rehype-sort-attribute-values": "^2.0.1",
46 | "unified": "^7.1.0",
47 | "unified-engine": "^6.0.1",
48 | "update-notifier": "^3.0.0",
49 | "vfile": "^4.0.1",
50 | "vfile-reporter": "^6.0.0"
51 | },
52 | "publishConfig": {
53 | "access": "public"
54 | },
55 | "gitHead": "c7bfe5fdd9ef240ddf235e50a81be52b30828c8f",
56 | "devDependencies": {
57 | "ava": "^2.1.0",
58 | "nyc": "^14.1.1"
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/packages/prettyhtml/test-helpers/prepareVfile.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | module.exports = prepareVfile
4 |
5 | function prepareVfile(vfile) {
6 | // eslint-disable-next-line no-param-reassign
7 | vfile.cwd = 'skipped in tests'
8 | return vfile
9 | }
10 |
--------------------------------------------------------------------------------
/packages/prettyhtml/test-helpers/util.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | const { PassThrough } = require('stream')
4 |
5 | module.exports = spy
6 |
7 | function spy() {
8 | const stream = new PassThrough()
9 | const output = []
10 | const originalWrite = stream.write
11 |
12 | stream.write = write
13 |
14 | done.stream = stream
15 |
16 | return done
17 |
18 | function write(chunk, encoding, callback) {
19 | const cb = typeof encoding === 'function' ? encoding : callback
20 |
21 | if (typeof cb === 'function') {
22 | setImmediate(cb)
23 | }
24 |
25 | output.push(chunk)
26 | }
27 |
28 | function done() {
29 | stream.write = originalWrite
30 |
31 | return output.join('')
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/packages/prettyhtml/test/api.js:
--------------------------------------------------------------------------------
1 | // eslint-disable-next-line import/no-extraneous-dependencies
2 | const test = require('ava')
3 | const prettyhtml = require('..')
4 | const prepareVfile = require('../test-helpers/prepareVfile')
5 |
6 | test('Should format with default settings', t => {
7 | const result = prettyhtml(
8 | ``
9 | )
10 | t.snapshot(prepareVfile(result))
11 | })
12 |
--------------------------------------------------------------------------------
/packages/prettyhtml/test/snapshots/api.js.md:
--------------------------------------------------------------------------------
1 | # Snapshot report for `test/api.js`
2 |
3 | The actual snapshot is saved in `api.js.snap`.
4 |
5 | Generated by [AVA](https://ava.li).
6 |
7 | ## Should format with default settings
8 |
9 | > Snapshot 1
10 |
11 | VFile {
12 | contents: `␊
16 | `,
17 | cwd: 'skipped in tests',
18 | data: {},
19 | history: [],
20 | messages: [],
21 | }
22 |
--------------------------------------------------------------------------------
/packages/prettyhtml/test/snapshots/api.js.snap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Prettyhtml/prettyhtml/5db9a8b7357d57a1997b6c293a9eaaab8afd6108/packages/prettyhtml/test/snapshots/api.js.snap
--------------------------------------------------------------------------------
/packages/prettyhtml/test/snapshots/cli.js.md:
--------------------------------------------------------------------------------
1 | # Snapshot report for `test/cli.js`
2 |
3 | The actual snapshot is saved in `cli.js.snap`.
4 |
5 | Generated by [AVA](https://ava.li).
6 |
7 | ## Should format with default settings
8 |
9 | > Snapshot 1
10 |
11 | VFile {
12 | contents: `␊
16 | `,
17 | cwd: 'skipped in tests',
18 | data: {
19 | unifiedEngineGiven: true,
20 | unifiedEngineStreamIn: true,
21 | },
22 | history: [],
23 | messages: [],
24 | }
25 |
--------------------------------------------------------------------------------
/packages/prettyhtml/test/snapshots/cli.js.snap:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Prettyhtml/prettyhtml/5db9a8b7357d57a1997b6c293a9eaaab8afd6108/packages/prettyhtml/test/snapshots/cli.js.snap
--------------------------------------------------------------------------------
/packages/rehype-minify-whitespace/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dustin Deus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/rehype-minify-whitespace/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/rehype-minify-whitespace
2 |
3 | Collapse whitespace.
4 |
5 | Normally, collapses to a single space. If `newlines: true`,
6 | collapses white-space containing newlines to `'\n'` instead
7 | of `' '`.
8 |
9 | ## Installation
10 |
11 | ```
12 | npm install --save @starptech/rehype-minify-whitespace
13 | ```
14 |
15 | ## Usage
16 |
17 | ##### In
18 |
19 | ```html
20 | Heading
21 | ···→ →···foo···→
22 | This and that
23 | ```
24 |
25 | ##### Out
26 |
27 | ```html
28 | Heading
29 | foo
30 | This and that
31 | ```
32 |
33 | ## Api
34 |
35 | ###### `node.data.ignore`
36 |
37 | When this property is `true` the node is skipped for whitespace handling.
38 |
39 | ###### `node.data.preserveWhitespace`
40 |
41 | When this property is `true` the node is skipped for whitespace handling.
42 |
43 | ## Caveats
44 |
45 | The implementation is a modified version of [**Rehype rehype-minify-whitespace 2.0.3**](https://github.com/rehypejs/rehype-minify/tree/master/packages/rehype-minify-whitespace)
46 |
--------------------------------------------------------------------------------
/packages/rehype-minify-whitespace/list.js:
--------------------------------------------------------------------------------
1 | module.exports = [
2 | 'a',
3 | 'abbr',
4 | 'acronym',
5 | 'b',
6 | 'basefont',
7 | 'big',
8 | 'bdi',
9 | 'bdo',
10 | 'blink',
11 | 'button',
12 | 'cite',
13 | 'code',
14 | 'data',
15 | 'del',
16 | 'dfn',
17 | 'em',
18 | 'font',
19 | 'i',
20 | 'input',
21 | 'ins',
22 | 'kbd',
23 | 'keygen',
24 | 'label',
25 | 'mark',
26 | 'marquee',
27 | 'meter',
28 | 'nobr',
29 | 'output',
30 | 'progress',
31 | 'q',
32 | 'ruby',
33 | 's',
34 | 'samp',
35 | 'select',
36 | 'small',
37 | 'spacer',
38 | 'span',
39 | 'strong',
40 | 'sub',
41 | 'sup',
42 | 'textarea',
43 | 'time',
44 | 'tt',
45 | 'u',
46 | 'var',
47 | // vue
48 | 'template',
49 | // angular
50 | 'ng-container',
51 | 'ng-template'
52 | ]
53 |
--------------------------------------------------------------------------------
/packages/rehype-minify-whitespace/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/rehype-minify-whitespace",
3 | "version": "0.10.0",
4 | "description": "",
5 | "main": "index.js",
6 | "keywords": [
7 | "prettyhtml",
8 | "collapse",
9 | "whitespace"
10 | ],
11 | "author": "Dustin Deus (http://www.starptech.de)",
12 | "license": "ISC",
13 | "files": [
14 | "index.js",
15 | "list.js"
16 | ],
17 | "dependencies": {
18 | "collapse-white-space": "^1.0.5",
19 | "hast-util-embedded": "^1.0.4",
20 | "hast-util-has-property": "^1.0.3",
21 | "hast-util-is-body-ok-link": "^1.0.2",
22 | "hast-util-is-element": "^1.0.3",
23 | "html-whitespace-sensitive-tag-names": "^1.0.1",
24 | "unist-util-is": "^2.1.3",
25 | "unist-util-modify-children": "^1.1.4"
26 | },
27 | "devDependencies": {
28 | "@starptech/prettyhtml-hastscript": "^0.10.0",
29 | "ava": "^2.1.0",
30 | "nyc": "^14.1.1",
31 | "rehype": "^8.0.0"
32 | },
33 | "scripts": {
34 | "test": "ava",
35 | "test-coverage": "nyc --reporter lcov ava"
36 | },
37 | "nyc": {
38 | "check-coverage": true,
39 | "lines": 100,
40 | "functions": 100,
41 | "branches": 100
42 | },
43 | "publishConfig": {
44 | "access": "public"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/packages/rehype-minify-whitespace/test.js:
--------------------------------------------------------------------------------
1 | 'use strict'
2 |
3 | /* eslint-disable import/no-extraneous-dependencies */
4 |
5 | var test = require('ava')
6 | var rehype = require('rehype')
7 | var h = require('hastscript')
8 | var min = require('.')
9 |
10 | test('rehype-minify-whitespace', function(t) {
11 | t.deepEqual(
12 | rehype()
13 | .use(min)
14 | .runSync(
15 | h('main', [
16 | ' ',
17 | h('p', [' ', h('strong', 'foo'), ' ', h('em', 'bar'), ' ', h('meta', { itemProp: true }), ' ']),
18 | ' ',
19 | h('p', [h('a', { href: 'example.com' }, ' baz'), ' ', h('em', ' qux')]),
20 | ' '
21 | ])
22 | ),
23 | h('main', [
24 | h('p', [h('strong', 'foo'), ' ', h('em', 'bar'), ' ', h('meta', { itemProp: true })]),
25 | h('p', [h('a', { href: 'example.com' }, 'baz'), ' ', h('em', 'qux')])
26 | ])
27 | )
28 |
29 | t.deepEqual(
30 | rehype()
31 | .use(min)
32 | .runSync(
33 | h('head', [
34 | ' ',
35 | h('meta', { itemProp: true }),
36 | ' ',
37 | h('noscript', [' ', h('link', { rel: ['stylesheet'], href: 'index.css' }), ' '])
38 | ])
39 | ),
40 | h('head', [
41 | h('meta', { itemProp: true }),
42 | h('noscript', [h('link', { rel: ['stylesheet'], href: 'index.css' })])
43 | ])
44 | )
45 |
46 | t.deepEqual(
47 | rehype()
48 | .use(min, { newlines: true })
49 | .runSync(
50 | h('main', [
51 | ' ',
52 | h('p', [
53 | '\n ',
54 | h('strong', 'foo'),
55 | ' ',
56 | h('em', 'bar'),
57 | ' \n',
58 | h('meta', { itemProp: true }),
59 | ' \n'
60 | ]),
61 | ' \n',
62 | h('p', [h('a', { href: 'example.com' }, ' baz'), ' ', h('em', ' qux')]),
63 | ' '
64 | ])
65 | ),
66 | h('main', [
67 | h('p', [h('strong', 'foo'), ' ', h('em', 'bar'), '\n', h('meta', { itemProp: true })]),
68 | h('p', [h('a', { href: 'example.com' }, 'baz'), ' ', h('em', 'qux')])
69 | ])
70 | )
71 | })
72 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dustin Deus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/rehype-webparser
2 |
3 | Parses HTML via [**Webparser**](https://github.com/Prettyhtml/prettyhtml/tree/master/packages/webparser) to a [**HAST**](https://github.com/syntax-tree/hast) syntax tree.
4 |
5 | ## Installation
6 |
7 | ```
8 | npm install --save @starptech/rehype-webparser
9 | ```
10 |
11 | ## Usage
12 |
13 | This example shows how we parse HTML with [**Webparser**](https://github.com/Prettyhtml/prettyhtml/blob/master/packages/webparser) transform it into [**HAST**](https://github.com/syntax-tree/hast) compatible structure and finally compile that data back to HTML with [hast-util-to-html](https://github.com/syntax-tree/hast-util-to-html).
14 |
15 | Say we have the following file, `example.html`:
16 |
17 | ```html
18 |
19 | Hello!
20 | World!
21 | ```
22 |
23 | And our script, `example.js`, looks as follows:
24 |
25 | ```javascript
26 | const vfile = require('to-vfile')
27 | const report = require('vfile-reporter')
28 | const unified = require('unified')
29 | const parse = require('@starptech/rehype-webparser')
30 | const toHTML = require('hast-util-to-html')
31 |
32 | // A compiler is needed to inform unified how to transform it back to HTML
33 | function stringify() {
34 | this.Compiler = compiler
35 |
36 | function compiler(tree) {
37 | return toHTML(tree)
38 | }
39 | }
40 |
41 | unified()
42 | .use(parse)
43 | //.use(yourPlugin)
44 | .use(stringify)
45 | .process(vfile.readSync('example.html'), function(err, file) {
46 | console.error(report(err || file))
47 | console.log(String(file))
48 | })
49 | ```
50 |
51 | Now, running `node example` yields:
52 |
53 | ```text
54 |
55 | Hello!
56 | World!
57 | ```
58 |
59 | ## API
60 |
61 | ### `processor.use(webparser[, options])`
62 |
63 | Configure the `processor` to read HTML as input and process a
64 | [**HAST**](https://github.com/syntax-tree/hast) syntax tree.
65 |
66 | ###### `options.*`
67 |
68 | [**Webparser**](https://github.com/Prettyhtml/prettyhtml/blob/master/packages/webparser) options.
69 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | globals: {
3 | 'ts-jest': {
4 | tsConfig: 'tsconfig.json'
5 | }
6 | },
7 | moduleFileExtensions: ['ts', 'js'],
8 | transform: {
9 | '^.+\\.(ts|tsx)$': 'ts-jest'
10 | },
11 | testMatch: ['**/test/**/*.test.ts'],
12 | testEnvironment: 'node'
13 | }
14 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/rehype-webparser",
3 | "version": "0.10.0",
4 | "description": "",
5 | "main": "./dist/index.js",
6 | "scripts": {
7 | "start": "ts-node index.ts",
8 | "build-ts": "tsc",
9 | "watch-ts": "tsc -w",
10 | "test": "jest --forceExit --detectOpenHandles",
11 | "test-coverage": "yarn run test -- --coverage",
12 | "tslint": "tslint -c tslint.json -p tsconfig.json",
13 | "prepublish": "yarn run build-ts"
14 | },
15 | "files": [
16 | "index.ts",
17 | "dist"
18 | ],
19 | "keywords": [
20 | "webparser",
21 | "parser",
22 | "rehype"
23 | ],
24 | "author": "Dustin Deus (http://www.starptech.de)",
25 | "license": "MIT",
26 | "dependencies": {
27 | "@starptech/hast-util-from-webparser": "^0.10.0",
28 | "@starptech/webparser": "^0.10.0"
29 | },
30 | "devDependencies": {
31 | "jest": "^24.8.0",
32 | "ts-jest": "^24.0.2",
33 | "ts-node": "^8.3.0",
34 | "tslint": "^5.17.0",
35 | "tslint-eslint-rules": "^5.4.0",
36 | "typescript": "^3.5.2",
37 | "vrsource-tslint-rules": "^6.0.0"
38 | },
39 | "publishConfig": {
40 | "access": "public"
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/test/index.test.ts:
--------------------------------------------------------------------------------
1 | import parse from '../index'
2 |
3 | test('Simple', () => {
4 | const parser: any = {}
5 | parse.bind(parser)()
6 |
7 | expect(parser.Parser).toBeInstanceOf(Function)
8 | })
9 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "esModuleInterop": true,
5 | "target": "es6",
6 | "noImplicitAny": true,
7 | "moduleResolution": "node",
8 | "sourceMap": true,
9 | "outDir": "dist",
10 | "baseUrl": "."
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/packages/rehype-webparser/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/vrsource-tslint-rules/rules",
4 | "node_modules/tslint-eslint-rules/dist/rules"
5 | ],
6 | "rules": {
7 | "no-console": [
8 | true,
9 | "log"
10 | ],
11 | "no-duplicate-imports": true,
12 | "no-duplicate-variable": true,
13 | "no-jasmine-focus": true,
14 | "no-var-keyword": true,
15 | "semicolon": [
16 | false
17 | ],
18 | "variable-name": [
19 | true,
20 | "ban-keywords"
21 | ],
22 | "no-inner-declarations": [
23 | true,
24 | "function"
25 | ],
26 | "no-debugger": true
27 | },
28 | "jsRules": {
29 | "no-console": [
30 | true,
31 | "log"
32 | ],
33 | "no-duplicate-imports": true,
34 | "no-duplicate-variable": true,
35 | "no-jasmine-focus": true,
36 | "semicolon": [
37 | false
38 | ],
39 | "variable-name": [
40 | true,
41 | "ban-keywords"
42 | ],
43 | "no-inner-declarations": [
44 | true,
45 | "function"
46 | ]
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/packages/webparser/.npmignore:
--------------------------------------------------------------------------------
1 | coverage
2 |
--------------------------------------------------------------------------------
/packages/webparser/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2018 Dustin Deus
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/packages/webparser/README.md:
--------------------------------------------------------------------------------
1 | # @starptech/webparser
2 |
3 | Optimized html parser for HTML5 Web Components.
4 | The parser supports features which are very useful if you want to implement a HTML formatter or anything else where a less strict parser is needed to keep all informations in the ast.
5 |
6 | ## Installation
7 |
8 | ```
9 | npm install --save @starptech/webparser
10 | ```
11 |
12 | ## Usage
13 |
14 | This example shows how we parse HTML
15 |
16 | ```js
17 | const parser = new HtmlParser(options)
18 | const result = parser.parse('
')
19 | ```
20 |
21 | ## Representation
22 |
23 | There are four different types of nodes
24 |
25 | - Doctype
26 |
27 | ```js
28 | {
29 | value: '',
30 | sourceSpan: null
31 | }
32 | ```
33 |
34 | - Element
35 |
36 | ```js
37 | {
38 | name: 'div',
39 | attrs: [],
40 | children: [],
41 | implicitNs: false,
42 | sourceSpan: null,
43 | startSourceSpan: null,
44 | endSourceSpan
45 | }
46 | ```
47 |
48 | Void or self-closing elements can be checked when the `startSourceSpan` is equals the `endSourceSpan`.
49 |
50 | - Attribute
51 |
52 | ```js
53 | {
54 | name: 'div',
55 | value: 'foo',
56 | children: [],
57 | implicitNs: false,
58 | sourceSpan:null,
59 | valueSpan: null
60 | }
61 | ```
62 |
63 | - Comment
64 |
65 | ```js
66 | {
67 | value: 'foo comment',
68 | sourceSpan: null
69 | }
70 | ```
71 |
72 | ## API
73 |
74 | ##### `HtmlParser.parse(doc: string): ParseTreeResult`
75 |
76 | Parse a document and returns a `ParseTreeResult` result.
77 |
78 | ###### `options.decodeEntities` (enabled by default)
79 |
80 | Decode html entities in text and attributes according to HTML5 specification.
81 |
82 | ###### `options.ignoreFirstLf` (enabled by default)
83 |
84 | Ignore first line feed of `pre`, `textarea` and `listing` tags according to HTML5 specification.
85 |
86 | ###### `options.selfClosingCustomElements` (disabled by default)
87 |
88 | Allow custom self-closing elements.
89 |
90 | ###### `options.selfClosingElements` (disabled by default)
91 |
92 | Allow custom and known self closing HTML elements.
93 |
94 | ###### `options.insertRequiredParents` (disabled by default)
95 |
96 | Insert the required parent element according to the HTML5 specification.
97 |
98 | ## Credits
99 |
100 | The parser is a modificated version of [Angular 6](https://github.com/angular/angular) template parser.
101 |
--------------------------------------------------------------------------------
/packages/webparser/jest.config.js:
--------------------------------------------------------------------------------
1 | module.exports = {
2 | globals: {
3 | 'ts-jest': {
4 | tsConfig: 'tsconfig.json'
5 | }
6 | },
7 | moduleFileExtensions: ['ts', 'js'],
8 | transform: {
9 | '^.+\\.(ts|tsx)$': 'ts-jest'
10 | },
11 | testMatch: ['**/test/**/*.spec.ts'],
12 | testEnvironment: 'node'
13 | }
14 |
--------------------------------------------------------------------------------
/packages/webparser/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "@starptech/webparser",
3 | "version": "0.10.0",
4 | "description": "Optimized html parser for HTML5 Web Components.",
5 | "main": "./dist/public_api.js",
6 | "scripts": {
7 | "build-ts": "tsc",
8 | "watch-ts": "tsc -w",
9 | "test": "jest --forceExit --detectOpenHandles",
10 | "test-coverage": "yarn run test -- --coverage",
11 | "tslint": "tslint -c tslint.json -p tsconfig.json",
12 | "prepublish": "yarn run build-ts"
13 | },
14 | "files": [
15 | "dist"
16 | ],
17 | "keywords": [
18 | "formatter",
19 | "webparser",
20 | "parser",
21 | "htmlparser",
22 | "html5"
23 | ],
24 | "author": "Dustin Deus (http://www.starptech.de)",
25 | "license": "MIT",
26 | "devDependencies": {
27 | "jest": "^24.8.0",
28 | "ts-jest": "^24.0.2",
29 | "ts-node": "^8.3.0",
30 | "tslint": "^5.17.0",
31 | "tslint-eslint-rules": "^5.4.0",
32 | "typescript": "^3.5.2",
33 | "vrsource-tslint-rules": "^6.0.0"
34 | },
35 | "publishConfig": {
36 | "access": "public"
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/packages/webparser/src/assertions.ts:
--------------------------------------------------------------------------------
1 | export function assertArrayOfStrings(identifier: string, value: any) {
2 | if (value == null) {
3 | return
4 | }
5 | if (!Array.isArray(value)) {
6 | throw new Error(`Expected '${identifier}' to be an array of strings.`)
7 | }
8 | for (let i = 0; i < value.length; i += 1) {
9 | if (typeof value[i] !== 'string') {
10 | throw new Error(`Expected '${identifier}' to be an array of strings.`)
11 | }
12 | }
13 | }
14 |
15 | const INTERPOLATION_BLACKLIST_REGEXPS = [
16 | /^\s*$/, // empty
17 | /[<>]/, // html tag
18 | /^[{}]$/, // i18n expansion
19 | /&(#|[a-z])/i, // character reference,
20 | /^\/\// // comment
21 | ]
22 |
23 | export function assertInterpolationSymbols(identifier: string, value: any): void {
24 | if (value != null && !(Array.isArray(value) && value.length == 2)) {
25 | throw new Error(`Expected '${identifier}' to be an array, [start, end].`)
26 | } else if (value != null) {
27 | const start = value[0] as string
28 | const end = value[1] as string
29 | // black list checking
30 | INTERPOLATION_BLACKLIST_REGEXPS.forEach(regexp => {
31 | if (regexp.test(start) || regexp.test(end)) {
32 | throw new Error(`['${start}', '${end}'] contains unusable interpolation symbol.`)
33 | }
34 | })
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/packages/webparser/src/ast_path.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * A path is an ordered set of elements. Typically a path is to a
3 | * particular offset in a source file. The head of the list is the top
4 | * most node. The tail is the node that contains the offset directly.
5 | *
6 | * For example, the expression `a + b + c` might have an ast that looks
7 | * like:
8 | * +
9 | * / \
10 | * a +
11 | * / \
12 | * b c
13 | *
14 | * The path to the node at offset 9 would be `['+' at 1-10, '+' at 7-10,
15 | * 'c' at 9-10]` and the path the node at offset 1 would be
16 | * `['+' at 1-10, 'a' at 1-2]`.
17 | */
18 | export class AstPath {
19 | constructor(private path: T[], public position: number = -1) {}
20 |
21 | get empty(): boolean {
22 | return !this.path || !this.path.length
23 | }
24 | get head(): T | undefined {
25 | return this.path[0]
26 | }
27 | get tail(): T | undefined {
28 | return this.path[this.path.length - 1]
29 | }
30 |
31 | parentOf(node: T | undefined): T | undefined {
32 | return node && this.path[this.path.indexOf(node) - 1]
33 | }
34 | childOf(node: T): T | undefined {
35 | return this.path[this.path.indexOf(node) + 1]
36 | }
37 |
38 | first(ctor: { new (...args: any[]): N }): N | undefined {
39 | for (let i = this.path.length - 1; i >= 0; i--) {
40 | let item = this.path[i]
41 | if (item instanceof ctor) return item
42 | }
43 | }
44 |
45 | push(node: T) {
46 | this.path.push(node)
47 | }
48 |
49 | pop(): T {
50 | return this.path.pop()!
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/packages/webparser/src/ast_spec_utils.ts:
--------------------------------------------------------------------------------
1 | import * as html from './ast'
2 | import { ParseTreeResult } from './html_parser'
3 | import { ParseLocation } from './parse_util'
4 |
5 | export function humanizeDom(parseResult: ParseTreeResult, addSourceSpan: boolean = false): any[] {
6 | if (parseResult.errors.length > 0) {
7 | const errorString = parseResult.errors.join('\n')
8 | throw new Error(`Unexpected parse errors:\n${errorString}`)
9 | }
10 |
11 | return humanizeNodes(parseResult.rootNodes, addSourceSpan)
12 | }
13 |
14 | export function humanizeDomSourceSpans(parseResult: ParseTreeResult): any[] {
15 | return humanizeDom(parseResult, true)
16 | }
17 |
18 | export function humanizeNodes(nodes: html.Node[], addSourceSpan: boolean = false): any[] {
19 | const humanizer = new _Humanizer(addSourceSpan)
20 | html.visitAll(humanizer, nodes)
21 | return humanizer.result
22 | }
23 |
24 | export function humanizeLineColumn(location: ParseLocation): string {
25 | return `${location.line}:${location.col}`
26 | }
27 |
28 | class _Humanizer implements html.Visitor {
29 | result: any[] = []
30 | elDepth: number = 0
31 |
32 | constructor(private includeSourceSpan: boolean) {}
33 |
34 | visitElement(element: html.Element, context: any): any {
35 | const input: any = [html.Element, element.name, this.elDepth++]
36 |
37 | if (element.implicitNs) {
38 | input.push(element.implicitNs)
39 | }
40 |
41 | const res = this._appendContext(element, input)
42 | this.result.push(res)
43 | html.visitAll(this, element.attrs)
44 | html.visitAll(this, element.children)
45 | this.elDepth--
46 | }
47 |
48 | visitAttribute(attribute: html.Attribute, context: any): any {
49 | const res = this._appendContext(attribute, [html.Attribute, attribute.name, attribute.value])
50 | this.result.push(res)
51 | }
52 |
53 | visitText(text: html.Text, context: any): any {
54 | const res = this._appendContext(text, [html.Text, text.value, this.elDepth])
55 | this.result.push(res)
56 | }
57 |
58 | visitComment(comment: html.Comment, context: any): any {
59 | const res = this._appendContext(comment, [html.Comment, comment.value, this.elDepth])
60 | this.result.push(res)
61 | }
62 |
63 | visitDoctype(doctype: html.Doctype, context: any): any {
64 | const res = this._appendContext(doctype, [html.Doctype, doctype.value, this.elDepth])
65 | this.result.push(res)
66 | }
67 |
68 | private _appendContext(ast: html.Node, input: any[]): any[] {
69 | if (!this.includeSourceSpan) return input
70 | input.push(ast.sourceSpan!.toString())
71 | return input
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/packages/webparser/src/chars.ts:
--------------------------------------------------------------------------------
1 | export const $EOF = 0
2 | export const $TAB = 9
3 | export const $LF = 10
4 | export const $VTAB = 11
5 | export const $FF = 12
6 | export const $CR = 13
7 | export const $SPACE = 32
8 | export const $BANG = 33
9 | export const $DQ = 34
10 | export const $HASH = 35
11 | export const $$ = 36
12 | export const $PERCENT = 37
13 | export const $AMPERSAND = 38
14 | export const $SQ = 39
15 | export const $LPAREN = 40
16 | export const $RPAREN = 41
17 | export const $STAR = 42
18 | export const $PLUS = 43
19 | export const $COMMA = 44
20 | export const $MINUS = 45
21 | export const $PERIOD = 46
22 | export const $SLASH = 47
23 | export const $COLON = 58
24 | export const $SEMICOLON = 59
25 | export const $LT = 60
26 | export const $EQ = 61
27 | export const $GT = 62
28 | export const $QUESTION = 63
29 |
30 | export const $0 = 48
31 | export const $9 = 57
32 |
33 | export const $A = 65
34 | export const $E = 69
35 | export const $F = 70
36 | export const $X = 88
37 | export const $Z = 90
38 |
39 | export const $LBRACKET = 91
40 | export const $BACKSLASH = 92
41 | export const $RBRACKET = 93
42 | export const $CARET = 94
43 | export const $_ = 95
44 |
45 | export const $a = 97
46 | export const $e = 101
47 | export const $f = 102
48 | export const $n = 110
49 | export const $r = 114
50 | export const $t = 116
51 | export const $u = 117
52 | export const $v = 118
53 | export const $x = 120
54 | export const $z = 122
55 |
56 | export const $LBRACE = 123
57 | export const $BAR = 124
58 | export const $RBRACE = 125
59 | export const $NBSP = 160
60 |
61 | export const $PIPE = 124
62 | export const $TILDA = 126
63 | export const $AT = 64
64 |
65 | export const $BT = 96
66 |
67 | export function isWhitespace(code: number): boolean {
68 | return (code >= $TAB && code <= $SPACE) || code == $NBSP
69 | }
70 |
71 | export function isDigit(code: number): boolean {
72 | return $0 <= code && code <= $9
73 | }
74 |
75 | export function isAsciiLetter(code: number): boolean {
76 | return (code >= $a && code <= $z) || (code >= $A && code <= $Z)
77 | }
78 |
79 | export function isAsciiHexDigit(code: number): boolean {
80 | return (code >= $a && code <= $f) || (code >= $A && code <= $F) || isDigit(code)
81 | }
82 |
--------------------------------------------------------------------------------
/packages/webparser/src/html_parser.ts:
--------------------------------------------------------------------------------
1 | import { getHtmlTagDefinition } from './html_tags'
2 | import { DEFAULT_INTERPOLATION_CONFIG, InterpolationConfig } from './interpolation_config'
3 | import { ParseTreeResult, Parser, ParserOptions } from './parser'
4 |
5 | export { ParseTreeResult, TreeError } from './parser'
6 |
7 | export class HtmlParser extends Parser {
8 | constructor(
9 | public options: ParserOptions = {
10 | decodeEntities: true,
11 | ignoreFirstLf: true,
12 | insertRequiredParents: false,
13 | selfClosingElements: false,
14 | selfClosingCustomElements: false
15 | }
16 | ) {
17 | super(options, getHtmlTagDefinition)
18 | }
19 |
20 | parse(
21 | source: string,
22 | url: string,
23 | interpolationConfig: InterpolationConfig = DEFAULT_INTERPOLATION_CONFIG
24 | ): ParseTreeResult {
25 | return super.parse(source, url, interpolationConfig)
26 | }
27 | }
28 |
--------------------------------------------------------------------------------
/packages/webparser/src/interpolation_config.ts:
--------------------------------------------------------------------------------
1 | import { assertInterpolationSymbols } from './assertions'
2 |
3 | export class InterpolationConfig {
4 | static fromArray(markers: [string, string] | null): InterpolationConfig {
5 | if (!markers) {
6 | return DEFAULT_INTERPOLATION_CONFIG
7 | }
8 |
9 | assertInterpolationSymbols('interpolation', markers)
10 | return new InterpolationConfig(markers[0], markers[1])
11 | }
12 |
13 | constructor(public start: string, public end: string) {}
14 | }
15 |
16 | export const DEFAULT_INTERPOLATION_CONFIG: InterpolationConfig = new InterpolationConfig('{{', '}}')
17 |
--------------------------------------------------------------------------------
/packages/webparser/src/public_api.ts:
--------------------------------------------------------------------------------
1 | /**
2 | * @module
3 | * @description
4 | * Entry point for all APIs of the parser package.
5 | *
6 | */
7 |
8 | export * from './html_parser'
9 | export * from './ast'
10 | export * from './parse_util'
11 | export * from './tags'
12 |
--------------------------------------------------------------------------------
/packages/webparser/tsconfig.json:
--------------------------------------------------------------------------------
1 | {
2 | "compilerOptions": {
3 | "module": "commonjs",
4 | "esModuleInterop": true,
5 | "target": "es6",
6 | "noImplicitAny": true,
7 | "moduleResolution": "node",
8 | "declaration": true,
9 | "sourceMap": true,
10 | "outDir": "dist",
11 | "baseUrl": "."
12 | },
13 | "include": ["src/**/*"]
14 | }
15 |
--------------------------------------------------------------------------------
/packages/webparser/tslint.json:
--------------------------------------------------------------------------------
1 | {
2 | "rulesDirectory": [
3 | "node_modules/vrsource-tslint-rules/rules",
4 | "node_modules/tslint-eslint-rules/dist/rules"
5 | ],
6 | "rules": {
7 | "no-console": [
8 | true,
9 | "log"
10 | ],
11 | "no-duplicate-imports": true,
12 | "no-duplicate-variable": true,
13 | "no-jasmine-focus": true,
14 | "no-var-keyword": true,
15 | "semicolon": [
16 | false
17 | ],
18 | "variable-name": [
19 | true,
20 | "ban-keywords"
21 | ],
22 | "no-inner-declarations": [
23 | true,
24 | "function"
25 | ],
26 | "no-debugger": true
27 | },
28 | "jsRules": {
29 | "no-console": [
30 | true,
31 | "log"
32 | ],
33 | "no-duplicate-imports": true,
34 | "no-duplicate-variable": true,
35 | "no-jasmine-focus": true,
36 | "semicolon": [
37 | false
38 | ],
39 | "variable-name": [
40 | true,
41 | "ban-keywords"
42 | ],
43 | "no-inner-declarations": [
44 | true,
45 | "function"
46 | ]
47 | }
48 | }
49 |
--------------------------------------------------------------------------------