Skip to content

Commit 4f46c08

Browse files
add svg blog entry
1 parent 3f21906 commit 4f46c08

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
---
2+
title: "SVG Integration"
3+
slug: "svg-integration"
4+
date: 2025-07-23
5+
draft: false
6+
authors:
7+
- André Dietrich
8+
- Sebastian Zug
9+
image: "https://upload.wikimedia.org/wikipedia/commons/6/6b/Bitmap_VS_SVG.svg"
10+
image_alt: "Difference between bitmap and SVG images"
11+
image_credit: "“Bitmap VS SVG” by Yug (mods: Cfaerber et al.)"
12+
image_credit_link: "https://commons.wikimedia.org/wiki/File:Bitmap_VS_SVG.svg"
13+
image_license: "CC BY-SA 2.5"
14+
image_license_link: "https://creativecommons.org/licenses/by-sa/2.5/"
15+
image_changes: "none"
16+
17+
tags:
18+
- LiaScript
19+
- Documentation
20+
---
21+
22+
Although SVGs have been usable in LiaScript for quite a while, their integration just got a lot tighter. In short: you can now *mix SVG and LiaScript content directly*, turning static vector graphics into living, clickable, even quiz-enabled experiences.
23+
24+
## Quick refresher: What is SVG?
25+
26+
**SVG** stands for **Scalable Vector Graphics**. It’s an XML-based image format for describing two‑dimensional graphics (lines, shapes, text, etc.) that scale perfectly at any resolution. Because SVGs are text files, you can read and edit them, script them with JavaScript or CSS, and now—thanks to LiaScript—embed teaching elements right inside them.
27+
28+
👉 Official docs: [https://developer.mozilla.org/docs/Web/SVG](https://developer.mozilla.org/docs/Web/SVG)
29+
30+
<iframe style="height: 80vh; min-width: 100%; border: 1px black solid" src="https://liascript.github.io/LiveEditor/?/embed/code/H4sIAAAAAAAAAzWOPW7DMBSDd52CeB2ytJbitkMCy0D/xqJLL6AqivQQ2Q5kIXJuXzt1N5IA+fEOL/jknjsT8TGZ7hzdHu/JFO49DN442eiEaMaLR+FDDpqelCIExz7k1VzYlddh0qSgMCe4pVMX+1FTyPm8l7KUUpXHakhe1kopOQ9SK4DG3hCwc71eava6iqRpu3smHDlGTXHh+WSuhDGn4eQ0/URjT//2YX1XE2QrmmW/FeI7mLwZwbnCV++Qjb/HMIs/aPULISnQHP4AAAA="></iframe>
31+
32+
## Enter `<foreignObject>` …and LiaScript!
33+
34+
SVG has a special element called `<foreignObject>`. Traditionally, you use it to place arbitrary HTML inside an SVG. Now the LiaScript parser will **look for ****\`\`**** blocks and interpret their contents as LiaScript**. That means formulas, quizzes, code blocks, animations—anything you can do in LiaScript—can live right inside the graphic.
35+
36+
### How it works
37+
38+
1. Write (or export) your SVG as usual.
39+
2. Add a `<foreignObject>` element where you want interactive content.
40+
3. Put LiaScript markup inside that element.
41+
4. When LiaScript renders, the parser finds that block and executes it as LiaScript.
42+
43+
### Example: A Circle With Embedded LiaScript
44+
45+
<iframe style="height: 80vh; min-width: 100%; border: 1px black solid" src="https://liascript.github.io/LiveEditor/?/embed/code/H4sIAAAAAAAAA22QTU7DMBCF9z7Fk5Mt9cQhCKE4qHAAlizaIqXBiQ1pUzlWU27PJCoLpGoW86N53zxNgnWwNYYWNV59aHorRDmeO5y9nV6Gi5EEQkEErUnicuiPo5EuxtOTUtM0raZ8NYROaSJSrJOVKJuFg4bFWcai5udaBM5USLS+741MWppDYoxh+LY8yPP8r7ub/Gd0RvJAVWypHYL13fFt/2WbCCZrLcHcB8ZdV7NHZjnectHIgthJkiBNsYbB9uQRPjS3olT/WDfhOdFCv6fbdL3g310d4UdEZ1HPX/QtAh8rnoXYbADoAtjtkGIb/cGOs4sb98v5b9UvfbHl+YkBAAA="></iframe>
46+
47+
> **Tip:** Pay attention to the `x`, `y`, `width`, and `height` attributes of `<foreignObject>`. They define the rectangle in SVG coordinates where your LiaScript block will appear.
48+
49+
## What Can You Build?
50+
51+
The combination unlocks a whole new universe:
52+
53+
- **Inline formulas** rendered with LiaScript’s LaTeX support.
54+
- **Quizzes and polls** overlaid on diagrams.
55+
- **Animated SVGs** synchronized with explanations.
56+
- **Dynamic compositions** via scripts that manipulate both SVG and LiaScript states.
57+
- **Interactive infographics and timelines** without switching tools.
58+
59+
If you can picture it in SVG, you can likely make it *interactive* with LiaScript.
60+
61+
## A Few Practical Notes
62+
63+
- Keep your SVG code tidy. Group related elements and comment generously.
64+
- Test your coordinate system. `viewBox` makes scaling easier, but it also affects where your `<foreignObject>` shows up.
65+
- Remember accessibility: provide titles/desc elements and consider keyboard navigability for embedded interactions.
66+
67+
## Documentation
68+
69+
Checkout the new chapter in the documentation:
70+
71+
{{< button link="https://liascript.github.io/course/?https://raw.githubusercontent.com/liaScript/docs/master/README.md#scaleable-vector-graphics" label="SVG in LiaScript" >}}
72+
73+
Or—as always—watch the video 😉
74+
75+
{{< youtube k8VSso6aEjI >}}
76+
77+
78+
## Learn More
79+
80+
- MDN SVG docs (specs, attributes, browser quirks): [https://developer.mozilla.org/docs/Web/SVG](https://developer.mozilla.org/docs/Web/SVG)
81+
- LiaScript documentation: [https://liascript.github.io](https://liascript.github.io)
82+
- SVG 2 specification (for the curious): [https://www.w3.org/TR/SVG2/](https://www.w3.org/TR/SVG2/)

0 commit comments

Comments
 (0)