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';
73 const configurationDescriptions = [];
74 configurationDescriptions.links = {}
77 configurationAboutHtml: '',
79 configurationDescriptions,
85 const ast = this.configurationDescriptions
86 .filter(({ head, text, stable }) => {
89 text.includes(this.searchCondition) === false &&
90 head.includes(this.searchCondition) === false
94 return (this.shouldStable)
98 .reduce((stack, { value }) => {
99 return stack.concat(value);
102 return marked.parser(ast);
105 mounted: async function() {
106 const res = await axios.get(ConfigurationMdUrl);
110 configurationDescriptions
111 } = parseMarkdownAst(res.data);
112 this.aboutHtml = marked.parser(about);
113 this.configurationAboutHtml = marked.parser(configurationAbout);
114 this.configurationDescriptions = configurationDescriptions;
117 const extractDepthOnes = (ast) => {
118 return ast.reduce((stack, next) => {
119 if (next.depth === 1) {
122 const lastIndex = stack.length - 1;
123 stack[lastIndex].push(next);
127 const extractDepthTwos = (ast) => {
128 return ast.map((elem) => {
129 return elem.reduce((stack, next) => {
130 if (next.depth === 2) {
133 const lastIndex = stack.length - 1;
134 stack[lastIndex].push(next);
140 const createHeadAndValue = (ast) => {
141 return ast.map((elem) => {
142 return elem.map((val) => {
146 stable: val.some((elem) => {
147 return !!elem.text && elem.text.includes("**Stable**: Yes")
149 text: val.reduce((result, next) => {
150 return next.text != null
151 ? `${result} ${next.text}`
158 const parseMarkdownAst = (rawMarkdown) => {
159 const ast = marked.lexer(rawMarkdown);
160 const depthOnes = extractDepthOnes(ast);
161 const depthTwos = extractDepthTwos(depthOnes);
163 abouts, configurations
164 ] = createHeadAndValue(depthTwos);
165 const about = abouts[0].value;
168 configurationAbout, ...configurationDescriptions
170 configurationAbout.value.links = {};
174 configurationAbout: configurationAbout.value,
175 configurationDescriptions