weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.66k stars 174 forks source link

Hi How to write hiccup code for observable embed code in Roam ? #166

Closed ghost closed 4 years ago

ghost commented 4 years ago
  1. visit this link https://observablehq.com/@d3/sketchy-earth
  2. get embed code : image

<div id="observablehq-476e08a1"></div> <script type="module"> import {Runtime, Inspector} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js"; import define from "https://api.observablehq.com/@d3/sketchy-earth.js?v=3"; const inspect = Inspector.into("#observablehq-476e08a1"); (new Runtime).module(define, name => (name === "chart") && inspect()); </script>

  1. transfer hiccup code

:hiccup [:div {:id "observablehq-3a3c7c79"} {:script {:type "module"} {"import {Runtime, Inspector} from "https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js"; import define from "https://api.observablehq.com/@d3/sketchy-earth.js?v=3"; const inspect = Inspector.into("#observablehq-3a3c7c79"); (new Runtime).module(define, name => (name === "chart") && inspect());"}} ]

image

Result failed.

Please help convert right hiccup code.

I can't figure it out where is it wrong .

Thanks.

weavejester commented 4 years ago

The Hiccup code you've posted doesn't match up to the HTML you've posted, and the syntax has several problems. Quotes in strings should be escaped, the :script element should come after the :div, and the :script element should be a vector, not a map. It should be:

(list
 [:div {:id "observablehq-476e08a1"}]
 [:script {:type "module"}
  "import {Runtime, Inspector} from \"https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js\"; import define from \"https://api.observablehq.com/@d3/sketchy-earth.js?v=3\"; const inspect = Inspector.into(\"#observablehq-476e08a1\"); (new Runtime).module(define, name => (name === \"chart\") && inspect());"])
ghost commented 4 years ago
(list

Thank you so much for help !

That code is run on Roam.
But image

ghost commented 4 years ago

I found solution

:hiccup [:iframe { :height 500 :width 600 :srcdoc "<div id=\"observablehq-b9a930e6\"></div> <script type=\"module\"> import {Runtime, Inspector} from \"https://cdn.jsdelivr.net/npm/@observablehq/runtime@4/dist/runtime.js\"; import define from \"https://api.observablehq.com/d/eceaa744227c4fea.js?v=3\"; const inspect = Inspector.into(\"#observablehq-b9a930e6\"); (new Runtime).module(define, name => ( name === \"vegaPetalsWidget\" || name === 'viewof sepalLengthLimits' || name === 'viewof sepalWidthLimits') && inspect()); </script> "}]