|
| 1 | +const { |
| 2 | + createFlavorContainer, |
| 3 | + codeBlocksPlugin, |
| 4 | + markFlavorHeadings, |
| 5 | + wrapFlavorContainersInTabs, |
| 6 | +} = require('./theme/nativescript-theme/plugins') |
| 7 | + |
1 | 8 | module.exports = {
|
2 | 9 | lang: 'en-US',
|
3 | 10 | title: 'NativeScript',
|
@@ -56,7 +63,12 @@ module.exports = {
|
56 | 63 |
|
57 | 64 | markdown: {
|
58 | 65 | config: (md) => {
|
| 66 | + // Flavor related |
59 | 67 | md.use(...createFlavorContainer())
|
| 68 | + md.use(markFlavorHeadings) |
| 69 | + md.use(wrapFlavorContainersInTabs) |
| 70 | + |
| 71 | + // other. |
60 | 72 | md.use(codeBlocksPlugin)
|
61 | 73 | },
|
62 | 74 | },
|
@@ -209,71 +221,3 @@ function getBestPracticeSidebar() {
|
209 | 221 | },
|
210 | 222 | ]
|
211 | 223 | }
|
212 |
| - |
213 |
| -/** |
214 |
| - * Adds flavor containers |
215 |
| - * |
216 |
| - * For example: |
217 |
| - * /// flavor vue |
218 |
| - * ...vue specific content... |
219 |
| - * /// |
220 |
| - */ |
221 |
| -function createFlavorContainer() { |
222 |
| - const container = require('markdown-it-container') |
223 |
| - const klass = 'flavor' |
224 |
| - |
225 |
| - return [ |
226 |
| - container, |
227 |
| - klass, |
228 |
| - { |
229 |
| - marker: '/', |
230 |
| - render(tokens, idx) { |
231 |
| - const token = tokens[idx] |
232 |
| - const info = token.info.trim().slice(klass.length).trim() |
233 |
| - if (token.nesting === 1) { |
234 |
| - return `<div class="${klass} ${info}">\n` |
235 |
| - } else { |
236 |
| - return `</div>\n` |
237 |
| - } |
238 |
| - }, |
239 |
| - }, |
240 |
| - ] |
241 |
| -} |
242 |
| - |
243 |
| -/** |
244 |
| - * Adds .code-block to highlighted code blocks |
245 |
| - * Adds data-tab-title="<lang>" or looks for <!-- tab:CustomTabName --> comment above code block to override |
246 |
| - * todo: |
247 |
| - * - group into tabs |
248 |
| - * - implement global selector to automatically switch all tabs |
249 |
| - */ |
250 |
| -function codeBlocksPlugin(md) { |
251 |
| - const fence = md.renderer.rules.fence |
252 |
| - md.renderer.rules.fence = (...args) => { |
253 |
| - const rawCode = fence(...args) |
254 |
| - |
255 |
| - const [tokens, idx] = args |
256 |
| - const token = tokens[idx] |
257 |
| - const prev = idx > 0 ? tokens[idx - 1] : null |
258 |
| - // const next = idx < tokens.length - 1 ? tokens[idx+1] : null; |
259 |
| - // if(prev && prev.type === 'fence') { |
260 |
| - // } |
261 |
| - // if(next && next.type === 'fence') { |
262 |
| - // } |
263 |
| - |
264 |
| - let tabTitle = token.info |
265 |
| - if (prev && prev.type === 'html_block') { |
266 |
| - // <!-- tab:CustomTabName -->\n |
267 |
| - const matched = prev.content.match(/<!--\s*tab:(\w+)\s*-->/) |
268 |
| - if (matched) { |
269 |
| - tabTitle = matched[1] |
270 |
| - } |
271 |
| - } |
272 |
| - const finalCode = rawCode.replace( |
273 |
| - /"(language-\w+)"/, |
274 |
| - `"$1 code-block" data-tab-title="${tabTitle}"` |
275 |
| - ) |
276 |
| - |
277 |
| - return finalCode |
278 |
| - } |
279 |
| -} |
0 commit comments