From: Raghavendra Nyshadham <raghnysh@gmail.com>
To: "Dr. Volker Zell" <vzell@volkerzell.de>
Cc: emacs-orgmode@gnu.org
Subject: Re: How can I export a table to HTML with header and footers
Date: Mon, 21 Oct 2024 09:10:00 +0530 [thread overview]
Message-ID: <c7f53b3b-78c5-4d72-aac1-fb34896a8127@gmail.com> (raw)
In-Reply-To: <9f759599-e81b-430c-b152-16a6edcf6a37@volkerzell.de>
On 2024-10-20 18:35 +05:30, Dr. Volker Zell wrote:
> how would you do it with the export-filter mechanism of Org mode...
> mayb this comes in handy later
For example, as follows.
#+title: Org Tables to DataTables
#+html_doctype: html5
#+html_head: <script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
#+html_head: <script src="https://cdn.datatables.net/2.1.8/js/dataTables.min.js"></script>
#+html_head: <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/2.1.8/css/dataTables.dataTables.min.css" />
#+html_head: <script>$(document).ready(function () {$('#example').DataTable();});</script>
#+html_head: <script>$(document).ready(function () {$('#another-example').DataTable({lengthMenu: [3, {label: 'All', value: -1}]});});</script>
This is an example table.
#+attr_html: :id example :class cell-border hover compact :width 100%
| Name | Position | Office |
|-------------+------------------+---------------|
| Tiger Nixon | System Architect | Edinburgh |
| Ashton Cox | Technical Author | San Francisco |
------------------------------------------------------------
This is another example table.
#+attr_html: :id another-example :class display
| Author | Title | Shelf |
|-------------------+-------------------------+-------|
| Capote, Truman | In cold blood | D3B |
| Chandler, Raymond | The high window | D3B |
| Dai, Mamang | The legends of Pensam | D3B |
| Desai, Kiran | The inheritance of loss | D3B |
| Farrell, J. G. | The hill station | C1B |
# https://list.orgmode.org/87pprzuc74.fsf@gmx.us/T/#m0d6059de7f7301a19faee0de340d9067276f24cb
#+begin_src emacs-lisp :exports results :results none
;; List of lists of the form `(id footer1 footer2 ...)'.
(setq my-tfoot-specs '(("example" "Name" "Position" "Office")
("another-example" "Author" "Title" "Shelf")))
(defun my-insert-tfoot (tfoot-spec)
"Insert a tfoot as per TFOOT-SPEC in the current buffer."
(goto-char (point-min))
(let* ((id (car tfoot-spec))
(footers (cdr tfoot-spec))
(regex (rx (and (literal (format "id=\"%s\"" id))
(*? anychar)
"</tbody>"))))
(when (re-search-forward regex nil t)
(insert "\n<tfoot><tr><th scope=\"col\" class=\"org-left\">"
(mapconcat #'identity
footers
"</th><th scope=\"col\" class=\"org-left\">")
"</th></tr></tfoot>"))))
(defun my-insert-tfeet (text backend _info)
"Insert tfeet for tables in TEXT in HTML export."
(when (org-export-derived-backend-p backend 'html)
(with-temp-buffer
(insert text)
(mapc #'my-insert-tfoot my-tfoot-specs)
(buffer-string))))
(make-local-variable 'org-export-filter-final-output-functions)
(add-to-list 'org-export-filter-final-output-functions #'my-insert-tfeet)
#+end_src
next prev parent reply other threads:[~2024-10-21 3:40 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-18 20:38 How can I export a table to HTML with header and footers Dr. Volker Zell
2024-10-19 2:40 ` Raghavendra Nyshadham
2024-10-20 13:05 ` Dr. Volker Zell
2024-10-21 3:40 ` Raghavendra Nyshadham [this message]
-- strict thread matches above, loose matches on Subject: below --
2024-10-17 19:14 Dr. Volker Zell
2024-10-18 3:05 ` Raghavendra Nyshadham
2024-10-18 11:35 ` Raghavendra Nyshadham
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=c7f53b3b-78c5-4d72-aac1-fb34896a8127@gmail.com \
--to=raghnysh@gmail.com \
--cc=emacs-orgmode@gnu.org \
--cc=vzell@volkerzell.de \
/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).