2019-04-09 15:57:16 -05:00
|
|
|
<!doctype html>
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta name="viewport" content="width=device-width">
|
2021-09-01 06:15:16 -05:00
|
|
|
<title>Rustfmt</title>
|
2024-06-13 17:37:46 -05:00
|
|
|
<link rel="stylesheet"
|
|
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.min.css"
|
|
|
|
integrity="sha512-7e0rszTy0dKTIgYzCeBXpmycq0EOkwAvxZ0dv/LAtQfcXWCoaRhzs+v2Mn6of3jImxPazbYxiK0kpE/7wZ/UQA=="
|
|
|
|
crossorigin="anonymous"
|
|
|
|
referrerpolicy="no-referrer" />
|
|
|
|
<link rel="stylesheet"
|
|
|
|
href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/styles/github-gist.min.css"
|
|
|
|
integrity="sha512-od7JLoOTxM8w/HSKGzP9Kexc20K9p/M2zxSWsd7H1e4Ctf+8SQFtCWEZnW5u6ul5ehSECa5QmOk9ju2nQMmlVA=="
|
|
|
|
crossorigin="anonymous"
|
|
|
|
referrerpolicy="no-referrer" />
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/marked/12.0.2/marked.min.js"
|
|
|
|
integrity="sha512-xeUh+KxNyTufZOje++oQHstlMQ8/rpyzPuM+gjMFYK3z5ILJGE7l2NvYL+XfliKURMpBIKKp1XoPN/qswlSMFA=="
|
|
|
|
crossorigin="anonymous"
|
|
|
|
referrerpolicy="no-referrer"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.6.10/vue.min.js"
|
|
|
|
integrity="sha512-PwQ5+jgXxxprNGc80ycHE3spgj6TuDieHe/yTkbEJ+U5aol7dTupi/4VbwHHzlQVW77Vb0GLOIsiYigHgC5vcg=="
|
|
|
|
crossorigin="anonymous"
|
|
|
|
referrerpolicy="no-referrer"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.0.0/highlight.min.js"
|
|
|
|
integrity="sha512-av6ZR84Ldk6j29DMhf6v0cssEhow1VROFLoKbX7wrvzZB++/nV8m0jXbYeWcHPEzSNONImx6zwBskCUT9AQidA=="
|
|
|
|
crossorigin="anonymous"
|
|
|
|
referrerpolicy="no-referrer"></script>
|
|
|
|
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"
|
|
|
|
integrity="sha512-3BBFWr73Xrf8GRjO+0pl0cbVwESBvg3ovnuCXpoqOkC/mkt/hTkFtutUPrwRz8eLySYvy5v1daulkyUZYvH8jw=="
|
|
|
|
crossorigin="anonymous"
|
|
|
|
referrerpolicy="no-referrer"></script>
|
2020-05-31 19:12:09 -05:00
|
|
|
<script src="https://unpkg.com/vue-async-computed@3.8.1"></script>
|
2019-04-09 15:57:16 -05:00
|
|
|
<style>
|
|
|
|
@media (max-width: 767px) {
|
|
|
|
.markdown-body {
|
|
|
|
padding: 15px;
|
|
|
|
}
|
|
|
|
|
|
|
|
#search {
|
|
|
|
max-width: 85%;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
body {
|
|
|
|
overflow: scroll;
|
|
|
|
}
|
|
|
|
.markdown-body {
|
|
|
|
box-sizing: border-box;
|
|
|
|
min-width: 200px;
|
|
|
|
max-width: 980px;
|
|
|
|
margin: 0 auto;
|
|
|
|
padding: 45px;
|
|
|
|
}
|
|
|
|
#search {
|
|
|
|
border: 1px solid #d1d5da;
|
|
|
|
padding-left: 30px;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
|
|
|
.searchCondition {
|
|
|
|
display: flex;
|
|
|
|
flex-wrap: wrap;
|
|
|
|
}
|
|
|
|
.searchCondition > div {
|
|
|
|
margin-right: 30px;
|
|
|
|
}
|
2020-07-02 23:33:46 -05:00
|
|
|
.header-link {
|
|
|
|
position: relative;
|
|
|
|
}
|
|
|
|
.header-link:hover::before {
|
|
|
|
position: absolute;
|
|
|
|
left: -2em;
|
|
|
|
padding-right: 0.5em;
|
|
|
|
content: '\2002\00a7\2002';
|
|
|
|
}
|
2019-04-09 15:57:16 -05:00
|
|
|
</style>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<div id="app">
|
|
|
|
<article class="markdown-body">
|
|
|
|
<div class="searchCondition">
|
|
|
|
<div>
|
|
|
|
<form style="display:flex;">
|
|
|
|
<label for="search" style="margin-right: 3px;" >search:</label>
|
|
|
|
<div style="position: relative;">
|
|
|
|
<input id="search" placeholder="Search all options" v-model="searchCondition">
|
|
|
|
<svg style="position: absolute; left: 8px; top: 7px;" class="octicon octicon-search subnav-search-icon" viewBox="0 0 16 16" version="1.1" width="16" height="16" aria-hidden="true">
|
|
|
|
<path fill-rule="evenodd" d="M15.7 13.3l-3.81-3.83A5.93 5.93 0 0 0 13 6c0-3.31-2.69-6-6-6S1 2.69 1 6s2.69 6 6 6c1.3 0 2.48-.41 3.47-1.11l3.83 3.81c.19.2.45.3.7.3.25 0 .52-.09.7-.3a.996.996 0 0 0 0-1.41v.01zM7 10.7c-2.59 0-4.7-2.11-4.7-4.7 0-2.59 2.11-4.7 4.7-4.7 2.59 0 4.7 2.11 4.7 4.7 0 2.59-2.11 4.7-4.7 4.7z"></path>
|
|
|
|
</svg>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<label for="stable">stable: </label>
|
|
|
|
<input type="checkbox" id="stable" v-model="shouldStable">
|
|
|
|
</div>
|
2020-05-31 19:12:09 -05:00
|
|
|
<div>
|
2021-03-03 03:25:59 -06:00
|
|
|
<label for="viewVersion">version: </label>
|
|
|
|
<select name="viewVersion" id="viewVersion" v-model="viewVersion">
|
2020-05-31 19:12:09 -05:00
|
|
|
<option v-for="option in versionOptions" v-bind:value="option">
|
|
|
|
{{ option }}
|
|
|
|
</option>
|
|
|
|
</select>
|
|
|
|
</div>
|
2019-04-09 15:57:16 -05:00
|
|
|
</div>
|
|
|
|
<div v-html="aboutHtml"></div>
|
|
|
|
<div v-html="configurationAboutHtml"></div>
|
|
|
|
<div v-html="outputHtml"></div>
|
|
|
|
</article>
|
|
|
|
</div>
|
|
|
|
<script>
|
2023-08-27 14:46:09 -05:00
|
|
|
const RustfmtTagsUrl = 'https://api.github.com/repos/rust-lang/rustfmt/tags';
|
2021-01-15 14:04:11 -06:00
|
|
|
const RustfmtLatestUrl = 'https://api.github.com/repos/rust-lang/rustfmt/releases/latest';
|
2019-04-22 09:47:50 -05:00
|
|
|
const UrlHash = window.location.hash.replace(/^#/, '');
|
2020-06-22 21:30:45 -05:00
|
|
|
const queryParams = new URLSearchParams(window.location.search);
|
|
|
|
const searchParam = queryParams.get('search');
|
|
|
|
const searchTerm = null !== searchParam ? searchParam : '';
|
2020-06-23 18:42:40 -05:00
|
|
|
const versionParam = queryParams.get('version');
|
|
|
|
const parseVersionParam = (version) => {
|
|
|
|
if (version === 'master') return 'master';
|
|
|
|
if (version.startsWith('v')) return version;
|
|
|
|
return `v${version}`;
|
|
|
|
};
|
|
|
|
const versionNumber = null !== versionParam ? parseVersionParam(versionParam) : 'master';
|
2019-04-09 15:57:16 -05:00
|
|
|
new Vue({
|
|
|
|
el: '#app',
|
2020-05-31 19:12:09 -05:00
|
|
|
data: {
|
|
|
|
aboutHtml: '',
|
|
|
|
configurationAboutHtml: '',
|
|
|
|
configurationDescriptions: [],
|
2020-06-22 21:30:45 -05:00
|
|
|
searchCondition: searchTerm,
|
2020-05-31 19:12:09 -05:00
|
|
|
shouldStable: false,
|
2021-03-03 03:25:59 -06:00
|
|
|
viewVersion: versionNumber,
|
|
|
|
oldViewVersion: undefined,
|
2020-07-15 19:50:43 -05:00
|
|
|
versionOptions: ['master'],
|
|
|
|
scrolledOnce: false,
|
2019-04-09 15:57:16 -05:00
|
|
|
},
|
2020-05-31 19:12:09 -05:00
|
|
|
asyncComputed: {
|
2021-01-15 14:04:11 -06:00
|
|
|
async updateVersion() {
|
|
|
|
let latest;
|
|
|
|
try {
|
|
|
|
latest = (await axios.get(RustfmtLatestUrl)).data;
|
|
|
|
} catch(err) {
|
|
|
|
console.log(err);
|
|
|
|
return;
|
|
|
|
}
|
2021-01-21 13:31:20 -06:00
|
|
|
if (versionParam == null) {
|
2021-03-03 03:25:59 -06:00
|
|
|
this.viewVersion = latest.name;
|
2021-01-21 13:31:20 -06:00
|
|
|
}
|
2021-01-15 14:04:11 -06:00
|
|
|
},
|
2020-05-31 19:12:09 -05:00
|
|
|
async outputHtml() {
|
2021-03-03 03:25:59 -06:00
|
|
|
if (this.viewVersion !== this.oldViewVersion) {
|
2020-05-31 19:12:09 -05:00
|
|
|
const ConfigurationMdUrl =
|
2021-03-03 03:25:59 -06:00
|
|
|
`https://raw.githubusercontent.com/rust-lang/rustfmt/${this.viewVersion}/Configurations.md`;
|
2020-07-15 20:27:19 -05:00
|
|
|
let res;
|
2020-06-23 18:42:40 -05:00
|
|
|
try {
|
2020-07-15 20:27:19 -05:00
|
|
|
res = await axios.get(ConfigurationMdUrl).catch(e => { throw e });
|
|
|
|
} catch(e) {
|
|
|
|
this.handleReqFailure(e);
|
|
|
|
return;
|
2020-06-23 18:42:40 -05:00
|
|
|
}
|
2020-07-15 20:27:19 -05:00
|
|
|
const {
|
|
|
|
about,
|
|
|
|
configurationAbout,
|
|
|
|
configurationDescriptions
|
|
|
|
} = parseMarkdownAst(res.data);
|
|
|
|
this.aboutHtml = marked.parser(about);
|
|
|
|
this.configurationAboutHtml = marked.parser(configurationAbout);
|
|
|
|
this.configurationDescriptions = configurationDescriptions;
|
2021-03-03 03:25:59 -06:00
|
|
|
this.oldViewVersion = this.viewVersion;
|
2020-05-31 19:12:09 -05:00
|
|
|
}
|
2021-06-21 04:11:37 -05:00
|
|
|
|
2020-05-31 19:12:09 -05:00
|
|
|
const ast = this.configurationDescriptions
|
|
|
|
.filter(({ head, text, stable }) => {
|
|
|
|
if (text.includes(this.searchCondition) === false &&
|
|
|
|
head.includes(this.searchCondition) === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return (this.shouldStable)
|
|
|
|
? stable === true
|
|
|
|
: true;
|
|
|
|
})
|
|
|
|
.reduce((stack, { value }) => {
|
|
|
|
return stack.concat(value);
|
|
|
|
}, []);
|
2019-04-09 15:57:16 -05:00
|
|
|
ast.links = {};
|
2020-06-01 09:29:16 -05:00
|
|
|
|
2021-03-03 03:25:59 -06:00
|
|
|
queryParams.set('version', this.viewVersion);
|
2020-07-02 23:33:46 -05:00
|
|
|
queryParams.set('search', this.searchCondition);
|
|
|
|
const curUrl = window.location.pathname +
|
|
|
|
'?' + queryParams.toString() + window.location.hash;
|
|
|
|
history.pushState(null, '', curUrl);
|
|
|
|
|
|
|
|
const renderer = new marked.Renderer();
|
|
|
|
renderer.heading = function(text, level) {
|
|
|
|
const id = htmlToId(text);
|
|
|
|
return `<h${level}>
|
2020-07-15 19:50:43 -05:00
|
|
|
<a id="${id}" href="#${id}" name="${id}" class="header-link">${text}</a>
|
2020-07-02 23:33:46 -05:00
|
|
|
</h${level}>`;
|
|
|
|
};
|
|
|
|
|
2020-07-15 19:52:52 -05:00
|
|
|
return marked.parser(ast, {
|
2020-06-01 09:29:16 -05:00
|
|
|
highlight(code, lang) {
|
|
|
|
return hljs.highlight(lang ? lang : 'rust', code).value;
|
2020-06-22 21:30:45 -05:00
|
|
|
},
|
|
|
|
headerIds: true,
|
2020-07-02 23:33:46 -05:00
|
|
|
headerPrefix: '',
|
|
|
|
renderer,
|
2020-06-01 09:29:16 -05:00
|
|
|
});
|
2019-04-09 15:57:16 -05:00
|
|
|
}
|
|
|
|
},
|
2019-04-22 09:47:50 -05:00
|
|
|
created: async function() {
|
2020-07-15 20:27:19 -05:00
|
|
|
let tags;
|
|
|
|
try {
|
2023-08-27 14:46:09 -05:00
|
|
|
tags = (await axios.get(RustfmtTagsUrl)).data;
|
2020-07-15 20:27:19 -05:00
|
|
|
} catch(e) {
|
|
|
|
this.handleReqFailure(e);
|
|
|
|
return;
|
|
|
|
}
|
2020-10-03 18:05:31 -05:00
|
|
|
|
|
|
|
const excludedTagVersions = new Set(['v0.7', 'v0.8.1']);
|
|
|
|
|
2020-05-31 19:12:09 -05:00
|
|
|
const tagOptions = tags
|
|
|
|
.map(tag => tag.name)
|
2020-10-03 18:05:31 -05:00
|
|
|
.filter(tag => tag.startsWith('v') && !excludedTagVersions.has(tag));
|
2020-05-31 19:12:09 -05:00
|
|
|
this.versionOptions = this.versionOptions.concat(tagOptions);
|
2019-04-22 09:47:50 -05:00
|
|
|
},
|
2020-07-15 19:52:52 -05:00
|
|
|
updated() {
|
2019-04-22 09:47:50 -05:00
|
|
|
if (UrlHash === '') return;
|
2020-07-15 19:50:43 -05:00
|
|
|
this.$nextTick(() => {
|
|
|
|
const target = document.querySelector(`#${UrlHash}`);
|
|
|
|
if (target != null && !this.scrolledOnce) {
|
|
|
|
target.scrollIntoView(true);
|
|
|
|
this.scrolledOnce = true;
|
|
|
|
}
|
|
|
|
});
|
2020-07-15 20:27:19 -05:00
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
handleReqFailure(e) {
|
|
|
|
if (e.response.status === 404) {
|
|
|
|
this.aboutHtml =
|
|
|
|
"<p>Failed to get configuration options for this version, please select the version from the dropdown above.</p>";
|
|
|
|
} else if (
|
|
|
|
e.response.status === 403 &&
|
|
|
|
e.response.headers["X-RateLimit-Remaining"] === 0
|
|
|
|
) {
|
|
|
|
const resetDate = new Date(
|
|
|
|
e.response.headers['X-RateLimit-Reset'] * 1000
|
|
|
|
).toLocaleString();
|
|
|
|
this.aboutHtml =
|
|
|
|
`<p>You have hit the GitHub API rate limit; documentation cannot be updated.` +
|
|
|
|
`<p>The rate limit will be reset at ${resetDate}.</p>`;
|
|
|
|
} else {
|
|
|
|
this.aboutHtml =
|
2023-08-27 14:46:09 -05:00
|
|
|
`<p>Encountered an error when fetching documentation data:</p>` +
|
2020-07-15 20:27:19 -05:00
|
|
|
`<pre><code>${e.response.data}</code></pre>` +
|
|
|
|
`<p>We would appreciate <a href="https://github.com/rust-lang/rustfmt/issues/new?template=bug_report.md">a bug report</a>.` +
|
|
|
|
`<p>Try refreshing the page.</p>`;
|
|
|
|
}
|
|
|
|
}
|
2019-04-09 15:57:16 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
const extractDepthOnes = (ast) => {
|
|
|
|
return ast.reduce((stack, next) => {
|
|
|
|
if (next.depth === 1) {
|
|
|
|
stack.push([]);
|
|
|
|
}
|
|
|
|
const lastIndex = stack.length - 1;
|
|
|
|
stack[lastIndex].push(next);
|
|
|
|
return stack;
|
|
|
|
}, []);
|
|
|
|
}
|
|
|
|
const extractDepthTwos = (ast) => {
|
|
|
|
return ast.map((elem) => {
|
|
|
|
return elem.reduce((stack, next) => {
|
|
|
|
if (next.depth === 2) {
|
|
|
|
stack.push([]);
|
|
|
|
}
|
|
|
|
const lastIndex = stack.length - 1;
|
|
|
|
stack[lastIndex].push(next);
|
|
|
|
return stack;
|
2021-06-21 04:11:37 -05:00
|
|
|
},
|
2019-04-09 15:57:16 -05:00
|
|
|
[[]]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
const createHeadAndValue = (ast) => {
|
|
|
|
return ast.map((elem) => {
|
|
|
|
return elem.map((val) => {
|
|
|
|
return {
|
|
|
|
head: val[0].text,
|
|
|
|
value: val,
|
|
|
|
stable: val.some((elem) => {
|
2020-05-31 11:23:39 -05:00
|
|
|
return elem.type === "list" &&
|
|
|
|
!!elem.raw &&
|
|
|
|
elem.raw.includes("**Stable**: Yes");
|
2019-04-09 15:57:16 -05:00
|
|
|
}),
|
|
|
|
text: val.reduce((result, next) => {
|
|
|
|
return next.text != null
|
|
|
|
? `${result} ${next.text}`
|
|
|
|
: result;
|
|
|
|
}, '')
|
|
|
|
}
|
|
|
|
});
|
|
|
|
})
|
|
|
|
}
|
|
|
|
const parseMarkdownAst = (rawMarkdown) => {
|
|
|
|
const ast = marked.lexer(rawMarkdown);
|
|
|
|
const depthOnes = extractDepthOnes(ast);
|
|
|
|
const depthTwos = extractDepthTwos(depthOnes);
|
|
|
|
const [
|
|
|
|
abouts, configurations
|
|
|
|
] = createHeadAndValue(depthTwos);
|
|
|
|
const about = abouts[0].value;
|
|
|
|
about.links = {};
|
|
|
|
const [
|
|
|
|
configurationAbout, ...configurationDescriptions
|
|
|
|
] = configurations;
|
|
|
|
configurationAbout.value.links = {};
|
2021-06-21 04:11:37 -05:00
|
|
|
|
2019-04-09 15:57:16 -05:00
|
|
|
return {
|
|
|
|
about,
|
|
|
|
configurationAbout: configurationAbout.value,
|
|
|
|
configurationDescriptions
|
|
|
|
};
|
|
|
|
}
|
2020-07-02 23:33:46 -05:00
|
|
|
function htmlToId(text) {
|
|
|
|
const tmpl = document.createElement('template');
|
|
|
|
tmpl.innerHTML = text.trim();
|
|
|
|
return encodeURIComponent(CSS.escape(tmpl.content.textContent));
|
|
|
|
}
|
2019-04-09 15:57:16 -05:00
|
|
|
</script>
|
|
|
|
</body>
|
2020-05-31 11:23:39 -05:00
|
|
|
</html>
|