emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [ox-html] Multiple wraps around sections
@ 2014-03-15 23:32 Rasmus
  2014-03-16 10:01 ` Nicolas Goaziou
       [not found] ` <m2wqfuy2yf.fsf@uio.no>
  0 siblings, 2 replies; 6+ messages in thread
From: Rasmus @ 2014-03-15 23:32 UTC (permalink / raw)
  To: emacs-orgmode

Hi,

I'm trying to make a personal website with ox-html and ox-publish.  In
terms of output I am looking for something like:

#+begin_src html
<section id="CUSTOM_ID" class="HTML_CONTAINER_CLASS">
  <div class="indent-wrapper">
    <h2>Section title</h2>
    my text
  </div>
</section>
#+end_src

This seems to be how these fancy pages get colored boxes and indented
text¹. . .

I can almost get it with Org now using org-html-container-element
(:html-container in ox-html).

#+begin_src html
<section id="outline-container-CUSTOM_ID" class="outline-2 HTML_CONTAINER_CLASS">
  <h2 id="CUSTOM_ID"><a id="sec-2"></a>Section title</h2>
  <div class="outline-text-2" id="text-CUSTOM_ID">
    my text
  </div>
</section>
#+end_src

Is there any way I can easily get an /extra/ container around my
sections?  Or should I try to hack together a patch for multiple
containers myself?

Note, my knowledge of HTML(5) & CSS is very limited so maybe I'm
overlooking something obvious here.

Thanks,
Rasmus

Footnotes: 
¹   http://usablica.github.io/progress.js/, http://emacs.sexy/

-- 
I feel emotional landscapes they puzzle me

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ox-html] Multiple wraps around sections
  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>
  1 sibling, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2014-03-16 10:01 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Hello,

Rasmus <rasmus@gmx.us> writes:

> I'm trying to make a personal website with ox-html and ox-publish.  In
> terms of output I am looking for something like:
>
> #+begin_src html
> <section id="CUSTOM_ID" class="HTML_CONTAINER_CLASS">
>   <div class="indent-wrapper">
>     <h2>Section title</h2>
>     my text
>   </div>
> </section>
> #+end_src
>
> This seems to be how these fancy pages get colored boxes and indented
> text¹. . .
>
> I can almost get it with Org now using org-html-container-element
> (:html-container in ox-html).
>
> #+begin_src html
> <section id="outline-container-CUSTOM_ID" class="outline-2 HTML_CONTAINER_CLASS">
>   <h2 id="CUSTOM_ID"><a id="sec-2"></a>Section title</h2>
>   <div class="outline-text-2" id="text-CUSTOM_ID">
>     my text
>   </div>
> </section>
> #+end_src
>
> Is there any way I can easily get an /extra/ container around my
> sections?  Or should I try to hack together a patch for multiple
> containers myself?

Did you try using a filter (e.g., `org-export-filter-headline-functions')?


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ox-html] Multiple wraps around sections
       [not found] ` <m2wqfuy2yf.fsf@uio.no>
@ 2014-03-16 13:01   ` Rasmus
  2014-03-16 13:23     ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus @ 2014-03-16 13:01 UTC (permalink / raw)
  To: mail; +Cc: n.goaziou, emacs-orgmode

Hi Christian and Nicolas,

Christian Moe <mail@christianmoe.com> writes:

> Rasmus writes:
>
>> Is there any way I can easily get an /extra/ container around my
>> sections?
>
> You would probably want to create an export filter for sections. See the
> manual, Export > Advanced configuration > Filters.

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.  Thus, it'd obviously prefer not touch it.  Hence the
question.

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?)

>> Note, my knowledge of HTML(5) & CSS is very limited so maybe I'm
>> overlooking something obvious here.
>
> I don't think you're overlooking any way to add a container. 

Thanks, I also couldn't find anything else, examining ox-html.el.

> But since the exporter already provides a fair set of containers, it is
> possible that you are overlooking a way to accomplish whatever you want
> to do with the existing output and CSS.

Quite possibly.  I did HTML back in gymnasium, but I really haven't
followed the "trends" in this area.

—Rasmus

-- 
Evidence suggests Snowden used a powerful tool called monospaced fonts

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ox-html] Multiple wraps around sections
  2014-03-16 13:01   ` Rasmus
@ 2014-03-16 13:23     ` Nicolas Goaziou
  2014-03-16 14:02       ` Rasmus
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2014-03-16 13:23 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode, mail

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.

> 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.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ox-html] Multiple wraps around sections
  2014-03-16 13:23     ` Nicolas Goaziou
@ 2014-03-16 14:02       ` Rasmus
  2014-03-16 14:21         ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Rasmus @ 2014-03-16 14:02 UTC (permalink / raw)
  To: emacs-orgmode

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

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [ox-html] Multiple wraps around sections
  2014-03-16 14:02       ` Rasmus
@ 2014-03-16 14:21         ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2014-03-16 14:21 UTC (permalink / raw)
  To: Rasmus; +Cc: emacs-orgmode

Rasmus <rasmus@gmx.us> writes:

> 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.

You can also use a hook function that will mark first level headlines
with some special string before export. Within the filter, you will
recognize that string and remove it.

> 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".

Well, the whole point of filters is to be able to work from a string
instead of the full parse tree.

For the latter, you can use a parse tree filter that will alter the tree
in any way you like. For that task, some useful functions are
`org-element-extract-element', `org-element-insert-before' and
`org-element-adopt-elements'.


Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2014-03-16 14:21 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2014-03-16 14:21         ` Nicolas Goaziou

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).