Comments (7)
The {···}
notation will produce a list of strings, so it would also be possible to write the tag function to directly support (some subset of) DOT input:
#lang pollen
this is some text
◊include-digraph{
v0;
v1;
v2;
v0 -> v0;
v0 -> v1;
v1 -> v2;
v2 -> v0;
}
some more text after a picture of my FSM
from pollen-users.
This is easily doable. In your pollen.rkt
, create include-digraph
as follows:
#lang racket
(require graphviz)
(provide (all-defined-out))
(define (include-digraph name digraph
#:ext [ext 'png]
#:tag [tag (λ (x) `(image ,x))]
#:dir [dir "images"])
(make-directory* dir)
(define path (build-path dir (~a name (equal-hash-code digraph) "." ext)))
(unless (file-exists? path)
(send (pict->bitmap (digraph->pict (make-digraph digraph))) save-file path ext))
(tag (path->string path)))
This renders a digraph into an image file if it doesn't exist already, and then returns its path wrapped with tag
.
Then, the Pollen program:
#lang pollen
this is some text
◊(include-digraph "first-diagram"
`("v0" "v1" "v2" "v0 -> v0" "v0 -> v1" "v1 -> v2" "v2 -> v0")
#:tag (λ (img-path) `(img ([src ,img-path]))))
some more text after a picture of my FSM
would produce
'(root
"this is some text"
"\n"
"\n"
(img ((src "images/first-diagram-1065713455284007950.png")))
"\n"
"\n"
"some more text after a picture of my FSM")
The 1065713455284007950
is a (practically) unique identity of your digraph, so if you modify your digraph, it would render your digraph again. But if you make no changes to your digraph, it will reuse the existing file.
from pollen-users.
😮
This is so cool... Thank you so much @mbutterick and @sorawee!
from pollen-users.
Thank you so much! I'm pretty sure Pollen is going to become my go-to tool from now on for writing, I can't believe it's that easy to extend to include something like this!
from pollen-users.
Note: my code above will create a lot of junk files if you modify the digraph several times. One easy improvement is to read the file images/first-digraph.data
and compare it against your digraph. If they match, then skip rendering, but if it doesn't match, then update both images/first-digraph.data
and images/first-digraph.png
. I guess the main point is that you have a full power of programming here, so you can do whatever you want :)
from pollen-users.
PS. You say mixing diagrams inline with Markdown “isn't going to happen” but watch this final trick. You can use the #lang pollen/markdown
dialect and write in Markdown normally. When you get to the include-digraph
tag function, you’d need it to emit valid Markdown (instead of an X-expression, as it does now). But arbitrary HTML is valid inside a Markdown doc. So just run the output of your tag function through xexpr->html
and your dream comes true.
from pollen-users.
Looks like y'all have solutions, so I don't want to confuse things further, but for people looking to do more visual/graphical content inside Markdown (acknowledging how @mbutterick feels about Markdown <-:), there's Markdeep: https://casual-effects.com/markdeep/.
I don't know what it would take to incorporate into Pollen, but at least Markdeep offers something of real value, especially for diagrams, well beyond the thin veneer over HTML that Markdown is.
from pollen-users.
Related Issues (20)
- render index.ptree with subdirectories changes directory (though not project root) HOT 8
- Is parallel mode known to crash a lot? HOT 1
- decode-elements with decode-paragraphs inserts spurious <p> when nesting lists? HOT 2
- multiple text arguments? HOT 5
- serialising txexprs? HOT 2
- Beautiful Racket Racket docs HOT 1
- Classic tangle/weave support a la org/babel-mode HOT 2
- Add source tag to default block-tags HOT 3
- Importing text from other sources HOT 2
- One source file → multiple outputs of same type? HOT 6
- Having a hard time with maps HOT 4
- Metadata on pagenodes (?) / how to render link traversal HOT 5
- Filling templates multiple times, à la mail-merge -- maybe a non-use case? HOT 3
- Inserting html comment with pollen command HOT 4
- splitf-txexpr: how to use the resulting txexpr HOT 2
- Windows: Set Pollen environment variable HOT 2
- execute shell command via preprocessor?
- Mildy Dynamic Websites
- opinions sought: costs & benefits of switching to self-hosted Git server? HOT 17
- Could not find MANIFEST for package source HOT 7
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pollen-users.