;;; ox-conlang-md.el --- Markdown exporter for Phundrak’s org websites -*- lexical-binding: t -*- ;; Author: Lucien Cartier-Tilet ;; Maintainer: Lucien Cartier-Tilet ;; Version: 0.1.0 ;; Package-Requires: ((emacs "26") (org-mode "9.5")) ;; Homepage: https://labs.phundrak.com/phundrak/org-conlang ;; 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 . ;;; Commentary: ;; This package exports org files to a special Markdown format used by ;; Phundrak’s front-end for org-mode generated websites. ;;; Code: (require 'ox-publish) (require 'ox-md) (org-export-define-derived-backend 'conlang-md 'md :menu-entry '(?C "Conlang exporters" ((?M "To temporary markdown buffer" (lambda (a s v _) (org-conlang-md-export-as-md a s v))) (?m "To markdown file" (lambda (a s v _) (org-conlang-md-export-to-md a s v))) (?o "To markdown and open" (lambda (a s v b) (if a (org-conlang-md-export-to-md t s v b) (org-conlang-md-export-to-md nil s v b)))))) :options-alist '((:conlang-home "CONLANG-HOME" nil nil t) (:conlang-logo "CONLANG-LOGO" nil nil t) (:conlang-dictionary "CONLANG-DICTIONARY" nil nil t)) :translate-alist '((table . org-conlang-md-table))) ;;; Transcode Functions ;; Tables (defun org-conlang-md-table (datum _contents info) "Wrap DATUM in a table component for Vue. DATUM, and INFO are then passed on HTML’s converter." (format "%s
" (org-export-data-with-backend datum 'html info))) ;;; Interactive Functions ;;;###autoload (defun org-conlang-md-export-as-md (&optional async subtreep visible-only) "Export current buffer to a Conlang flavored MD 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 MD Export*\", which will be displayed when `org-export-show-temporary-export-buffer' is non-nil." (interactive) (org-export-to-buffer 'conlang-tsx "*Org Conlang MD Export*" async subtreep visible-only nil nil (lambda () (text-mode)))) ;;;###autoload (defun org-conlang-md-convert-region-to-md () "Assume the current region has org-mode syntax, and convert it to Conlang flavored MD. This can be used in any buffer. For example, you can write an itemized list in org-mode syntax in a MD buffer and use this command to convert it." (interactive) (org-export-replace-region-by 'conlang-md)) ;;;###autoload (defun org-conlang-md-export-to-md (&optional async subtreep visible-only ext-plist) "Export current buffer to a Conlang flavored MD 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 ".md" subtreep))) (org-export-to-file 'conlang-md outfile async subtreep visible-only))) ;;;###autoload (defun org-conlang-md-publish-to-md (plist filename pub-dir) "Publish an org file to Conlang MD. 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-md filename ".md" plist pub-dir)) (provide 'ox-conlang-md) ;;; ox-conlang-md.el ends here