From b0e849f4137772a424be55d022324cfd7761d3ff Mon Sep 17 00:00:00 2001 From: Dan Brown Date: Sat, 25 Feb 2017 13:16:26 +0000 Subject: [PATCH] Added checkbox sytax parsing to markdown lists Closes #319 --- resources/assets/js/directives.js | 17 +++++++++++++++-- resources/assets/sass/_text.scss | 8 ++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/resources/assets/js/directives.js b/resources/assets/js/directives.js index ef8bcd85c..10458e753 100644 --- a/resources/assets/js/directives.js +++ b/resources/assets/js/directives.js @@ -214,6 +214,19 @@ export default function (ngApp, events) { } }]); + let renderer = new markdown.Renderer(); + // Custom markdown checkbox list item + // Attribution: https://github.com/chjj/marked/issues/107#issuecomment-44542001 + renderer.listitem = function(text) { + if (/^\s*\[[x ]\]\s*/.test(text)) { + text = text + .replace(/^\s*\[ \]\s*/, '') + .replace(/^\s*\[x\]\s*/, ''); + return `
  • ${text}
  • `; + } + return `
  • ${text}
  • `; + }; + /** * Markdown input * Handles the logic for just the editor input field. @@ -231,13 +244,13 @@ export default function (ngApp, events) { element = element.find('textarea').first(); let content = element.val(); scope.mdModel = content; - scope.mdChange(markdown(content)); + scope.mdChange(markdown(content, {renderer: renderer})); element.on('change input', (event) => { content = element.val(); $timeout(() => { scope.mdModel = content; - scope.mdChange(markdown(content)); + scope.mdChange(markdown(content, {renderer: renderer})); }); }); diff --git a/resources/assets/sass/_text.scss b/resources/assets/sass/_text.scss index 79d3c3a92..a74a81647 100644 --- a/resources/assets/sass/_text.scss +++ b/resources/assets/sass/_text.scss @@ -281,6 +281,14 @@ ol { overflow: hidden; } +li.checkbox-item { + list-style: none; + margin-left: - ($-m * 1.3); + input[type="checkbox"] { + margin-right: $-xs; + } +} + /* * Generic text styling classes */