emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Rasmus <rasmus@gmx.us>
To: emacs-orgmode@gnu.org
Subject: Re: [ox-html] Multiple wraps around sections
Date: Sun, 16 Mar 2014 15:02:23 +0100	[thread overview]
Message-ID: <87a9cq5jio.fsf@gmx.us> (raw)
In-Reply-To: 87r462qntm.fsf@gmail.com

Hi,

Nicolas Goaziou <n.goaziou@gmail.com> writes:

> Hello,
>
> Rasmus <rasmus@gmx.us> 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 <h·> 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 "</%s>\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

  reply	other threads:[~2014-03-16 14:02 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-03-15 23:32 [ox-html] Multiple wraps around sections Rasmus
2014-03-16 10:01 ` Nicolas Goaziou
     [not found] ` <m2wqfuy2yf.fsf@uio.no>
2014-03-16 13:01   ` Rasmus
2014-03-16 13:23     ` Nicolas Goaziou
2014-03-16 14:02       ` Rasmus [this message]
2014-03-16 14:21         ` 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=87a9cq5jio.fsf@gmx.us \
    --to=rasmus@gmx.us \
    --cc=emacs-orgmode@gnu.org \
    /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).