mirror of
https://forge.chapril.org/tykayn/book_generator
synced 2025-06-20 01:34:43 +02:00
1 line
No EOL
14 KiB
JavaScript
1 line
No EOL
14 KiB
JavaScript
!function(t){"object"==typeof exports&&"object"==typeof module?t(require("../../lib/codemirror"),require("../xml/xml"),require("../meta")):"function"==typeof define&&define.amd?define(["../../lib/codemirror","../xml/xml","../meta"],t):t(CodeMirror)}(function(w){"use strict";w.defineMode("markdown",function(g,m){var d=w.getMode(g,"text/html"),u="null"==d.name;void 0===m.highlightFormatting&&(m.highlightFormatting=!1),void 0===m.maxBlockquoteDepth&&(m.maxBlockquoteDepth=0),void 0===m.taskLists&&(m.taskLists=!1),void 0===m.strikethrough&&(m.strikethrough=!1),void 0===m.emoji&&(m.emoji=!1),void 0===m.fencedCodeBlockHighlighting&&(m.fencedCodeBlockHighlighting=!0),void 0===m.fencedCodeBlockDefaultMode&&(m.fencedCodeBlockDefaultMode="text/plain"),void 0===m.xml&&(m.xml=!0),void 0===m.tokenTypeOverrides&&(m.tokenTypeOverrides={});var t,c={header:"header",code:"comment",quote:"quote",list1:"variable-2",list2:"variable-3",list3:"keyword",hr:"hr",image:"image",imageAltText:"image-alt-text",imageMarker:"image-marker",formatting:"formatting",linkInline:"link",linkEmail:"link",linkText:"link",linkHref:"string",em:"em",strong:"strong",strikethrough:"strikethrough",emoji:"builtin"};for(t in c)c.hasOwnProperty(t)&&m.tokenTypeOverrides[t]&&(c[t]=m.tokenTypeOverrides[t]);var f=/^([*\-_])(?:\s*\1){2,}\s*$/,k=/^(?:[*\-+]|^[0-9]+([.)]))\s+/,F=/^\[(x| )\](?=\s)/i,D=m.allowAtxHeaderWithoutSpace?/^(#+)/:/^(#+)(?: |$)/,p=/^ {0,3}(?:\={1,}|-{2,})\s*$/,i=/^[^#!\[\]*_\\<>` "'(~:]+/,E=/^(~~~+|```+)[ \t]*([\w\/+#-]*)[^\n`]*$/,x=/^\s*\[[^\]]+?\]:.*$/,A=/[!"#$%&'()*+,\-.\/:;<=>?@\[\\\]^_`{|}~\xA1\xA7\xAB\xB6\xB7\xBB\xBF\u037E\u0387\u055A-\u055F\u0589\u058A\u05BE\u05C0\u05C3\u05C6\u05F3\u05F4\u0609\u060A\u060C\u060D\u061B\u061E\u061F\u066A-\u066D\u06D4\u0700-\u070D\u07F7-\u07F9\u0830-\u083E\u085E\u0964\u0965\u0970\u0AF0\u0DF4\u0E4F\u0E5A\u0E5B\u0F04-\u0F12\u0F14\u0F3A-\u0F3D\u0F85\u0FD0-\u0FD4\u0FD9\u0FDA\u104A-\u104F\u10FB\u1360-\u1368\u1400\u166D\u166E\u169B\u169C\u16EB-\u16ED\u1735\u1736\u17D4-\u17D6\u17D8-\u17DA\u1800-\u180A\u1944\u1945\u1A1E\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B60\u1BFC-\u1BFF\u1C3B-\u1C3F\u1C7E\u1C7F\u1CC0-\u1CC7\u1CD3\u2010-\u2027\u2030-\u2043\u2045-\u2051\u2053-\u205E\u207D\u207E\u208D\u208E\u2308-\u230B\u2329\u232A\u2768-\u2775\u27C5\u27C6\u27E6-\u27EF\u2983-\u2998\u29D8-\u29DB\u29FC\u29FD\u2CF9-\u2CFC\u2CFE\u2CFF\u2D70\u2E00-\u2E2E\u2E30-\u2E42\u3001-\u3003\u3008-\u3011\u3014-\u301F\u3030\u303D\u30A0\u30FB\uA4FE\uA4FF\uA60D-\uA60F\uA673\uA67E\uA6F2-\uA6F7\uA874-\uA877\uA8CE\uA8CF\uA8F8-\uA8FA\uA8FC\uA92E\uA92F\uA95F\uA9C1-\uA9CD\uA9DE\uA9DF\uAA5C-\uAA5F\uAADE\uAADF\uAAF0\uAAF1\uABEB\uFD3E\uFD3F\uFE10-\uFE19\uFE30-\uFE52\uFE54-\uFE61\uFE63\uFE68\uFE6A\uFE6B\uFF01-\uFF03\uFF05-\uFF0A\uFF0C-\uFF0F\uFF1A\uFF1B\uFF1F\uFF20\uFF3B-\uFF3D\uFF3F\uFF5B\uFF5D\uFF5F-\uFF65]|\uD800[\uDD00-\uDD02\uDF9F\uDFD0]|\uD801\uDD6F|\uD802[\uDC57\uDD1F\uDD3F\uDE50-\uDE58\uDE7F\uDEF0-\uDEF6\uDF39-\uDF3F\uDF99-\uDF9C]|\uD804[\uDC47-\uDC4D\uDCBB\uDCBC\uDCBE-\uDCC1\uDD40-\uDD43\uDD74\uDD75\uDDC5-\uDDC9\uDDCD\uDDDB\uDDDD-\uDDDF\uDE38-\uDE3D\uDEA9]|\uD805[\uDCC6\uDDC1-\uDDD7\uDE41-\uDE43\uDF3C-\uDF3E]|\uD809[\uDC70-\uDC74]|\uD81A[\uDE6E\uDE6F\uDEF5\uDF37-\uDF3B\uDF44]|\uD82F\uDC9F|\uD836[\uDE87-\uDE8B]/;function C(t,e,i){return(e.f=e.inline=i)(t,e)}function S(t,e,i){return(e.f=e.block=i)(t,e)}function n(t){var e,i;return t.linkTitle=!1,t.linkHref=!1,t.linkText=!1,t.em=!1,t.strong=!1,t.strikethrough=!1,t.quote=0,t.indentedCode=!1,t.f!=v||(i=!(i=u)?"xml"==(e=w.innerMode(d,t.htmlState)).mode.name&&null===e.state.tagStart&&!e.state.context&&e.state.tokenize.isInText:i)&&(t.f=T,t.block=r,t.htmlState=null),t.trailingSpace=0,t.trailingSpaceNewLine=!1,t.prevLine=t.thisLine,t.thisLine={stream:null},null}function r(t,e){var i=t.column()===e.indentation,n=!(s=e.prevLine.stream)||!/\S/.test(s.string),u=e.indentedCode,r=e.prevLine.hr,a=!1!==e.list,o=(e.listStack[e.listStack.length-1]||0)+3;e.indentedCode=!1;var l=e.indentation;if(null===e.indentationDiff&&(e.indentationDiff=e.indentation,a)){for(e.list=null;l<e.listStack[e.listStack.length-1];)e.listStack.pop(),e.listStack.length?e.indentation=e.listStack[e.listStack.length-1]:e.list=!1;!1!==e.list&&(e.indentationDiff=l-e.listStack[e.listStack.length-1])}var h=!(n||r||e.prevLine.header||a&&u||e.prevLine.fencedCodeEnd),s=(!1===e.list||r||n)&&e.indentation<=o&&t.match(f),r=null;if(4<=e.indentationDiff&&(u||e.prevLine.fencedCodeEnd||e.prevLine.header||n))return t.skipToEnd(),e.indentedCode=!0,c.code;if(t.eatSpace())return null;if(i&&e.indentation<=o&&(r=t.match(D))&&r[1].length<=6)return e.quote=0,e.header=r[1].length,e.thisLine.header=!0,m.highlightFormatting&&(e.formatting="header"),e.f=e.inline,L(e);if(e.indentation<=o&&t.eat(">"))return e.quote=i?1:e.quote+1,m.highlightFormatting&&(e.formatting="quote"),t.eatSpace(),L(e);if(!s&&!e.setext&&i&&e.indentation<=o&&(r=t.match(k))){n=r[1]?"ol":"ul";return e.indentation=l+t.current().length,e.list=!0,e.quote=0,e.listStack.push(e.indentation),e.em=!1,e.strong=!1,e.code=!1,e.strikethrough=!1,m.taskLists&&t.match(F,!1)&&(e.taskList=!0),e.f=e.inline,m.highlightFormatting&&(e.formatting=["list","list-"+n]),L(e)}return i&&e.indentation<=o&&(r=t.match(E,!0))?(e.quote=0,e.fencedEndRE=new RegExp(r[1]+"+ *$"),e.localMode=m.fencedCodeBlockHighlighting&&(i=r[2]||m.fencedCodeBlockDefaultMode,!w.findModeByName||(o=w.findModeByName(i))&&(i=o.mime||o.mimes[0]),"null"==(i=w.getMode(g,i)).name?null:i),e.localMode&&(e.localState=w.startState(e.localMode)),e.f=e.block=B,m.highlightFormatting&&(e.formatting="code-block"),e.code=-1,L(e)):e.setext||!(h&&a||e.quote||!1!==e.list||e.code||s||x.test(t.string))&&(r=t.lookAhead(1))&&(r=r.match(p))?(e.setext?(e.header=e.setext,e.setext=0,t.skipToEnd(),m.highlightFormatting&&(e.formatting="header")):(e.header="="==r[0].charAt(0)?1:2,e.setext=e.header),e.thisLine.header=!0,e.f=e.inline,L(e)):s?(t.skipToEnd(),e.hr=!0,e.thisLine.hr=!0,c.hr):"["===t.peek()?C(t,e,b):C(t,e,e.inline)}function v(t,e){var i,n=d.token(t,e.htmlState);return u||("xml"==(i=w.innerMode(d,e.htmlState)).mode.name&&null===i.state.tagStart&&!i.state.context&&i.state.tokenize.isInText||e.md_inside&&-1<t.current().indexOf(">"))&&(e.f=T,e.block=r,e.htmlState=null),n}function B(t,e){var i,n=e.listStack[e.listStack.length-1]||0,u=e.indentation<n;return e.fencedEndRE&&e.indentation<=n+3&&(u||t.match(e.fencedEndRE))?(m.highlightFormatting&&(e.formatting="code-block"),u||(i=L(e)),e.localMode=e.localState=null,e.block=r,e.f=T,e.fencedEndRE=null,e.code=0,e.thisLine.fencedCodeEnd=!0,u?S(t,e,e.block):i):e.localMode?e.localMode.token(t,e.localState):(t.skipToEnd(),c.code)}function L(t){var e,i=[];if(t.formatting){i.push(c.formatting),"string"==typeof t.formatting&&(t.formatting=[t.formatting]);for(var n=0;n<t.formatting.length;n++)i.push(c.formatting+"-"+t.formatting[n]),"header"===t.formatting[n]&&i.push(c.formatting+"-"+t.formatting[n]+"-"+t.header),"quote"===t.formatting[n]&&(!m.maxBlockquoteDepth||m.maxBlockquoteDepth>=t.quote?i.push(c.formatting+"-"+t.formatting[n]+"-"+t.quote):i.push("error"))}return t.taskOpen?i.push("meta"):t.taskClosed?i.push("property"):(t.linkHref?i.push(c.linkHref,"url"):(t.strong&&i.push(c.strong),t.em&&i.push(c.em),t.strikethrough&&i.push(c.strikethrough),t.emoji&&i.push(c.emoji),t.linkText&&i.push(c.linkText),t.code&&i.push(c.code),t.image&&i.push(c.image),t.imageAltText&&i.push(c.imageAltText,"link"),t.imageMarker&&i.push(c.imageMarker)),t.header&&i.push(c.header,c.header+"-"+t.header),t.quote&&(i.push(c.quote),!m.maxBlockquoteDepth||m.maxBlockquoteDepth>=t.quote?i.push(c.quote+"-"+t.quote):i.push(c.quote+"-"+m.maxBlockquoteDepth)),!1!==t.list&&((e=(t.listStack.length-1)%3)?1==e?i.push(c.list2):i.push(c.list3):i.push(c.list1)),t.trailingSpaceNewLine?i.push("trailing-space-new-line"):t.trailingSpace&&i.push("trailing-space-"+(t.trailingSpace%2?"a":"b"))),i.length?i.join(" "):null}function e(t,e){if(t.match(i,!0))return L(e)}function T(t,e){var i=e.text(t,e);if(void 0!==i)return i;if(e.list)return e.list=null,L(e);if(e.taskList)return" "===t.match(F,!0)[1]?e.taskOpen=!0:e.taskClosed=!0,m.highlightFormatting&&(e.formatting="task"),e.taskList=!1,L(e);if(e.taskOpen=!1,e.taskClosed=!1,e.header&&t.match(/^#+$/,!0))return m.highlightFormatting&&(e.formatting="header"),L(e);var n=t.next();if(e.linkTitle){e.linkTitle=!1;i=((i="("===n?")":n)+"").replace(/([.?*+^\[\]\\(){}|-])/g,"\\$1");if(t.match(new RegExp("^\\s*(?:[^"+i+"\\\\]+|\\\\\\\\|\\\\.)"+i),!0))return c.linkHref}if("`"===n){var u=e.formatting;m.highlightFormatting&&(e.formatting="code"),t.eatWhile("`");var r=t.current().length;if(0!=e.code||e.quote&&1!=r){if(r!=e.code)return e.formatting=u,L(e);var a=L(e);return e.code=0,a}return e.code=r,L(e)}if(e.code)return L(e);if("\\"===n&&(t.next(),m.highlightFormatting)){var o=L(e),l=c.formatting+"-escape";return o?o+" "+l:l}if("!"===n&&t.match(/\[[^\]]*\] ?(?:\(|\[)/,!1))return e.imageMarker=!0,e.image=!0,m.highlightFormatting&&(e.formatting="image"),L(e);if("["===n&&e.imageMarker&&t.match(/[^\]]*\](\(.*?\)| ?\[.*?\])/,!1))return e.imageMarker=!1,e.imageAltText=!0,m.highlightFormatting&&(e.formatting="image"),L(e);if("]"===n&&e.imageAltText){m.highlightFormatting&&(e.formatting="image");o=L(e);return e.imageAltText=!1,e.image=!1,e.inline=e.f=q,o}if("["===n&&!e.image)return e.linkText&&t.match(/^.*?\]/)||(e.linkText=!0,m.highlightFormatting&&(e.formatting="link")),L(e);if("]"===n&&e.linkText){m.highlightFormatting&&(e.formatting="link");o=L(e);return e.linkText=!1,e.inline=e.f=t.match(/\(.*?\)| ?\[.*?\]/,!1)?q:T,o}if("<"===n&&t.match(/^(https?|ftps?):\/\/(?:[^\\>]|\\.)+>/,!1))return e.f=e.inline=M,m.highlightFormatting&&(e.formatting="link"),(o=L(e))?o+=" ":o="",o+c.linkInline;if("<"===n&&t.match(/^[^> \\]+@(?:[^\\>]|\\.)+>/,!1))return e.f=e.inline=M,m.highlightFormatting&&(e.formatting="link"),(o=L(e))?o+=" ":o="",o+c.linkEmail;if(m.xml&&"<"===n&&t.match(/^(!--|\?|!\[CDATA\[|[a-z][a-z0-9-]*(?:\s+[a-z_:.\-]+(?:\s*=\s*[^>]+)?)*\s*(?:>|$))/i,!1)){var h=t.string.indexOf(">",t.pos);return-1!=h&&(g=t.string.substring(t.start,h),/markdown\s*=\s*('|"){0,1}1('|"){0,1}/.test(g)&&(e.md_inside=!0)),t.backUp(1),e.htmlState=w.startState(d),S(t,e,v)}if(m.xml&&"<"===n&&t.match(/^\/\w*?>/))return e.md_inside=!1,"tag";if("*"===n||"_"===n){for(var s=1,u=1==t.pos?" ":t.string.charAt(t.pos-2);s<3&&t.eat(n);)s++;var r=t.peek()||" ",l=!/\s/.test(r)&&(!A.test(r)||/\s/.test(u)||A.test(u)),o=!/\s/.test(u)&&(!A.test(u)||/\s/.test(r)||A.test(r)),h=null,g=null;if(s%2&&(e.em||!l||"*"!==n&&o&&!A.test(u)?e.em!=n||!o||"*"!==n&&l&&!A.test(r)||(h=!1):h=!0),1<s&&(e.strong||!l||"*"!==n&&o&&!A.test(u)?e.strong!=n||!o||"*"!==n&&l&&!A.test(r)||(g=!1):g=!0),null!=g||null!=h){m.highlightFormatting&&(e.formatting=null==h?"strong":null==g?"em":"strong em"),!0===h&&(e.em=n),!0===g&&(e.strong=n);a=L(e);return!1===h&&(e.em=!1),!1===g&&(e.strong=!1),a}}else if(" "===n&&(t.eat("*")||t.eat("_"))){if(" "===t.peek())return L(e);t.backUp(1)}if(m.strikethrough)if("~"===n&&t.eatWhile(n)){if(e.strikethrough){m.highlightFormatting&&(e.formatting="strikethrough");a=L(e);return e.strikethrough=!1,a}if(t.match(/^[^\s]/,!1))return e.strikethrough=!0,m.highlightFormatting&&(e.formatting="strikethrough"),L(e)}else if(" "===n&&t.match("~~",!0)){if(" "===t.peek())return L(e);t.backUp(2)}if(m.emoji&&":"===n&&t.match(/^(?:[a-z_\d+][a-z_\d+-]*|\-[a-z_\d+][a-z_\d+-]*):/)){e.emoji=!0,m.highlightFormatting&&(e.formatting="emoji");a=L(e);return e.emoji=!1,a}return" "===n&&(t.match(/^ +$/,!1)?e.trailingSpace++:e.trailingSpace&&(e.trailingSpaceNewLine=!0)),L(e)}function M(t,e){if(">"!==t.next())return t.match(/^[^>]+/,!0),c.linkInline;e.f=e.inline=T,m.highlightFormatting&&(e.formatting="link");e=L(e);return e?e+=" ":e="",e+c.linkInline}function q(t,e){if(t.eatSpace())return null;var i,t=t.next();return"("===t||"["===t?(e.f=e.inline=(i="("===t?")":"]",function(t,e){if(t.next()!==i)return t.match(a[i]),e.linkHref=!0,L(e);e.f=e.inline=T,m.highlightFormatting&&(e.formatting="link-string");t=L(e);return e.linkHref=!1,t}),m.highlightFormatting&&(e.formatting="link-string"),e.linkHref=!0,L(e)):"error"}var a={")":/^(?:[^\\\(\)]|\\.|\((?:[^\\\(\)]|\\.)*\))*?(?=\))/,"]":/^(?:[^\\\[\]]|\\.|\[(?:[^\\\[\]]|\\.)*\])*?(?=\])/};function b(t,e){return t.match(/^([^\]\\]|\\.)*\]:/,!1)?(e.f=o,t.next(),m.highlightFormatting&&(e.formatting="link"),e.linkText=!0,L(e)):C(t,e,T)}function o(t,e){if(t.match("]:",!0)){e.f=e.inline=l,m.highlightFormatting&&(e.formatting="link");var i=L(e);return e.linkText=!1,i}return t.match(/^([^\]\\]|\\.)+/,!0),c.linkText}function l(t,e){return t.eatSpace()?null:(t.match(/^[^\s]+/,!0),void 0===t.peek()?e.linkTitle=!0:t.match(/^(?:\s+(?:"(?:[^"\\]|\\.)+"|'(?:[^'\\]|\\.)+'|\((?:[^)\\]|\\.)+\)))?/,!0),e.f=e.inline=T,c.linkHref+" url")}var h={startState:function(){return{f:r,prevLine:{stream:null},thisLine:{stream:null},block:r,htmlState:null,indentation:0,inline:T,text:e,formatting:!1,linkText:!1,linkHref:!1,linkTitle:!1,code:0,em:!1,strong:!1,header:0,setext:0,hr:!1,taskList:!1,list:!1,listStack:[],quote:0,trailingSpace:0,trailingSpaceNewLine:!1,strikethrough:!1,emoji:!1,fencedEndRE:null}},copyState:function(t){return{f:t.f,prevLine:t.prevLine,thisLine:t.thisLine,block:t.block,htmlState:t.htmlState&&w.copyState(d,t.htmlState),indentation:t.indentation,localMode:t.localMode,localState:t.localMode?w.copyState(t.localMode,t.localState):null,inline:t.inline,text:t.text,formatting:!1,linkText:t.linkText,linkTitle:t.linkTitle,linkHref:t.linkHref,code:t.code,em:t.em,strong:t.strong,strikethrough:t.strikethrough,emoji:t.emoji,header:t.header,setext:t.setext,hr:t.hr,taskList:t.taskList,list:t.list,listStack:t.listStack.slice(0),quote:t.quote,indentedCode:t.indentedCode,trailingSpace:t.trailingSpace,trailingSpaceNewLine:t.trailingSpaceNewLine,md_inside:t.md_inside,fencedEndRE:t.fencedEndRE}},token:function(t,e){if(e.formatting=!1,t!=e.thisLine.stream){if(e.header=0,e.hr=!1,t.match(/^\s*$/,!0))return n(e),null;if(e.prevLine=e.thisLine,e.thisLine={stream:t},e.taskList=!1,e.trailingSpace=0,e.trailingSpaceNewLine=!1,!e.localState&&(e.f=e.block,e.f!=v)){var i=t.match(/^\s*/,!0)[0].replace(/\t/g," ").length;if(e.indentation=i,e.indentationDiff=null,0<i)return null}}return e.f(t,e)},innerMode:function(t){return t.block==v?{state:t.htmlState,mode:d}:t.localState?{state:t.localState,mode:t.localMode}:{state:t,mode:h}},indent:function(t,e,i){return t.block==v&&d.indent?d.indent(t.htmlState,e,i):t.localState&&t.localMode.indent?t.localMode.indent(t.localState,e,i):w.Pass},blankLine:n,getType:L,blockCommentStart:"\x3c!--",blockCommentEnd:"--\x3e",closeBrackets:"()[]{}''\"\"``",fold:"markdown"};return h},"xml"),w.defineMIME("text/markdown","markdown"),w.defineMIME("text/x-markdown","markdown")}); |