| Author | DaveJarvis <email> |
|---|---|
| Date | 2021-12-30 15:16:32 GMT-0800 |
| Commit | 28aae82cdd3fec80d8fe116a5906867f7e35dd04 |
| Parent | d8a84b5 |
| Delta | 5 lines added, 15 lines removed, 10-line decrease |
| import javax.script.ScriptEngineManager; | ||
| import java.util.Map; | ||
| -import java.util.function.Function; | ||
| import static com.keenwrite.Messages.get; | ||
| * | ||
| * @param r R expression to evaluate. | ||
| - * @param f Post-processing to apply after evaluating the R expression. | ||
| * @return The object resulting from the evaluation. | ||
| */ | ||
| - public static String eval( final String r, final Function<String, String> f ) { | ||
| - return sCache.computeIfAbsent( r, __ -> f.apply( eval( r ) ) ); | ||
| + public static String eval( final String r ) { | ||
| + return sCache.computeIfAbsent( r, __ -> evaluate( r ) ); | ||
| } | ||
| /** | ||
| * Returns the result of an R expression as an object converted to string. | ||
| * | ||
| * @param r R expression to evaluate. | ||
| * @return The object resulting from the evaluation. | ||
| */ | ||
| - public static String eval( final String r ) { | ||
| + private static String evaluate( final String r ) { | ||
| try { | ||
| return ENGINE.eval( r ).toString(); | ||
| import com.keenwrite.processors.ProcessorContext; | ||
| import com.keenwrite.processors.VariableProcessor; | ||
| -import com.keenwrite.processors.markdown.extensions.r.ROutputProcessor; | ||
| import com.keenwrite.util.InterpolatingMap; | ||
| import javafx.beans.property.Property; | ||
| public final class InlineRProcessor extends VariableProcessor { | ||
| private static final int PREFIX_LENGTH = PREFIX.length(); | ||
| - | ||
| - /** | ||
| - * Converts the given string to HTML, trimming new lines, and inlining | ||
| - * the text if it is a paragraph. Otherwise, the resulting HTML is most likely | ||
| - * complex (e.g., a Markdown table) and should be rendered as its HTML | ||
| - * equivalent. | ||
| - */ | ||
| - private final Processor<String> mPostProcessor = new ROutputProcessor(); | ||
| /** | ||
| try { | ||
| // Append the string representation of the result into the text. | ||
| - sb.append( Engine.eval( r, mPostProcessor ) ); | ||
| + sb.append( Engine.eval( r ) ); | ||
| } catch( final Exception ex ) { | ||
| // Inform the user that there was a problem. | ||
| final var irp = new InlineRProcessor( IDENTITY, context ); | ||
| final var rvp = new RVariableProcessor( irp, context ); | ||
| + | ||
| mProcessor = new ExecutorProcessor<>( rvp ); | ||
| mInlineRProcessor = irp; |