Registering new language
-
Hi,
I’m trying to register a new brush language for the Syntax Highlighter Evolved plugin. I have succesfully done this before for a language called DAX. And now I would like to do this again for another language which I’ve named ‘powerquery’. However, WordPress is struggling to recognize it.
To minimize issues I have tried to use the .js file from the dax version, and only tried to register it under a new name called ‘powerquery’. The idea is if this works, I can then adjust the .js to fit the PowerQuery language. Unfortunately, I can’t get this to work either. Let me show you what I tried. Below codes I have used, where every instance of ‘DAX’ has been replaced to ‘powerquery’
In the PHP snippets plugin I have pasted:
add_action('init', function () { wp_register_script( 'syntaxhighlighter-brush-powerquery', get_template_directory_uri() .'/assets/js/shbrushpowerquery.js', array('syntaxhighlighter-core'), '1.2' ); }); add_filter('syntaxhighlighter_brushes', function ($brushes) { $brushes['pq'] = 'powerquery'; return $brushes; });
And the brushfile that is saved at:
/applications/vtmgdmemrk/public_html/wp-content/themes/generatepress_child/assets/jsHas the following code.
SyntaxHighlighter.brushes.powerquery = function() { var funcs = 'abs acos acosh acot acoth addcolumns addmissingitems all allcrossfiltered allexcept allnoblankrow allselected and approximatedistinctcount asin asinh atan atanh average averagea averagex beta.dist beta.inv blank calculate calculatetable calendar calendarauto ceiling chisq.dist chisq.dist.rt chisq.inv chisq.inv.rt closingbalancemonth closingbalancequarter closingbalanceyear coalesce combin combina combinevalues concatenate concatenatex confidence.norm confidence.t contains containsrow containsstring containsstringexact convert cos cosh cot coth count counta countax countblank countrows countx crossfilter crossjoin currency currentgroup customdata datatable date dateadd datediff datesbetween datesinperiod datesmtd datesqtd datesytd datevalue day degrees detailrows distinct distinctcount distinctcountnoblank divide earlier earliest edate endofmonth endofquarter endofyear eomonth error even exact except exp expon.dist fact false filter filters find firstdate firstnonblank firstnonblankvalue fixed floor format gcd generate generateall generateseries geomean geomeanx groupby hasonefilter hasonevalue hour if if.eager iferror ignore int intersect isblank iscrossfiltered isempty iserror iseven isfiltered isinscope islogical isnontext isnumber iso.ceiling isodd isonorafter isselectedmeasure issubtotal istext keepfilters keywordmatch lastdate lastnonblank lastnonblankvalue lcm left len ln log log10 lookupvalue lower max maxa maxx median medianx mid min mina minute minx mod month mround naturalinnerjoin naturalleftouterjoin nextday nextmonth nextquarter nextyear nonvisual norm.dist norm.inv norm.s.dist norm.s.inv not now odd openingbalancemonth openingbalancequarter openingbalanceyear or parallelperiod path pathcontains pathitem pathitemreverse pathlength percentile.exc percentile.inc percentilex.exc percentilex.inc permut pi poisson.dist power previousday previousmonth previousquarter previousyear product productx quarter quotient radians rand randbetween rank.eq rankx related relatedtable removefilters replace rept right rollup rollupaddissubtotal rollupgroup rollupissubtotal round rounddown roundup row sameperiodlastyear sample search second selectcolumns selectedmeasure selectedmeasureformatstring selectedmeasurename selectedvalue sign sin sinh sqrt sqrtpi startofmonth startofquarter startofyear stdev.p stdev.s stdevx.p stdevx.s substitute substitutewithindex sum summarize summarizecolumns sumx switch t.dist t.dist.2t t.dist.rt t.inv t.inv.2t tan tanh time timevalue today topn topnskip totalmtd totalqtd totalytd treatas trim true trunc unichar unicode union upper userelationship username userobjectid userprincipalname utcnow utctoday value values var.p var.s varx.p varx.s weekday weeknum xirr xnpv year yearfrac'; var keywords = 'at asc boolean both by create currency datetime day define desc double evaluate false integer measure month none order return single start string table true var year'; this.regexList = [ { regex: /(^|[^\\])(?:\/\*[\s\S]*?\*\/|(?:--|\/\/).*)/gm, css: 'comments' }, // Comment: #39A03B { regex: /"(?:[^"]|"")*"(?!")/gm, css: 'string' }, // StringLiteral: #D93124 { regex: /'(?:[^']|'')*'(?!')(?:\[[ \w\xA0-\uFFFF]+\])?|\w+\[[ \w\xA0-\uFFFF]+\]/gm, css: 'columns' }, // Column reference --> Columns/measures: #333333 { regex: /\[[ \w\xA0-\uFFFF]+\]/gm, css: 'measures' }, // measure reference --> Columns/measures: #333333 { regex: new RegExp(this.getKeywords(funcs), 'gmi'), css: 'functions' }, // Functions: #035ACA { regex: new RegExp(this.getKeywords(keywords), 'gmi'), css: 'keyword' }, // Keyword: #035ACA { regex: /:=|[-+*\/=^]|\b(?:IN|NOT)\b/i, css: 'operator' }, // Operator: #333333 { regex: /\b\d+\.?\d*|\B\.\d+\b/i, css: 'number' }, // Number: #EE7F18 { regex: /[\[\](){},.]/gm, css: 'parenthesis' } // Parenthesis: #808080 ]; }; SyntaxHighlighter.brushes.powerquery.prototype = new SyntaxHighlighter.Highlighter(); SyntaxHighlighter.brushes.powerquery.aliases = ['powerquery'];
When I try to use the ‘powerquery’ brush language on the ‘syntax highlighter code block’, the code is not highlighted at all, and the formatting box with the numbering does not even show.
For the DAX version, I saved the brush file under the same location, with the only diffrence that the words ‘powerquery’ are then shown with the words ‘dax’. Any suggestions where this may have gone wrong?
- This topic was modified 2 years, 9 months ago by .
- This topic was modified 2 years, 9 months ago by .
The page I need help with: [log in to see the link]
- The topic ‘Registering new language’ is closed to new replies.