Skip to content

Commit fde970b

Browse files
committed
Switched out markdown render
Fixes #304. Fixes #359.
1 parent ec7be1b commit fde970b

File tree

4 files changed

+25
-21
lines changed

4 files changed

+25
-21
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@
3333
"clipboard": "^1.5.16",
3434
"dropzone": "^4.0.1",
3535
"gulp-util": "^3.0.8",
36-
"marked": "^0.3.5",
36+
"markdown-it": "^8.3.1",
37+
"markdown-it-task-lists": "^2.0.0",
3738
"moment": "^2.12.0",
3839
"vue": "^2.2.6"
3940
},

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ These are the great projects used to help build BookStack:
7474
* [Dropzone.js](http://www.dropzonejs.com/)
7575
* [ZeroClipboard](http://zeroclipboard.org/)
7676
* [TinyColorPicker](http://www.dematte.at/tinyColorPicker/index.html)
77-
* [Marked](https://github.com/chjj/marked)
77+
* [markdown-it](https://github.com/markdown-it/markdown-it) and [markdown-it-task-lists](https://github.com/revin/markdown-it-task-lists)
7878
* [Moment.js](http://momentjs.com/)
7979
* [BarryVD](https://github.com/barryvdh)
8080
* [Debugbar](https://github.com/barryvdh/laravel-debugbar)

resources/assets/js/directives.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"use strict";
22
const DropZone = require("dropzone");
3-
const markdown = require("marked");
3+
const MarkdownIt = require("markdown-it");
4+
const mdTasksLists = require('markdown-it-task-lists');
45

56
module.exports = function (ngApp, events) {
67

@@ -214,18 +215,8 @@ module.exports = function (ngApp, events) {
214215
}
215216
}]);
216217

217-
let renderer = new markdown.Renderer();
218-
// Custom markdown checkbox list item
219-
// Attribution: https://github.com/chjj/marked/issues/107#issuecomment-44542001
220-
renderer.listitem = function(text) {
221-
if (/^\s*\[[x ]\]\s*/.test(text)) {
222-
text = text
223-
.replace(/^\s*\[ \]\s*/, '<input type="checkbox"/>')
224-
.replace(/^\s*\[x\]\s*/, '<input type="checkbox" checked/>');
225-
return `<li class="checkbox-item">${text}</li>`;
226-
}
227-
return `<li>${text}</li>`;
228-
};
218+
const md = new MarkdownIt();
219+
md.use(mdTasksLists, {label: true});
229220

230221
/**
231222
* Markdown input
@@ -244,20 +235,20 @@ module.exports = function (ngApp, events) {
244235
element = element.find('textarea').first();
245236
let content = element.val();
246237
scope.mdModel = content;
247-
scope.mdChange(markdown(content, {renderer: renderer}));
238+
scope.mdChange(md.render(content));
248239

249240
element.on('change input', (event) => {
250241
content = element.val();
251242
$timeout(() => {
252243
scope.mdModel = content;
253-
scope.mdChange(markdown(content, {renderer: renderer}));
244+
scope.mdChange(md.render(content));
254245
});
255246
});
256247

257248
scope.$on('markdown-update', (event, value) => {
258249
element.val(value);
259250
scope.mdModel = value;
260-
scope.mdChange(markdown(value));
251+
scope.mdChange(md.render(value));
261252
});
262253

263254
}

resources/assets/sass/_text.scss

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -269,19 +269,31 @@ span.highlight {
269269
/*
270270
* Lists
271271
*/
272+
ul, ol {
273+
overflow: hidden;
274+
p {
275+
margin: 0;
276+
}
277+
}
272278
ul {
273279
padding-left: $-m * 1.3;
274280
list-style: disc;
275-
overflow: hidden;
281+
ul {
282+
list-style: circle;
283+
margin-top: 0;
284+
margin-bottom: 0;
285+
}
286+
label {
287+
margin: 0;
288+
}
276289
}
277290

278291
ol {
279292
list-style: decimal;
280293
padding-left: $-m * 2;
281-
overflow: hidden;
282294
}
283295

284-
li.checkbox-item {
296+
li.checkbox-item, li.task-list-item {
285297
list-style: none;
286298
margin-left: - ($-m * 1.3);
287299
input[type="checkbox"] {

0 commit comments

Comments
 (0)