|
51 | 51 | import nh3 |
52 | 52 | import pyparsing |
53 | 53 | import six |
54 | | -from calc.preview import latex_preview |
55 | 54 | from chem import chemcalc |
56 | 55 | from lxml import etree |
57 | 56 |
|
@@ -1300,18 +1299,18 @@ def preview_formcalc(self, get): |
1300 | 1299 |
|
1301 | 1300 | result["request_start"] = int(get.get("request_start", 0)) |
1302 | 1301 |
|
1303 | | - try: |
1304 | | - # TODO add references to valid variables and functions |
1305 | | - # At some point, we might want to mark invalid variables as red |
1306 | | - # or something, and this is where we would need to pass those in. |
1307 | | - result["preview"] = latex_preview(formula) |
1308 | | - except pyparsing.ParseException: |
1309 | | - result["error"] = _("Sorry, couldn't parse formula") |
| 1302 | + # TODO add references to valid variables and functions |
| 1303 | + # At some point, we might want to mark invalid variables as red |
| 1304 | + # or something, and this is where we would need to pass those in. |
| 1305 | + from xmodule.capa_block import ProblemBlock |
| 1306 | + numeric_result = ProblemBlock.preview_numeric_input(formula) |
| 1307 | + # Map results into the correct format |
| 1308 | + result["preview"] = numeric_result["preview"] |
| 1309 | + if numeric_result["error"]: |
| 1310 | + result["error"] = numeric_result["error"] |
| 1311 | + # if formula is invalid retrn formula |
| 1312 | + if not numeric_result["is_valid"]: |
1310 | 1313 | result["formula"] = formula |
1311 | | - except Exception: # lint-amnesty, pylint: disable=broad-except |
1312 | | - # this is unexpected, so log |
1313 | | - log.warning("Error while previewing formula", exc_info=True) |
1314 | | - result["error"] = _("Error while rendering preview") |
1315 | 1314 |
|
1316 | 1315 | return result |
1317 | 1316 |
|
|
0 commit comments