151 lines
4.9 KiB
EmacsLisp
151 lines
4.9 KiB
EmacsLisp
|
;;; ox-conlang-tsx.el --- NextJS exporter for org-mode -*- lexical-binding: t -*-
|
|||
|
|
|||
|
;; Author: Lucien Cartier-Tilet <lucien@phundrak.com>
|
|||
|
;; Maintainer: Lucien Cartier-Tilet <lucien@phundrak.com>
|
|||
|
;; Version: 0.1.0
|
|||
|
;; Package-Requires: ((emacs "26.1") (org "9.5"))
|
|||
|
;; Homepage: https://labs.phundrak.com/phundrak/ox-conlang-tsx.el
|
|||
|
;; Keywords: outlines
|
|||
|
|
|||
|
|
|||
|
;; This file is not part of GNU Emacs
|
|||
|
|
|||
|
;; This program is free software: you can redistribute it and/or modify
|
|||
|
;; it under the terms of the GNU General Public License as published by
|
|||
|
;; the Free Software Foundation, either version 3 of the License, or
|
|||
|
;; (at your option) any later version.
|
|||
|
|
|||
|
;; This program is distributed in the hope that it will be useful,
|
|||
|
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|||
|
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|||
|
;; GNU General Public License for more details.
|
|||
|
|
|||
|
;; You should have received a copy of the GNU General Public License
|
|||
|
;; along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|||
|
|
|||
|
|
|||
|
;;; Commentary:
|
|||
|
|
|||
|
;; This package exports org files and buffers to a TSX format meant to
|
|||
|
;; be used by NextJS (https://nextjs.org/).
|
|||
|
|
|||
|
;;; Code:
|
|||
|
|
|||
|
(require 'ox-publish)
|
|||
|
(require 'ox-html)
|
|||
|
|
|||
|
(org-export-define-derived-backend 'conlang-tsx 'html
|
|||
|
:menu-entry
|
|||
|
'(?C "Conlang export"
|
|||
|
((?T "To temporary buffer"
|
|||
|
(lambda (a s v _) (org-conlang-tsx-export-as-tsx a s v)))
|
|||
|
(?t "To TSX file"
|
|||
|
(lambda (a s v _) (org-conlang-tsx-export-to-tsx a s v)))
|
|||
|
(?o "To TSX file and open"
|
|||
|
(lambda (a s v b)
|
|||
|
(if a (org-conlang-tsx-export-to-tsx t s v)
|
|||
|
(org-open-file (org-conlang-tsx-export-to-tsx nil s v)))))))
|
|||
|
|
|||
|
:options-alist
|
|||
|
'((:conlang-logo "LOGO" nil nil t))
|
|||
|
|
|||
|
:translate-alist
|
|||
|
'((link . org-conlang-tsx-link)))
|
|||
|
|
|||
|
|
|||
|
|
|||
|
;; Transcode Functions
|
|||
|
|
|||
|
;; Links
|
|||
|
(defun org-conlang-tsx-link (link desc info)
|
|||
|
"Transcode a LINK object from Org to TSX.
|
|||
|
The link object is described by DESC and INFO."
|
|||
|
(let* ((html (org-html-link link desc info))
|
|||
|
(href-regex "href=\"\\([^\"]+\\)")
|
|||
|
(href (save-match-data
|
|||
|
(string-match href-regex html)
|
|||
|
(substring html (match-beginning 1) (match-end 1))))
|
|||
|
(a-link (replace-regexp-in-string " *href=\"[^\"]+\"" "" html)))
|
|||
|
(format "<Link href=\"%s\">%s</Link>" href a-link)))
|
|||
|
|
|||
|
|
|||
|
|
|||
|
;;; Interactive Functions
|
|||
|
|
|||
|
;;;###autoload
|
|||
|
(defun org-conlang-tsx-export-as-tsx (&optional async subtreep visible-only)
|
|||
|
"Export current buffer to a Conlang flavored TSX buffer.
|
|||
|
|
|||
|
If narrowing is active in the current buffer, only export its
|
|||
|
narrowed part.
|
|||
|
|
|||
|
If a region is active, export that region.
|
|||
|
|
|||
|
A non-nil optional argument ASYNC means the process should happen
|
|||
|
asynchronously. The resulting buffer should be accessible through
|
|||
|
the `org-export-stack' interface.
|
|||
|
|
|||
|
When optional argument SUBTREEP is non-nil, export the sub-tree
|
|||
|
at point, extracting information from the headline properties
|
|||
|
first.
|
|||
|
|
|||
|
When optional argument VISIBLE-ONLY is non-nil, don't export
|
|||
|
contents of hidden elements.
|
|||
|
|
|||
|
Export is done in a buffer named \"*Org Conlang TSX Export*\",
|
|||
|
which will be displayed when
|
|||
|
`org-export-show-temporary-export-buffer' is non-nil."
|
|||
|
(interactive)
|
|||
|
(org-export-to-buffer 'conlang-tsx "*Org Conlang TSX Export*"
|
|||
|
async subtreep visible-only nil nil (lambda () (text-mode))))
|
|||
|
|
|||
|
|
|||
|
;;;###autoload
|
|||
|
(defun org-conlang-tsx-convert-region-to-tsx ()
|
|||
|
"Assume the current region has org-mode syntax, and convert it to Conlang flavored TSX.
|
|||
|
|
|||
|
This can be used in any buffer. For example, you can write an
|
|||
|
itemized list in org-mode syntax in a TSX buffer and use
|
|||
|
this command to convert it."
|
|||
|
(interactive)
|
|||
|
(org-export-replace-region-by 'conlang-tsx))
|
|||
|
|
|||
|
|
|||
|
;;;###autoload
|
|||
|
(defun org-conlang-tsx-export-to-tsx (&optional async subtreep visible-only ext-plist)
|
|||
|
"Export current buffer to a Conlang flavored TSX file.
|
|||
|
|
|||
|
If narrowing is active in the current buffer, only export its
|
|||
|
narrowed part.
|
|||
|
|
|||
|
If a region is active, export that region.
|
|||
|
|
|||
|
A non-nil optional argument ASYNC means the process should happen
|
|||
|
asynchronously. The resulting file should be accessible through
|
|||
|
the `org-export-stack' interface.
|
|||
|
|
|||
|
When optional argument SUBTREEP is non-nil, export the sub-tree
|
|||
|
at point, extracting information from the headline properties
|
|||
|
first.
|
|||
|
|
|||
|
When optional argument VISIBLE-ONLY is non-nil, don't export
|
|||
|
contents of hidden elements.
|
|||
|
|
|||
|
Return output file's name."
|
|||
|
(interactive)
|
|||
|
(let* ((outfile (org-export-output-file-name ".tsx" subtreep)))
|
|||
|
(org-export-to-file 'conlang-tsx outfile async subtreep visible-only)))
|
|||
|
|
|||
|
;;;###autoload
|
|||
|
(defun org-conlang-tsx-publish-to-tsx (plist filename pub-dir)
|
|||
|
"Publish an org file to Conlang TSX.
|
|||
|
FILENAME is the filename of the Org file to be published. PLIST
|
|||
|
is the property list for the given project. PUB-DIR is the
|
|||
|
publishing directory.
|
|||
|
Return output file name."
|
|||
|
(org-publish-org-to 'conlang-tsx filename ".tsx" plist pub-dir))
|
|||
|
|
|||
|
(provide 'ox-conlang-tsx)
|
|||
|
|
|||
|
;;; ox-conlang-tsx.el ends here
|