| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 97748c6 commit 0d21f95
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -330,6 +330,21 @@ hr { | |||
| 330 | 330 | margin-top: .666em; | |
| 331 | 331 | } | |
| 332 | 332 | ||
| 333 | + #toc .stability_0::after { | ||
| 334 | + background-color: #d50027; | ||
| 335 | + color: #fff; | ||
| 336 | + } | ||
| 337 | + | ||
| 338 | + #toc .stability_0::after { | ||
| 339 | + content: "deprecated"; | ||
| 340 | + font-size: .8em; | ||
| 341 | + position: relative; | ||
| 342 | + top: -.18em; | ||
| 343 | + left: .5em; | ||
| 344 | + padding: 0 .3em .2em; | ||
| 345 | + border-radius: 3px; | ||
| 346 | + } | ||
| 347 | + | ||
| 333 | 348 | #apicontent li { | |
| 334 | 349 | margin-bottom: .5em; | |
| 335 | 350 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -9,6 +9,8 @@ const typeParser = require('./type-parser.js'); | |||
| 9 | 9 | ||
| 10 | 10 | module.exports = toHTML; | |
| 11 | 11 | ||
| 12 | + const STABILITY_TEXT_REG_EXP = /(.*:)\s*(\d)([\s\S]*)/; | ||
| 13 | + | ||
| 12 | 14 | // customized heading without id attribute | |
| 13 | 15 | var renderer = new marked.Renderer(); | |
| 14 | 16 | renderer.heading = function(text, level) { | |
@@ -153,8 +155,11 @@ function parseLists(input) { | |||
| 153 | 155 | var savedState = []; | |
| 154 | 156 | var depth = 0; | |
| 155 | 157 | var output = []; | |
| 158 | + let headingIndex = -1; | ||
| 159 | + let heading = null; | ||
| 160 | + | ||
| 156 | 161 | output.links = input.links; | |
| 157 | - input.forEach(function(tok) { | ||
| 162 | + input.forEach(function(tok, index) { | ||
| 158 | 163 | if (tok.type === 'blockquote_start') { | |
| 159 | 164 | savedState.push(state); | |
| 160 | 165 | state = 'MAYBE_STABILITY_BQ'; | |
@@ -167,6 +172,17 @@ function parseLists(input) { | |||
| 167 | 172 | if ((tok.type === 'paragraph' && state === 'MAYBE_STABILITY_BQ') || | |
| 168 | 173 | tok.type === 'code') { | |
| 169 | 174 | if (tok.text.match(/Stability:.*/g)) { | |
| 175 | + const stabilityMatch = tok.text.match(STABILITY_TEXT_REG_EXP); | ||
| 176 | + const stability = Number(stabilityMatch[2]); | ||
| 177 | + const isStabilityIndex = | ||
| 178 | + index - 2 === headingIndex || // general | ||
| 179 | + index - 3 === headingIndex; // with api_metadata block | ||
| 180 | + | ||
| 181 | + if (heading && isStabilityIndex) { | ||
| 182 | + heading.stability = stability; | ||
| 183 | + headingIndex = -1; | ||
| 184 | + heading = null; | ||
| 185 | + } | ||
| 170 | 186 | tok.text = parseAPIHeader(tok.text); | |
| 171 | 187 | output.push({ type: 'html', text: tok.text }); | |
| 172 | 188 | return; | |
@@ -178,6 +194,8 @@ function parseLists(input) { | |||
| 178 | 194 | if (state === null || | |
| 179 | 195 | (state === 'AFTERHEADING' && tok.type === 'heading')) { | |
| 180 | 196 | if (tok.type === 'heading') { | |
| 197 | + headingIndex = index; | ||
| 198 | + heading = tok; | ||
| 181 | 199 | state = 'AFTERHEADING'; | |
| 182 | 200 | } | |
| 183 | 201 | output.push(tok); | |
@@ -280,7 +298,7 @@ function linkJsTypeDocs(text) { | |||
| 280 | 298 | ||
| 281 | 299 | function parseAPIHeader(text) { | |
| 282 | 300 | text = text.replace( | |
| 283 | - /(.*:)\s(\d)([\s\S]*)/, | ||
| 301 | + STABILITY_TEXT_REG_EXP, | ||
| 284 | 302 | '<pre class="api_stability api_stability_$2">$1 $2$3</pre>' | |
| 285 | 303 | ); | |
| 286 | 304 | return text; | |
@@ -324,8 +342,8 @@ function buildToc(lexed, filename, cb) { | |||
| 324 | 342 | const realFilename = path.basename(realFilenames[0], '.md'); | |
| 325 | 343 | const id = getId(realFilename + '_' + tok.text.trim()); | |
| 326 | 344 | toc.push(new Array((depth - 1) * 2 + 1).join(' ') + | |
| 327 | - '* <a href="#' + id + '">' + | ||
| 328 | - tok.text + '</a>'); | ||
| 345 | + '* <span class="stability_' + tok.stability + '">' + | ||
| 346 | + '<a href="#' + id + '">' + tok.text + '</a></span>'); | ||
| 329 | 347 | tok.text += '<span><a class="mark" href="#' + id + '" ' + | |
| 330 | 348 | 'id="' + id + '">#</a></span>'; | |
| 331 | 349 | }); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments