-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from timja/theme-manager-integration
Theme manager integration
- Loading branch information
Showing
11 changed files
with
110 additions
and
57 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
Empty file.
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
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
6 changes: 2 additions & 4 deletions
6
src/main/resources/io/jenkins/plugins/prism/SourceCodeViewModel/index.jelly
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,24 @@ | ||
<?jelly escape-by-default='true'?> | ||
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler"> | ||
<st:documentation> | ||
Loads prism and a number of plugins | ||
<st:attribute name="configuration" use="required"> | ||
Pass a reference to the 'PrismConfiguration' instance. | ||
</st:attribute> | ||
</st:documentation> | ||
|
||
<st:once> | ||
<link type="text/css" rel="stylesheet" href="${resURL}/plugin/prism-api/css/prism/line-highlight/prism-line-highlight.css"/> | ||
<link type="text/css" rel="stylesheet" href="${resURL}/plugin/prism-api/css/prism/line-numbers/prism-line-numbers.css"/> | ||
<link type="text/css" rel="stylesheet" href="${resURL}/plugin/prism-api/css/prism/match-braces/prism-match-braces.css"/> | ||
|
||
<script id="prism-theme-loader" type="text/javascript" data-selected-theme="${attrs.configuration.theme.fileName}" src="${resURL}/plugin/prism-api/js/theme-loader.js"/> | ||
|
||
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism/prism-core.min.js"/> | ||
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism/autoloader/prism-autoloader.min.js" data-autoloader-path="${resURL}/plugin/prism-api/js/prism/"/> | ||
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism/line-highlight/prism-line-highlight.min.js"/> | ||
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism/line-numbers/prism-line-numbers.min.js"/> | ||
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism/match-braces/prism-match-braces.min.js"/> | ||
<script type="text/javascript" src="${resURL}/plugin/prism-api/js/prism/keep-markup/prism-keep-markup.min.js"/> | ||
</st:once> | ||
</j:jelly> |
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,36 @@ | ||
// We wait till the DOM is loaded to make sure theme manager has loaded | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const head = document.getElementsByTagName('head')[0] | ||
const resUrl = head.dataset.resurl | ||
|
||
function setTheme() { | ||
const themeElement = document.getElementById('prism-theme-loader') | ||
let themeCss = themeElement.dataset.selectedTheme || "prism.css" | ||
|
||
// if default theme is in use then use theme manager API to get light / dark version | ||
if (themeCss === 'prism.css' && window.getThemeManagerProperty) { | ||
const themeName = window.getThemeManagerProperty('prism-api', 'theme') | ||
|
||
if (themeName) { | ||
themeCss = `prism-${themeName}.css` | ||
} | ||
} | ||
|
||
const activeTheme = document.getElementById('prism-active-theme') | ||
if (activeTheme) { | ||
activeTheme.remove() | ||
} | ||
|
||
head.insertAdjacentHTML( | ||
'beforeend', | ||
`<link id="prism-active-theme" rel="stylesheet" href="${resUrl}/plugin/prism-api/css/prism/${themeCss}" />`); | ||
} | ||
|
||
if (window.getThemeManagerProperty && window.isSystemRespectingTheme) { | ||
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => { | ||
setTheme() | ||
}); | ||
} | ||
|
||
setTheme() | ||
}) |