@@ -88,6 +88,7 @@ interface Props extends RouteComponentProps<MainRouteParams> {
8888 repoScope : string [ ] ;
8989 fetchMoreCommits ( repoUri : string ) : void ;
9090}
91+ const LANG_MD = 'markdown' ;
9192
9293enum ButtonOption {
9394 Code = 'Code' ,
@@ -96,13 +97,18 @@ enum ButtonOption {
9697 Folder = 'Directory' ,
9798}
9899
100+ enum ButtonLabel {
101+ Code = 'Code' ,
102+ Content = 'Content' ,
103+ Download = 'Download' ,
104+ Raw = 'Raw' ,
105+ }
106+
99107const Title = styled ( EuiTitle ) `
100108 margin: ${ theme . euiSizeXS } 0 ${ theme . euiSize } ;
101109` ;
102110
103111class CodeContent extends React . PureComponent < Props > {
104- public rawButtonOptions = [ { id : 'Raw' , label : 'Raw' } ] ;
105-
106112 public findNode = ( pathSegments : string [ ] , node : FileTree ) : FileTree | undefined => {
107113 if ( ! node ) {
108114 return undefined ;
@@ -169,12 +175,14 @@ class CodeContent extends React.PureComponent<Props> {
169175 currentTree &&
170176 ( currentTree . type === FileTreeItemType . File || currentTree . type === FileTreeItemType . Link )
171177 ) {
172- const { isUnsupported, isOversize, isImage } = this . props . file ! ;
178+ const { isUnsupported, isOversize, isImage, lang } = this . props . file ! ;
179+ const isMarkdown = lang === LANG_MD ;
180+ const isText = ! isUnsupported && ! isOversize && ! isImage ;
173181
174182 const buttonOptions = [
175183 {
176184 id : ButtonOption . Code ,
177- label : ButtonOption . Code ,
185+ label : isText && ! isMarkdown ? ButtonLabel . Code : ButtonLabel . Content ,
178186 } ,
179187 {
180188 id : ButtonOption . Blame ,
@@ -186,6 +194,9 @@ class CodeContent extends React.PureComponent<Props> {
186194 label : ButtonOption . History ,
187195 } ,
188196 ] ;
197+ const rawButtonOptions = [
198+ { id : 'Raw' , label : isText ? ButtonLabel . Raw : ButtonLabel . Download } ,
199+ ] ;
189200
190201 return (
191202 < ButtonsContainer >
@@ -200,7 +211,7 @@ class CodeContent extends React.PureComponent<Props> {
200211 < EuiButtonGroup
201212 buttonSize = "s"
202213 color = "primary"
203- options = { this . rawButtonOptions }
214+ options = { rawButtonOptions }
204215 type = "single"
205216 idSelected = { '' }
206217 onChange = { this . openRawFile }
@@ -338,7 +349,7 @@ class CodeContent extends React.PureComponent<Props> {
338349 />
339350 ) ;
340351 }
341- if ( fileLanguage === 'markdown' ) {
352+ if ( fileLanguage === LANG_MD ) {
342353 return (
343354 < div className = "markdown-body code-markdown-container" >
344355 < Markdown source = { fileContent } escapeHtml = { true } skipHtml = { true } />
0 commit comments