aboutsummaryrefslogtreecommitdiff
path: root/app.js
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-12-06 12:28:48 +0100
committerache <ache@ache.one>2017-12-06 12:28:48 +0100
commit749e7200f5fbff27bc20250ceb410ec8629e4a26 (patch)
treea2679d9e870ac0c711b2395d15cbc5e0705d2c64 /app.js
Init commit
Diffstat (limited to 'app.js')
-rw-r--r--app.js63
1 files changed, 63 insertions, 0 deletions
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..b244cb8
--- /dev/null
+++ b/app.js
@@ -0,0 +1,63 @@
+'use strict';
+
+
+const START = /^(\[_+)/g;
+const END = /(_+])/g;
+
+function locator(value, fromIndex) {
+ var index = value.indexOf(START, fromIndex);
+ return index;
+}
+
+function plugin() {
+ function blockTokenizer(eat, value, silent) {
+
+ if (!this.options.gfm || value.search(START) != 0) {
+ return;
+ }
+ if( value.search(END) > 0 ) {
+ return eat(value.slice(0,value.search(END))+value.match(END)[0])({
+ type:'html',
+ value:'<textarea>' + value.slice(value.match(START)[0].length+1, value.search(END)-1 ) + '</textarea>'
+ /*
+ type: 'form',
+ children: [ {
+ type: 'texterea',
+ children: [ { type: 'text',
+ value: value.slice(value.match(START)[0].length+1, value.search(END)-1 )
+ } ],
+ data: {
+ hName: 'textarea'
+ }
+ }],
+ data: {
+ hName: 'form'
+ }*/
+ });
+ } else
+ return true;
+ }
+
+ blockTokenizer.locator = locator;
+
+ var Parser = this.Parser;
+
+ // Inject blockTokenizer
+ const blockTokenizers = Parser.prototype.blockTokenizers
+ const blockMethods = Parser.prototype.blockMethods
+ blockTokenizers.textinput = blockTokenizer
+ blockMethods.splice(blockMethods.indexOf('fencedCode') + 1, 0, 'textinput')
+
+
+ var Compiler = this.Compiler;
+
+ // Stringify
+ if (Compiler) {
+ var visitors = Compiler.prototype.visitors;
+ visitors.textinput = function (node) {
+ return '[__' + this.all(node).join('') + '__]';
+ };
+ }
+}
+
+module.exports = plugin;