emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* define a new export backend
@ 2014-07-31  7:11 Shiyuan
  2014-07-31  7:27 ` Thorsten Jolitz
  0 siblings, 1 reply; 7+ messages in thread
From: Shiyuan @ 2014-07-31  7:11 UTC (permalink / raw)
  To: emacs-orgmode@gnu.org

[-- Attachment #1: Type: text/plain, Size: 1455 bytes --]

Hi,
    I try to define a new export backend in the new export framework. My
export backend should behaves like the html except that it transcodes
*bold* differently.  I try to following the Worg tutorial
http://orgmode.org/worg/dev/org-export-reference.html , ox-html.el and use
org-export-define-derived-backend. I can see the new backend showing up in
the export menu(C-c C-e), but my transcoder for bold is not used.  Any help
or reference pointer is appreciated.

Shiyuan


-------------------------
(org-export-define-derived-backend 'my-html-enlish 'html
  :traslate-alist '((bold . my-org-html-english-bold))
   :menu-entry
  '(?E "Export to HTML-ENGLISH"
       ((?H "As HTML buffer" my-org-html-english-export-as-html)
)))
------------------------------
(defun my-org-html-english-export-as-html
  (&optional async subtreep visible-only body-only ext-plist)
 "This is almost copied from org-html-export-as-html except using my newly
defined backend"
  (interactive)
  (org-export-to-buffer 'my-html-enlish "*Org HTML-ENG Export*"
    async subtreep visible-only body-only ext-plist
    (lambda () (set-auto-mode t))))
-------------------
(defun my-org-html-english-bold (bold contents info)
  "Transcode BOLD from Org to HTML. Intead of using ordinary bold, we use
color to highlight the
CONTENTS is the text with bold markup.  INFO is a plist holding
contextual information."
  (format "<span style=\"color: #a020f0\"> %s </span>"
  contents))

[-- Attachment #2: Type: text/html, Size: 2133 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: define a new export backend
  2014-07-31  7:11 define a new export backend Shiyuan
@ 2014-07-31  7:27 ` Thorsten Jolitz
  2014-07-31  8:08   ` Nicolas Richard
  0 siblings, 1 reply; 7+ messages in thread
From: Thorsten Jolitz @ 2014-07-31  7:27 UTC (permalink / raw)
  To: emacs-orgmode

Shiyuan <gshy2014@gmail.com> writes:

> Hi, 
> I try to define a new export backend in the new export framework. My
> export backend should behaves like the html except that it transcodes
> *bold* differently. I try to following the Worg tutorial
> http://orgmode.org/worg/dev/org-export-reference.html , ox-html.el and
> use org-export-define-derived-backend. I can see the new backend
> showing up in the export menu(C-c C-e), but my transcoder for bold is
> not used. Any help or reference pointer is appreciated. 
>
> Shiyuan 
>
> -------------------------
> (org-export-define-derived-backend 'my-html-enlish 'html
> :traslate-alist '((bold . my-org-html-english-bold))


:translate-alist ?

-- 
cheers,
Thorsten

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: define a new export backend
  2014-07-31  7:27 ` Thorsten Jolitz
