From 7f41bc8973551c1fa9b19c62a7dbd6a0b8be5af2 Mon Sep 17 00:00:00 2001 From: Alexander Kachkaev Date: Sun, 15 Jul 2018 10:47:36 +0100 Subject: [PATCH] Add html / h block attribute --- .../src/renderEnhancers/literateElm.ts | 8 ++++++++ .../src/renderEnhancers/vegaBlockKeywords.ts | 13 +++++++++++++ packages/litvis/src/attributeDerivatives.ts | 5 +++++ packages/litvis/src/types.ts | 4 ++++ 4 files changed, 30 insertions(+) diff --git a/packages/litvis-integration-mume/src/renderEnhancers/literateElm.ts b/packages/litvis-integration-mume/src/renderEnhancers/literateElm.ts index 2865979..b111c6d 100644 --- a/packages/litvis-integration-mume/src/renderEnhancers/literateElm.ts +++ b/packages/litvis-integration-mume/src/renderEnhancers/literateElm.ts @@ -193,6 +193,14 @@ export default async function enhance( evaluatedOutputExpression.data.valueStringRepresentation, ); break; + case OutputFormat.H: + $result = $( + `${evaluatedOutputExpression.data.valueStringRepresentation}` + .replace(/\\"/g, '"') + .replace(/^"/, "") + .replace(/"$/, ""), + ); + break; case OutputFormat.J: $result = $(`
`);
           resultNormalizedInfo = {
diff --git a/packages/litvis-integration-mume/src/renderEnhancers/vegaBlockKeywords.ts b/packages/litvis-integration-mume/src/renderEnhancers/vegaBlockKeywords.ts
index 5e446f9..d05e72d 100644
--- a/packages/litvis-integration-mume/src/renderEnhancers/vegaBlockKeywords.ts
+++ b/packages/litvis-integration-mume/src/renderEnhancers/vegaBlockKeywords.ts
@@ -75,6 +75,19 @@ export default async function enhance(
           };
           resultText = text;
           break;
+        case BlockOutputFormat.H:
+          try {
+            $result = $(data);
+          } catch (e) {
+            $result = $(`
`);
+            resultNormalizedInfo = {
+              language: "",
+              attributes: {},
+              style: "display: inline-block",
+            };
+            resultText = e.message;
+          }
+          break;
         case BlockOutputFormat.J:
           $result = $(`
`);
           resultNormalizedInfo = {
diff --git a/packages/litvis/src/attributeDerivatives.ts b/packages/litvis/src/attributeDerivatives.ts
index dbeb611..32211ad 100644
--- a/packages/litvis/src/attributeDerivatives.ts
+++ b/packages/litvis/src/attributeDerivatives.ts
@@ -58,6 +58,11 @@ export function extractAttributeDerivatives(
           isLitVis = true;
           addOutputExpressions(result, OutputFormat.J, value);
           break;
+        case "h":
+        case "html":
+          isLitVis = true;
+          addOutputExpressions(result, OutputFormat.H, value);
+          break;
         case "interactive":
           result.interactive = !!value;
           break;
diff --git a/packages/litvis/src/types.ts b/packages/litvis/src/types.ts
index 5e028ec..b6f346d 100644
--- a/packages/litvis/src/types.ts
+++ b/packages/litvis/src/types.ts
@@ -16,6 +16,8 @@ export enum OutputFormat {
   R = "r",
   /** json */
   J = "j",
+  /** html */
+  H = "h",
   /** visual */
   V = "v",
 }
@@ -28,6 +30,8 @@ export enum BlockOutputFormat {
   R = "r",
   /** json */
   J = "j",
+  /** html */
+  H = "h",
   /** visual */
   V = "v",