aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2017-12-06 12:27:56 +0100
committerache <ache@ache.one>2017-12-06 12:27:56 +0100
commit9db7066e980364d6efa057fd7ad2251be3073008 (patch)
tree7065ee3fa9734933473aa09a6e0a314aa87ffc44
Init commit
-rw-r--r--LICENSE19
-rw-r--r--README.md3
-rw-r--r--app.js74
-rw-r--r--package.json19
4 files changed, 115 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..9cf1062
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,19 @@
+MIT License
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1b8bcdf
--- /dev/null
+++ b/README.md
@@ -0,0 +1,3 @@
+# remark-line-input
+
+
diff --git a/app.js b/app.js
new file mode 100644
index 0000000..afc4eee
--- /dev/null
+++ b/app.js
@@ -0,0 +1,74 @@
+'use strict';
+
+
+const START = '[__';
+const END = '__]';
+
+function locator(value, fromIndex) {
+ var index = value.indexOf(START, fromIndex);
+ return index;
+}
+
+function plugin() {
+ function inlineTokenizer(eat, value, silent) {
+ if (!this.options.gfm || !value.startsWith(START)) {
+ return;
+ }
+
+ var character = '';
+ var previous = '';
+ var preceding = '';
+ var subvalue = '';
+ var index = 1;
+ var length = value.length;
+ var now = eat.now();
+ now.column += 2;
+ now.offset += 2;
+
+ while (!value.startsWith(END, index) && ++index < length) {
+ subvalue+=value.charAt(index);
+ if( value.charAt(index) == '\n' )
+ return true;
+
+ }
+ /* istanbul ignore if - never used (yet) */
+ if (silent) return true;
+
+ if( index < length )
+ return eat(START + subvalue.slice(1) + END.slice(1) )({
+ type: 'lineEdit',
+ children: [],
+ data: {
+ hName: 'input',
+ hProperties: {
+ type: 'text',
+ placeholder: subvalue
+ }
+ }
+ });
+ else
+ return true;
+
+ }
+ inlineTokenizer.locator = locator;
+
+ var Parser = this.Parser;
+
+ // Inject inlineTokenizer
+ var inlineTokenizers = Parser.prototype.inlineTokenizers;
+ var inlineMethods = Parser.prototype.inlineMethods;
+ inlineTokenizers.input = inlineTokenizer;
+ inlineMethods.splice(inlineMethods.indexOf('url'), 0, 'input');
+
+ var Compiler = this.Compiler;
+
+ // Stringify
+ if (Compiler) {
+ var visitors = Compiler.prototype.visitors;
+ visitors.lineinput = function (node) {
+ return '[__' + this.all(node).join('') + '__]';
+ };
+ }
+}
+
+module.exports = plugin;
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..c28d895
--- /dev/null
+++ b/package.json
@@ -0,0 +1,19 @@
+{
+ "name": "remark-line-input",
+ "version": "0.1.0",
+ "description": "A remark plugin to parse line input syntax.",
+ "main": "app.js",
+ "scripts": {
+ "start": "node app.js"
+ },
+ "dependencies": {
+ "unist-util-visit": "^1.1.3"
+ },
+ "author": "ache",
+ "license": "MIT",
+ "keywords": [
+ "line",
+ "input",
+ "remark"
+ ]
+}