From mboxrd@z Thu Jan 1 00:00:00 1970 From: Rasmus Subject: Re: [ox-html] Multiple wraps around sections Date: Sun, 16 Mar 2014 15:02:23 +0100 Message-ID: <87a9cq5jio.fsf@gmx.us> References: <87eh233unt.fsf@gmx.us> <87pplm5mch.fsf@gmx.us> <87r462qntm.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:33765) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WPBeI-0007JN-V8 for emacs-orgmode@gnu.org; Sun, 16 Mar 2014 10:02:53 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WPBeC-0001TO-P7 for emacs-orgmode@gnu.org; Sun, 16 Mar 2014 10:02:46 -0400 Received: from plane.gmane.org ([80.91.229.3]:44675) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WPBeC-0001TJ-IY for emacs-orgmode@gnu.org; Sun, 16 Mar 2014 10:02:40 -0400 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WPBe9-0007vn-H5 for emacs-orgmode@gnu.org; Sun, 16 Mar 2014 15:02:37 +0100 Received: from 109.201.154.156 ([109.201.154.156]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 16 Mar 2014 15:02:37 +0100 Received: from rasmus by 109.201.154.156 with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Sun, 16 Mar 2014 15:02:37 +0100 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: emacs-orgmode@gnu.org Hi, Nicolas Goaziou writes: > Hello, > > Rasmus writes: > >> The thing is semantics are pretty easy to mess up in HTML-like >> languages compared to, say, LaTeX, since I have to figure out the >> ending point. > > You don't have to figure that out. When using a headline filter, the > first headline relative tag always opens the current headline and the > last one always close it. Of course, this assumes that you can recognize > a top level headline just by looking at its tags. With a filter the endpoint isn't a problem. Only identifying the top-level can be tricky—but you could use tags, assuming they are not varying. >> A short trial suggests that this filter does the job: >> >> #+begin_src html >> (defun rasmus/org-html-headline-add-extra-div (headline backend info) >> "Add an extra :html-container around top level sections." >> (when (org-export-derived-backend-p backend 'html) >> (let ((element >> (plist-get (text-properties-at (next-property-change 0 headline) headline) :parent))) >> (when (= 1 (org-element-property :level element)) >> (save-match-data >> (string-match "\n" headline) >> (concat >> (replace-match >> (format "\n<%s class=\"outline-container-top\">\n" (org-html--container element info)) >> t nil headline) >> (format "\n" (org-html--container element info)))))))) >> #+end_html >> >> The critical part is the next-property-change. I assume that the >> first element is always the headline in question. >> (Do you know if this is generally true, Nicolas?) > > This will not always work. Text properties only exist on raw text. If > a headline do not contain raw text at all, like the following one, > > * =Verbatim= > > you will not get the correct element. That a shame. Is there any other 'easy' way to recover the element representation of, say, a headline? Often it's a lot easier to work with than regexp "hacks". Thanks, Rasmus -- Evidence suggests Snowden used a powerful tool called monospaced fonts