; -*- emacs-lisp -*- ; The name of file containing table MUST end in lowercase .rst ; First arugment must be absolute path to .rst file containing table ; Output file .HTM saved to same dir where .RST exists (defun self-table-rst-to-html (rst-full-path) "Converts table in `rst-full-path' (abs. path string) to .HTM. Caption taken from first line of table." ; M-x self-table-rst-to-html and enter full path in minibuffer ; emacsclient --eval '(self-table-rst-to-html "/home/user/somewhere/table.rst")' ; or call from IELM, like (self-table-rst-to-html "/path/to/table.rst") (interactive "fEnter buffer or file name (full path): ") (progn (setq default-dir default-directory) ; cd to dir where .RST exists (cd (file-name-directory rst-full-path)) ; strip away /absolute/full/path/ and get file name only (setq rst-file (file-name-nondirectory rst-full-path)) ; replace filename extension from RST to HTM (setq html-file (replace-regexp-in-string "rst$" "htm" rst-file)) (find-file-read-only rst-file) ; C-x C-q to toggle read-only mode (beginning-of-buffer) ; go to beginning of rst file ; extract first line of file as string (setq first-line (buffer-substring-no-properties (line-beginning-position) (line-end-position))) ; delete ..table directive from first line, the rest of line is caption (setq tbl-caption (replace-regexp-in-string ".. table::" "" first-line)) ; Line 6, Column 4 most likely has a table to recognize, lol (goto-line 6 rst-file) (move-to-column 4) (table-recognize) (table-generate-source 'html html-file tbl-caption) (with-current-buffer html-file (progn (beginning-of-buffer) ; add 2 spaces at beginning of each line (^) for whole buffer (replace-regexp "^" " ") (beginning-of-buffer) (insert ".. raw:: html\n\n") (delete-trailing-whitespace) (write-file html-file) (kill-buffer html-file) ) ) (cd default-dir) ; revert back to original directory ) )