Git Product home page Git Product logo

Comments (7)

mbutterick avatar mbutterick commented on September 25, 2024 3

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.

sorawee avatar sorawee commented on September 25, 2024 2

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.

nixin72 avatar nixin72 commented on September 25, 2024 2

😮

This is so cool... Thank you so much @mbutterick and @sorawee!

from pollen-users.

nixin72 avatar nixin72 commented on September 25, 2024

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.

sorawee avatar sorawee commented on September 25, 2024

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.

mbutterick avatar mbutterick commented on September 25, 2024

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.

shriram avatar shriram commented on September 25, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.