aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorache <ache@ache.one>2018-12-30 08:11:30 +0100
committerache <ache@ache.one>2018-12-30 08:11:30 +0100
commit5c7c481804a67aeda770ed90727e4b51119c563b (patch)
treea46fa410961a2289a5339e00630b53e6ce43684d
parentDistribution with babel (diff)
Add distribution file
-rw-r--r--dist/index.js94
1 files changed, 94 insertions, 0 deletions
diff --git a/dist/index.js b/dist/index.js
new file mode 100644
index 0000000..c93b66e
--- /dev/null
+++ b/dist/index.js
@@ -0,0 +1,94 @@
+'use strict';
+
+var parseAttr = require('md-attr-parser');
+
+var START = '[__';
+var END = '__]';
+/* Function used to locate the start of a line input filed
+ * Used by remark
+ */
+
+function locator(value, fromIndex) {
+ var index = value.indexOf(START, fromIndex);
+ return index;
+}
+/* Funtion which is exported */
+
+
+function plugin() {
+ /* Verifie if it's the syntax of a line input and return a line input node */
+ function inlineTokenizer(eat, value) {
+ if (!value.startsWith(START)) {
+ return;
+ }
+
+ var subvalue = '';
+ var index = START.length;
+ var length = value.length;
+ /* Try to locale the end of the line input */
+
+ while (!value.startsWith(END, index) && index < length) {
+ subvalue += value.charAt(index);
+
+ if (value.charAt(index) === '\n') {
+ return true;
+ }
+
+ index++;
+ }
+
+ var letsEat = '';
+ var prop = {
+ /* key: undefined {} class: undefined [] id: undefined */
+ };
+ /* Parse the attributes if any with md-attr-parser */
+
+ if (value.charAt(index + END.length) === '{') {
+ var res = parseAttr(value, index + END.length);
+ letsEat = res.eaten;
+ prop = res.prop;
+ }
+ /* Allow some other kind of input */
+
+
+ if (prop.type !== 'password') {
+ prop.type = 'text';
+ }
+ /* Underscores in the placeholder become whitespaces */
+
+
+ prop.placeholder = subvalue.replace(/^_*/g, '').replace(/_*$/g, '') || undefined;
+
+ if (index < length) {
+ return eat(START + subvalue + END + letsEat)({
+ type: 'line-input',
+ children: [],
+ data: {
+ hName: 'input',
+ hProperties: prop
+ }
+ });
+ }
+
+ 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 "[__".concat(this.all(node).join(''), "__]");
+ };
+ }
+}
+
+module.exports = plugin; \ No newline at end of file