clarkgrubb / hyperpolyglot

hyperpolyglot.org
Other
473 stars 94 forks source link

Related to org mode #107

Open gnusupport opened 4 years ago

gnusupport commented 4 years ago

Related to org mode and the page here: http://hyperpolyglot.org/lightweight-markup you could update the column related to Org Mode and insert information as following.

  1. Under sandbox you would write "GNU Emacs editor installable from https://www.gnu.org/s/emacs with Org Mode mode like M-x org-mode. Isn't it sandbox for Org mode?

  2. Under command line tool well, I use Org Mode under command line tool all the time. It is also used to prepare web site pages. The database containts org mode text inside, pages are extracted and on the fly converted to HTML files. There are some references to using org mode on a command line, even those may not be straight forward:

    1. https://stackoverflow.com/questions/46295511/how-to-run-org-mode-commands-from-shell

Myself, I am using a complicated version which uses the below common lisp script (CLISP) and exports Org Mode on the fly to markdown, and them converts markdown to HTML. That is my preference. But I will write for you how to do it with Emacs only

#!/home/data1/protected/bin/lisp
(defparameter memdir "/dev/shm/")
(defparameter tmp-file "rcd-wrs-XXXXXX")
(defparameter tmp-org (format nil "~a~a.org" memdir tmp-file))
(defparameter tmp-md (format nil "~a~a.md" memdir tmp-file))
;;(delete-file tmp-org)
;;(delete-file tmp-md)
(load "/home/data1/protected/Programming/git/RCDBusiness/lib/lisp/streamtools.lisp")
;; (require "syscalls")

(defparameter org-autoloads.el
  (concatenate
   'string
   (namestring (car (directory "/home/data1/protected/.emacs.d/elpa/org-20??????/")))
   "org-autoloads.el"))

(defun main ()
  (let ((input '())
        (output '()))
    (with-open-file (out tmp-org :direction :output :external-format "utf-8" :if-exists :supersede)
      (loop for line = (read-line *standard-input* nil nil)
         while line do
           (write-line line out)))
    (shell (format nil "emacs -Q -l ~a \"~a\" --batch -f org-mode -f org-md-export-to-markdown --kill" org-autoloads.el tmp-org))
    (setf output
            (with-open-file (stream tmp-md :direction :input :external-format "utf-8")
              (loop for line = (read-line stream nil nil)
                 while line collect line)))
    (setf output (format nil "~{~a~^~%~}" output))
    (setf output (slurp-stream-io-command "/usr/local/bin/markdown -F 0x4" output))
    (princ output))
  (exit))

(main)
gnusupport commented 4 years ago

I have found solution on how to accept STDIN and export ORG html either full or only within the content. This is similar to invocation of markdown on command line. I can just think, that to speed up, one could use emacsclient with --eval

#!/usr/local/bin/emacs --script
;;;; Good idea from https://joelmccracken.github.io/entries/reading-writing-data-in-emacs-batch-via-stdin-stdout/

(defun org-stding-to-html-full ()
  "Reads org text body from STDIN and export full HTML"
  (let ((org-document-content "")
        this-read)
    (while (setq this-read (ignore-errors
                             (read-from-minibuffer "")))
      (setq org-document-content (concat org-document-content "\n" this-read)))

    (with-temp-buffer
      (org-mode)
      (insert org-document-content)
      (org-html-export-as-html)
      (princ (buffer-string)))))

(defun org-stding-to-html-body-only ()
  "Reads org text body from STDIN and export full only body HTML"
  (let ((org-document-content "")
        this-read)
    (while (setq this-read (ignore-errors
                             (read-from-minibuffer "")))
      (setq org-document-content (concat org-document-content "\n" this-read)))

    (with-temp-buffer
      (org-mode)
      (insert org-document-content)
      (org-html-export-as-html nil nil nil t)
      (princ (buffer-string)))))

(org-stding-to-html-body-only)