diff --git a/.gitignore b/.gitignore
index f4dbe42..ca5205a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,3 +11,7 @@ release.properties
.DS_Store
.idea
/package-lock.json
+work/
+
+src/main/webapp/css/prism/**
+src/main/webapp/js/prism/**
diff --git a/.mvn_exec_node b/.mvn_exec_node
new file mode 100644
index 0000000..e69de29
diff --git a/README.adoc b/README.adoc
index 659a9b3..897052f 100644
--- a/README.adoc
+++ b/README.adoc
@@ -52,13 +52,25 @@ Then you can use Prism in your jelly files using the following snippet:
[source,xml]
----
-
+
+
+
+----
+
+In your descriptor you will need to add a `getPrismConfiguration()` method:
+
+[source,java]
+----
+public PrismConfiguration getPrismConfiguration() {
+ return PrismConfiguration.getInstance();
+}
----
== Examples
-Currently, no additional help is available for this plugin. You can have a look into the
+For source code rendering look into the
https://github.com/jenkinsci/warnings-ng-plugin[warnings plugin] that
uses the `SourceCodeViewModel` to render the source code with the selected warning.
+For general prism API integration see https://github.com/jenkinsci/design-library-plugin/pull/72[design-library-plugin PR#72].
diff --git a/package.json b/package.json
index 621a8e7..2382e6a 100644
--- a/package.json
+++ b/package.json
@@ -14,7 +14,9 @@
"remark-preset-lint-recommended": "6.1.3"
},
"scripts": {
- "lint-md": "remark ."
+ "lint-md": "remark .",
+ "mvnbuild": "",
+ "mvntest": ""
},
"remarkConfig": {
"plugins": [
diff --git a/pom.xml b/pom.xml
index 614f8e3..2eca7f3 100644
--- a/pom.xml
+++ b/pom.xml
@@ -18,7 +18,7 @@
https://github.com/jenkinsci/prism-api-plugin
- 1.29.0-7
+ 1.29.0-8
-SNAPSHOT
${project.groupId}.prism
@@ -26,6 +26,9 @@
1.18.3
1.16.1
+ 18.12.0
+ 8.19.4
+
@@ -160,36 +163,16 @@
**/*
+
+ ${project.basedir}/src/main/webapp
+
+ css/prism/**/*
+ js/prism/**/*
+
+
-
- com.github.eirslett
- frontend-maven-plugin
- 1.13.3
-
-
- install node and npm
-
- install-node-and-npm
-
- generate-resources
-
- v18.12.0
-
-
-
- npm install
-
- npm
-
- generate-resources
-
- install
-
-
-
-
org.apache.maven.plugins
maven-resources-plugin
@@ -201,7 +184,7 @@
copy-resources
- ${project.build.directory}/${project.artifactId}/js
+ ${project.basedir}/src/main/webapp/js/prism
${project.basedir}/node_modules/prismjs/components
@@ -224,7 +207,7 @@
copy-resources
- ${project.build.directory}/${project.artifactId}/css
+ ${project.basedir}/src/main/webapp/css/prism
${project.basedir}/node_modules/prismjs/themes
diff --git a/src/main/java/io/jenkins/plugins/prism/PrismTheme.java b/src/main/java/io/jenkins/plugins/prism/PrismTheme.java
index 68a4a8e..59bf71a 100644
--- a/src/main/java/io/jenkins/plugins/prism/PrismTheme.java
+++ b/src/main/java/io/jenkins/plugins/prism/PrismTheme.java
@@ -8,7 +8,7 @@
* @author Ullrich Hafner
*/
public enum PrismTheme {
- PRISM("Default", "prism.css"),
+ PRISM("Default (light and dark mode)", "prism.css"),
COY("Coy", "prism-coy.css"),
DARK("Dark", "prism-dark.css"),
FUNKY("Funky", "prism-funky.css"),
diff --git a/src/main/java/io/jenkins/plugins/prism/SourceCodeViewModel.java b/src/main/java/io/jenkins/plugins/prism/SourceCodeViewModel.java
index 1eb176e..d526646 100644
--- a/src/main/java/io/jenkins/plugins/prism/SourceCodeViewModel.java
+++ b/src/main/java/io/jenkins/plugins/prism/SourceCodeViewModel.java
@@ -40,6 +40,10 @@ public SourceCodeViewModel(final Run, ?> owner, final String fileName, final R
sourceCode = render(sourceCodeReader, marker);
}
+ public PrismConfiguration getPrismConfiguration() {
+ return PrismConfiguration.getInstance();
+ }
+
private String render(final Reader affectedFile, final Marker marker) {
try (BufferedReader reader = new BufferedReader(affectedFile)) {
SourcePrinter sourcePrinter = new SourcePrinter();
@@ -72,14 +76,5 @@ public String getDisplayName() {
public String getSourceCode() {
return sourceCode;
}
-
- /**
- * Returns the filename of the prism theme. Themes are stored in the package below the css folder.
- *
- * @return the theme CSS file
- */
- public String getThemeCssFileName() {
- return PrismConfiguration.getInstance().getTheme().getFileName();
- }
}
diff --git a/src/main/resources/io/jenkins/plugins/prism.jelly b/src/main/resources/io/jenkins/plugins/prism.jelly
index d84a9e4..91b7ea8 100644
--- a/src/main/resources/io/jenkins/plugins/prism.jelly
+++ b/src/main/resources/io/jenkins/plugins/prism.jelly
@@ -7,15 +7,14 @@ Use it like
${h.initPageVariables(context)}
-
-
-
+
+
+
-
-
-
-
-
-
+
+
+
+
+
+
diff --git a/src/main/resources/io/jenkins/plugins/prism/SourceCodeViewModel/index.jelly b/src/main/resources/io/jenkins/plugins/prism/SourceCodeViewModel/index.jelly
index 113180a..1a6c026 100644
--- a/src/main/resources/io/jenkins/plugins/prism/SourceCodeViewModel/index.jelly
+++ b/src/main/resources/io/jenkins/plugins/prism/SourceCodeViewModel/index.jelly
@@ -1,14 +1,12 @@
-
+
-
+
-
-
${%sourcedetail.header(it.displayName)}
diff --git a/src/main/resources/prism/prism.jelly b/src/main/resources/prism/prism.jelly
new file mode 100644
index 0000000..e9b7dff
--- /dev/null
+++ b/src/main/resources/prism/prism.jelly
@@ -0,0 +1,24 @@
+
+
+
+ Loads prism and a number of plugins
+
+ Pass a reference to the 'PrismConfiguration' instance.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/main/webapp/js/theme-loader.js b/src/main/webapp/js/theme-loader.js
new file mode 100644
index 0000000..d114739
--- /dev/null
+++ b/src/main/webapp/js/theme-loader.js
@@ -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',
+ ``);
+ }
+
+ if (window.getThemeManagerProperty && window.isSystemRespectingTheme) {
+ window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', event => {
+ setTheme()
+ });
+ }
+
+ setTheme()
+})