Skip to content

Commit

Permalink
Added support for inline code blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
lyu4321 committed Sep 29, 2021
1 parent d0d502b commit cf3c65d
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,19 +81,20 @@ const getHtml = (file, isTxt) => {
.split(/\r?\n\r?\n/)
.map((para) => {
if (para == html.title) {
`<h1>${para.replace(/\r?\n/, " ")}</h1>\n`;
`<h1>${para.replace(/\r?\n/, ' ')}</h1>\n`;
} else {
if (isTxt) {
return `<p>${para.replace(/\r?\n/, ' ')}</p>\n`;
} else {
let string = para
.replace(/^\s*#{1} (.*$)/, "<h1>$1</h1>")
.replace(/^\s*#{2} (.*$)/, "<h2>$1</h2>")
.replace(/^\s*#{3} (.*$)/, "<h3>$1</h3>");
.replace(/^\s*#{1} (.*$)/, '<h1>$1</h1>')
.replace(/^\s*#{2} (.*$)/, '<h2>$1</h2>')
.replace(/^\s*#{3} (.*$)/, '<h3>$1</h3>')
.replace(/\`{1,}(.*?)\`{1,}/g, '<code>$1</code>')

return string.startsWith("<h")
? string + "\n"
: `<p>${string.replace(/\r?\n/, " ")}</p>\n`;
return string.startsWith('<h')
? string + '\n'
: `<p>${string.replace(/\r?\n/, ' ')}</p>\n`;
}
}
})
Expand Down

0 comments on commit cf3c65d

Please sign in to comment.