Skip to content

tpl/transform: Capture and display warnings when KaTeX strict mode is warn #13735

Closed
@jmooring

Description

@jmooring

Currently, if the KaTex strict mode is warn, we throw an error regardless of error code:

execute of template failed at <transform.ToMath>: error calling ToMath: not a function

Instead, we should capture and display the warnings as described in the KaTeX documentation. There are some related comments in the code:

// The console.log in the Javy/quickjs WebAssembly module will write to stderr.
// In non-error situations, write that to the provided infof logger.
if errBuff.Len() > 0 {
opts.Infof("%s", errBuff.String())
}

This isn't a pressing issue in that #13736 changed the default strict mode from "warn" to "error", and we have not documented "warn" mode.


Notes:

  • The "not a function" message comes from here (i.e., e.message is "not a function"):
    header.err = e.message;
  • This is an educated guess, but I think if the user sets strict to warn, we have to pass in a JS function (instead of warn) that somehow captures an error (without throwing one) instead of calling console.warn. See https://katex.org/docs/error. If my guess is correct, this is a bit ugly and probably not worth the effort.
  • I've looked at this for a few hours and have no idea how to approach it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions