[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How can I export a table to HTML with header and footers
From: |
Raghavendra Nyshadham |
Subject: |
Re: How can I export a table to HTML with header and footers |
Date: |
Mon, 21 Oct 2024 09:10:00 +0530 |
User-agent: |
Mozilla Thunderbird |
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