fixeria submitted this change.
gerrit: patch in TTCN-3 syntax highlighting
Gerrit already maps *.ttcn, *.ttcn3 and *.ttcnpp to text/x-ttcn
(mime-types.properties), but the web UI has no highlight.js language
for it, so TTCN-3 files are shown without highlighting. As a
workaround, we hacked Gerrit to render TTCN-3 files as JavaScript.
Let's enable better TTCN-3 syntax highlighting by patching Gerrit's
bundled highlight.min.js, adding our TTCN-3 language plugin [1], and
mapping text/x-ttcn to it in gr-app.js.
[1] https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3
Change-Id: Ic19fdb7241755ffed84578a0bb776f5ff18c8b23
Related: OS#5514
---
M gerrit/Dockerfile
A gerrit/highlightjs-ttcn3.min.js
2 files changed, 30 insertions(+), 2 deletions(-)
diff --git a/gerrit/Dockerfile b/gerrit/Dockerfile
index cf6d979..af4b8ad 100644
--- a/gerrit/Dockerfile
+++ b/gerrit/Dockerfile
@@ -9,17 +9,33 @@
ARG gerritwar="/var/gerrit/bin/gerrit.war"
ARG libopenid="WEB-INF/lib/com_google_gerrit_httpd_auth_openid_libopenid.jar"
ARG loginform="com/google/gerrit/httpd/auth/openid/LoginForm.html"
+ARG highlightjs="polygerrit_ui/bower_components/highlightjs/highlight.min.js"
+ARG grapp="polygerrit_ui/elements/gr-app.js"
RUN \
- unzip "$gerritwar" "$libopenid" && \
+ unzip "$gerritwar" "$libopenid" "$highlightjs" "$grapp" && \
unzip "$libopenid" "$loginform"
COPY add_osmocom.diff /tmp
RUN patch -p0 < /tmp/add_osmocom.diff
+# TTCN-3 syntax highlighting
+# Gerrit already maps *.ttcn{,3,pp} to text/x-ttcn (mime-types.properties),
+# but the frontend has no highlight.js language for it. Register the language
+# in the bundled highlight.min.js and map text/x-ttcn to it in gr-app.js.
+#
+# highlightjs-ttcn3.min.js is ttcn3.js from https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3
+# To regenerate it, run `make` in a highlightjs-ttcn3.git checkout and copy the resulting
+# highlightjs-ttcn3.min.js here.
+COPY highlightjs-ttcn3.min.js /tmp
+RUN \
+ { printf '\n'; cat /tmp/highlightjs-ttcn3.min.js; } >> "$highlightjs" && \
+ sed -i 's|\["text/x-tcl","tcl"\]|&,["text/x-ttcn","ttcn3"]|' "$grapp" && \
+ grep -q '\["text/x-ttcn","ttcn3"\]' "$grapp"
+
RUN \
zip -u "$libopenid" "$loginform" && \
- zip -u "$gerritwar" "$libopenid"
+ zip -u "$gerritwar" "$libopenid" "$highlightjs" "$grapp"
USER gerrit
diff --git a/gerrit/highlightjs-ttcn3.min.js b/gerrit/highlightjs-ttcn3.min.js
new file mode 100644
index 0000000..2eaa54e
--- /dev/null
+++ b/gerrit/highlightjs-ttcn3.min.js
@@ -0,0 +1,12 @@
+/* https://gitea.osmocom.org/ttcn3/highlightjs-ttcn3 (6daccff) */
+hljs.registerLanguage("ttcn3",(e=>{const t={className:"string",variants:[{
+match:/'([a-fA-F0-9]{2}|\?|\*)*'O/,relevance:10},{match:/'[a-fA-F0-9\?\*]*'H/,
+relevance:10},{match:/'[01\?\*]*'B/,relevance:10
+},e.APOS_STRING_MODE,e.QUOTE_STRING_MODE]};return{name:"TTCN-3",
+aliases:["ttcn","ttcn3","ttcnpp"],keywords:{
+keyword:["action","activate","address","alive","all","alt","altstep","and","and4b","any","anytype","bitstring","boolean","break","case","call","catch","char","charstring","check","clear","complement","component","connect","const","continue","control","create","deactivate","decmatch","default","disconnect","display","do","done","else","encode","enumerated","error","except","exception","execute","extends","extension","external","fail","false","float","for","friend","from","function","getverdict","getcall","getreply","goto","group","halt","hexstring","if","ifpresent","import","in","inconc","infinity","inout","integer","interleave","isbound","ischosen","ispresent","isvalue","kill","killed","label","language","length","log","map","match","message","mixed","mod","modifies","module","modulepar","mtc","noblock","none","not","not_a_number","not4b","nowait","null","octetstring","of","omit","on","optional","or","or4b","out","override","param","pass","pattern","permutation","port","present","private","procedure","public","raise","read","receive","record","recursive","rem","repeat","reply","return","running","runs","select","self","send","sender","set","setencode","setverdict","signature","start","stop","subset","superset","system","template","testcase","timeout","timer","to","trigger","true","type","union","universal","unmap","value","valueof","var","variant","verdicttype","while","with","xor","xor4b"],
+built_in:["action","activate","any2unistr","bit2hex","bit2int","bit2oct","bit2str","call","catch","char2int","char2oct","check","clear","complement","connect","create","deactivate","decmatch","decvalue","decvalue_o","decvalue_unichar","disconnect","encode","encvalue","encvalue_o","encvalue_unichar","enum2int","execute","float2int","get_stringencoding","getcall","getreply","getverdict","halt","hex2bit","hex2int","hex2oct","hex2str","hostid","int2bit","int2char","int2enum","int2float","int2hex","int2oct","int2str","int2unichar","isbound","ischosen","ispresent","istemplatekind","isvalue","kill","killed","length","lengthof","log","map","match","oct2bit","oct2char","oct2hex","oct2int","oct2str","oct2unichar","raise","receive","record","regexp","remove_bom","replace","reply","rnd","running","send","setencode","setverdict","sizeof","start","stop","str2float","str2hex","str2int","str2oct","substr","testcasename","timeout","trigger","unichar2int","unichar2oct","unmap","value","valueof"],
+literal:["error","fail","false","inconc","infinity","none","null","omit","pass","true"],
+type:["address","anytype","bitstring","boolean","charstring","default","float","hexstring","integer","octetstring","universal","universal charstring","verdicttype"]
+},illegal:"(\\*=|\\+=|-=)",
+contains:[e.C_BLOCK_COMMENT_MODE,e.C_LINE_COMMENT_MODE,t]}}));
To view, visit change 37971. To unsubscribe, or for help writing mail filters, visit settings.