Skip to content
This repository has been archived by the owner on Jan 15, 2022. It is now read-only.

Better handling of markdown body #232

Closed
wants to merge 1 commit into from
Closed
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
22 changes: 19 additions & 3 deletions lib/utils/check-for-body.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
const { lineBreak } = require('./helpers')
const showdown = require('showdown')
const { JSDOM } = require('jsdom')

/**
* Prepares some details about the TODO
Expand All @@ -20,10 +22,24 @@ module.exports = (changes, changeIndex, config) => {
if (!matches.groups.body) {
bodyPieces.push('\n')
} else {
if (bodyPieces.length > 0 && bodyPieces[bodyPieces.length - 1] !== '\n') bodyPieces.push(' ')
bodyPieces.push(lineBreak(matches.groups.body).trim())
bodyPieces.push(lineBreak(matches.groups.body))
}
}

return bodyPieces.length ? bodyPieces.join('') : false
if (bodyPieces.length === 0) {
return false
}

// Avoid GFM comment soft-breaks by parsing and unparsing the Markdown.
const converter = new showdown.Converter({
simplifiedAutoLink: true,
parseImgDimensions: true,
strikethrough: true,
tables: true,
tasklists: true
})

const dom = new JSDOM('<!DOCTYPE html>')

return converter.makeMd(converter.makeHtml(bodyPieces.join('\n')), dom.window.document).trim()
}
Loading