diff --git a/HISTORY.md b/HISTORY.md
index f5fcf0c063..0b79a9bb0e 100644
--- a/HISTORY.md
+++ b/HISTORY.md
@@ -4,6 +4,8 @@
# not yet released, version 5.9.0
- Implemented functions `row` and `column` (see #1413). Thanks @SzechuanSage.
+- Fixed #1465: `node.toHTML()` not correct for unary operators like
+ `factorial`.
# 2019-03-20, version 5.8.0
diff --git a/src/expression/node/OperatorNode.js b/src/expression/node/OperatorNode.js
index 35b971b6fc..e1cade11c5 100644
--- a/src/expression/node/OperatorNode.js
+++ b/src/expression/node/OperatorNode.js
@@ -463,12 +463,9 @@ function factory (type, config, load, typed) {
if (assoc === 'right') { // prefix operator
return '' + escape(this.op) + '' + operand
- } else if (assoc === 'left') { // postfix
- return '' + escape(this.op) + '' + operand
+ } else { // postfix when assoc === 'left' or undefined
+ return operand + '' + escape(this.op) + ''
}
-
- // fall back to postfix
- return '' + escape(this.op) + '' + operand
} else if (args.length === 2) { // binary operatoes
let lhs = args[0].toHTML(options) // left hand side
let rhs = args[1].toHTML(options) // right hand side
diff --git a/test/expression/node/OperatorNode.test.js b/test/expression/node/OperatorNode.test.js
index cc47e85088..383a12b421 100644
--- a/test/expression/node/OperatorNode.test.js
+++ b/test/expression/node/OperatorNode.test.js
@@ -766,6 +766,29 @@ describe('OperatorNode', function () {
assert.strictEqual(h.toTex({ implicit: 'show' }), '2\\cdot\\left(3+4\\right)')
})
+ it('should HTML operators', function () {
+ assert.strictEqual(math.parse('2 + 3').toHTML(),
+ '2' +
+ '+' +
+ '3'
+ )
+
+ assert.strictEqual(math.parse('not 5').toHTML(),
+ 'not' +
+ '5'
+ )
+
+ assert.strictEqual(math.parse('5!').toHTML(),
+ '5' +
+ '!'
+ )
+
+ assert.strictEqual(math.parse('5\'').toHTML(),
+ '5' +
+ '''
+ )
+ })
+
it('should stringify implicit multiplications between ConstantNodes with parentheses', function () {
const a = math.parse('(4)(4)(4)(4)')
const b = math.parse('4b*4(4)')