8

I'm rewriting my personal home page as an org-file that I export to HTML. In this HTML document, I'd like to include the content of some pregenerated HTML fragments stored in other files (my list of publications as generated by bibtex2html).

Here is an example document:

* My personal home page
** Articles
[insert HTML file with list of articles here]

** Posters
[insert HTML file with list of posters here]

I tried using #+INCLUDE: but that escapes all HTML and hence shows the HTML source in the resulting web page not the rendered HTML fragment.

I also tried the following

#+BEGIN_HTML
#+INCLUDE: "file.html"
#+END_HTML

but the #+INCLUDE directive is not interpreted inside the HTML block.

It seems like there should be an easy way to achieve this but I can't seem to find it.

tmalsburg
  • 2,540
  • 1
  • 14
  • 29
  • First I would look into defining an appropriate `:html-preamble` or a `:html-postamble`, maybe using a `#+SETUPFILE:` to invoke it. Another approach would be to add a `org-export-html-final-hook`, possibly with help from `auto-insert`. – Brian Z Mar 18 '15 at 06:31
  • 1
    Thanks @BrianZ for these suggestions. Unfortunately, `:html-preamble` and `:html-postamble` won't work because I need to insert the HTML fragments in the middle of the file not at the beginning and end. `org-export-html-final-hook` is mentioned in a ChangeLog but I can't find its definition anywhere in source. `apropos` also doesn't know it. I'll post a feature request for a verbatim flag for `#+INCLUDE`. – tmalsburg Mar 18 '15 at 18:00

2 Answers2

10

Cf. the second paragraph in the Org manual on #+INCLUDE you can archive what you want using (Org v9 syntax)

#+INCLUDE: "file.html" export html

For Org v8 you would write #+INCLUDE: "file.html" html.

This inserts is a block and requires org-mode v8.3 or higher.

11.4 Include files

During export, you can include the content of another file. For example, to include your ‘.emacs’ file, you could use:

 #+INCLUDE: "~/.emacs" src emacs-lisp

The first parameter names the the file to include. The optional second and third parameter specify the markup (i.e., ‘example’ or ‘src’), and, if the markup is ‘src’, the language for formatting the contents.

rasmus
  • 2,682
  • 13
  • 20
  • 1
    As I said in the original question, this doesn't work. It escapes all HTML such that I see the HTML source but not the rendered version of the HTML in the output file. – tmalsburg Mar 18 '15 at 17:42
  • Ok, it works but only in org mode version 8.3 (unstable). Perhaps you could add that crucial piece of information to the solution. Thank you. – tmalsburg Mar 18 '15 at 19:37
  • Same prob with latest org from github 8.3.4, I try to include html code from http://www.htmlcommentbox.com/ to enable comments. – barrios Mar 14 '16 at 13:46
3

I'm using org-mode 8.2.10

Although I was expecting #+INCLUDE: "path" html to work, it was formatting the file contents in <p> tags.

To work around this problem, I used an sh code block:

#+BEGIN_SRC sh :exports results :results value html
#!/bin/bash
/bin/cat ~/path/to/file.html
#+END_SRC
wsdookadr
  • 130
  • 4