emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: John Kitchin <jkitchin@andrew.cmu.edu>
To: Marcin Borkowski <mbork@wmi.amu.edu.pl>
Cc: emacs-orgmode@gnu.org
Subject: Re: Extending the Org syntax by a custom exporter - how to do it?
Date: Wed, 26 Nov 2014 09:23:56 -0500	[thread overview]
Message-ID: <m2oaru82gz.fsf@andrew.cmu.edu> (raw)
In-Reply-To: <m2tx1mlluw.fsf@andrew.cmu.edu> (John Kitchin's message of "Tue, 25 Nov 2014 21:46:47 -0500")

I played around with this a little. Here is a minimal kind of example
with a custom exporter that handles quiz blocks separately. The quiz
block can have some attributes defined that get used in rendering the
HTML. Is this along the lines of what you are trying to do? 

* A custom type

#+BEGIN_EXAMPLE
Example text in a block to make sure it gets handled
#+END_EXAMPLE

Some instructions for the quiz.

#+ATTR_quiz: :points 5 :correct-answer A
#+BEGIN_quiz
test quiz
- [ ] answer A
- [ ] answer B
#+END_quiz


#+BEGIN_SRC emacs-lisp :exports none
(defun my-org-html-export-block (export-block contents info)
  "Transcode a EXPORT-BLOCK element from Org to HTML.
CONTENTS is nil.  INFO is a plist used as a communication
channel. QUIZ blocks are handled separately."

  (cond
   ;; handle our special quiz block
   ((string= (org-element-property :type export-block) "QUIZ")

    (format
     "<b>got it:</b> %s points, correct answer = %s 
<br>
You would have to parse the body to generate your html here.
<br>
<pre>%s</pre>"
     (plist-get 
      (read (format "%s" (org-element-property :attr_quiz export-block)))
     :points)
     (plist-get 
      (read (format "%s" (org-element-property :attr_quiz export-block)))
     :correct-answer)
     (org-element-property :value export-block)
     ))
   ;; handle every other kind of block
   (t
    (org-html-export-block (export-block contents info)))))

(org-export-define-derived-backend 'my-html 'html
  :translate-alist '((export-block . my-org-html-export-block))
  ;; quiz blocks will not be parsed, they are handled directly in org-html-export-block.
  :export-block "quiz"
)


(browse-url (org-export-to-file 'my-html "custom-element.html"))
#+END_SRC

#+RESULTS:
: #<process open custom-element.html>






John Kitchin <jkitchin@andrew.cmu.edu> writes:

> Could you remind us of what you are trying to do? It seems like you may
> not necessarily need custom elements (although that could be
> useful). For example, you can put a lot of information in properties of
> a headline.
>
> You might be interested in this:
>
> http://kitchingroup.cheme.cmu.edu/blog/2014/11/23/Machine-gradable-quizzes-in-emacs+org-modex/
>
> I recently used this is in my class of 58 students (who all used emacs
> and org-mode to take a quiz!).
>
>
> Marcin Borkowski <mbork@wmi.amu.edu.pl> writes:
>
>> Hello there,
>>
>> this is close to necromancy, but let me revive this old thread.
>>
>> On 2014-03-16, at 11:16, Nicolas Goaziou wrote:
>>
>>> Another, more advanced option, is to use a parse tree filter to create
>>> pseudo-types, i.e., element or object types that don't exist in regular
>>> Org syntax. See `math-block' type in "ox-latex.el", in particular
>>> `org-latex-math-block-tree-filter'.
>>
>> Now that I actually started work on my exporter, I'd like to investigate
>> this further.  The thing is, I'm not sure where to start.  First of all,
>> I have a bit old Org-mode (without latex-math-blocks); I guess I'll just
>> have to update it (I'll try to do an Elpa update in a minute).  But my
>> question is:
>>
>> 1. Is it a good idea to instrument `org-latex--wrap-latex-math-block'
>> for Edebug to learn what's happening?
>>
>> 2. Is there any other (possibly simpler) instance of pseudo-blocks I
>> could study?  It seems to me (from the docstring) that latex-math-blocks
>> are a bit tricky; what I'm interested in is more like creating a new
>> element similar to e.g. italics.
>>
>> (Reagrdless of the answer, I'll try with Edebug, but I'm a bit afraid
>> that I won't understand what's going on).
>>
>> Also, if (when?) I "get it", I'm going to describe the process of adding
>> a pseudo-object somewhere (I consider my blog, or maybe I could upload
>> it to Worg?), so that other people can learn it easier.  But for now, I
>> might need help.
>>
>> Best,

-- 
-----------------------------------
John Kitchin
Professor
Doherty Hall A207F
Department of Chemical Engineering
Carnegie Mellon University
Pittsburgh, PA 15213
412-268-7803
http://kitchingroup.cheme.cmu.edu

  reply	other threads:[~2014-11-26 14:24 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-15 10:10 Extending the Org syntax by a custom exporter - how to do it? Marcin Borkowski
2014-03-15 11:10 ` John Kitchin
2014-03-15 11:25   ` Marcin Borkowski
2014-03-15 11:29     ` Marcin Borkowski
2014-03-15 21:22 ` Marcin Borkowski
2014-03-16 10:16   ` Nicolas Goaziou
2014-03-16 11:18     ` Marcin Borkowski
2014-03-16 11:57       ` Nicolas Goaziou
2014-03-16 13:33         ` Marcin Borkowski
2014-03-16 14:12           ` Nicolas Goaziou
2014-03-17 15:43             ` Marcin Borkowski
2014-03-16 16:05         ` Aaron Ecay
2014-03-17 16:31     ` Marcin Borkowski
2014-03-22 11:23       ` Nicolas Goaziou
2014-11-25 21:25     ` Marcin Borkowski
2014-11-25 21:46       ` Marcin Borkowski
2014-11-26  2:46       ` John Kitchin
2014-11-26 14:23         ` John Kitchin [this message]
2014-11-26 11:59       ` Nicolas Goaziou

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=m2oaru82gz.fsf@andrew.cmu.edu \
    --to=jkitchin@andrew.cmu.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=mbork@wmi.amu.edu.pl \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).