4 <meta name="viewport" content="width=device-width">
5 <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-markdown-css/3.0.1/github-markdown.css" />
6 <script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script>
7 <script src="https://cdn.jsdelivr.net/npm/vue@2.6.10/dist/vue.js"></script>
8 <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.18.0/axios.min.js"></script>
10 @media (max-width: 767px) {
23 box-sizing: border-box;
30 border: 1px solid #d1d5da;
38 .searchCondition > div {
45 <article class="markdown-body">
46 <div class="searchCondition">
48 <form style="display:flex;">
49 <label for="search" style="margin-right: 3px;" >search:</label>
50 <div style="position: relative;">
51 <input id="search" placeholder="Search all options" v-model="searchCondition">
52 <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">
53 <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>
59 <label for="stable">stable: </label>
60 <input type="checkbox" id="stable" v-model="shouldStable">
63 <div v-html="aboutHtml"></div>
64 <div v-html="configurationAboutHtml"></div>
65 <div v-html="outputHtml"></div>
69 const ConfigurationMdUrl = 'https://raw.githubusercontent.com/rust-lang/rustfmt/master/Configurations.md';
70 const UrlHash = window.location.hash.replace(/^#/, '');
74 const configurationDescriptions = [];
75 configurationDescriptions.links = {};
78 configurationAboutHtml: '',
79 searchCondition: UrlHash,
80 configurationDescriptions,
86 const ast = this.configurationDescriptions
87 .filter(({ head, text, stable }) => {
90 text.includes(this.searchCondition) === false &&
91 head.includes(this.searchCondition) === false
95 return (this.shouldStable)
99 .reduce((stack, { value }) => {
100 return stack.concat(value);
103 return marked.parser(ast);
106 created: async function() {
107 const res = await axios.get(ConfigurationMdUrl);
111 configurationDescriptions
112 } = parseMarkdownAst(res.data);
113 this.aboutHtml = marked.parser(about);
114 this.configurationAboutHtml = marked.parser(configurationAbout);
115 this.configurationDescriptions = configurationDescriptions;
118 if (UrlHash === '') return;
119 const interval = setInterval(() => {
120 const target = document.querySelector(`#${UrlHash}`);
121 if (target != null) {
122 target.scrollIntoView(true);
123 clearInterval(interval);
128 const extractDepthOnes = (ast) => {
129 return ast.reduce((stack, next) => {
130 if (next.depth === 1) {
133 const lastIndex = stack.length - 1;
134 stack[lastIndex].push(next);
138 const extractDepthTwos = (ast) => {
139 return ast.map((elem) => {
140 return elem.reduce((stack, next) => {
141 if (next.depth === 2) {
144 const lastIndex = stack.length - 1;
145 stack[lastIndex].push(next);
151 const createHeadAndValue = (ast) => {
152 return ast.map((elem) => {
153 return elem.map((val) => {
157 stable: val.some((elem) => {
158 return !!elem.text && elem.text.includes("**Stable**: Yes")
160 text: val.reduce((result, next) => {
161 return next.text != null
162 ? `${result} ${next.text}`
169 const parseMarkdownAst = (rawMarkdown) => {
170 const ast = marked.lexer(rawMarkdown);
171 const depthOnes = extractDepthOnes(ast);
172 const depthTwos = extractDepthTwos(depthOnes);
174 abouts, configurations
175 ] = createHeadAndValue(depthTwos);
176 const about = abouts[0].value;
179 configurationAbout, ...configurationDescriptions
181 configurationAbout.value.links = {};
185 configurationAbout: configurationAbout.value,
186 configurationDescriptions