~daviwil/ox-gemini-clean

a6f7eab2970a1f5b1b31bd3e6ab95396db98bafc — David Wilson 3 years ago
Basic working implementation
2 files changed, 76 insertions(+), 0 deletions(-)

A README.md
A ox-gemini-clean.el
A  => README.md +13 -0
@@ 1,13 @@
# Org Mode Gemini Export Backend

This is an attempt to live-code an Org Mode export backend for Gemini's gemtext specification.

The goal is to produce clean Gemini-friendly output from Org Mode files by writing an exporter backend from scratch for this purpose.

Once it is finished, I'll publish it on MELPA!

### Videos

This package was developed live as part of the following streams:

- [System Crafters Life! - April 23, 2021](https://youtu.be/E-g3Ls1GRz4)

A  => ox-gemini-clean.el +63 -0
@@ 1,63 @@
;; -*- lexical-binding: t; -*-

(defun org-gemini-template (contents info)
  (concat
   "# " (org-export-data (plist-get info :title) info) "\n\n"
   contents))

(defun org-gemini-section (_section contents _info)
  contents)

(defun org-gemini-paragraph (paragraph contents info)
  ;; TODO: Annotate links with indexes that refer to the link list
  (concat
   contents
   "\n"
   (mapconcat (lambda (item)
                (if (and (listp item)
                         (equal (car item) 'link))
                    (format "=> %s %s\n"
                            (org-element-property :raw-link item)
                            (org-export-data (org-element-contents item) info))
                  ""))
              paragraph
              "")))

(defun org-gemini-code (code contents _info)
  (format "`%s`" (org-element-property :value code)))

(defun org-gemini-verbatim (verbatim contents _info)
  (format "`%s`" (org-element-property :value verbatim)))

(defun org-gemini-headline (headline contents info)
  (let ((level (+ 1 (org-export-get-relative-level headline info))))
    (concat
     (make-string (min level 3) ?#)
     " "
     (org-export-data (org-element-property :title headline) info)
     "\n\n"
     (org-export-data contents info))))

(org-export-define-backend 'gemini-clean
  '((template . org-gemini-template)
    (section . org-gemini-section)
    (paragraph . org-gemini-paragraph)
    (code . org-gemini-code)
    (verbatim . org-gemini-verbatim)
    ;; (link . dw/org-html-link)
    (headline . org-gemini-headline)))

(defun org-gemini-publish-to-gemini (plist filename pub-dir)
  (org-publish-org-to 'gemini-clean filename ".gmi" plist pub-dir))

;; (setq org-publish-project-alist
;;       (list
;;        (list "systemcrafters:gemini"
;;              :recursive t
;;              :base-extension "org"
;;              :base-directory "./content"
;;              :publishing-function '(org-gemini-publish-to-gemini)
;;              :publishing-directory "./gemini"
;;              :with-timestamps t)))

;; (org-publish-all t)