├── HTML as Markdown in Emacs.applescript ├── README.md └── markdown-mode+.el /HTML as Markdown in Emacs.applescript: -------------------------------------------------------------------------------- 1 | on mktemp() 2 | return do shell script "mktemp -t md" 3 | end mktemp 4 | 5 | try 6 | -- set appname to name of (info for (path to frontmost application)) 7 | set tmpfile to mktemp() & ".md" 8 | set mods to {control down, option down, shift down, command down} 9 | tell application "System Events" 10 | keystroke "a" using {command down} 11 | delay 0.1 12 | keystroke "c" using {command down} 13 | delay 0.1 14 | set txt to Unicode text of (the clipboard as record) 15 | end tell 16 | 17 | do shell script "pbpaste | ~/.cabal/bin/pandoc --from=html --to=markdown > " & quoted form of tmpfile 18 | 19 | do shell script "echo " & (quoted form of (path to frontmost application as text)) & " > " & tmpfile & ".meta" 20 | 21 | -- do shell script "emacsclient --eval '(setq markdown-paste-app: " & (path to frontmost application as text) & ")'" 22 | delay 0.1 23 | tell application "Emacs" 24 | open (POSIX file tmpfile as string) 25 | activate 26 | end tell 27 | end try -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # markdown-mode+ 2 | 3 | **DEPRECATED:** This package is not currently used by the maintainer and has an [active issue](https://github.com/milkypostman/markdown-mode-plus/issues/4) with undefined functions, so it seems reasonable to deprecated the package and remove it from MELPA. If the package gets updates in the future it will get un-deprecated and put back in to circulation. 4 | 5 | Additional functions for Emacs [markdown-mode]. Default support for 6 | [pandoc]. Much of the functionality is tailored to OS X, with the end 7 | goal to extend `markdown-mode` in useful ways for all platforms. 8 | 9 | 10 | ## Functions 11 | 12 | `markdown-cleanup-list-numbers` 13 | : Renumber the numbered lists in the current Markdown document. 14 | 15 | `markdown-export-latex` 16 | : Export the document to [LaTeX]. 17 | 18 | `markdown-copy-html` 19 | : Render the Markdown as HTML, using the program specified by 20 | `markdown-command`, and copy it by piping it to `markdown-copy-command`. 21 | 22 | `markdown-copy-paste-html` **OS X Only** 23 | : By default, generates HTML, copies to clipboard, changes to 24 | previous application, and pastes. If a file with the current 25 | buffer name followed by `.meta` exists, the command reads the 26 | first line and changes to that application. Allows use of the 27 | `HTML as Markdown in Emacs.applescript` which automatically 28 | generates this *meta* file. 29 | 30 | `markdown-copy-rtf` 31 | : Generates RTF from Markdown using the `markdown-rtf-command` and 32 | copies to the clipboard. 33 | 34 | ## Variables 35 | 36 | `markdown-copy-command` 37 | : Command that takes data as input and copies it to the clipboard. 38 | 39 | `markdown-rtf-command` 40 | : Command to generate RTF from Markdown 41 | 42 | `markdown-latex-export-command` 43 | : Command to export Markdown to LaTeX, destination filename is 44 | appended and is either the basename -- without extension -- with 45 | `.tex` appended. 46 | 47 | 48 | 49 | markdown-mode: http://jblevins.org/projects/markdown-mode/ 50 | pandoc: http://johnmacfarlane.net/pandoc/ 51 | -------------------------------------------------------------------------------- /markdown-mode+.el: -------------------------------------------------------------------------------- 1 | ;;; markdown-mode+.el --- extra functions for markdown-mode 2 | 3 | ;; Copyright (c) 2011 Donald Ephraim Curtis 4 | 5 | ;; Author: Donald Ephraim Curtis 6 | ;; URL: http://github.com/milkypostman/markdown-mode-plus 7 | ;; Version: 0.8 8 | ;; Keywords: markdown, latex, osx, rtf 9 | ;; Package-Requires: ((markdown-mode "20111229")) 10 | 11 | ;;; License: 12 | 13 | ;; This program is free software; you can redistribute it and/or 14 | ;; modify it under the terms of the GNU General Public License 15 | ;; as published by the Free Software Foundation; either version 3 16 | ;; of the License, or (at your option) any later version. 17 | ;; 18 | ;; This program is distributed in the hope that it will be useful, 19 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | ;; GNU General Public License for more details. 22 | ;; 23 | ;; You should have received a copy of the GNU General Public License 24 | ;; along with GNU Emacs; see the file COPYING. If not, write to the 25 | ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 26 | ;; Boston, MA 02110-1301, USA. 27 | 28 | ;;; Code: 29 | 30 | (defcustom markdown-rtf-command "pandoc -s -t rtf" 31 | "Command to generate RTF from Markdown" 32 | :group 'markdown 33 | :type 'string) 34 | 35 | (defcustom markdown-copy-command "pbcopy" 36 | "Command to copy directory to the clipboard and interpret MIME type." 37 | :group 'markdown 38 | :type 'string) 39 | 40 | (defcustom markdown-latex-command "pandoc -s --mathjax -t latex" 41 | "Command to output LaTeX from Markdown." 42 | :group 'markdown 43 | :type 'string) 44 | 45 | (defcustom markdown-pandoc-pdf-command "pandoc -s --mathjax" 46 | "Command to output LaTeX from Markdown." 47 | :group 'markdown 48 | :type 'string) 49 | 50 | ;;;###autoload 51 | (defun markdown-export-latex () 52 | "Output the Markdown file as LaTeX." 53 | (interactive) 54 | (let ((output-file (markdown-export-file-name ".tex"))) 55 | (when output-file 56 | (let ((output-buffer-name (buffer-name 57 | (find-file-noselect output-file nil t))) 58 | (markdown-command markdown-latex-command)) 59 | (markdown output-buffer-name) 60 | (with-current-buffer output-buffer-name 61 | (save-buffer) 62 | (kill-buffer output-buffer-name)) 63 | output-file)))) 64 | 65 | 66 | ;;;###autoload 67 | (defun markdown-export-pdf () 68 | "Output the Markdown file as LaTeX." 69 | (interactive) 70 | (save-window-excursion 71 | (markdown-export-latex) 72 | (let ((output-buffer-name (concat "*" (markdown-export-file-name "") "*"))) 73 | (shell-command (concat "pdflatex" " --synctex=1 -interaction=nonstopmode " 74 | (shell-quote-argument 75 | (markdown-export-file-name ".tex"))) 76 | output-buffer-name)))) 77 | 78 | 79 | ;;;###autoload 80 | (defun markdown-export-pandoc-pdf () 81 | "Output the Markdown file as LaTeX." 82 | (interactive) 83 | (let ((output-file (markdown-export-file-name ".pdf"))) 84 | (when output-file 85 | (let ((output-buffer-name (buffer-name 86 | (find-file-noselect output-file nil t))) 87 | (markdown-command (concat markdown-pandoc-pdf-command 88 | " -o " output-file))) 89 | (markdown output-buffer-name) 90 | output-file)))) 91 | 92 | 93 | ;;;###autoload 94 | (defun markdown-code-copy (begin end) 95 | "Copy region from BEGIN to END to the clipboard with four spaces indenteded on each line. 96 | 97 | Taken from 98 | http://stackoverflow.com/questions/3519244/emacs-command-to-indent-code-by-4-spaces-to-format-for-paste-into-stackoverflow." 99 | (interactive "r") 100 | (let ((buffer (current-buffer))) 101 | (with-temp-buffer 102 | (insert-buffer-substring-no-properties buffer begin end) 103 | (indent-rigidly (point-min) (point-max) 4) 104 | (clipboard-kill-ring-save (point-min) (point-max))))) 105 | 106 | ;;;###autoload 107 | (defun markdown-copy-rtf () 108 | "Render markdown and copy as RTF." 109 | (interactive) 110 | (save-window-excursion 111 | (let ((markdown-command markdown-rtf-command)) 112 | (markdown) 113 | (with-current-buffer markdown-output-buffer-name 114 | (shell-command-on-region 115 | (point-min) 116 | (point-max) 117 | markdown-copy-command))))) 118 | 119 | ;;;###autoload 120 | (defun markdown-copy-paste-html () 121 | "Process file with multimarkdown, copy it to the clipboard, and paste in safari's selected textarea." 122 | (interactive) 123 | (markdown-copy-html) 124 | (do-applescript 125 | (concat 126 | (let ((metafn (concat (buffer-file-name) ".meta"))) 127 | (cond 128 | ((and (buffer-file-name) (file-exists-p metafn)) 129 | (save-buffer) 130 | (with-temp-buffer 131 | (insert-file-contents-literally metafn) 132 | (goto-char (point-min)) 133 | (do-applescript 134 | (concat 135 | "tell application \"" 136 | (buffer-substring-no-properties (point-at-bol) (point-at-eol)) 137 | "\" to activate")))) 138 | (t 139 | " 140 | tell application \"System Events\" to keystroke tab using {command down} 141 | delay 0.2" 142 | ))) 143 | " 144 | tell application \"System Events\" to keystroke \"a\" using {command down} 145 | tell application \"System Events\" to keystroke \"v\" using {command down}"))) 146 | 147 | 148 | (provide 'markdown-mode+) 149 | 150 | ;;; markdown-mode+.el ends here 151 | --------------------------------------------------------------------------------