Skip to content

Commit

Permalink
Added checkbox sytax parsing to markdown lists
Browse files Browse the repository at this point in the history
Closes #319
  • Loading branch information
ssddanbrown committed Feb 25, 2017
1 parent af3c0e4 commit b0e849f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions resources/assets/js/directives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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*/, '<input type="checkbox"/>')
.replace(/^\s*\[x\]\s*/, '<input type="checkbox" checked/>');
return `<li class="checkbox-item">${text}</li>`;
}
return `<li>${text}</li>`;
};

/**
* Markdown input
* Handles the logic for just the editor input field.
Expand All @@ -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}));
});
});

Expand Down
8 changes: 8 additions & 0 deletions resources/assets/sass/_text.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit b0e849f

Please sign in to comment.