MCPcopy
hub / github.com/josdejong/mathjs / _toHTML

Method _toHTML

src/expression/node/OperatorNode.js:503–593  ·  view source on GitHub ↗

* Get HTML representation. * @param {Object} options * @return {string} str

(options)

Source from the content-addressed store, hash-verified

501 * @return {string} str
502 */
503 _toHTML (options) {
504 const parenthesis =
505 (options && options.parenthesis) ? options.parenthesis : 'keep'
506 const implicit = (options && options.implicit) ? options.implicit : 'hide'
507 const args = this.args
508 const parens =
509 calculateNecessaryParentheses(this, parenthesis, implicit, args, false)
510
511 if (args.length === 1) { // unary operators
512 const assoc = getAssociativity(this, parenthesis)
513
514 let operand = args[0].toHTML(options)
515 if (parens[0]) {
516 operand =
517 '<span class="math-parenthesis math-round-parenthesis">(</span>' +
518 operand +
519 '<span class="math-parenthesis math-round-parenthesis">)</span>'
520 }
521
522 if (assoc === 'right') { // prefix operator
523 return '<span class="math-operator math-unary-operator ' +
524 'math-lefthand-unary-operator">' + escape(this.op) + '</span>' +
525 operand
526 } else { // postfix when assoc === 'left' or undefined
527 return operand +
528 '<span class="math-operator math-unary-operator ' +
529 'math-righthand-unary-operator">' + escape(this.op) + '</span>'
530 }
531 } else if (args.length === 2) { // binary operatoes
532 let lhs = args[0].toHTML(options) // left hand side
533 let rhs = args[1].toHTML(options) // right hand side
534 if (parens[0]) { // left hand side in parenthesis?
535 lhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' +
536 lhs +
537 '<span class="math-parenthesis math-round-parenthesis">)</span>'
538 }
539 if (parens[1]) { // right hand side in parenthesis?
540 rhs = '<span class="math-parenthesis math-round-parenthesis">(</span>' +
541 rhs +
542 '<span class="math-parenthesis math-round-parenthesis">)</span>'
543 }
544
545 if (this.implicit &&
546 (this.getIdentifier() === 'OperatorNode:multiply') &&
547 (implicit === 'hide')) {
548 return lhs +
549 '<span class="math-operator math-binary-operator ' +
550 'math-implicit-binary-operator"></span>' + rhs
551 }
552
553 return lhs +
554 '<span class="math-operator math-binary-operator ' +
555 'math-explicit-binary-operator">' + escape(this.op) + '</span>' +
556 rhs
557 } else {
558 const stringifiedArgs = args.map(function (arg, index) {
559 arg = arg.toHTML(options)
560 if (parens[index]) { // put in parenthesis?

Callers

nothing calls this directly

Calls 6

getIdentifierMethod · 0.95
getAssociativityFunction · 0.90
escapeFunction · 0.90
toHTMLMethod · 0.65
mapMethod · 0.65

Tested by

no test coverage detected