all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Jean Louis <bugs@gnu.support>
To: Gottfried <gottfried@posteo.de>
Cc: help-gnu-emacs@gnu.org
Subject: Re: pandoc-mode /Asciidoc
Date: Thu, 23 Feb 2023 20:48:16 +0300	[thread overview]
Message-ID: <Y/em4NNU8qNMRzwa@protected.localdomain> (raw)
In-Reply-To: <8ae47be3-a333-4b7b-bf0d-82e7a53f77cf@posteo.de>

This is what you should put:

(defun string-to-file-force (string file)
  "Prints string into file, matters not if file exists. Return FILE as file
name."
  (with-temp-file file
    (insert string))
  file)

(defun rcd-command-output-from-input (program input &rest args)
  "Return output string from PROGRAM with given INPUT string and optional
ARGS."
  (let* ((output (with-temp-buffer
                   (insert input)
                   (apply #'call-process-region nil nil program t '(t nil) nil args)
                   (buffer-string))))
    output))

(defun rcd-asciidoctor (string &rest args)
  "Return HTML by using Asciidoctor markup STRING."
  (let ((asciidoctor (executable-find "asciidoctor")))
    (apply 'rcd-command-output-from-input "asciidoctor" string "-" args)))

(defun rcd-asciidoctor-preview ()
  "Preview asciidoctor"
  (interactive)
  (let ((asciidoctor (executable-find "asciidoctor")))
    (when asciidoctor
      (let* ((output (buffer-string))
             (output (rcd-asciidoctor output))
             (file (string-to-file-force output "asciidoctor-preview.html")))
        (browse-url file)))))

(require 'adoc-mode)
(define-key adoc-mode-map (kbd "C-c a") #'rcd-asciidoctor-preview)

;;Asciidoctor refresh output quickly

(defun rcd-asciidoctor-preview-buffer-as-html ()
  "Convert asciidoctor to file `/tmp/my.html'"
  (let* ((asciidoc (buffer-string))
         (tmp-file "/tmp/my.html")
         (html (rcd-asciidoctor asciidoc)))
    (with-temp-file tmp-file
      (insert html))))

;; Though I would not recommend putting this in init.el as that is
;; too many times preview. It is better turning on and off the timer
;; function only when you need it.
(run-with-timer 1 3 #'rcd-asciidoctor-preview-buffer-as-html)

(defun rcd-markdown (text &rest args)
  "Markdown processing"
  (let ((markdown (executable-find "markdown")))
    (cond (markdown
           (cond (text
                  (apply 'rcd-command-output-from-input markdown (append (list text) args)))
                 (t ""))
           (t (user-error "Command `markdown' not available"))))))

(defun rcd-markdown-preview ()
  "Preview Markdown."
  (interactive)
  (let* ((output (rcd-markdown (buffer-string)))
         (file (concat (buffer-file-name) "-MD.html")))
    (with-temp-file file (insert output))
    (browse-url file)))

;;(define-key KEYMAP KEY DEF &optional REMOVE)
(require 'markdown-mode)
(define-key markdown-mode-map (kbd "C-c a") #'rcd-markdown-preview)

-- 
Jean

Take action in Free Software Foundation campaigns:
https://www.fsf.org/campaigns

In support of Richard M. Stallman
https://stallmansupport.org/



  reply	other threads:[~2023-02-23 17:48 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-13 14:26 pandoc-mode Gottfried
2023-02-13 14:40 ` pandoc-mode Jean Louis
2023-02-22 14:26   ` pandoc-mode /Asciidoc Gottfried
2023-02-23 11:33     ` Jean Louis
2023-02-23 11:34     ` Jean Louis
2023-02-23 14:13       ` Gottfried
2023-02-23 17:48         ` Jean Louis [this message]
2023-02-23 20:17         ` Jean Louis
2023-02-25 12:24           ` Gottfried
2023-02-26  1:36             ` David Masterson
2023-02-26 10:31               ` Gottfried
2023-02-26 10:53                 ` Stephen Berman
2023-02-26 16:06                   ` Gottfried
2023-02-26 16:50                     ` Jean Louis
2023-02-27  8:41                       ` Gottfried
2023-03-01  3:24                       ` David Masterson
2023-03-02 18:06                       ` Gottfried
2023-03-02 18:51                         ` Gottfried
2023-03-13  4:17                           ` Jean Louis
2023-03-15 15:42                             ` Gottfried
2023-03-15 16:37                               ` Emanuel Berg
2023-02-14 18:35 ` pandoc-mode Bruno Barbier
2023-02-14 19:52   ` pandoc-mode Joost Kremers
2023-02-22 14:13     ` pandoc-mode Gottfried

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Y/em4NNU8qNMRzwa@protected.localdomain \
    --to=bugs@gnu.support \
    --cc=gottfried@posteo.de \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.