From 18469edf18bf64448cf593754765fa64470fb4d6 Mon Sep 17 00:00:00 2001 From: ansuz Date: Thu, 30 Mar 2017 12:02:31 +0200 Subject: [PATCH] extend list item rendering to support gfm task lists --- www/slide/slide.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/www/slide/slide.js b/www/slide/slide.js index c49ec5ea5..b4db44922 100644 --- a/www/slide/slide.js +++ b/www/slide/slide.js @@ -6,6 +6,29 @@ define([ var $ = window.jQuery; var DiffDOM = window.diffDOM; + var renderer = new Marked.Renderer(); + + var checkedTaskItemPtn = /^\s*\[x\]\s*/; + var uncheckedTaskItemPtn = /^\s*\[ \]\s*/; + renderer.listitem = function (text, level) { + var isCheckedTaskItem = checkedTaskItemPtn.test(text); + var isUncheckedTaskItem = uncheckedTaskItemPtn.test(text); + if (isCheckedTaskItem) { + text = text.replace(checkedTaskItemPtn, + ' ') + '\n'; + } + if (isUncheckedTaskItem) { + text = text.replace(uncheckedTaskItemPtn, + ' ') + '\n'; + } + var cls = (isCheckedTaskItem || isUncheckedTaskItem) ? ' class="todo-list-item"' : ''; + return '' + text + '\n'; + }; + + Marked.setOptions({ + renderer: renderer + }); + var truthy = function (x) { return x; }; var Slide = {