commit 8f281253eb5b76ae8ff89afa71994530023a3fe2
parent f56ce3a25737a447f688a81e9b5e7757f664c0df
Author: ebutler <e.c.butler@outlook.com>
Date: Thu, 30 Sep 2021 09:41:19 -0400
changed html format package.
Diffstat:
4 files changed, 44 insertions(+), 39 deletions(-)
diff --git a/package-lock.json b/package-lock.json
@@ -5833,11 +5833,6 @@
"parse-passwd": "^1.0.0"
}
},
- "html-formatter": {
- "version": "0.1.9",
- "resolved": "https://registry.npmjs.org/html-formatter/-/html-formatter-0.1.9.tgz",
- "integrity": "sha1-WOiFlxLz1NnnCUAnUXxMRvTDNrg="
- },
"htmlparser2": {
"version": "3.10.1",
"resolved": "https://registry.npmjs.org/htmlparser2/-/htmlparser2-3.10.1.tgz",
@@ -7963,6 +7958,11 @@
"integrity": "sha1-tf3AjxKH6hF4Yo5BXiUTK3NkbG0=",
"dev": true
},
+ "simply-beautiful": {
+ "version": "0.2.10",
+ "resolved": "https://registry.npmjs.org/simply-beautiful/-/simply-beautiful-0.2.10.tgz",
+ "integrity": "sha512-y60ypyb7Y06ufzR9z1K8VLS7zqqcvbnbJ89uaU7jrgoLIripkVAb29T9LW1E3SexxoTAt2ENmzN0M5mU113BNA=="
+ },
"smartquotes": {
"version": "2.3.1",
"resolved": "https://registry.npmjs.org/smartquotes/-/smartquotes-2.3.1.tgz",
diff --git a/package.json b/package.json
@@ -52,8 +52,8 @@
"webpack-cli": "^3.3.9"
},
"dependencies": {
- "html-formatter": "^0.1.9",
"js-beautify": "^1.11.0",
- "linkifyjs": "^2.1.9"
+ "linkifyjs": "^2.1.9",
+ "simply-beautiful": "^0.2.10"
}
}
diff --git a/src/ko-striveneditor.js b/src/ko-striveneditor.js
@@ -1,22 +1,22 @@
import StrivenEditor from './striveneditor';
export default class KoStrivenEditor {
- constructor(ko, bindingName = 'striveneditor') {
- if (!ko.bindingHandlers.striveneditor) {
- ko.bindingHandlers.striveneditor = {
- init: function (
- element,
- valueAccessor,
- allBindings,
- viewModel,
- bindingContext,
- ) {
- // Get options
- let options = valueAccessor();
- // Options must be passed as an observable
- if (!ko.isObservable(options)) {
- throw 'Options must be an observable.';
- }
+ constructor(ko, bindingName = 'striveneditor') {
+ if (!ko.bindingHandlers.striveneditor) {
+ ko.bindingHandlers.striveneditor = {
+ init: function (
+ element,
+ valueAccessor,
+ allBindings,
+ viewModel,
+ bindingContext,
+ ) {
+ // Get options
+ let options = valueAccessor();
+ // Options must be passed as an observable
+ if (!ko.isObservable(options)) {
+ throw 'Options must be an observable.';
+ }
// Get the value binding in case we are binding the editor's contents to an observable
let value = allBindings().value;
@@ -45,16 +45,16 @@ export default class KoStrivenEditor {
});
let pauseUpdate = false;
- // Handle updates and changes to value observable
- if (ko.isObservable(value)) {
- // Listen to input event
- editor.body.oninput = e => {
- pauseUpdate = true;
- value(editor.getContent());
- setTimeout(function () {
- pauseUpdate = false;
- }, 0);
- };
+ // Handle updates and changes to value observable
+ if (ko.isObservable(value)) {
+ // Listen to input event
+ editor.body.oninput = e => {
+ pauseUpdate = true;
+ value(editor.getContent());
+ setTimeout(function () {
+ pauseUpdate = false;
+ }, 0);
+ };
// Subscribe to the value observable to detect when it is changed and update the editor
value.subscribe(newValue => {
diff --git a/src/striveneditor.js b/src/striveneditor.js
@@ -32,7 +32,7 @@ import './classic.min.css';
import Pickr from './pickr.min.js';
// Formatting
-import htmlFormatter from "html-formatter";
+import beautify from "simply-beautiful";
/* Represents an instance of the Striven Editor */
export default class StrivenEditor {
@@ -488,7 +488,9 @@ export default class StrivenEditor {
const toolbarTemplate = document.createElement('div');
toolbarTemplate.id = 'toolbar-template';
toolbarTemplate.setAttribute('style', 'display: flex');
-
+ toolbarTemplate.addEventListener('click', (ev) => {
+ ev.stopImmediatePropagation();
+ });
toolbarTemplate.appendChild(se.options.toolbarTemplate);
toolbar.appendChild(toolbarTemplate);
@@ -3040,12 +3042,15 @@ export default class StrivenEditor {
se.body.style.whiteSpace = "pre";
// Format the HTML so that it looks somewhat pretty
- let formatedHtml = htmlFormatter.render(se.body.innerHTML, );
- // This library uses /t for indenting. Replace with spaces to make it less
- // drastic.
- formatedHtml = formatedHtml.replaceAll("\t", " ");
+ var options = {
+ indent_size: 2,
+ unformatted: []
+ };
+
+ let formatedHtml = beautify.html(se.body.innerHTML, options);
// Set the content of the editor to the formatted html
se.body.textContent = formatedHtml;
+ se.overflow();
break;
case 'fullscreen':