diff --git a/CHANGELOG.md b/CHANGELOG.md index 9a6fc39..f8620aa 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Fixed - Fix cursor displayed position on activity ([#183]). +- Checkboxes always have bullets in front of them ([#136]). ## [2.10.1] - 2020-04-06 ### Fixed @@ -148,7 +149,9 @@ Project forked from [SimpleMDE](https://github.com/sparksuite/simplemde-markdown - Cursor not always showing in "text" mode over the edit field +[#183]: https://github.com/Ionaru/easy-markdown-editor/issues/183 [#178]: https://github.com/Ionaru/easy-markdown-editor/issues/178 +[#136]: https://github.com/Ionaru/easy-markdown-editor/issues/136 [#126]: https://github.com/Ionaru/easy-markdown-editor/issues/126 [#99]: https://github.com/Ionaru/easy-markdown-editor/issues/99 [#45]: https://github.com/Ionaru/easy-markdown-editor/issues/45 diff --git a/example/index.html b/example/index.html index d4ddd1e..efccc4b 100644 --- a/example/index.html +++ b/example/index.html @@ -17,4 +17,4 @@ - \ No newline at end of file + diff --git a/src/js/easymde.js b/src/js/easymde.js index 6a07d00..b6c7a1e 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -97,6 +97,33 @@ function addAnchorTargetBlank(htmlText) { return htmlText; } +/** + * Modify HTML to remove the list-style when rendering checkboxes. + * @param {string} htmlText - HTML to be modified. + * @return {string} The modified HTML text. + */ +function removeListStyleWhenCheckbox(htmlText) { + + var parser = new DOMParser(); + var htmlDoc = parser.parseFromString(htmlText, 'text/html'); + var listItems = htmlDoc.getElementsByTagName('li'); + + for (var i = 0; i < listItems.length; i++) { + var listItem = listItems[i]; + + for (var j = 0; j < listItem.children.length; j++) { + var listItemChild = listItem.children[j]; + + if (listItemChild instanceof HTMLInputElement && listItemChild.type === 'checkbox') { + // From Github: margin: 0 .2em .25em -1.6em; + listItem.style.marginLeft = '-1.5em'; + listItem.style.listStyleType = 'none'; + } + } + } + + return htmlDoc.documentElement.innerHTML; +} /** * Fix shortcut. Mac use Command, others use Ctrl. @@ -1831,6 +1858,9 @@ EasyMDE.prototype.markdown = function (text) { // Edit the HTML anchors to add 'target="_blank"' by default. htmlText = addAnchorTargetBlank(htmlText); + // Remove list-style when rendering checkboxes + htmlText = removeListStyleWhenCheckbox(htmlText); + return htmlText; } };