Skip to content

Commit 0c1ec4b

Browse files
committed
Merge branch 'develop' of https://github.com/NativeScript/docs-new into develop
2 parents fcef570 + 5577be4 commit 0c1ec4b

19 files changed

+12922
-567
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.vitepress/dist
22
node_modules
3-
package-lock.json
3+
package-lock.json
4+
yarn.lock

.vitepress/config.js

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
const {
2+
createFlavorContainer,
3+
codeBlocksPlugin,
4+
markFlavorHeadings,
5+
wrapFlavorContainersInTabs,
6+
} = require('./theme/nativescript-theme/plugins')
7+
18
module.exports = {
29
lang: 'en-US',
310
title: 'NativeScript',
@@ -56,7 +63,12 @@ module.exports = {
5663

5764
markdown: {
5865
config: (md) => {
66+
// Flavor related
5967
md.use(...createFlavorContainer())
68+
md.use(markFlavorHeadings)
69+
md.use(wrapFlavorContainersInTabs)
70+
71+
// other.
6072
md.use(codeBlocksPlugin)
6173
},
6274
},
@@ -209,71 +221,3 @@ function getBestPracticeSidebar() {
209221
},
210222
]
211223
}
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-
}

.vitepress/theme/index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import DefaultTheme from 'vitepress/theme'
2-
import './styles.css'
1+
import Theme from './nativescript-theme'
2+
import './nativescript-theme/styles.css'
33

44
export default {
5-
...DefaultTheme,
5+
...Theme(),
66
}

0 commit comments

Comments
 (0)