From 4840fd944c20e99c1556a586051334cd1e8987fc Mon Sep 17 00:00:00 2001 From: Kgothatso Ngako Date: Sat, 26 Feb 2022 11:18:50 +0200 Subject: [PATCH] Parse the markdown to tokenize it --- server/router/versions/index.js | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/server/router/versions/index.js b/server/router/versions/index.js index f1abed2..8b07e41 100644 --- a/server/router/versions/index.js +++ b/server/router/versions/index.js @@ -1,5 +1,6 @@ +const md = require("markdown-it")().disable(['link']) const express = require('express'); -const req = require('express/lib/request'); + module.exports = function (options) { const db = options.db; @@ -174,13 +175,9 @@ module.exports = function (options) { }).then(artifactVersion => { const isString = typeof request.body.text === "string" || request.body.text instanceof String if (artifactVersion && isString) { - const chunks = request.body.text.trim().split(/\r?\n/).filter(text => { - if (text) { - return true - } else { - return false - } - }) + const chunks = md.parse( + request.body.text + ).filter(token => token.content).map(token => token.content/*.replace(/\n/g,' ')*/) db.Chapter.create({ creatorId: request.user.id, name: chunks[0].trim(),