-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Re-implementing source code viewer component (using prism-based synta…
…x highlighter instead of ACE editor).
- Loading branch information
1 parent
6768475
commit add9c9a
Showing
12 changed files
with
402 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/components/helpers/SourceCodeViewer/SourceCodeViewer.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
.sourceCodeViewer { | ||
margin: 0; | ||
padding: 0; | ||
|
||
} | ||
|
||
.sourceCodeViewer span[data-line] { | ||
display: block; | ||
line-height: 25px; | ||
} | ||
|
||
.sourceCodeViewer span[data-line] .linenumber { | ||
margin-right: 0.25rem; | ||
background-color: #e0e0e0; | ||
text-align: right; | ||
min-width: 5em!important; | ||
text-shadow: none; | ||
color: #666; | ||
} | ||
|
||
.sourceCodeViewer span[data-line]:hover, .sourceCodeViewer span[data-line]:hover * { | ||
background-color: #f3f3f3; | ||
} | ||
|
||
.sourceCodeViewer span[data-line]:hover .linenumber { | ||
background-color: #d0d0d0; | ||
} | ||
|
||
.sourceCodeViewer span[data-line-style="selected"] { | ||
background-color: #ff9; | ||
} | ||
|
||
.sourceCodeViewer span[data-line-style="selected"] .linenumber { | ||
background-color: yellow; | ||
} |
54 changes: 36 additions & 18 deletions
54
src/components/helpers/SourceCodeViewer/SourceCodeViewer.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
const commonMapping = { | ||
cs: 'csharp', | ||
css: 'css', | ||
groovy: 'groovy', | ||
java: 'java', | ||
js: 'javascript', | ||
kt: 'kotlin', | ||
kts: 'kotlin', | ||
ktm: 'kotlin', | ||
lpr: 'pascal', | ||
makefile: 'makefile', | ||
md: 'markdown', | ||
markdown: 'markdown', | ||
pas: 'pascal', | ||
php: 'php', | ||
py: 'python', | ||
rs: 'rust', | ||
sc: 'scala', | ||
scala: 'scala', | ||
ts: 'typescript', | ||
}; | ||
|
||
const aceMapping = { | ||
...commonMapping, | ||
c: 'c_cpp', | ||
cpp: 'c_cpp', | ||
h: 'c_cpp', | ||
hpp: 'c_cpp', | ||
ino: 'c_cpp', | ||
html: 'html', | ||
}; | ||
|
||
export const createExtensionTranslator = mapping => ext => { | ||
ext = ext.trim().toLowerCase(); | ||
if (ext === '') { | ||
return mapping.makefile; // makefile has no extension | ||
} else if (mapping[ext]) { | ||
return mapping[ext]; // mapping found | ||
} else { | ||
return mapping.cpp; // C/C++ is default | ||
} | ||
}; | ||
|
||
const prismMapping = { | ||
...commonMapping, | ||
bash: 'bash', | ||
c: 'cpp', | ||
cpp: 'cpp', | ||
cu: 'cpp', // CUDA | ||
go: 'go', | ||
h: 'cpp', | ||
hpp: 'cpp', | ||
hs: 'haskell', | ||
html: 'cshtml', | ||
ino: 'arduino', | ||
pl: 'prolog', | ||
sh: 'bash', | ||
sql: 'sql', | ||
y: 'bison', | ||
}; | ||
|
||
export const getAceModeFromExtension = createExtensionTranslator(aceMapping); | ||
export const getPrismModeFromExtension = createExtensionTranslator(prismMapping); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.