{"title":"$:/plugins/tiddlywiki/codemirror-closetag","name":"CodeMirror Close Tag","description":"Close tags automatically for CodeMirror","parent-plugin":"$:/plugins/tiddlywiki/codemirror","list":"readme","version":"5.2.2","plugin-type":"plugin","dependents":"","type":"application/json","tiddlers":{"$:/config/codemirror/autoCloseTags":{"title":"$:/config/codemirror/autoCloseTags","type":"bool","text":"true\n"},"$:/language/codemirror/autoCloseTags/hint":{"title":"$:/language/codemirror/autoCloseTags/hint","text":"Auto-close tags"},"$:/language/codemirror/autoCloseTags/info":{"title":"$:/language/codemirror/autoCloseTags/info","text":"Whether or not to automatically close tags"},"$:/plugins/tiddlywiki/codemirror/addon/fold/xml-fold.js":{"text":"// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: https://codemirror.net/LICENSE\n!function(e){\"object\"==typeof exports&&\"object\"==typeof module?e(require(\"../../lib/codemirror\")):\"function\"==typeof define&&define.amd?define([\"../../lib/codemirror\"],e):e(CodeMirror)}(function(e){\"use strict\";var l=e.Pos;function c(e,n){return e.line-n.line||e.ch-n.ch}var n=\"A-Z_a-z\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD\",i=new RegExp(\"<(/?)([\"+n+\"][A-Z_a-z\\\\u00C0-\\\\u00D6\\\\u00D8-\\\\u00F6\\\\u00F8-\\\\u02FF\\\\u0370-\\\\u037D\\\\u037F-\\\\u1FFF\\\\u200C-\\\\u200D\\\\u2070-\\\\u218F\\\\u2C00-\\\\u2FEF\\\\u3001-\\\\uD7FF\\\\uF900-\\\\uFDCF\\\\uFDF0-\\\\uFFFD-:.0-9\\\\u00B7\\\\u0300-\\\\u036F\\\\u203F-\\\\u2040]*)\",\"g\");function a(e,n,t,i){this.line=n,this.ch=t,this.cm=e,this.text=e.getLine(n),this.min=i?Math.max(i.from,e.firstLine()):e.firstLine(),this.max=i?Math.min(i.to-1,e.lastLine()):e.lastLine()}function s(e,n){var t=e.cm.getTokenTypeAt(l(e.line,n));return t&&/\\btag\\b/.test(t)}function r(e){return!(e.line>=e.max)&&(e.ch=0,e.text=e.cm.getLine(++e.line),1)}function h(e){return!(e.line<=e.min)&&(e.text=e.cm.getLine(--e.line),e.ch=e.text.length,1)}function F(e){for(;;){var n=e.text.indexOf(\">\",e.ch);if(-1==n){if(r(e))continue;return}if(s(e,n+1)){var t=e.text.lastIndexOf(\"/\",n),i=-1<t&&!/\\S/.test(e.text.slice(t+1,n));return e.ch=n+1,i?\"selfClose\":\"regular\"}e.ch=n+1}}function x(e){for(;;){var n=e.ch?e.text.lastIndexOf(\"<\",e.ch-1):-1;if(-1==n){if(h(e))continue;return}if(s(e,n+1)){i.lastIndex=n,e.ch=n;var t=i.exec(e.text);if(t&&t.index==n)return t}else e.ch=n}}function g(e){for(;;){i.lastIndex=e.ch;var n=i.exec(e.text);if(!n){if(r(e))continue;return}if(s(e,n.index+1))return e.ch=n.index+n[0].length,n;e.ch=n.index+1}}function v(e,n){for(var t=[];;){var i,r=g(e),u=e.line,f=e.ch-(r?r[0].length:0);if(!r||!(i=F(e)))return;if(\"selfClose\"!=i)if(r[1]){for(var o=t.length-1;0<=o;--o)if(t[o]==r[2]){t.length=o;break}if(o<0&&(!n||n==r[2]))return{tag:r[2],from:l(u,f),to:l(e.line,e.ch)}}else t.push(r[2])}}function d(e,n){for(var t=[];;){var i=function(e){for(;;){var n=e.ch?e.text.lastIndexOf(\">\",e.ch-1):-1;if(-1==n){if(h(e))continue;return}if(s(e,n+1)){var t=e.text.lastIndexOf(\"/\",n),i=-1<t&&!/\\S/.test(e.text.slice(t+1,n));return e.ch=n+1,i?\"selfClose\":\"regular\"}e.ch=n}}(e);if(!i)return;if(\"selfClose\"!=i){var r=e.line,u=e.ch,f=x(e);if(!f)return;if(f[1])t.push(f[2]);else{for(var o=t.length-1;0<=o;--o)if(t[o]==f[2]){t.length=o;break}if(o<0&&(!n||n==f[2]))return{tag:f[2],from:l(e.line,e.ch),to:l(r,u)}}}else x(e)}}e.registerHelper(\"fold\",\"xml\",function(e,n){for(var t=new a(e,n.line,0);;){var i=g(t);if(!i||t.line!=n.line)return;var r=F(t);if(!r)return;if(!i[1]&&\"selfClose\"!=r){var u=l(t.line,t.ch),f=v(t,i[2]);return f&&0<c(f.from,u)?{from:u,to:f.from}:null}}}),e.findMatchingTag=function(e,n,t){var i=new a(e,n.line,n.ch,t);if(-1!=i.text.indexOf(\">\")||-1!=i.text.indexOf(\"<\")){var r=F(i),u=r&&l(i.line,i.ch),f=r&&x(i);if(r&&f&&!(0<c(i,n))){var o={from:l(i.line,i.ch),to:u,tag:f[2]};return\"selfClose\"==r?{open:o,close:null,at:\"open\"}:f[1]?{open:d(i,f[2]),close:o,at:\"close\"}:{open:o,close:v(i=new a(e,u.line,u.ch,t),f[2]),at:\"open\"}}}},e.findEnclosingTag=function(e,n,t,i){for(var r=new a(e,n.line,n.ch,t);;){var u=d(r,i);if(!u)break;var f=v(new a(e,n.line,n.ch,t),u.tag);if(f)return{open:u,close:f}}},e.scanForClosingTag=function(e,n,t,i){return v(new a(e,n.line,n.ch,i?{from:0,to:i}:null),t)}});\n","type":"application/javascript","title":"$:/plugins/tiddlywiki/codemirror/addon/fold/xml-fold.js","module-type":"codemirror"},"$:/plugins/tiddlywiki/codemirror/addon/edit/closetag.js":{"text":"// CodeMirror, copyright (c) by Marijn Haverbeke and others\n// Distributed under an MIT license: https://codemirror.net/LICENSE\n!function(e){\"object\"==typeof exports&&\"object\"==typeof module?e(require(\"../../lib/codemirror\"),require(\"../fold/xml-fold\")):\"function\"==typeof define&&define.amd?define([\"../../lib/codemirror\",\"../fold/xml-fold\"],e):e(CodeMirror)}(function(y){y.defineOption(\"autoCloseTags\",!1,function(e,t,n){var o;n!=y.Init&&n&&e.removeKeyMap(\"autoCloseTags\"),t&&(o={name:\"autoCloseTags\"},\"object\"==typeof t&&!1===t.whenClosing||(o[\"'/'\"]=function(e){return(t=e).getOption(\"disableInput\")?y.Pass:r(t,!0);var t}),\"object\"==typeof t&&!1===t.whenOpening||(o[\"'>'\"]=function(e){if(e.getOption(\"disableInput\"))return y.Pass;for(var t=e.listSelections(),n=[],o=e.getOption(\"autoCloseTags\"),r=0;r<t.length;r++){if(!t[r].empty())return y.Pass;var a=t[r].head,i=e.getTokenAt(a),l=y.innerMode(e.getMode(),i.state),s=l.state,d=l.mode.xmlCurrentTag&&l.mode.xmlCurrentTag(s),c=d&&d.name;if(!c)return y.Pass;var f=\"html\"==l.mode.configuration,g=\"object\"==typeof o&&o.dontCloseTags||f&&x,u=\"object\"==typeof o&&o.indentTags||f&&P;i.end>a.ch&&(c=c.slice(0,c.length-i.end+a.ch));var m=c.toLowerCase();if(!c||\"string\"==i.type&&(i.end!=a.ch||!/[\\\"\\']/.test(i.string.charAt(i.string.length-1))||1==i.string.length)||\"tag\"==i.type&&d.close||i.string.indexOf(\"/\")==a.ch-i.start-1||g&&-1<T(g,m)||j(e,l.mode.xmlCurrentContext&&l.mode.xmlCurrentContext(s)||[],c,a,!0))return y.Pass;var h,p=\"object\"==typeof o&&o.emptyTags;p&&-1<T(p,c)?n[r]={text:\"/>\",newPos:y.Pos(a.line,a.ch+2)}:(h=u&&-1<T(u,m),n[r]={indent:h,text:\">\"+(h?\"\\n\\n\":\"\")+\"</\"+c+\">\",newPos:h?y.Pos(a.line+1,0):y.Pos(a.line,a.ch+1)})}for(var C=\"object\"==typeof o&&o.dontIndentOnAutoClose,r=t.length-1;0<=r;r--){var b=n[r];e.replaceRange(b.text,t[r].head,t[r].anchor,\"+insert\");var v=e.listSelections().slice(0);v[r]={head:b.newPos,anchor:b.newPos},e.setSelections(v),!C&&b.indent&&(e.indentLine(b.newPos.line,null,!0),e.indentLine(b.newPos.line+1,null,!0))}}),e.addKeyMap(o))});var x=[\"area\",\"base\",\"br\",\"col\",\"command\",\"embed\",\"hr\",\"img\",\"input\",\"keygen\",\"link\",\"meta\",\"param\",\"source\",\"track\",\"wbr\"],P=[\"applet\",\"blockquote\",\"body\",\"button\",\"div\",\"dl\",\"fieldset\",\"form\",\"frameset\",\"h1\",\"h2\",\"h3\",\"h4\",\"h5\",\"h6\",\"head\",\"html\",\"iframe\",\"layer\",\"legend\",\"object\",\"ol\",\"p\",\"select\",\"table\",\"ul\"];function r(e,t){for(var n=e.listSelections(),o=[],r=t?\"/\":\"</\",a=e.getOption(\"autoCloseTags\"),i=\"object\"==typeof a&&a.dontIndentOnSlash,l=0;l<n.length;l++){if(!n[l].empty())return y.Pass;var s=n[l].head,d=e.getTokenAt(s),c=y.innerMode(e.getMode(),d.state),f=c.state;if(t&&(\"string\"==d.type||\"<\"!=d.string.charAt(0)||d.start!=s.ch-1))return y.Pass;var g,u=\"xml\"!=c.mode.name&&\"htmlmixed\"==e.getMode().name;if(u&&\"javascript\"==c.mode.name)g=r+\"script\";else if(u&&\"css\"==c.mode.name)g=r+\"style\";else{var m=c.mode.xmlCurrentContext&&c.mode.xmlCurrentContext(f);if(!m||m.length&&j(e,m,m[m.length-1],s))return y.Pass;g=r+m[m.length-1]}\">\"!=e.getLine(s.line).charAt(d.end)&&(g+=\">\"),o[l]=g}if(e.replaceSelections(o),n=e.listSelections(),!i)for(l=0;l<n.length;l++)(l==n.length-1||n[l].head.line<n[l+1].head.line)&&e.indentLine(n[l].head.line)}function T(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0,o=e.length;n<o;++n)if(e[n]==t)return n;return-1}function j(e,t,n,o,r){if(y.scanForClosingTag){var a=Math.min(e.lastLine()+1,o.line+500),i=y.scanForClosingTag(e,o,null,a);if(i&&i.tag==n){for(var l=r?1:0,s=t.length-1;0<=s&&t[s]==n;s--)++l;o=i.to;for(s=1;s<l;s++){var d=y.scanForClosingTag(e,o,null,a);if(!d||d.tag!=n)return;o=d.to}return 1}}}y.commands.closeTag=function(e){return r(e)}});\n","type":"application/javascript","title":"$:/plugins/tiddlywiki/codemirror/addon/edit/closetag.js","module-type":"codemirror"},"$:/plugins/tiddlywiki/codemirror-closetag/readme":{"title":"$:/plugins/tiddlywiki/codemirror-closetag/readme","text":"This plugin adds the ability to ''automatically close Tags''. It needs the latest [[CodeMirror plugin|$:/plugins/tiddlywiki/codemirror]] to be installed\n\n\n"},"$:/core/ui/ControlPanel/Settings/codemirror/autoCloseTags":{"title":"$:/core/ui/ControlPanel/Settings/codemirror/autoCloseTags","tags":"$:/tags/ControlPanel/Settings/CodeMirror","caption":"{{$:/language/codemirror/autoCloseTags/hint}}","text":"\\define lingo-base() $:/language/codemirror/autoCloseTags/\n<<lingo hint>>\n\n<$checkbox tiddler=\"$:/config/codemirror/autoCloseTags\" field=\"text\" checked=\"true\" unchecked=\"false\" default=\"true\"> <$link to=\"$:/config/codemirror/autoCloseTags\"><<lingo info>></$link> </$checkbox>\n\n"}}}