Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
20
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
22
20
30 changes: 29 additions & 1 deletion default-md-files/morty-docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,28 @@ Do images still work?
- `critical` - an alarm that 247/Ops should act on indicating direct audience impact. Ops will
consult your product runbook and perform the required escalation actions listed there.

## Blockquote 1
> Lorem Ipsum is simply dummy text of the printing and typesetting industry.
>
- list item 1
- list item 2
- list item 3
- list item 4
>
> 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.
>
> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

## Blockquote 2
>
> 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.
>
> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

## Blockquote 3
> 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.
> It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged.

## ⚠️ Github Alerts

> [!NOTE]
Expand All @@ -52,6 +74,12 @@ Do images still work?

> [!CAUTION]
> Negative potential consequences of an action.

> [!CAUTION]
>
> Testing blank spaces
>
> Testing blank spaces

## Mermaid Image Conversion

Expand All @@ -67,7 +95,7 @@ John->>Bob: How about you?
Bob-->>John: Jolly good!
```

converted image below.....hopefully
converted images below.....hopefully

```mermaid
sequenceDiagram
Expand Down
25 changes: 13 additions & 12 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 13 additions & 4 deletions src/markdown-to-html-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,19 @@ const parseToHTML = (markdown, options = {}) => {
return `<h${depth} id="${escapedText}">${text}</h${depth}>`
},
blockquote ({ tokens }) {
const textString = this.parser.parseInline(tokens[0].tokens)
const alertMatch = textString.match(/\[!(NOTE|TIP|WARNING|IMPORTANT|CAUTION)\]/i)
let textString = ''
tokens.forEach(token => {
if (token.tokens) {
textString += this.parser.parseInline(token.tokens)
} else if (token.type === 'space') {
textString += this.parser.parseInline([{ type: 'br', text: token.text, raw: token.raw }])
} else {
textString += this.parser.parseInline(tokens)
}
})

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

const type = alertMatch[1].toLowerCase()
let content = textString.replace(/\[![A-Z]+\]/i, '')
Expand All @@ -60,7 +69,7 @@ const parseToHTML = (markdown, options = {}) => {
// Custom replacements
html = html.replace(/<a href="([^:\n]*?).md">/g, '<a href="$1.html">') // convertMdLinksToHtmlLinks
html = html.replace(/<a href="([^:\n]*?).md#(.*?)">/g, '<a href="$1.html#$2">') // convertMdHashLinksToHtmlLinks
html = html.replace(/<(h[123456]) id="([^"]+)">(.*)<\/\1>/g, '<$1 id="$2"><a href="#$2">$3</a></$1>') // headingExtension
html = html.replace(/<(h[123456]) id="([^"]+)">([\s\S]*?)<\/\1>/g, '<$1 id="$2"><a href="#$2">$3</a></$1>') // headingExtension
html = html.replace(/<table(.*)>/g, '<table class="table" $1>') // add class to table tags
html = html.replace(/<img(.*)>/g, '<img class="img-responsive" $1 />') // add class to image tags
html = html.replace(/<li>(<input.*)<\/li>/g, '<li class="task-list-item">$1</li>') // add class for list items (must have input at beginning)
Expand Down
7 changes: 4 additions & 3 deletions src/transform.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const path = require('path')

const transformContent = require('./transform-content')
const generateMermaidContent = require('./generate-mermaid-content')
// const generateMermaidContent = require('./generate-mermaid-content')
const generateIndexes = require('./generate-indexes')

const validate = (inputObjs) => {
Expand All @@ -22,8 +22,9 @@ const transform = (inputObjs, options) => {
const ext = path.extname(inputObj.relativePath)
if (ext === '.md') { // || ext === '.asciidoc' || ext === '.adoc' || ext === '.asc'
// Create mermaid images and transform markdown
const mermaidContent = generateMermaidContent(inputObj, options.rootPath)
mermaidImages.push(...mermaidContent.images)
// const mermaidContent = generateMermaidContent(inputObj, options.rootPath)
// mermaidImages.push(...mermaidContent.images)
const mermaidContent = { inputObj }
return transformContent(mermaidContent.inputObj, options)
} else {
return inputObj
Expand Down
2 changes: 1 addition & 1 deletion test/unit/markdown-to-html-parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ describe('Markdown Parser', () => {
},
{
markdown: '> Normal quote text',
expected: '<blockquote>Normal quote text</blockquote>'
expected: '<blockquote><p>Normal quote text</p></blockquote>'
},
{
markdown: '> [!TIP]\n> Multi-line\n> Multi-line\n> Multi-line',
Expand Down