@deskeen/markdown
Advanced tools
Comparing version 5.2.2 to 5.3.1
# Changelog | ||
## 5.3.1 - 2023-08-27 | ||
**🌟 New** | ||
- Escaped closing brackets are supported in links. | ||
## 5.2.2 - 2023-08-24 | ||
@@ -4,0 +10,0 @@ |
{ | ||
"name": "@deskeen/markdown", | ||
"version": "5.2.2", | ||
"version": "5.3.1", | ||
"description": "Node.js Markdown to HTML Parser", | ||
@@ -5,0 +5,0 @@ "author": "Morgan Schmiedt", |
@@ -326,3 +326,3 @@ # Parseur Markdown vers HTML pour Node.js | ||
Un lien est composé de deux parties. Le texte, entouré de crochets (`[]`) suivi du lien, entouré de parenthèses (`( )`). i.e. `[Link](url)` | ||
Un lien est composé de deux parties. Le texte, entouré de crochets (`[]`) suivi du lien, entouré de parenthèses (`( )`), i.e. `[Link](url)`. Les crochets fermants dans le texte doivent être précédés du caractère d'échappement. | ||
@@ -339,2 +339,13 @@ *Exemple* | ||
*Exemple avec un crochet fermant* | ||
``` | ||
Selon [[1\]](#ref1), ce module est le meilleur ! | ||
``` | ||
```html | ||
<p>Selon <a href="#ref1">[1]</a>, ce module est le meilleur !</p> | ||
``` | ||
### Image | ||
@@ -341,0 +352,0 @@ |
@@ -327,3 +327,3 @@ # Node.js Markdown to HTML Parser | ||
A link is made up of two parts. The text in square brackets (`[]`), followed by an URL in round brackets (`( )`). i.e. `[Link](url)` | ||
A link is made up of two parts. The text in square brackets (`[]`), followed by an URL in round brackets (`( )`), i.e. `[Link](url)`. Closing brackets in the text must be escaped. | ||
@@ -339,3 +339,13 @@ *Example* | ||
*Example with a closing bracket* | ||
``` | ||
According to [[1\]](#ref1), this package is the best! | ||
``` | ||
```html | ||
<p>According to <a href="#ref1">[1]</a>, this package is the best!</p> | ||
``` | ||
### Image | ||
@@ -342,0 +352,0 @@ |
@@ -26,2 +26,6 @@ 'use strict' | ||
new RegExp(`\\${MD_ESCAPE_CHAR}([${MD_CHARS}])`, 'g') | ||
const REGEX_REP_ESC_CHAR_LINK_TEXT = | ||
new RegExp(`\\${MD_ESCAPE_CHAR}\\]`, 'g') | ||
const REGEX_CLOSING_LINK = | ||
new RegExp(`^((?:[^\\]]|\\${MD_ESCAPE_CHAR}])+?)]\\(([^)]+?)\\)`) | ||
@@ -657,3 +661,3 @@ const removeEscapeChars = text => | ||
} else if (allowLink) { | ||
const endMatch = /^([^\]]+?)]\(([^)]+?)\)/.exec(restLineText) | ||
const endMatch = REGEX_CLOSING_LINK.exec(restLineText) | ||
@@ -664,2 +668,3 @@ if (endMatch) { | ||
const title = endMatch[1] | ||
.replace(REGEX_REP_ESC_CHAR_LINK_TEXT, ']') | ||
const url = endMatch[2] | ||
@@ -666,0 +671,0 @@ |
@@ -34,2 +34,10 @@ 'use strict' | ||
test('Link with a closing bracket inside', function (t) { | ||
const input = 'see [[1\\]](#ref1) (...)' | ||
const output = '<p>see <a href="#ref1">[1]</a> (...)</p>' | ||
t.equal(parseToHtml(input), output, 'Output is valid') | ||
t.end() | ||
}) | ||
test('Link with callback', function (t) { | ||
@@ -36,0 +44,0 @@ const input = 'This is a [link](https://example.com)' |
168605
3268
927