From mboxrd@z Thu Jan 1 00:00:00 1970 From: Olaf Dietsche Subject: Re: Use id property as anchor in the Table of Contents Date: Tue, 13 Sep 2011 12:05:40 +0200 Message-ID: <87hb4geozv.fsf@rat.lan> References: <87zkifx45t.fsf@norang.ca> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([140.186.70.92]:46039) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3PsL-0004LC-4A for emacs-orgmode@gnu.org; Tue, 13 Sep 2011 06:05:58 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1R3PsJ-0008NY-LE for emacs-orgmode@gnu.org; Tue, 13 Sep 2011 06:05:57 -0400 Received: from www85.your-server.de ([213.133.104.85]:38853) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1R3PsJ-0008MP-B8 for emacs-orgmode@gnu.org; Tue, 13 Sep 2011 06:05:55 -0400 In-Reply-To: ("Pere Quintana =?utf-8?Q?Segu=C3=AD=22's?= message of "Thu, 8 Sep 2011 12:53:05 +0200") List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: pquintana@obsebre.es Cc: emacs-orgmode@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Pere Quintana Segu=C3=AD writes: > 2011/9/8 Bernt Hansen >> >> Pere Quintana Segu=C3=AD writes: >> >> > Hi, >> > >> > I'm using Org-mode to publish my website. One of my site's pages has >> > a lot of sections and the number of sections is increasing rapidly. >> > >> > My problem is that the HTML exporter, in the Table of Contents, is >> > using the section numbers as anchors. As the section numbers change >> > with time, I can't get stable links=C2=A0across=C2=A0versions of the d= ocument. >> > >> > As many of the sections (headings) have id properties, I'd like the >> > HTML exporter to use them as anchor for the Table of Contents, when >> > available. >> > >> > Is this possible? I didn't find an answer in the manual. >> > >> > As an example. This is the document I'm working on: >> > http://pere.quintanasegui.com/diccionari-tecnologia.html#sec-2-78 >> > >> > As you can see, section 2.78, called RSS, has the anchor sec-2-78. If >> > the anchor was its id "04E3903E-EAF1-499F-98CD-9E3E4BA0806A", the >> > link would remain the same in the future. I don't mind if the URL is >> > not human readable. Sec-2-78 isn't human readable too. >> >> Hi Pere, >> >> You can manually provide CUSTOM_ID properties. =C2=A0These ids are used = in >> the TOC. >> >> e.g. >> >> * Reminders >> =C2=A0:PROPERTIES: >> =C2=A0:CUSTOM_ID: Reminders >> =C2=A0:END: >> >> for >> >> http://doc.norang.ca/org-mode.html#Reminders > > OK, thanks for the tip. That's an option, but unfortunately it is not > automatic. > >> I don't know if there is a way to use the ID property automatically. > > Unfortunately I don't know lisp, so I can't modify org-mode to provide > this feature :'( > > If anyone is willing, I would be very grateful. You might try this *untested* patch. It is against git master. How did you create ID properties for all entries? Have you exported your org-files to icalendar? And please, don't forget to backup your files! --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=use-id-as-target.diff Content-Description: Use ID property as target diff --git a/lisp/org-html.el b/lisp/org-html.el index fde563b..806bbb9 100644 --- a/lisp/org-html.el +++ b/lisp/org-html.el @@ -1438,8 +1438,9 @@ lang=\"%s\" xml:lang=\"%s\"> (replace-regexp-in-string "\\." "-" (format "sec-%s" snumber))) (setq href (org-solidify-link-text - (or (cdr (assoc href - org-export-preferred-target-alist)) href))) + (or (cdr (assoc href org-export-preferred-target-alist)) + (cdr (assoc href org-export-id-target-alist)) + href))) (push (format (if todo @@ -2413,7 +2414,8 @@ When TITLE is nil, just close all open levels." (assoc target org-export-target-aliases))) (extra-class (and title (org-get-text-property-any 0 'html-container-class title))) (preferred (and target - (cdr (assoc target org-export-preferred-target-alist)))) + (or (cdr (assoc target org-export-preferred-target-alist)) + (cdr (assoc target org-export-id-target-alist))))) (l org-level-max) (num (plist-get opt-plist :section-numbers)) snumber snu href suffix) --=-=-= Regards, Olaf --=-=-=--