forked from phcode-dev/staging.phcode.dev
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhtmlmixed.js
More file actions
1 lines (1 loc) · 4.05 KB
/
Copy pathhtmlmixed.js
File metadata and controls
1 lines (1 loc) · 4.05 KB
1
!function(mod){"object"==typeof exports&&"object"==typeof module?mod(require("../../lib/codemirror"),require("../xml/xml"),require("../javascript/javascript"),require("../css/css")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../xml/xml","../javascript/javascript","../css/css"],mod):mod(CodeMirror)}(function(CodeMirror){"use strict";var defaultTags={script:[["lang",/(javascript|babel)/i,"javascript"],["type",/^(?:text|application)\/(?:x-)?(?:java|ecma)script$|^module$|^$/i,"javascript"],["type",/./,"text/plain"],[null,null,"javascript"]],style:[["lang",/^css$/i,"css"],["type",/^(text\/)?(x-)?(stylesheet|css)$/i,"css"],["type",/./,"text/plain"],[null,null,"css"]]};function maybeBackup(stream,pat,style){var cur=stream.current(),close=cur.search(pat);return close>-1?stream.backUp(cur.length-close):cur.match(/<\/?$/)&&(stream.backUp(cur.length),stream.match(pat,!1)||stream.match(cur)),style}var attrRegexpCache={};function getAttrRegexp(attr){var regexp=attrRegexpCache[attr];return regexp||(attrRegexpCache[attr]=new RegExp("\\s+"+attr+"\\s*=\\s*('|\")?([^'\"]+)('|\")?\\s*"))}function getAttrValue(text,attr){var match=text.match(getAttrRegexp(attr));return match?/^\s*(.*?)\s*$/.exec(match[2])[1]:""}function getTagRegexp(tagName,anchored){return new RegExp((anchored?"^":"")+"</\\s*"+tagName+"\\s*>","i")}function addTags(from,to){for(var tag in from)for(var dest=to[tag]||(to[tag]=[]),source=from[tag],i=source.length-1;i>=0;i--)dest.unshift(source[i])}function findMatchingMode(tagInfo,tagText){for(var i=0;i<tagInfo.length;i++){var spec=tagInfo[i];if(!spec[0]||spec[1].test(getAttrValue(tagText,spec[0])))return spec[2]}}CodeMirror.defineMode("htmlmixed",function(config,parserConfig){var htmlMode=CodeMirror.getMode(config,{name:"xml",htmlMode:!0,multilineTagIndentFactor:parserConfig.multilineTagIndentFactor,multilineTagIndentPastTag:parserConfig.multilineTagIndentPastTag,allowMissingTagName:parserConfig.allowMissingTagName}),tags={},configTags=parserConfig&&parserConfig.tags,configScript=parserConfig&&parserConfig.scriptTypes;if(addTags(defaultTags,tags),configTags&&addTags(configTags,tags),configScript)for(var i=configScript.length-1;i>=0;i--)tags.script.unshift(["type",configScript[i].matches,configScript[i].mode]);function html(stream,state){var style=htmlMode.token(stream,state.htmlState),tag=/\btag\b/.test(style),tagName;if(tag&&!/[<>\s\/]/.test(stream.current())&&(tagName=state.htmlState.tagName&&state.htmlState.tagName.toLowerCase())&&tags.hasOwnProperty(tagName))state.inTag=tagName+" ";else if(state.inTag&&tag&&/>$/.test(stream.current())){var inTag=/^([\S]+) (.*)/.exec(state.inTag);state.inTag=null;var modeSpec=">"==stream.current()&&findMatchingMode(tags[inTag[1]],inTag[2]),mode=CodeMirror.getMode(config,modeSpec),endTagA=getTagRegexp(inTag[1],!0),endTag=getTagRegexp(inTag[1],!1);state.token=function(stream,state){return stream.match(endTagA,!1)?(state.token=html,state.localState=state.localMode=null,null):maybeBackup(stream,endTag,state.localMode.token(stream,state.localState))},state.localMode=mode,state.localState=CodeMirror.startState(mode,htmlMode.indent(state.htmlState,"",""))}else state.inTag&&(state.inTag+=stream.current(),stream.eol()&&(state.inTag+=" "));return style}return{startState:function(){var state;return{token:html,inTag:null,localMode:null,localState:null,htmlState:CodeMirror.startState(htmlMode)}},copyState:function(state){var local;return state.localState&&(local=CodeMirror.copyState(state.localMode,state.localState)),{token:state.token,inTag:state.inTag,localMode:state.localMode,localState:local,htmlState:CodeMirror.copyState(htmlMode,state.htmlState)}},token:function(stream,state){return state.token(stream,state)},indent:function(state,textAfter,line){return!state.localMode||/^\s*<\//.test(textAfter)?htmlMode.indent(state.htmlState,textAfter,line):state.localMode.indent?state.localMode.indent(state.localState,textAfter,line):CodeMirror.Pass},innerMode:function(state){return{state:state.localState||state.htmlState,mode:state.localMode||htmlMode}}}},"xml","javascript","css"),CodeMirror.defineMIME("text/html","htmlmixed")});