126 lines
4.1 KiB
EmacsLisp
126 lines
4.1 KiB
EmacsLisp
;;; ox-conlang-json.el --- Export conlang dictionaries to JSON -*- 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-mode "9.5"))
|
||
;; Homepage: homepage
|
||
;; 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:
|
||
|
||
;; commentary
|
||
|
||
;;; Code:
|
||
|
||
(require 'ox-publish)
|
||
(require 'ox-md)
|
||
|
||
(org-export-define-derived-backend 'conlang-json 'md
|
||
:menu-entry
|
||
'(?C 1
|
||
((?J "To temporary JSON buffer"
|
||
(lambda (a s v _) (org-conlang-json-export-as-json a s v)))
|
||
(?j "To JSON file"
|
||
(lambda (a s v _) (org-conlang-json-export-to-json a s v)))
|
||
(?O "To JSON and open"
|
||
(lambda (a s v b)
|
||
(if a (org-conlang-json-export-to-json t s v b)
|
||
(org-conlang-json-export-to-md nil s v b)))))))
|
||
|
||
|
||
;;; Interactive Functions
|
||
|
||
;;;###autoload
|
||
(defun org-conlang-json-export-as-json (&optional async subtreep visible-only)
|
||
"Export current buffer to a Conlang flavored JSON 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 JSON Export*\",
|
||
which will be displayed when
|
||
`org-export-show-temporary-export-buffer' is non-nil."
|
||
(interactive)
|
||
(org-export-to-buffer 'conlang-tsx "*Org Conlang JSON Export*"
|
||
async subtreep visible-only nil nil (lambda () (text-mode))))
|
||
|
||
;;;###autoload
|
||
(defun org-conlang-json-convert-region-to-json ()
|
||
"Assume the current region has org-mode syntax, and convert it to Conlang flavored JSON.
|
||
|
||
This can be used in any buffer. For example, you can write an
|
||
itemized list in org-mode syntax in a JSON buffer and use this
|
||
command to convert it."
|
||
(interactive)
|
||
(org-export-replace-region-by 'conlang-json))
|
||
|
||
|
||
;;;###autoload
|
||
(defun org-conlang-json-export-to-json (&optional async subtreep visible-only ext-plist)
|
||
"Export current buffer to a Conlang flavored JSON 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 ".json" subtreep)))
|
||
(org-export-to-file 'conlang-json outfile async subtreep visible-only)))
|
||
|
||
;;;###autoload
|
||
(defun org-conlang-json-publish-to-json (plist filename pub-dir)
|
||
"Publish an org file to Conlang JSON.
|
||
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-json filename ".json" plist pub-dir))
|
||
|
||
(provide 'ox-conlang-json)
|
||
|
||
;;; ox-conlang-json.el ends here
|