emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [O] [ox-html] Multiple wraps around sections


From: Rasmus
Subject: Re: [O] [ox-html] Multiple wraps around sections
Date: Sun, 16 Mar 2014 15:02:23 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux)

Hi,

Nicolas Goaziou <address@hidden> writes:

> Hello,
>
> Rasmus <address@hidden> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]