Skip to content

Commit

Permalink
PackageDetail: file browser: add syntax highlighting
Browse files Browse the repository at this point in the history
  • Loading branch information
dmstern committed Nov 3, 2018
1 parent cf2d3d1 commit d9230fa
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/components/CodeBlock.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export default class CodeBlock extends Vue {
flex-grow: 1;
align-self: flex-end;
max-width: calc(100% - 52px);
min-height: 4em;
}
}
Expand Down
28 changes: 28 additions & 0 deletions src/views/PackageDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
class="file-content transition"
:class="(data.activeTreeItem.name && !isLoadingCode)? 'visible' : 'hidden'"
:key="data.activeTreeItem.id"
:language="getLanguage(data.activeTreeItem.name)"
></CodeBlock>
</div>
</v-card-text>
Expand Down Expand Up @@ -582,6 +583,33 @@ export default class PackageDetail extends Vue {
return extensionIcon || icons.file;
}
private getLanguage(filename: string): string {
const languages = {
js: 'javascript',
ts: 'typescript',
jsx: 'javascript',
md: 'markdown',
css: 'css',
html: 'html',
htm: 'html',
scss: 'scss',
hbs: 'handlebars',
xml: 'xml',
json: 'json',
svg: 'svg',
ftl: 'xml',
sh: 'bash',
}
const parts = filename.split('.');
if (parts.length > 0) {
const extension = parts[parts.length - 1];
if (languages[extension]) {
return languages[extension];
}
}
return 'javascript';
}
private isOld(): boolean | undefined {
if (!this.data.packageDetail || !this.data.currentPackage) {
return false;
Expand Down

0 comments on commit d9230fa

Please sign in to comment.