marked-underline 1.0.1 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -2,16 +2,33 @@
2
2
 
3
3
  Add underline markup to Markdown by repurposing `_Text_`.
4
4
 
5
+ With the flag justUnderline set true, it will strip double and triple underline markup and leave it normal rather than
6
+
5
7
  # Usage
6
8
  <!-- Show most examples of how to use this extension -->
7
9
 
10
+ ## Default
11
+
12
+ ```js
13
+ const marked = require("marked");
14
+ const markedUnderline = require("marked-underline");
15
+
16
+ marked.use(markedUnderline());
17
+
18
+ const html = marked.parse("This is _underlined_.\nThis is __strong__.");
19
+ console.log(html);
20
+ // <p>This is <u>underlined</u>.\nThis is <strong>strong</strong>.</p>
21
+ ```
22
+
23
+ ## justUnderline enabled
24
+
8
25
  ```js
9
26
  const marked = require("marked");
10
- const markedSubSuper = require("marked-underline");
27
+ const markedUnderline = require("marked-underline");
11
28
 
12
- marked.use(markedSubSuper());
29
+ marked.use(markedUnderline({justUnderline: true}));
13
30
 
14
- const html = marked.parse("This is _underlined_.");
31
+ const html = marked.parse("This is _underlined_.\nThis is __normal__.");
15
32
  console.log(html);
16
- // <p>This is <u>underlined</u>.</p>
33
+ // <p>This is <u>underlined</u>.\nThis is normal.</p>
17
34
  ```
package/lib/index.cjs CHANGED
@@ -1,25 +1,29 @@
1
1
  'use strict';
2
2
 
3
- function index() {
3
+ function index({ justUnderline = false }) {
4
4
  return {
5
5
  extensions: [
6
6
  {
7
7
  name : 'underline',
8
8
  level : 'inline',
9
- start(src) { return src.match(/\b_([^_]*?)_\b/m)?.index;},
9
+ start(src) { return src.match(/\b_([^_]*?)_\b/m)?.index; },
10
10
  tokenizer(src, tokens) {
11
- const regex = /^\b_([^_]*?)_\b/m;
12
- const match = regex.exec(src);
13
- if(match?.length) {
14
- return {
15
- type : 'underline',
16
- raw : match[0],
17
- tokens : this.lexer.inlineTokens(match[1])
18
- };
11
+ const regex = /^\b(_{1,3})([^_]*?)(_{1,3})\b/m;
12
+ const match = regex.exec(src);
13
+ if (match?.length) {
14
+ if (match[1].length === match[3].length) {
15
+ const returnObj = {
16
+ type: 'underline',
17
+ raw: match[0],
18
+ tokens: this.lexer.inlineTokens(match[2]),
19
+ skip: justUnderline ? (match[1].length > 1) : false
20
+ };
21
+ if (justUnderline || (!justUnderline && (match[1].length === 1))) return returnObj;
22
+ }
19
23
  }
20
24
  },
21
- renderer(token) {
22
- return `<u>${this.parser.parseInline(token.tokens)}</u>`;
25
+ renderer(token) {
26
+ return `${token.skip ? '' : '<u>'}${this.parser.parseInline(token.tokens)}${token.skip ? '' : '</u>'}`;
23
27
  }
24
28
  }
25
29
  ]
package/lib/index.umd.js CHANGED
@@ -4,26 +4,30 @@
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global["subsuper-text"] = factory());
5
5
  })(this, (function () { 'use strict';
6
6
 
7
- function index() {
7
+ function index({ justUnderline = false }) {
8
8
  return {
9
9
  extensions: [
10
10
  {
11
11
  name : 'underline',
12
12
  level : 'inline',
13
- start(src) { return src.match(/\b_([^_]*?)_\b/m)?.index;},
13
+ start(src) { return src.match(/\b_([^_]*?)_\b/m)?.index; },
14
14
  tokenizer(src, tokens) {
15
- const regex = /^\b_([^_]*?)_\b/m;
16
- const match = regex.exec(src);
17
- if(match?.length) {
18
- return {
19
- type : 'underline',
20
- raw : match[0],
21
- tokens : this.lexer.inlineTokens(match[1])
22
- };
15
+ const regex = /^\b(_{1,3})([^_]*?)(_{1,3})\b/m;
16
+ const match = regex.exec(src);
17
+ if (match?.length) {
18
+ if (match[1].length === match[3].length) {
19
+ const returnObj = {
20
+ type: 'underline',
21
+ raw: match[0],
22
+ tokens: this.lexer.inlineTokens(match[2]),
23
+ skip: justUnderline ? (match[1].length > 1) : false
24
+ };
25
+ if (justUnderline || (!justUnderline && (match[1].length === 1))) return returnObj;
26
+ }
23
27
  }
24
28
  },
25
- renderer(token) {
26
- return `<u>${this.parser.parseInline(token.tokens)}</u>`;
29
+ renderer(token) {
30
+ return `${token.skip ? '' : '<u>'}${this.parser.parseInline(token.tokens)}${token.skip ? '' : '</u>'}`;
27
31
  }
28
32
  }
29
33
  ]
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "marked-underline",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Underline markup for Marked.js",
5
5
  "main": "./lib/index.cjs",
6
6
  "module": "./src/index.js",
package/src/index.js CHANGED
@@ -1,23 +1,27 @@
1
- export default function() {
1
+ export default function({ justUnderline = false }) {
2
2
  return {
3
3
  extensions: [
4
4
  {
5
5
  name : 'underline',
6
6
  level : 'inline',
7
- start(src) { return src.match(/\b_([^_]*?)_\b/m)?.index;},
7
+ start(src) { return src.match(/\b_([^_]*?)_\b/m)?.index; },
8
8
  tokenizer(src, tokens) {
9
- const regex = /^\b_([^_]*?)_\b/m;
10
- const match = regex.exec(src);
11
- if(match?.length) {
12
- return {
13
- type : 'underline',
14
- raw : match[0],
15
- tokens : this.lexer.inlineTokens(match[1])
16
- };
9
+ const regex = /^\b(_{1,3})([^_]*?)(_{1,3})\b/m;
10
+ const match = regex.exec(src);
11
+ if (match?.length) {
12
+ if (match[1].length === match[3].length) {
13
+ const returnObj = {
14
+ type: 'underline',
15
+ raw: match[0],
16
+ tokens: this.lexer.inlineTokens(match[2]),
17
+ skip: justUnderline ? (match[1].length > 1) : false
18
+ };
19
+ if (justUnderline || (!justUnderline && (match[1].length === 1))) return returnObj;
20
+ }
17
21
  }
18
22
  },
19
- renderer(token) {
20
- return `<u>${this.parser.parseInline(token.tokens)}</u>`;
23
+ renderer(token) {
24
+ return `${token.skip ? '' : '<u>'}${this.parser.parseInline(token.tokens)}${token.skip ? '' : '</u>'}`;
21
25
  }
22
26
  }
23
27
  ]