From 30dd124a07a6c783a2875f781c53b9ed59b952cb Mon Sep 17 00:00:00 2001 From: ache Date: Sun, 30 Dec 2018 08:01:31 +0100 Subject: Clean the code and description --- README.md | 46 +++++++++++++++++++++++++++++----------------- app.js | 13 +++++-------- 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/README.md b/README.md index 60c80ae..709e07c 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,8 @@ # remark-line-input -A [remark](https://github.com/remarkjs/remark/) plugin that parse Mardown syntax to add support for line input. +A [remark](https://github.com/remarkjs/remark/) plugin that parse markdown syntax to add support for line input. +This plugin is intend to be used with Javascript to create interaction. ## Syntax @@ -11,48 +12,55 @@ You can add a line input this way : [___Placeholder___] ``` -Wich leads to : +Which leads to : ![Screenshot](https://raw.githubusercontent.com/arobase-che/remark-line-input/master/images/example_1.png) -You must use at least 2 underscores, and no spaces are allowed between the opening bracket and the first underscore nor between the last underscore and the closing bracket. Spaces can be used in the placeholder : +A markdown line input starts by `[__` and ends by `__]`. ```markdown [___hold my beer___] ``` +That syntax is not valid : +```markdown +[___ Spaces_are_not_allowed ___] + ^ ^^ + +[___Nor line feeds +____] +``` + ## Installation -Easy as npm i +Easy as [npm][npm] i ```shell $ npm install remark-line-input ``` -You install also that plugins : "unified remark-parse rehype-stringify remark-rehype" -```shell -$ npm install unified remark-parse rehype-stringify remark-rehype -``` - -## Usage - -An example of code : +## Dependencies: -```js +```javascript const unified = require('unified') const remarkParse = require('remark-parse') const stringify = require('rehype-stringify') const remark2rehype = require('remark-rehype') - const lineInput = require('remark-line-input') +``` + +## Usage +An example of code : + +```javascript const testFile = `Login : [__email or username__]{#login} Passwd: [__Passwd__]{#password type=password}` unified() .use(remarkParse) .use(lineInput) - .use(remark2rehype) + .use(remark2rehype) .use(stringify) .process( testFile, (err, file) => { console.log(String(file)); @@ -62,7 +70,7 @@ unified() ## Configuration -This plugin support custom HTML attributes : +This plugin support custom HTML attributes thought [md-attr-parser][attr] : ```markdown [___Password___]{type=password} @@ -80,5 +88,9 @@ Or : ## Licence -MIT +Distributed under a MIT-like license. + +[attr]: "https://github.com/arobase-che/md-attr-parser" + +[npm]: "https://www.npmjs.com/package/remark-line-input" diff --git a/app.js b/app.js index 447d560..a267474 100644 --- a/app.js +++ b/app.js @@ -16,8 +16,8 @@ function locator(value, fromIndex) { /* 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, silent) { - if (!this.options.gfm || !value.startsWith(START)) { + function inlineTokenizer(eat, value) { + if (!value.startsWith(START)) { return; } @@ -25,6 +25,7 @@ function plugin() { let index = START.length; const {length} = value; + /* 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') { @@ -36,23 +37,19 @@ function plugin() { let letsEat = ''; let prop = { /* key: undefined {} class: undefined [] id: undefined */}; - /* Parse the attributes if any */ + /* Parse the attributes if any with md-attr-parser */ if (value.charAt(index + END.length) === '{') { const res = parseAttr(value, index + END.length); letsEat = res.eaten; ({prop} = res); } - /* istanbul ignore if - never used (yet) */ - if (silent) { - return true; - } - /* 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) { -- cgit v1.2.3