observablehq / framework

A static site generator for data apps, dashboards, reports, and more. Observable Framework combines JavaScript on the front-end for interactive graphics with any language on the back-end for data analysis.
https://observablehq.com/framework/
ISC License
2.41k stars 109 forks source link

Support inline expressions for attributes (and in other places) #32

Open mbostock opened 11 months ago

mbostock commented 11 months ago

Currently inline expression ${…} are only supported for node content. So you can’t do this:

```js
const link = "https://example.com";

This is a link.


You can workaround it using [Hypertext Literal](https://github.com/observablehq/htl) like so:

````md
```js
const link = "https://example.com";

This is a ${htl.html<a href=${link}>link</a>}.



I’m not immediately sure how we would support this. It might involve writing our own Markdown parser? Or at least pre-processing the content to remove the live code expressions before passing it to markdown-it? Presumably we could repurpose parts of Hypertext Literal to parse the HTML.
mbostock commented 10 months ago

This is one of the trickiest outstanding questions in the CLI. If we do this, it probably requires radical changes to how we parse Markdown and generate HTML & JavaScript. We should decide whether we want to do that before Early Access.