You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Write a react-syntax-highlighter mode for MDX. Build on this:
// Adapted from Pivot4J:// https://github.com/mysticfall/pivot4j/blob/33aa47129f02ce6eb1638ce5464e701ecf7e64d7/pivot4j-analytics/src/main/webapp/resources/pivot4j/js/codemirror-mode.jsvarmdxMode=function(config,parserConfig){varkeywords=parserConfig.keywords,functions=parserConfig.functions,properties=parserConfig.properties,multiLineStrings=parserConfig.multiLineStrings;varisOperatorChar=/[+\-*&%=<>!?:\/|]/;functionchain(stream,state,f){state.tokenize=f;returnf(stream,state);}functionret(tp,style){type=tp;returnstyle;}functiontokenBase(stream,state){varch=stream.next();// start of string?if(ch=='"'||ch=="'")returnchain(stream,state,tokenString(ch));// is it one of the special signs {}().,;? Seperator?elseif(/[{}\(\),;\.]/.test(ch))returnret("bracket","bracket");// start of a number value?elseif(/\d/.test(ch)){stream.eatWhile(/[\w\.]/);returnret("number","number");}// multi line comment or simple operator?elseif(ch=="/"){if(stream.eat("*")){returnchain(stream,state,tokenComment);}else{stream.eatWhile(isOperatorChar);returnret("operator","operator");}}// single line comment or simple operator?elseif(ch=="-"){if(stream.eat("-")){stream.skipToEnd();returnret("comment","comment");}else{stream.eatWhile(isOperatorChar);returnret("operator","operator");}}// is it an identifier?elseif(ch=="["){returnchain(stream,state,tokenString("]"));}// is it a operator?elseif(isOperatorChar.test(ch)){stream.eatWhile(isOperatorChar);returnret("operator","operator");}else{// get the whole wordstream.eatWhile(/[\w\$_]/);// is it one of the listed keywords?if(keywords&&keywords.propertyIsEnumerable(stream.current().toLowerCase()))returnret("keyword","keyword");// is it one of the listed functions?if(functions&&functions.propertyIsEnumerable(stream.current().toLowerCase()))returnret("keyword","builtin");// is it one of the listed types?if(properties&&properties.propertyIsEnumerable(stream.current().toLowerCase()))returnret("keyword","variable-2");// default: just a "variable"returnret("word","variable");}}functiontokenString(quote){returnfunction(stream,state){varescaped=false,next,end=false;while((next=stream.next())!=null){if(next==quote&&!escaped){end=true;break;}escaped=!escaped&&next=="\\";}if(end||!(escaped||multiLineStrings))state.tokenize=tokenBase;returnret("string","qualifier");};}functiontokenComment(stream,state){varmaybeEnd=false,ch;while(ch=stream.next()){if(ch=="/"&&maybeEnd){state.tokenize=tokenBase;break;}maybeEnd=(ch=="*");}returnret("comment","comment");}// Interfacereturn{startState : function(basecolumn){return{tokenize : tokenBase,startOfLine : true};},token : function(stream,state){if(stream.eatSpace())returnnull;varstyle=state.tokenize(stream,state);returnstyle;}};};functionkeywords(str){varobj={},words=str.split(" ");for(vari=0;i<words.length;++i)obj[words[i]]=true;returnobj;}varmdxKeywords="select from on columns rows where with not in properties";varmdxFunctions="hierarchize crossjoin union filter iif format exists except "+"dateDiff dateAdd bottomCount bottomSum";varmdxProperties="null children descendants members firstChild firstSibling lastChild "+"lastSibling parent name uniqueName nextMember hierarchy dimension currentMember "+"defaultMember allMembers";varmdxMime={name : "mdx",keywords : keywords(mdxKeywords),functions : keywords(mdxFunctions),properties : keywords(mdxProperties)};module.exports={mdxType: mdxMode,mdxMime: mdxMime};
The text was updated successfully, but these errors were encountered:
Write a
react-syntax-highlighter
mode for MDX. Build on this:The text was updated successfully, but these errors were encountered: