emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to add new type of block to a derived back-end?


From: Salomon Turgman
Subject: How to add new type of block to a derived back-end?
Date: Fri, 10 Apr 2020 10:56:51 -0400

Hello all,

Thanks in advance for any hints you can provide for this. I am trying to create a derived back-end that handles a new type of block in org-mode. I am trying to derive using the html export backend as a parent.

Currently I am solving my problem like this:
#+CAPTION[Manual control]: Simulation 1: Manual control of the tank level.
#+BEGIN_EXPORT html
<div class="caption">Simulation 1: Manual control of the tank level.</div>
<div class="simulation">
<div id="main1">
<noscript>
Some other cool stuff here.
</noscript>
</div>
</div>
<script>var app = Main1.init({node: document.getElementById("main1")});</script>
#+END_EXPORT

This has a few downsides:
1. I have to specify the caption twice since export translator does not handle captions.
2. I have to include substantial amounts of html.
3. I have keep track of references to simulations manually (simulation 1, simulation 2, etc)
4. I have to include the identifier `main1` or `Main1` in several locations in the snippet.

I could solve some of this with an automated snippet insertion tool but I thought that maybe I can get the export back-end to do most of the work for me.

So I am trying to derive as follows (in pseudo-elisp-code):
(require 'ox)
(require 'ox-html)

(org-export-define-derived-backend 'textbook 'html
  :menu-entry
  '(?I "Export textbook section"
       ((?b "To buffer" org-html-export-as-html)
        (?I "To file" org-html-export-to-html)
        (?o "As HTML file and open"
            (lambda (a s v b)
              (if a (org-html-export-to-html t s v b)
                (org-open-file (org-html-export-to-html nil s v b)))))))
  :translate-alist '((simulation . org-textbook-simulation)))

(defun org-textbook-simulation (element contents info)
  (let* ((simnum (extract simnum value))
         (caption (org-export-get-caption element))
         (divid (extrac divid value))
         (modid (convert divid into modid))
         )
    (format "<div class=\"caption\">Simulation %simnum%: %Caption%.</div>
  <div class=\"simulation\">
    <div id=\"%divid%\">
    </div>
  </div>
<script>var app = %modid%.init({node: document.getElementById(\"%divid%\")});</script>"
   simnum caption divid modid divid)))

With the hope that I can do something like this in my .org file:

#+CAPTION[Manual control]: Simulation 1: Manual control of the tank level.
#+BEGIN_SIMULATION main1
Some other cool stuff here
#+END_SIMULATION

Am I on the right track here? Can someone point me to an example on how to:
1. Keep track of the number of simulations for referencing?
2. Extract the caption properly? The above is just my guess.
3. Extract the divid value (main1)
4. And finally, how to get org to recognize the new SIMULATION block so that it can apply `org-textbook-simulation`? Do I need to register this type of block somewhere? Or is the name of the first member of the :translate-alist translation pair have some special meaning?

Thank you very much for any assistance and thank you for org-mode!

-s-


reply via email to

[Prev in Thread] Current Thread [Next in Thread]