@ 2014-07-31  8:08   ` Nicolas Richard
  2014-07-31  8:39     ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Richard @ 2014-07-31  8:08 UTC (permalink / raw)
  To: Thorsten Jolitz; +Cc: emacs-orgmode, Nicolas Goaziou

Thorsten Jolitz <tjolitz@gmail.com> writes:
> Shiyuan <gshy2014@gmail.com> writes:
>> (org-export-define-derived-backend 'my-html-enlish 'html
>> :traslate-alist '((bold . my-org-html-english-bold))
>
>
> :translate-alist ?

Perhaps org-export-define-derived-backend could do a sanity check that
all keywords are known. use-package does that, and it has saved me
multiple times ! Nicolas, what am I overlooking ?

	Modified   lisp/ox.el
diff --git a/lisp/ox.el b/lisp/ox.el
index 03bd8bb..e931723 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1187,9 +1187,9 @@ The back-end could then be called with, for example:
 
   \(org-export-to-buffer 'my-latex \"*Test my-latex*\")"
   (declare (indent 2))
-  (let (blocks filters menu-entry options transcoders contents)
+  (let (blocks filters menu-entry options transcoders contents keyword)
     (while (keywordp (car body))
-      (case (pop body)
+      (case (setq keyword (pop body))
 	(:export-block (let ((names (pop body)))
 			 (setq blocks (if (consp names) (mapcar 'upcase names)
 					(list (upcase names))))))
@@ -1197,7 +1197,7 @@ The back-end could then be called with, for example:
 	(:menu-entry (setq menu-entry (pop body)))
         (:options-alist (setq options (pop body)))
         (:translate-alist (setq transcoders (pop body)))
-        (t (pop body))))
+        (t (error "Unknown keyword in `org-export-define-derived-backend': %s" keyword))))
     (org-export-register-backend
      (org-export-create-backend :name child
 				:parent parent

-- 
Nico.

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: define a new export backend
  2014-07-31  8:08   ` Nicolas Richard
@ 2014-07-31  8:39     ` Nicolas Goaziou
  2014-07-31  9:17       ` Nicolas Richard
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2014-07-31  8:39 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: emacs-orgmode, Thorsten Jolitz

Hello,

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> Perhaps org-export-define-derived-backend could do a sanity check that
> all keywords are known.

Good idea, as long as `org-export-define-backend' does the same.

> -  (let (blocks filters menu-entry options transcoders contents)
> +  (let (blocks filters menu-entry options transcoders contents keyword)

KEYWORD should be let-bound within the while loop.

>      (while (keywordp (car body))
> -      (case (pop body)
> +      (case (setq keyword (pop body))


  (while (keywordp (car body))
    (let ((keyword (pop body)))
      (case keyword
        (...)
        (t (error "Unknown keyword: %s" keyword)))))


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: define a new export backend
  2014-07-31  8:39     ` Nicolas Goaziou
@ 2014-07-31  9:17       ` Nicolas Richard
  2014-07-31 11:41         ` Nicolas Goaziou
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Richard @ 2014-07-31  9:17 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: emacs-orgmode, Thorsten Jolitz

[-- Attachment #1: Type: text/plain, Size: 226 bytes --]

Nicolas Goaziou <mail@nicolasgoaziou.fr> writes:
> Good idea, as long as `org-export-define-backend' does the same.

Oops, I forgot to remove the verbosity (initially I had wrote it as a
(warn ...)). Here's an updated patch.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Signal-an-error-if-keyword-is-unknown-while-defining.patch --]
[-- Type: text/x-diff, Size: 2694 bytes --]

From 117623cec251cd036b601e2481643296cc4e2c37 Mon Sep 17 00:00:00 2001
From: Nicolas Richard <theonewiththeevillook@yahoo.fr>
Date: Thu, 31 Jul 2014 10:48:54 +0200
Subject: [PATCH] Signal an error if keyword is unknown while defining backends

* lisp/ox.el (org-export-define-backend):
(org-export-define-derived-backend): Signal an error if keyword is unknown
---
 lisp/ox.el | 36 +++++++++++++++++++-----------------
 1 file changed, 19 insertions(+), 17 deletions(-)

diff --git a/lisp/ox.el b/lisp/ox.el
index 03bd8bb..e2965c4 100644
--- a/lisp/ox.el
+++ b/lisp/ox.el
@@ -1118,14 +1118,15 @@ keywords are understood:
   (declare (indent 1))
   (let (blocks filters menu-entry options contents)
     (while (keywordp (car body))
-      (case (pop body)
-        (:export-block (let ((names (pop body)))
-			 (setq blocks (if (consp names) (mapcar 'upcase names)
-					(list (upcase names))))))
-	(:filters-alist (setq filters (pop body)))
-	(:menu-entry (setq menu-entry (pop body)))
-        (:options-alist (setq options (pop body)))
-        (t (pop body))))
+      (let ((keyword (pop body)))
+	(case keyword
+	  (:export-block (let ((names (pop body)))
+			   (setq blocks (if (consp names) (mapcar 'upcase names)
+					  (list (upcase names))))))
+	  (:filters-alist (setq filters (pop body)))
+	  (:menu-entry (setq menu-entry (pop body)))
+	  (:options-alist (setq options (pop body)))
+	  (t (error "Unknown keyword: %s" keyword)))))
     (org-export-register-backend
      (org-export-create-backend :name backend
 				:transcoders transcoders
@@ -1189,15 +1190,16 @@ The back-end could then be called with, for example:
   (declare (indent 2))
   (let (blocks filters menu-entry options transcoders contents)
     (while (keywordp (car body))
-      (case (pop body)
-	(:export-block (let ((names (pop body)))
-			 (setq blocks (if (consp names) (mapcar 'upcase names)
-					(list (upcase names))))))
-        (:filters-alist (setq filters (pop body)))
-	(:menu-entry (setq menu-entry (pop body)))
-        (:options-alist (setq options (pop body)))
-        (:translate-alist (setq transcoders (pop body)))
-        (t (pop body))))
+      (let ((keyword (pop body)))
+	(case keyword
+	  (:export-block (let ((names (pop body)))
+			   (setq blocks (if (consp names) (mapcar 'upcase names)
+					  (list (upcase names))))))
+	  (:filters-alist (setq filters (pop body)))
+	  (:menu-entry (setq menu-entry (pop body)))
+	  (:options-alist (setq options (pop body)))
+	  (:translate-alist (setq transcoders (pop body)))
+	  (t (error "Unknown keyword: %s" keyword)))))
     (org-export-register-backend
      (org-export-create-backend :name child
 				:parent parent
-- 
1.8.5.5


[-- Attachment #3: Type: text/plain, Size: 11 bytes --]


-- 
Nico.

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: define a new export backend
  2014-07-31  9:17       ` Nicolas Richard
@ 2014-07-31 11:41         ` Nicolas Goaziou
  2014-07-31 22:04           ` Shiyuan
  0 siblings, 1 reply; 7+ messages in thread
From: Nicolas Goaziou @ 2014-07-31 11:41 UTC (permalink / raw)
  To: Nicolas Richard; +Cc: Thorsten Jolitz, emacs-orgmode

Hello,

Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:

> Oops, I forgot to remove the verbosity (initially I had wrote it as a
> (warn ...)). Here's an updated patch.

Applied. Thank you.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: define a new export backend
  2014-07-31 11:41         ` Nicolas Goaziou
@ 2014-07-31 22:04           ` Shiyuan
  0 siblings, 0 replies; 7+ messages in thread
From: Shiyuan @ 2014-07-31 22:04 UTC (permalink / raw)
  To: Nicolas Richard, emacs-orgmode@gnu.org, Thorsten Jolitz

[-- Attachment #1: Type: text/plain, Size: 465 bytes --]

Oops,  I've asked the dumpest question ever in the mailing list :) That's
what happens when working late.

Thanks for reply.


On Thu, Jul 31, 2014 at 4:41 AM, Nicolas Goaziou <mail@nicolasgoaziou.fr>
wrote:

> Hello,
>
> Nicolas Richard <theonewiththeevillook@yahoo.fr> writes:
>
> > Oops, I forgot to remove the verbosity (initially I had wrote it as a
> > (warn ...)). Here's an updated patch.
>
> Applied. Thank you.
>
>
> Regards,
>
> --
> Nicolas Goaziou
>
>

[-- Attachment #2: Type: text/html, Size: 1021 bytes --]

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-07-31 22:04 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-07-31  7:11 define a new export backend Shiyuan
2014-07-31  7:27 ` Thorsten Jolitz
2014-07-31  8:08   ` Nicolas Richard
2014-07-31  8:39     ` Nicolas Goaziou
2014-07-31  9:17       ` Nicolas Richard
2014-07-31 11:41         ` Nicolas Goaziou
2014-07-31 22:04           ` Shiyuan

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).