]> git.ardis.lu - ardislu.dev/commitdiff
Add Solidity syntax highlighting
authorArdis Lu <ardisglu@gmail.com>
Sat, 12 Nov 2022 04:32:35 +0000 (20:32 -0800)
committerArdis Lu <ardisglu@gmail.com>
Sat, 12 Nov 2022 04:32:35 +0000 (20:32 -0800)
highlightjs-solidity.min.js [new file with mode: 0644]
script.js

diff --git a/highlightjs-solidity.min.js b/highlightjs-solidity.min.js
new file mode 100644 (file)
index 0000000..7324eca
--- /dev/null
@@ -0,0 +1 @@
+var v=(e,n)=>()=>(n||e((n={exports:{}}).exports,n),n.exports);var w=v((re,A)=>{function L(){try{return new RegExp("(?<!.)"),!0}catch{return!1}}var g=/-?(\b0[xX]([a-fA-F0-9]_?)*[a-fA-F0-9]|(\b[1-9](_?\d)*(\.((\d_?)*\d)?)?|\.\d(_?\d)*)([eE][-+]?\d(_?\d)*)?|\b0)(?!\w|\$)/;L()&&(g=g.source.replace(/\\b/g,"(?<!\\$)\\b"));var b={className:"number",begin:g,relevance:0},u={keyword:"assembly let function if switch case default for leave break continue u256 jump jumpi stop return revert selfdestruct invalid",built_in:"add sub mul div sdiv mod smod exp not lt gt slt sgt eq iszero and or xor byte shl shr sar addmod mulmod signextend keccak256 pc pop dup1 dup2 dup3 dup4 dup5 dup6 dup7 dup8 dup9 dup10 dup11 dup12 dup13 dup14 dup15 dup16 swap1 swap2 swap3 swap4 swap5 swap6 swap7 swap8 swap9 swap10 swap11 swap12 swap13 swap14 swap15 swap16 mload mstore mstore8 sload sstore msize gas address balance selfbalance caller callvalue calldataload calldatasize calldatacopy codesize codecopy extcodesize extcodecopy returndatasize returndatacopy extcodehash create create2 call callcode delegatecall staticcall log0 log1 log2 log3 log4 chainid origin gasprice basefee blockhash coinbase timestamp number difficulty gaslimit",literal:"true false"},C={className:"string",begin:/\bhex'(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?'/},y={className:"string",begin:/\bhex"(([0-9a-fA-F]{2}_?)*[0-9a-fA-F]{2})?"/};function T(e){return e.inherit(e.APOS_STRING_MODE,{begin:/(\bunicode)?'/})}function x(e){return e.inherit(e.QUOTE_STRING_MODE,{begin:/(\bunicode)?"/})}function W(e){var n=T(e),t=x(e),s=/[A-Za-z_$][A-Za-z_$0-9.]*/,r=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:s,keywords:u}),c={className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:s,keywords:u,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,n,t,b]},d={className:"operator",begin:/:=|->/};return{keywords:u,lexemes:s,contains:[n,t,C,y,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,b,d,{className:"function",lexemes:s,beginKeywords:"function",end:"{",excludeEnd:!0,contains:[r,c,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,d]}]}}A.exports={SOL_ASSEMBLY_KEYWORDS:u,baseAssembly:W,solAposStringMode:T,solQuoteStringMode:x,HEX_APOS_STRING_MODE:C,HEX_QUOTE_STRING_MODE:y,SOL_NUMBER:b,isNegativeLookbehindAvailable:L}});var ae=v((ie,I)=>{var{baseAssembly:q,solAposStringMode:J,solQuoteStringMode:j,HEX_APOS_STRING_MODE:D,HEX_QUOTE_STRING_MODE:R,SOL_NUMBER:B,isNegativeLookbehindAvailable:k}=w();function ee(e){for(var n=J(e),t=j(e),s=[],r=0;r<32;r++)s[r]=r+1;var c=s.map(function(a){return a*8}),d=[];for(r=0;r<=80;r++)d[r]=r;var K=s.map(function(a){return"bytes"+a}),z=K.join(" ")+" ",P=c.map(function(a){return"uint"+a}),$=P.join(" ")+" ",Z=c.map(function(a){return"int"+a}),Y=Z.join(" ")+" ",p=[].concat.apply([],c.map(function(a){return d.map(function(m){return a+"x"+m})})),G=p.map(function(a){return"fixed"+a}),U=G.join(" ")+" ",F=p.map(function(a){return"ufixed"+a}),h=F.join(" ")+" ",E={keyword:"var bool string int uint "+Y+$+"byte bytes "+z+"fixed ufixed "+U+h+"enum struct mapping address new delete if else for while continue break return throw emit try catch revert unchecked _ function modifier event constructor fallback receive error virtual override constant immutable anonymous indexed storage memory calldata external public internal payable pure view private returns import from as using global pragma contract interface library is abstract type assembly",literal:"true false wei gwei szabo finney ether seconds minutes hours days weeks years",built_in:"self this super selfdestruct suicide now msg block tx abi blockhash gasleft assert require Error Panic sha3 sha256 keccak256 ripemd160 ecrecover addmod mulmod log0 log1 log2 log3 log4"},M={className:"operator",begin:/[+\-!~*\/%<>&^|=]/},i=/[A-Za-z_$][A-Za-z_$0-9]*/,S={className:"params",begin:/\(/,end:/\)/,excludeBegin:!0,excludeEnd:!0,lexemes:i,keywords:E,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,n,t,B,"self"]},f={begin:/\.\s*/,end:/[^A-Za-z0-9$_\.]/,excludeBegin:!0,excludeEnd:!0,keywords:{built_in:"gas value selector address length push pop send transfer call callcode delegatecall staticcall balance code codehash wrap unwrap name creationCode runtimeCode interfaceId min max"},relevance:2},_=e.inherit(e.TITLE_MODE,{begin:/[A-Za-z$_][0-9A-Za-z$_]*/,lexemes:i,keywords:E}),Q=["gas","value","salt"],X="("+Q.join("|")+")(?=:)",O={className:"built_in",begin:(k()?"(?<!\\$)\\b":"\\b")+X};function o(a,m){return{begin:(k()?"(?<!\\$)\\b":"\\b")+a+"\\.\\s*",end:/[^A-Za-z0-9$_\.]/,excludeBegin:!1,excludeEnd:!0,lexemes:i,keywords:{built_in:a+" "+m},contains:[f],relevance:10}}var H={begin:/_/,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,excludeEnd:!0,keywords:{built_in:"slot offset"},relevance:2},V={begin:/\./,end:/[^A-Za-z0-9$.]/,excludeBegin:!0,excludeEnd:!0,keywords:{built_in:"slot offset length address selector"},relevance:2},N=q(e),l=e.inherit(N,{contains:N.contains.concat([V,H])});return{aliases:["sol"],keywords:E,lexemes:i,contains:[n,t,D,R,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,B,O,M,{className:"function",lexemes:i,beginKeywords:"function modifier event constructor fallback receive error",end:/[{;]/,excludeEnd:!0,contains:[_,S,O,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE],illegal:/%/},o("msg","gas value data sender sig"),o("block","blockhash coinbase difficulty gaslimit basefee number timestamp chainid"),o("tx","gasprice origin"),o("abi","decode encode encodePacked encodeWithSelector encodeWithSignature encodeCall"),o("bytes","concat"),o("string","concat"),f,{className:"class",lexemes:i,beginKeywords:"contract interface library",end:"{",excludeEnd:!0,illegal:/[:"\[\]]/,contains:[{beginKeywords:"is",lexemes:i},_,S,O,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{lexemes:i,beginKeywords:"struct enum",end:"{",excludeEnd:!0,illegal:/[:"\[\]]/,contains:[_,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE]},{beginKeywords:"import",end:";",lexemes:i,keywords:"import from as",contains:[_,n,t,D,R,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,M]},{beginKeywords:"using",end:";",lexemes:i,keywords:"using for global",contains:[_,e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,M]},{className:"meta",beginKeywords:"pragma",end:";",lexemes:i,keywords:{keyword:"pragma solidity experimental abicoder",built_in:"ABIEncoderV2 SMTChecker v1 v2"},contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(n,{className:"meta-string"}),e.inherit(t,{className:"meta-string"})]},{beginKeywords:"assembly",end:/\b\B/,contains:[e.C_LINE_COMMENT_MODE,e.C_BLOCK_COMMENT_MODE,e.inherit(n,{className:"meta-string"}),e.inherit(t,{className:"meta-string"}),e.inherit(l,{begin:"{",end:"}",endsParent:!0,contains:l.contains.concat([e.inherit(l,{begin:"{",end:"}",contains:l.contains.concat(["self"])})])})]}],illegal:/#/}}I.exports=ee});export default ae();
index 14ae773b0208bd0f3f6e139f998f5085555595d5..2f9d837a4d69bf2fd0498ae24df319327d1e2265 100644 (file)
--- a/script.js
+++ b/script.js
@@ -2,7 +2,9 @@ import FlexDocument from 'https://cdn.jsdelivr.net/gh/nextapps-de/flexsearch@0.7
 import { marked } from 'https://cdn.jsdelivr.net/npm/marked@4.0.18/lib/marked.esm.min.js';
 import hljs from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.6.0/build/es/highlight.min.js';
 import powershell from 'https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.6.0/build/es/languages/powershell.min.js';
+import solidity from '/highlightjs-solidity.min.js';
 hljs.registerLanguage('powershell', powershell);
+hljs.registerLanguage('solidity', solidity);
 
 /* Set up stale-while-revalidate cache strategy: if there's anything in the cache, return that immediately.
   Wait for the origin server's response in parallel and show the refresh toast if the cache changed. */
This page took 0.036866 seconds and 4 git commands to generate.