Diagrams inside Nanoc markdown

30 views
Skip to first unread message

Pito Salas

unread,
Aug 11, 2019, 2:22:38 PM8/11/19
to Nanoc
I would like to make it easy and clean to embed diagrams (ala graphviz or mermaid) right inside my Nanoc markdown. Has anyone done this who can share their experience?

-- Pito

Denis Defreyne

unread,
Aug 17, 2019, 4:25:30 AM8/17/19
to na...@googlegroups.com
Hey Pito,

I am not aware of a way to embed diagrams directly into Markdown, though what you could do is add raw HTML to your Markdown files and have it be rendered via e.g. mermaid. Here’s an example of what I came up with:


I imagine that with other tools (other than mermaid) you could have a similar experience.

Hope this helps,

Denis

On Sun, Aug 11, 2019 at 8:22 PM Pito Salas <pito...@gmail.com> wrote:
I would like to make it easy and clean to embed diagrams (ala graphviz or mermaid) right inside my Nanoc markdown. Has anyone done this who can share their experience?

-- Pito

--
You received this message because you are subscribed to the Google Groups "nanoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanoc+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nanoc/CA%2B%2B7fQxbmcXwYbEf3bGWibXaLSkUUpJjWJo6P7fnEzHZRoSZEg%40mail.gmail.com.

Pito Salas

unread,
Aug 18, 2019, 6:19:32 AM8/18/19
to na...@googlegroups.com
Thanks! I never gave much thought to filters. But could I write one myself? For example to recognize a special symbol I invent (e.g. $$mermaid and $$end) to make it prettier? Just musing, not sure it would be worth the trouble anyway. 

But continuing on that thread, my coursegen package has tons of “macros” which I write 10 times a day such as

<%= include_topic :writing_macros %>

Which would be much cooler if written

$$include_topic :writing_macros

Would it be easy to write a filter in nanoc to do that?

Thanks again,

Pito

Sent from my iPad

Denis Defreyne

unread,
Dec 26, 2019, 5:31:51 AM12/26/19
to na...@googlegroups.com
Hey Pito,

A late reply, my apologies! You certainly can create a filter for that. Off the top of my head:

    Nanoc::Filter.define(:handle_shortcodes) do |content, _params = {}|
      content.gsub(/^\$\$include_topic :(\w+)$/) { "<%= include_topic(#{$1}) %>" }
    end

($1 is the first matched regex group.)

This filter turns e.g.
    $$include_topic :writing_macros
into
    <%= include_topic :writing_macros %>

Now, right before filter :erb you call filter :handle_shortcodes. That should get you what you want!

Denis




--

Pito Salas

unread,
Feb 26, 2021, 10:46:13 AM2/26/21
to na...@googlegroups.com
Hi Denis

This is the slowest moving glacial conversation ever!!! Do you remember writing this almost 2 years ago? Well, I finally got to it. Question, where would I put the code snippet Nanoc::Filter.define? In Rules? If it doesn't matter, then where would you put it, idiomatically? THanks,

Pito Salas
Faculty, Computer Science
Brandeis University
> To view this discussion on the web visit https://groups.google.com/d/msgid/nanoc/CALjsL%3D1yOGJc_PE-dy5ADvzyMjPZyWi24yEj_d-OtA3pDhRYXg%40mail.gmail.com.

google...@ml.th-h.de

unread,
Feb 26, 2021, 12:37:31 PM2/26/21
to nanoc
On Friday, 26 February 2021 at 16:46:13 UTC+1 pito...@gmail.com wrote:

Question, where would I put the code snippet Nanoc::Filter.define?


Documentation on writing filters is found at https://nanoc.ws/doc/filters/#writing-filters

Denis Defreyne

unread,
Feb 27, 2021, 9:07:21 AM2/27/21
to noreply-spamdigest via nanoc
Hey both,

Thomas is correct — anywhere in lib/ will do.

My preference is to use the naming scheme lib/filters/FILTERNAME.rb. For your case, I’d therefore have a file lib/filters/handle_shortcodes.rb containing the Nanoc::Filter.define(…) code.

Cheers,

Denis Defreyne
[dəˈni] • pronouns: he/him
--
You received this message because you are subscribed to the Google Groups "nanoc" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nanoc+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages