Pass through breaks option to published note

The markdown for the publish-view is generated
using the `Note.extractMeta` method.
It uses meta-marked to separate the metadata from markdown.
Only the raw markdown is then sent to the client,
so it cannot respect the `breaks` option.

This adds an evil hack to send the `breaks` option with the markdown
if it is contained in the metadata block.

Fixes https://github.com/hedgedoc/hedgedoc/issues/2358

Signed-off-by: David Mehren <git@herrmehren.de>
This commit is contained in:
David Mehren 2022-10-03 14:19:44 +02:00
parent a71b4923e7
commit 3aeb2a619b
2 changed files with 7 additions and 1 deletions

View file

@ -90,8 +90,13 @@ exports.newNote = async function (req, res, body) {
exports.getPublishData = function (req, res, note, callback) { exports.getPublishData = function (req, res, note, callback) {
const body = note.content const body = note.content
const extracted = models.Note.extractMeta(body) const extracted = models.Note.extractMeta(body)
const markdown = extracted.markdown let markdown = extracted.markdown
const meta = models.Note.parseMeta(extracted.meta) const meta = models.Note.parseMeta(extracted.meta)
// extractMeta() will remove the meta part from markdown,
// so we need to re-add the `breaks` option for proper rendering
if (typeof extracted.meta.breaks === 'boolean') {
markdown = '---\nbreaks: ' + extracted.meta.breaks + '\n---\n' + markdown
}
const createtime = note.createdAt const createtime = note.createdAt
const updatetime = note.lastchangeAt const updatetime = note.lastchangeAt
let title = models.Note.decodeTitle(note.title) let title = models.Note.decodeTitle(note.title)

View file

@ -8,6 +8,7 @@
### Bugfixes ### Bugfixes
- Fix a crash when using LDAP authentication with custom search attributes (thanks to [@aboettger-tuhh](https://github.com/aboettger-tuhh) for reporting) - Fix a crash when using LDAP authentication with custom search attributes (thanks to [@aboettger-tuhh](https://github.com/aboettger-tuhh) for reporting)
- Fix crash caused by a long note history when the MySQL database is used - Fix crash caused by a long note history when the MySQL database is used
- Fix `breaks` option not being respected in the publish-view
## <i class="fa fa-tag"></i> 1.9.4 <i class="fa fa-calendar-o"></i> 2022-07-10 ## <i class="fa fa-tag"></i> 1.9.4 <i class="fa fa-calendar-o"></i> 2022-07-10