Search in sources :

Example 1 with FormattedFormula

use of org.freeplane.features.format.FormattedFormula in project freeplane by freeplane.

the class FormulaTextTransformer method transformContent.

public Object transformContent(TextController textController, final Object obj, final NodeModel node, Object transformedExtension) {
    if (obj instanceof FormattedFormula) {
        final FormattedFormula formattedFormula = (FormattedFormula) obj;
        final Object evaluationResult = transformContent(textController, formattedFormula.getObject(), node, transformedExtension);
        return new FormattedObject(evaluationResult, formattedFormula.getPattern());
    }
    if (!(obj instanceof String)) {
        return obj;
    }
    if (textController.isTextFormattingDisabled(node))
        return obj;
    final String text = obj.toString();
    if (!FormulaUtils.containsFormulaCheckHTML(text)) {
        return obj;
    }
    final String plainText = HtmlUtils.htmlToPlain(text);
    // starting a new ScriptContext in evalIfScript
    final Object result = FormulaUtils.evalIfScript(node, null, plainText);
    if (result == null) {
        throw new ExecuteScriptException("got null result from evaluating " + node.getID() + ", text='" + plainText.substring(1) + "'");
    }
    return result;
}
Also used : FormattedFormula(org.freeplane.features.format.FormattedFormula) FormattedObject(org.freeplane.features.format.FormattedObject) FormattedObject(org.freeplane.features.format.FormattedObject) ExecuteScriptException(org.freeplane.plugin.script.ExecuteScriptException)

Aggregations

FormattedFormula (org.freeplane.features.format.FormattedFormula)1 FormattedObject (org.freeplane.features.format.FormattedObject)1 ExecuteScriptException (org.freeplane.plugin.script.ExecuteScriptException)1