diff --git a/.github/scripts/build_javadocs.sh b/.github/scripts/build_javadocs.sh
index 91be8dc6c8..0d5404e62f 100755
--- a/.github/scripts/build_javadocs.sh
+++ b/.github/scripts/build_javadocs.sh
@@ -36,7 +36,18 @@ public class ImplementationFactory {
EOF
find "$CN1_DIR/build/tempJavaSources" "$ROOT_DIR/Ports/CLDC11/src" -name "*.java" -not -path "$ROOT_DIR/Ports/CLDC11/src/java/*" \
- | /usr/bin/xargs "$JAVADOC_CMD" --allow-script-in-comments --release 8 -exclude com.codename1.impl -Xdoclint:none -quiet -protected -d "$CN1_DIR/dist/javadoc" -windowtitle "Codename One API" || true
+ | /usr/bin/xargs "$JAVADOC_CMD" \
+ --allow-script-in-comments \
+ --add-stylesheet "$ROOT_DIR/maven/javadoc-resources/highlight.css" \
+ --add-script "$ROOT_DIR/maven/javadoc-resources/highlight.min.js" \
+ --add-script "$ROOT_DIR/maven/javadoc-resources/javadoc-highlight-init.js" \
+ --release 8 \
+ -exclude com.codename1.impl \
+ -Xdoclint:none \
+ -quiet \
+ -protected \
+ -d "$CN1_DIR/dist/javadoc" \
+ -windowtitle "Codename One API" || true
(
cd "$CN1_DIR/dist/javadoc"
diff --git a/maven/javadoc-resources/highlight.css b/maven/javadoc-resources/highlight.css
new file mode 100644
index 0000000000..34dfb61e21
--- /dev/null
+++ b/maven/javadoc-resources/highlight.css
@@ -0,0 +1,17 @@
+pre code {
+ color: #24292e;
+}
+
+.javadoc-keyword {
+ color: #d73a49;
+ font-weight: 600;
+}
+
+.javadoc-string {
+ color: #032f62;
+}
+
+.javadoc-comment {
+ color: #6a737d;
+ font-style: italic;
+}
diff --git a/maven/javadoc-resources/highlight.min.js b/maven/javadoc-resources/highlight.min.js
new file mode 100644
index 0000000000..46c06fc498
--- /dev/null
+++ b/maven/javadoc-resources/highlight.min.js
@@ -0,0 +1,59 @@
+(function(){
+ const KEYWORDS = [
+ 'abstract','assert','boolean','break','byte','case','catch','char','class','const','continue',
+ 'default','do','double','else','enum','extends','final','finally','float','for','goto',
+ 'if','implements','import','instanceof','int','interface','long','native','new','package',
+ 'private','protected','public','return','short','static','strictfp','super','switch',
+ 'synchronized','this','throw','throws','transient','try','void','volatile','while',
+ 'true','false','null'
+ ];
+
+ function escapeHtml(text) {
+ return text
+ .replace(/&/g, '&')
+ .replace(//g, '>')
+ .replace(/"/g, '"')
+ .replace(/'/g, ''');
+ }
+
+ function classifyToken(token) {
+ if (token.startsWith('/*') || token.startsWith('//')) {
+ return 'javadoc-comment';
+ }
+ if (token.startsWith('"') || token.startsWith("'")) {
+ return 'javadoc-string';
+ }
+ return 'javadoc-keyword';
+ }
+
+ function highlightJava(text) {
+ const keywordPattern = KEYWORDS.join('|');
+ const tokenPattern = new RegExp(
+ '(\\/\\*[\\s\\S]*?\\*\\/|\\/\\/[^\\n]*|"(?:\\\\.|[^"\\\\])*"|\'(?:\\\\.|[^\'\\\\])*\'|\\b(?:' + keywordPattern + ')\\b)',
+ 'g'
+ );
+
+ let result = '';
+ let lastIndex = 0;
+ let match;
+ while ((match = tokenPattern.exec(text)) !== null) {
+ const token = match[0];
+ result += escapeHtml(text.slice(lastIndex, match.index));
+ const tokenClass = classifyToken(token);
+ result += '' + escapeHtml(token) + '';
+ lastIndex = match.index + token.length;
+ }
+ result += escapeHtml(text.slice(lastIndex));
+ return result;
+ }
+
+ function highlightElement(element) {
+ const text = element.textContent || '';
+ element.innerHTML = highlightJava(text);
+ }
+
+ window.Cn1JavaDocHighlight = {
+ highlightElement
+ };
+})();
diff --git a/maven/javadoc-resources/javadoc-highlight-init.js b/maven/javadoc-resources/javadoc-highlight-init.js
new file mode 100644
index 0000000000..ec09b5ebc6
--- /dev/null
+++ b/maven/javadoc-resources/javadoc-highlight-init.js
@@ -0,0 +1,26 @@
+document.addEventListener('DOMContentLoaded', () => {
+ const highlighter = window.Cn1JavaDocHighlight;
+ if (!highlighter) {
+ return;
+ }
+
+ const shouldHighlight = (className) =>
+ className === '' || className.includes('language-') || className.includes('lang-');
+
+ document.querySelectorAll('pre').forEach((pre) => {
+ const code = pre.querySelector('code');
+ const target = code || pre;
+ if (shouldHighlight(target.className || '')) {
+ highlighter.highlightElement(target);
+ }
+ });
+
+ document.querySelectorAll('code').forEach((code) => {
+ if (code.closest('pre')) {
+ return;
+ }
+ if (shouldHighlight(code.className || '')) {
+ highlighter.highlightElement(code);
+ }
+ });
+});
diff --git a/maven/pom.xml b/maven/pom.xml
index 98dc96f004..4f43ccaa6a 100644
--- a/maven/pom.xml
+++ b/maven/pom.xml
@@ -339,6 +339,19 @@
protected
false
none
+
+
+ ]]>
+
+ --allow-script-in-comments
+ --add-stylesheet
+ ${maven.multiModuleProjectDirectory}/javadoc-resources/highlight.css
+ --add-script
+ ${maven.multiModuleProjectDirectory}/javadoc-resources/highlight.min.js
+ --add-script
+ ${maven.multiModuleProjectDirectory}/javadoc-resources/javadoc-highlight-init.js
+
@@ -407,8 +420,18 @@
none
false
+
+
+ ]]>
--allow-script-in-comments
+ --add-stylesheet
+ ${maven.multiModuleProjectDirectory}/javadoc-resources/highlight.css
+ --add-script
+ ${maven.multiModuleProjectDirectory}/javadoc-resources/highlight.min.js
+ --add-script
+ ${maven.multiModuleProjectDirectory}/javadoc-resources/javadoc-highlight-init.js
@@ -574,4 +597,4 @@
-
\ No newline at end of file
+