-
Notifications
You must be signed in to change notification settings - Fork 109
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(new-ui): Syntax Highlighting and Theme support
* No Logic Changes. Refactored syntax-highlight feature into code shared between new and old uis * No Logic Changes. Renamed syntaxHighlight to syntaxHighlightOld * Implemented Syntax Highlighting for New PR UI * Adds Prism Theme CSS files to solution * Commenting Out Code blocks as they don't play nicely with BB's line by line html structure On the old diff tools, this results in backgrounds that are intended to be applied once for an entire code block instead appearing line by line, resulting in very weird patterns and bordering issues * Implements syntax highlighting themes * Updated New UI Syntax Implementation to Conserve Word Highlighting The previous implementation included an optimized way of handling DOM updates, but it resulted in erasing child elements of each line of code. Bitbucket handles word comparison highlighting by inserting <ins> and <del> into the code, therefore these were lost. The current implementation now highlights each row of code in-place on the DOM, taking a small performance decrease but allowing the Prism library to ensure that <ins> and <del> are respected and word highlighting is not lost. Co-authored-by: Ronald Rey <reyronald@gmail.com>
- Loading branch information
1 parent
b67ab69
commit c3c339c
Showing
25 changed files
with
902 additions
and
68 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
File renamed without changes.
File renamed without changes.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import test from 'ava' | ||
|
||
import * as sourceHandler from './source-handler' | ||
|
||
import '../../vendor/prism' | ||
|
||
test('Returns a language-xxxx class from the native Prism languages list', t => { | ||
const languageClass = sourceHandler.getLanguageClass( | ||
'z/path/to/file/the-file.java' | ||
) | ||
|
||
t.is( | ||
languageClass, | ||
'language-java', | ||
'proper language-xxxx class returned from native Prism languages list' | ||
) | ||
}) | ||
|
||
test('Returns a language-xxx from the language extensions file', t => { | ||
const languageClass = sourceHandler.getLanguageClass( | ||
'filepath/withALanguage/Extension/like.coffee' | ||
) | ||
|
||
t.is( | ||
languageClass, | ||
'language-coffeescript', | ||
'proper language-cofeescript returned from language extension list' | ||
) | ||
}) | ||
|
||
test('Returns a language-ruby class when handling non-extension but globally file named Vagrantfiles', t => { | ||
const languageClass = sourceHandler.getLanguageClass( | ||
'z/path/to/Vagrantfile' | ||
) | ||
|
||
t.is( | ||
languageClass, | ||
'language-ruby', | ||
'proper language-ruby class returned for globally named vagrantfile' | ||
) | ||
}) | ||
|
||
test('Returns a language-ruby class when handling non-extension but globally file named named Jenknsfiles', t => { | ||
const languageClass = sourceHandler.getLanguageClass( | ||
'z/path/to/Jenkinsfile' | ||
) | ||
|
||
t.is( | ||
languageClass, | ||
'language-groovy', | ||
'proper language-groovy returned for globally named Jenknsfile' | ||
) | ||
}) |
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 |
---|---|---|
@@ -1 +1,4 @@ | ||
export { default } from './syntax-highlight' | ||
// @flow | ||
|
||
export { default as syntaxHighlightOldUI } from './syntax-highlight-old' | ||
export { default as syntaxHighlightNewUI } from './syntax-highlight-new' |
File renamed without changes.
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,16 @@ | ||
// @flow | ||
|
||
/** | ||
* Retrieves the filename of an element according to its `data-identifier`, * `data-filename` or `data-path` attributes. | ||
* | ||
* @param {HTMLElement} element An HTML element. Pass anything different and bear the consequences :) | ||
* @return {string} The filename | ||
*/ | ||
export function getFilepathFromElement(element: HTMLElement): string { | ||
const filepath = | ||
element.getAttribute('data-identifier') || | ||
element.getAttribute('data-filename') || | ||
element.getAttribute('data-path') || | ||
'' | ||
return filepath.trim() | ||
} |
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,16 @@ | ||
// @jsx h | ||
|
||
import test from 'ava' | ||
import { h } from 'dom-chef' | ||
|
||
import * as getFilePath from './get-file-path' | ||
import '../../../test/setup-jsdom' | ||
|
||
test('Test reading the filepath from a PR (Old UI) element', t => { | ||
const filePath = 'z/path/to/file/the-file.java' | ||
const element = <div data-filename={filePath} /> | ||
|
||
const res = getFilePath.getFilepathFromElement(element) | ||
|
||
t.is(res, filePath, 'Test reading the filepath from a PR (Old UI) element') | ||
}) |
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,45 @@ | ||
// @flow | ||
|
||
'use strict' | ||
|
||
let stylesImported = false | ||
|
||
export default function loadThemeOnce(themeName: string) { | ||
if (stylesImported) return | ||
|
||
switch (themeName) { | ||
case 'prism-coy': | ||
require('./prism-coy.css') | ||
break | ||
|
||
case 'prism-dark': | ||
require('./prism-dark.css') | ||
break | ||
|
||
case 'prism-funky': | ||
require('./prism-funky.css') | ||
break | ||
|
||
case 'prism-okaidia': | ||
require('./prism-okaidia.css') | ||
break | ||
|
||
case 'prism-solarizedlight': | ||
require('./prism-solarizedlight.css') | ||
break | ||
|
||
case 'prism-tomorrow': | ||
require('./prism-tomorrow.css') | ||
break | ||
|
||
case 'prism-twilight': | ||
require('./prism-twilight.css') | ||
break | ||
|
||
case 'prism': | ||
default: | ||
require('./prism.css') | ||
} | ||
|
||
stylesImported = true | ||
} |
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,86 @@ | ||
/** | ||
* prism.js Coy theme for JavaScript, CoffeeScript, CSS and HTML | ||
* Based on https://github.com/tshedor/workshop-wp-theme (Example: http://workshop.kansan.com/category/sessions/basics or http://workshop.timshedor.com/category/sessions/basics); | ||
* @author Tim Shedor | ||
* | ||
* Updated by Robert Christ for Bitbucket-Refined. | ||
* I took this file, and in the current commit, removed all components | ||
* that do not play nicely with Bitbucket. | ||
*/ | ||
.token.comment, | ||
.token.block-comment, | ||
.token.prolog, | ||
.token.doctype, | ||
.token.cdata { | ||
color: #7d8b99; | ||
} | ||
|
||
.token.punctuation { | ||
color: #5f6364; | ||
} | ||
|
||
.token.property, | ||
.token.tag, | ||
.token.boolean, | ||
.token.number, | ||
.token.function-name, | ||
.token.constant, | ||
.token.symbol, | ||
.token.deleted { | ||
color: #c92c2c; | ||
} | ||
|
||
.token.selector, | ||
.token.attr-name, | ||
.token.string, | ||
.token.char, | ||
.token.function, | ||
.token.builtin, | ||
.token.inserted { | ||
color: #2f9c0a; | ||
} | ||
|
||
.token.operator, | ||
.token.entity, | ||
.token.url, | ||
.token.variable { | ||
color: #a67f59; | ||
background: rgba(255, 255, 255, 0.5); | ||
} | ||
|
||
.token.atrule, | ||
.token.attr-value, | ||
.token.keyword, | ||
.token.class-name { | ||
color: #1990b8; | ||
} | ||
|
||
.token.regex, | ||
.token.important { | ||
color: #e90; | ||
} | ||
|
||
.language-css .token.string, | ||
.style .token.string { | ||
color: #a67f59; | ||
background: rgba(255, 255, 255, 0.5); | ||
} | ||
|
||
.token.important { | ||
font-weight: normal; | ||
} | ||
|
||
.token.bold { | ||
font-weight: bold; | ||
} | ||
.token.italic { | ||
font-style: italic; | ||
} | ||
|
||
.token.entity { | ||
cursor: help; | ||
} | ||
|
||
.namespace { | ||
opacity: 0.7; | ||
} |
Oops, something went wrong.