2017-01-12 15:59:32 +03:00
|
|
|
<meta charset="utf-8">
|
|
|
|
<title>Prettier</title>
|
|
|
|
|
2017-01-11 21:22:12 +03:00
|
|
|
<script>global = window;</script>
|
2017-01-19 01:24:42 +03:00
|
|
|
<script>Buffer = {isBuffer: function() { return false; }};</script>
|
2017-01-11 21:22:12 +03:00
|
|
|
<script src="prettier.min.js"></script>
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="https://codemirror.net/lib/codemirror.css">
|
2017-01-14 01:14:48 +03:00
|
|
|
<link rel="stylesheet" href="https://codemirror.net/theme/base16-dark.css">
|
2017-01-11 21:22:12 +03:00
|
|
|
<script src="https://codemirror.net/lib/codemirror.js"></script>
|
|
|
|
<script src="https://codemirror.net/mode/javascript/javascript.js"></script>
|
|
|
|
<script src="https://codemirror.net/addon/display/rulers.js"></script>
|
2017-01-14 01:14:48 +03:00
|
|
|
<script src="https://codemirror.net/addon/search/searchcursor.js"></script>
|
|
|
|
<script src="https://codemirror.net/addon/edit/matchbrackets.js"></script>
|
|
|
|
<script src="https://codemirror.net/addon/edit/closebrackets.js"></script>
|
|
|
|
<script src="https://codemirror.net/addon/comment/comment.js"></script>
|
|
|
|
<script src="https://codemirror.net/addon/wrap/hardwrap.js"></script>
|
|
|
|
<script src="https://codemirror.net/keymap/sublime.js"></script>
|
2017-01-11 21:22:12 +03:00
|
|
|
|
|
|
|
<style type="text/css">
|
|
|
|
html, body {
|
|
|
|
font-family: "Helvetica Neue", "Open Sans", sans-serif;
|
|
|
|
font-size: 11.7px;
|
|
|
|
margin: 0;
|
|
|
|
padding: 0;
|
|
|
|
background-color: #444444;
|
|
|
|
color: #e2e1e1;
|
|
|
|
}
|
|
|
|
.title {
|
|
|
|
font-style: italic;
|
|
|
|
line-height: 19px;
|
|
|
|
margin-right: 10px;
|
|
|
|
}
|
|
|
|
.container {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
height: 100%;
|
|
|
|
}
|
|
|
|
.editors {
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
flex: 1;
|
|
|
|
margin: 5px;
|
|
|
|
}
|
|
|
|
.editor {
|
|
|
|
display: flex;
|
|
|
|
flex: 1;
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
.CodeMirror {
|
|
|
|
height: auto;
|
|
|
|
position: absolute;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
|
|
|
right: 0;
|
|
|
|
bottom: 0;
|
|
|
|
font-family: Menlo, monospace;
|
|
|
|
font-size: 11.05px;
|
|
|
|
line-height: 17.68px;
|
|
|
|
}
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
.editor {
|
|
|
|
margin-left: 5px;
|
|
|
|
}
|
|
|
|
.editor:first-child {
|
|
|
|
margin-left: 0;
|
2017-01-11 21:22:12 +03:00
|
|
|
}
|
|
|
|
.options {
|
|
|
|
display: flex;
|
|
|
|
margin: 5px;
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
2017-01-14 01:14:48 +03:00
|
|
|
.title a {
|
|
|
|
color: #e2e1e1;
|
|
|
|
}
|
|
|
|
.title a:hover {
|
|
|
|
color: #fdfcfc;
|
|
|
|
}
|
2017-01-11 21:22:12 +03:00
|
|
|
label {
|
|
|
|
margin-right: 5px;
|
|
|
|
}
|
|
|
|
input[type="number"] {
|
|
|
|
max-width: 40px;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
|
|
|
<div class="container">
|
|
|
|
<div class="options">
|
2017-01-19 01:24:42 +03:00
|
|
|
<label class="title"><a href="https://github.com/jlongster/prettier">prettier v<span class="version"></span></a></label>
|
2017-01-11 21:22:12 +03:00
|
|
|
<label><input type="number" value="80" id="printWidth"></input> printWidth</label>
|
|
|
|
<label><input type="number" value="2" id="tabWidth"></input> tabWidth</label>
|
2017-04-13 19:31:37 +03:00
|
|
|
<label><input type="checkbox" id="useTabs"></input> useTabs</label>
|
|
|
|
<label><input type="checkbox" id="semi" checked></input> semi</label>
|
2017-01-11 21:22:12 +03:00
|
|
|
<label><input type="checkbox" id="singleQuote"></input> singleQuote</label>
|
|
|
|
<label><input type="checkbox" id="bracketSpacing" checked></input> bracketSpacing</label>
|
2017-02-13 20:57:05 +03:00
|
|
|
<label><input type="checkbox" id="jsxBracketSameLine"></input> jsxBracketSameLine</label>
|
2017-02-28 01:02:41 +03:00
|
|
|
<label>trailingComma <select id="trailingComma"><option value="none">none</option><option value="es5">es5</option><option value="all">all</option></select></label>
|
|
|
|
<label>parser <select id="parser"><option value="babylon">babylon</option><option value="flow">flow</option></select></label>
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
<span style="flex: 1"></span>
|
|
|
|
<label><input type="checkbox" id="doc"></input> doc</label>
|
2017-01-11 21:22:12 +03:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="editors">
|
|
|
|
<div class="editor input">
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
<textarea id="input-editor"></textarea>
|
|
|
|
</div>
|
|
|
|
<div class="editor doc">
|
|
|
|
<textarea id="doc-editor"></textarea>
|
2017-01-11 21:22:12 +03:00
|
|
|
</div>
|
|
|
|
<div class="editor output">
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
<textarea id="output-editor"></textarea>
|
2017-01-11 21:22:12 +03:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<script id="code">
|
2017-04-13 19:31:37 +03:00
|
|
|
var OPTIONS = ['printWidth', 'tabWidth', 'singleQuote', 'trailingComma', 'bracketSpacing', 'jsxBracketSameLine', 'parser', 'semi', 'useTabs', 'doc'];
|
2017-01-11 21:22:12 +03:00
|
|
|
function setOptions(options) {
|
|
|
|
OPTIONS.forEach(function(option) {
|
|
|
|
var elem = document.getElementById(option);
|
2017-02-28 01:02:41 +03:00
|
|
|
if (elem.tagName === 'SELECT') {
|
|
|
|
elem.value = options[option];
|
|
|
|
} else if (elem.type === 'number') {
|
2017-01-11 21:22:12 +03:00
|
|
|
elem.value = options[option];
|
|
|
|
} else {
|
|
|
|
elem.checked = options[option];
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getOptions() {
|
|
|
|
var options = {};
|
|
|
|
OPTIONS.forEach(function(option) {
|
|
|
|
var elem = document.getElementById(option);
|
2017-02-28 01:02:41 +03:00
|
|
|
if (elem.tagName === 'SELECT') {
|
|
|
|
options[option] = elem.value;
|
|
|
|
} else if (elem.type === 'number') {
|
|
|
|
options[option] = Number(elem.value);
|
|
|
|
} else {
|
|
|
|
options[option] = elem.checked;
|
|
|
|
}
|
2017-01-11 21:22:12 +03:00
|
|
|
});
|
|
|
|
return options;
|
|
|
|
}
|
|
|
|
|
2017-04-16 21:32:06 +03:00
|
|
|
function omitNonFormatterOptions(options) {
|
|
|
|
var optionsClone = Object.assign({}, options);
|
|
|
|
delete optionsClone.doc;
|
|
|
|
return optionsClone;
|
|
|
|
}
|
|
|
|
|
2017-02-15 08:02:17 +03:00
|
|
|
function replaceHash(hash) {
|
|
|
|
if (
|
|
|
|
typeof URL === "function" &&
|
|
|
|
typeof history === "object" &&
|
|
|
|
typeof history.replaceState === "function"
|
|
|
|
) {
|
|
|
|
var url = new URL(location);
|
|
|
|
url.hash = hash;
|
|
|
|
history.replaceState(null, null, url);
|
|
|
|
} else {
|
|
|
|
location.hash = hash;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-11 21:22:12 +03:00
|
|
|
function format() {
|
|
|
|
var options = getOptions();
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
[docEditor, outputEditor].forEach(function(editor) {
|
|
|
|
editor.setOption(
|
|
|
|
'rulers',
|
|
|
|
[{column: options.printWidth, color: '#444444'}]
|
|
|
|
);
|
|
|
|
});
|
|
|
|
document.getElementsByClassName('doc')[0].style.display = options.doc ? 'flex' : 'none';
|
|
|
|
|
2017-01-11 21:22:12 +03:00
|
|
|
var value = encodeURIComponent(
|
|
|
|
JSON.stringify(
|
|
|
|
Object.assign({content: inputEditor.getValue(), options: options})
|
|
|
|
)
|
|
|
|
);
|
2017-02-15 08:02:17 +03:00
|
|
|
replaceHash(value);
|
2017-04-16 21:32:06 +03:00
|
|
|
var formatterOptions = omitNonFormatterOptions(options);
|
2017-01-11 21:22:12 +03:00
|
|
|
var res;
|
|
|
|
try {
|
2017-04-16 21:32:06 +03:00
|
|
|
res = prettier.format(inputEditor.getValue(), formatterOptions);
|
2017-01-11 21:22:12 +03:00
|
|
|
} catch (e) {
|
|
|
|
res = e.toString();
|
|
|
|
}
|
|
|
|
outputEditor.setValue(res);
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
|
|
|
|
if (options.doc) {
|
|
|
|
var debug;
|
|
|
|
try {
|
2017-04-16 21:32:06 +03:00
|
|
|
var doc = prettier.__debug.printToDoc(inputEditor.getValue(), formatterOptions);
|
|
|
|
debug = prettier.__debug.formatDoc(doc, formatterOptions);
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
} catch (e) {
|
|
|
|
debug = e.toString();
|
|
|
|
}
|
|
|
|
docEditor.setValue(debug);
|
|
|
|
}
|
2017-01-11 21:22:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
document.getElementsByClassName('options')[0].onchange = format;
|
|
|
|
|
2017-01-14 01:14:48 +03:00
|
|
|
var editorOptions = {
|
|
|
|
lineNumbers: true,
|
|
|
|
keyMap: "sublime",
|
|
|
|
autoCloseBrackets: true,
|
|
|
|
matchBrackets: true,
|
|
|
|
showCursorWhenSelecting: true,
|
|
|
|
theme: 'base16-dark',
|
|
|
|
tabWidth: 2
|
|
|
|
};
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
var inputEditor = CodeMirror.fromTextArea(
|
|
|
|
document.getElementById('input-editor'),
|
|
|
|
editorOptions
|
|
|
|
);
|
2017-01-11 21:22:12 +03:00
|
|
|
inputEditor.on('change', format);
|
Add debugging support for doc IR (#347)
This PR adds two things:
`--debug-print-doc` command that prints the formatted doc
```js
echo "<div><</div>" | ./bin/prettier.js --stdin --debug-print-doc
[
groupConditional(
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
[
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
"<",
"</",
"div",
">"
]),
group([
group([ "<", "div", group([ indent(2, []), softline() ]), ">" ]),
indent(2, groupBreak([ hardline(), "<" ])),
hardline(),
"</",
"div",
">"
])
]
),
";",
hardline()
];
```
The ability to view the IR in real time on the browser display:
![image](https://cloud.githubusercontent.com/assets/197597/22134741/4f172f20-de7e-11e6-84bc-5f813976dc19.png)
The way it works is pretty cool, we take the doc IR and print a valid JavaScript string out of it, that we then send to prettier in order to make it look good :)
2017-01-20 20:54:32 +03:00
|
|
|
|
|
|
|
var docEditor = CodeMirror.fromTextArea(
|
|
|
|
document.getElementById('doc-editor'),
|
|
|
|
{readOnly: true, lineNumbers: true, theme: 'base16-dark'}
|
|
|
|
);
|
|
|
|
|
|
|
|
var outputEditor = CodeMirror.fromTextArea(
|
|
|
|
document.getElementById('output-editor'),
|
|
|
|
{readOnly: true, lineNumbers: true, theme: 'base16-dark'}
|
|
|
|
);
|
2017-01-19 01:24:42 +03:00
|
|
|
|
|
|
|
document.getElementsByClassName('version')[0].innerText = prettier.version;
|
2017-01-11 21:22:12 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
try {
|
|
|
|
var json = JSON.parse(decodeURIComponent(location.hash.slice(1)));
|
|
|
|
setOptions(json.options);
|
|
|
|
inputEditor.setValue(json.content);
|
|
|
|
} catch (e) {
|
2017-01-14 01:14:48 +03:00
|
|
|
inputEditor.setValue(code.innerText.trim());
|
2017-01-11 21:22:12 +03:00
|
|
|
}
|
|
|
|
</script>
|