Navigation | Overlay |
---|---|
t Navigate files | h Toggle hits |
y Change url to tip of branch | m Toggle misses |
b / v Jump to prev/next hit line | p Toggle partial |
z / x Jump to prev/next missed or partial line | 1..9 Toggle flags |
shift + o Open current page in GitHub | a Toggle all on |
/ or ? Show keyboard shortcuts dialog | c Toggle context lines or commits |
1 | 1 |
import { parseComponent } from 'vue-template-compiler' |
2 | 1 |
import { isCodeVueSfc } from 'vue-inbrowser-compiler-utils' |
3 |
|
|
4 | 1 |
export default function (code: string, jsxInExamples: boolean): string { |
5 |
// In case we are loading a vue component as an example, extract script tag
|
|
6 |
if (isCodeVueSfc(code)) { |
|
7 | 1 |
const parts = parseComponent(code) |
8 |
return parts && parts.script ? parts.script.content : '' |
|
9 |
}
|
|
10 |
|
|
11 |
// if in JSX mode or litteral return examples code as is
|
|
12 |
if (jsxInExamples || /new Vue\(/.test(code)) { |
|
13 | 1 |
return code |
14 |
}
|
|
15 |
|
|
16 |
if (/\n\W+?export\W+default\W/.test(code) || /\n\W+?module.exports(\W+)?=/.test(code)) { |
|
17 | 1 |
return code |
18 |
}
|
|
19 |
|
|
20 |
//else it could be the weird almost jsx of vue-styleguidist
|
|
21 |
return /^</.test(code.trim()) ? '' : code.split(/\n[\t ]*</)[0] |
|
22 |
}
|
Read our documentation on viewing source code .