Skip to content

Commit 4425592

Browse files
authored
Bug fix - blockquote that start with a space (#108)
* hide mermaid stuff as not ready for this yet * bump lodash with audit fix * add blockquote test cases * should run on node 20 * Fix custom blockquotes that start with a space. spaces do not have tokens which breaks the `tokens[0].tokens` logic. Also when a standard blockquote is found it uses Marked standard renderer to convert it to html
1 parent 116b0e5 commit 4425592

7 files changed

Lines changed: 62 additions & 23 deletions

File tree

.node-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22
1+
20

.nvmrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
22
1+
20

default-md-files/morty-docs.md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,28 @@ Do images still work?
3333
- `critical` - an alarm that 247/Ops should act on indicating direct audience impact. Ops will
3434
consult your product runbook and perform the required escalation actions listed there.
3535

36+
## Blockquote 1
37+
> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
38+
>
39+
- list item 1
40+
- list item 2
41+
- list item 3
42+
- list item 4
43+
>
44+
> Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
45+
>
46+
> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
47+
48+
## Blockquote 2
49+
>
50+
> Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
51+
>
52+
> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
53+
54+
## Blockquote 3
55+
> Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.
56+
> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.
57+
3658
## ⚠️ Github Alerts
3759

3860
> [!NOTE]
@@ -52,6 +74,12 @@ Do images still work?
5274
5375
> [!CAUTION]
5476
> Negative potential consequences of an action.
77+
78+
> [!CAUTION]
79+
>
80+
> Testing blank spaces
81+
>
82+
> Testing blank spaces
5583
5684
## Mermaid Image Conversion
5785

@@ -67,7 +95,7 @@ John->>Bob: How about you?
6795
Bob-->>John: Jolly good!
6896
```
6997

70-
converted image below.....hopefully
98+
converted images below.....hopefully
7199

72100
```mermaid
73101
sequenceDiagram

package-lock.json

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/markdown-to-html-parser.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,19 @@ const parseToHTML = (markdown, options = {}) => {
4141
return `<h${depth} id="${escapedText}">${text}</h${depth}>`
4242
},
4343
blockquote ({ tokens }) {
44-
const textString = this.parser.parseInline(tokens[0].tokens)
45-
const alertMatch = textString.match(/\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]/i)
44+
let textString = ''
45+
tokens.forEach(token => {
46+
if (token.tokens) {
47+
textString += this.parser.parseInline(token.tokens)
48+
} else if (token.type === 'space') {
49+
textString += this.parser.parseInline([{ type: 'br', text: token.text, raw: token.raw }])
50+
} else {
51+
textString += this.parser.parseInline(tokens)
52+
}
53+
})
4654

47-
if (!alertMatch) return `<blockquote>${textString}</blockquote>`
55+
const alertMatch = textString.match(/\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]/i)
56+
if (!alertMatch) return marked.Renderer.prototype.blockquote.call(this, { tokens }) // default behavior
4857

4958
const type = alertMatch[1].toLowerCase()
5059
let content = textString.replace(/\[![A-Z]+\]/i, '')
@@ -60,7 +69,7 @@ const parseToHTML = (markdown, options = {}) => {
6069
// Custom replacements
6170
html = html.replace(/<a href="([^:\n]*?).md">/g, '<a href="$1.html">') // convertMdLinksToHtmlLinks
6271
html = html.replace(/<a href="([^:\n]*?).md#(.*?)">/g, '<a href="$1.html#$2">') // convertMdHashLinksToHtmlLinks
63-
html = html.replace(/<(h[123456]) id="([^"]+)">(.*)<\/\1>/g, '<$1 id="$2"><a href="#$2">$3</a></$1>') // headingExtension
72+
html = html.replace(/<(h[123456]) id="([^"]+)">([\s\S]*?)<\/\1>/g, '<$1 id="$2"><a href="#$2">$3</a></$1>') // headingExtension
6473
html = html.replace(/<table(.*)>/g, '<table class="table" $1>') // add class to table tags
6574
html = html.replace(/<img(.*)>/g, '<img class="img-responsive" $1 />') // add class to image tags
6675
html = html.replace(/<li>(<input.*)<\/li>/g, '<li class="task-list-item">$1</li>') // add class for list items (must have input at beginning)

src/transform.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const path = require('path')
22

33
const transformContent = require('./transform-content')
4-
const generateMermaidContent = require('./generate-mermaid-content')
4+
// const generateMermaidContent = require('./generate-mermaid-content')
55
const generateIndexes = require('./generate-indexes')
66

77
const validate = (inputObjs) => {
@@ -22,8 +22,9 @@ const transform = (inputObjs, options) => {
2222
const ext = path.extname(inputObj.relativePath)
2323
if (ext === '.md') { // || ext === '.asciidoc' || ext === '.adoc' || ext === '.asc'
2424
// Create mermaid images and transform markdown
25-
const mermaidContent = generateMermaidContent(inputObj, options.rootPath)
26-
mermaidImages.push(...mermaidContent.images)
25+
// const mermaidContent = generateMermaidContent(inputObj, options.rootPath)
26+
// mermaidImages.push(...mermaidContent.images)
27+
const mermaidContent = { inputObj }
2728
return transformContent(mermaidContent.inputObj, options)
2829
} else {
2930
return inputObj

test/unit/markdown-to-html-parser.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ describe('Markdown Parser', () => {
8181
},
8282
{
8383
markdown: '> Normal quote text',
84-
expected: '<blockquote>Normal quote text</blockquote>'
84+
expected: '<blockquote><p>Normal quote text</p></blockquote>'
8585
},
8686
{
8787
markdown: '> [!TIP]\n> Multi-line\n> Multi-line\n> Multi-line',

0 commit comments

Comments
 (0)