emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nick Dokos <nicholas.dokos@hp.com>
To: Sten Lindner <s.lindner@stenlindner.de>
Cc: nicholas.dokos@hp.com, org-mode Mailinglist <emacs-orgmode@gnu.org>
Subject: Re: custom IDs not exported
Date: Wed, 02 Nov 2011 01:33:52 -0400	[thread overview]
Message-ID: <9894.1320212032@alphaville.dokosmarshall.org> (raw)
In-Reply-To: Message from Sten Lindner <s.lindner@stenlindner.de> of "Tue\, 01 Nov 2011 18\:01\:54 BST." <20111101170154.GC1993@aberdeen>

Sten Lindner <s.lindner@stenlindner.de> wrote:

> On Sat, Jun 11, 2011 at 11:12:26PM -0400, Nick Dokos wrote:
> > 
> > I have a minimal patch that I think fixes this problem, but there are
> > other underscores used in various places in org-html.el so there might
> > be additional problems. I'd appreciate it if you (and/or others) test it
> > and report not only on this problem but on any other problems you find.
> 
> I'm having the same problem when exporting to Docbook, custom IDs are
> being ignored.
> 
> For example, when I export some org-mode text using C-c C-e D:
> 
> * heading1
>   :PROPERTIES:
>   :CUSTOM_ID: h1
>   :END:
> 
> ** heading2
>   :PROPERTIES:
>   :CUSTOM_ID: h2
>   :END:
> 
> some links:
> - see [[#h1][heading1]]
> - see [[#h2][heading2]]
> 
> I' getting the following XML output:
> 
> <section xml:id="sec-1">
> <title>heading1 </title>
> <section xml:id="sec-1_1">
> <title>heading2 </title>
> <para>
> some links:
> </para>
> <itemizedlist>
> <listitem>
> <para>see <link linkend="h1">heading1</link>
> </para>
> </listitem>
> <listitem>
> <para>see <link linkend="h2">heading2</link>
> </para>
> </listitem>
> </itemizedlist>
> </section>
> </section>
> </article>
> 
> I would expect to see my custom IDs "H1" and "H2" but instead get
> auto-generated IDs "sec-1" and "sec-1_1".
> 
> I'm using the latest org-mode version 7.7.
> 
> best regards,
> Sten
> 
> -- 
> Sten Lindner
> 
> e-mail: s.lindner@stenlindner.de
>


This is because org-docbook.el does not implement custom ID handling at
all. I don't know if Baoqiu Cui, the author of org-docbook.el, watches
this list any longer (I haven't seen any mail from him for some time):
if he is around, he would be the logical person to fix it.  But if you
are interested in fixing this problem, I'd be happy to provide
guidance.[fn:1]

The problem is the following code in the function
org-export-docbook-level-start in lisp/org-docbook.el:

      ...
      (setq section-number (org-section-number level))
      (insert (format "\n<section xml:id=\"%s%s\">\n<title>%s</title>"
		      org-export-docbook-section-id-prefix
		      (replace-regexp-in-string "\\." "_" section-number)
      ...

As you can see, the xml id is formed from
org-export-docbook-section-id-prefix (which has the value "sec-") and
the section-number (which is "1" for the top level heading and "1.1" for
the second level heading). We replace periods with underscores in the
section number and then construct the id as "sec-1_1". But there is no
provision anywhere for translating to custom IDs.

So one necessary change in order to conform to the changed convention is
to replace periods with hyphens in the section number. But in addition
to that, the xml id will have to be constructed differently if there is
a custom ID around.

Custom ids are passed to this function through a (dynamically scoped)
variable called org-export-preferred-target-alist which in the case
below has the value

    (("sec-1-1" . "h2") ("sec-1" . "h1"))

This variable provides the translations from the standard to the custom
IDs.

org-html.el provides a template to follow in reorganizing the above code
to do the translation. If you look at org-html-level-start [fn:2],
you'll find the following code

	(setq href (cdr (assoc (concat "sec-" snu) org-export-preferred-target-alist)))
        ...
	(setq href (org-solidify-link-text (or href (concat "sec-" snu))))
	(insert (format "\n<div id=\"outline-container-%s\" class=\"outline-%d%s\">\n<h%d id=\"%s\">%s%s</h%d>\n<div class=\"outline-text-%d\" id=\"text-%s\">\n"
			suffix level (if extra-class (concat " " extra-class) "")
			level href
			extra-targets
			title level level suffix))

In this case, snu is the section number (with periods already replaced
by hyphens).  The local variable href is used to construct the id: the
conventional section number ("sec-1-1" e.g.) is looked up in the alist
and it is either found, in which case href is set to the translation
("h2") or it is not found, in which case href is set to nil. Then the
second setq sets it to either the translated value or, if that is nil,
to the conventional value ("sec-1-1"). That is then used to fill in the
id in the html code.

With this information, do you think you could get a patch together?
Let me know if you have questions.

Nick

Footnotes:

[fn:1] For legal reasons, I cannot fix it myself.

[fn:2] As an aside, note the inconsistency in the function names. Bastien,
       is this worth fixing?

  reply	other threads:[~2011-11-02  5:33 UTC|newest]

Thread overview: 84+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-06-11 22:42 custom IDs not exported Daniel Clemente
2011-06-12  3:12 ` Nick Dokos
2011-06-13 10:04   ` Daniel Clemente
2011-06-13 13:16     ` Nick Dokos
2011-06-16 21:31   ` Daniel Clemente
2011-06-16 21:40     ` Nick Dokos
2011-06-16 22:25       ` Daniel Clemente
2011-06-16 22:47         ` Nick Dokos
2011-06-30 16:18           ` Bastien
2011-11-01 17:01   ` Sten Lindner
2011-11-02  5:33     ` Nick Dokos [this message]
2011-11-03  1:34       ` Bastien
2011-11-03 14:54         ` Nick Dokos
2011-11-03 17:08           ` Jambunathan K
  -- strict thread matches above, loose matches on Subject: below --
2011-08-22  2:12 Not merging org-lparse, org-xhtml & org-odt to the core Jambunathan K
2011-08-22  7:14 ` Vikas Rawal
2011-08-22  7:48 ` Detlef Steuer
2011-08-22 12:23   ` Sebastien Vauban
2011-08-23 23:46     ` Jambunathan K
2011-08-24  7:44       ` Thomas S. Dye
2011-08-24  8:40         ` Jambunathan K
2011-08-24 16:50           ` Thomas S. Dye
2011-08-24 10:10       ` Bastien
2011-08-24 10:50         ` Jambunathan K
     [not found]           ` <CAN_Dec_=WKB+ZxoP3bwPRexaFQnptV6rha8iQi+O=V61Frj3Zw@mail.gmail.com>
2011-08-25 14:45             ` Jambunathan K
2011-08-26  1:34               ` Matthew Sauer
2011-08-24 10:55       ` Štěpán Němec
2011-08-24 11:23         ` Jambunathan K
2011-08-24 11:38         ` Jambunathan K
2011-08-24 12:04         ` Jambunathan K
     [not found]           ` <87obzesvb7.fsf@gnu.org>
2011-08-25  2:12             ` My apprehensions listed (Re: Not merging org-lparse, org-xhtml & org-odt to the core) Jambunathan K
2011-08-25  2:39               ` Jambunathan K
2011-08-25  7:42                 ` Bastien
2011-08-25  7:21               ` Bastien
     [not found]               ` <kjambunathan@gmail.com>
2011-08-25  5:18                 ` Nick Dokos
2011-10-25  3:33                 ` How to include comments on export? org-exp-blocks.el? Nick Dokos
2011-10-25  4:32                   ` Jambunathan K
2011-10-27 16:28                 ` OT: collage of scripts [was: Re: table alignment failed for Asian characters] Nick Dokos
2011-10-28  6:41                   ` Jambunathan K
2011-10-30 17:48                   ` OT: collage of scripts Thomas S. Dye
2011-11-03 18:18                 ` custom IDs not exported Nick Dokos
2011-11-03 18:40                   ` Jambunathan K
2011-11-04  8:41                   ` Sten Lindner
2011-11-04 15:00                     ` Nick Dokos
2011-11-03 18:44                 ` Nick Dokos
2011-11-04  7:11                   ` [OT] FSF, GPL, cedit case (was: custom IDs not exported) Reiner Steib
2011-08-24 14:48         ` Not merging org-lparse, org-xhtml & org-odt to the core Nick Dokos
2011-08-24 23:26           ` Vikas Rawal
2011-08-24 17:30         ` Allen S. Rout
2011-08-24 18:50           ` Štěpán Němec
2011-08-24 19:30             ` Nick Dokos
2011-08-23 23:24   ` Jambunathan K
2011-08-22 18:09 ` Thomas Renkert
2011-08-23 23:49   ` Jambunathan K
2011-08-24  2:44     ` Vikas Rawal
2011-08-24  6:42       ` Jambunathan K
2011-08-24  7:26         ` Jambunathan K
2011-08-24 10:08           ` Bastien
2011-08-24 10:43             ` Jambunathan K
2011-08-24 10:48             ` Jambunathan K
2011-08-24 13:00             ` Christian Moe
2011-08-24 13:49               ` Stefan Vollmar
2011-08-24 14:10               ` Matt Price
2011-08-24 14:22             ` Rasmus
2011-08-24  9:59         ` Bastien
2011-08-24 10:56           ` Jambunathan K
2011-10-24 21:30 How to include comments on export? org-exp-blocks.el? Herbert Sitz
2011-10-24 22:20 ` Herbert Sitz
2011-10-24 22:52   ` Nick Dokos
2011-10-25  2:43     ` Jambunathan K
2011-10-25  1:57 ` Jambunathan K
2011-10-28 22:31   ` [odt] Support for annotations/comments Jambunathan K
2011-10-29  0:20     ` Herbert Sitz
2011-10-29 10:58     ` Bastien
2011-10-29 14:54     ` Torsten Wagner
2012-01-21  5:53 ` How to include comments on export? org-exp-blocks.el? Samuel Wales
2012-01-23 18:01   ` Eric Schulte
2011-10-27 11:33 table alignment failed for Asian characters Torsten Wagner
2011-10-27 11:55 ` Carsten Dominik
2011-10-27 13:26   ` Torsten Wagner
2011-10-27 13:46     ` Carsten Dominik
2011-10-27 14:00     ` Giovanni Ridolfi
2011-10-27 14:02       ` Carsten Dominik
2011-10-27 14:36         ` Jambunathan K

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=9894.1320212032@alphaville.dokosmarshall.org \
    --to=nicholas.dokos@hp.com \
    --cc=emacs-orgmode@gnu.org \
    --cc=s.lindner@stenlindner.de \
    /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).