Client javascript support: fixes #18

pull/23/head v0.7
Igor Shymko 6 years ago
parent 0e2edf3f48
commit 2fc9f06fdf
  1. 2
      .gitignore
  2. 14
      README.md
  3. 13
      markdown-preview-mode.el
  4. 2
      preview.html

2
.gitignore vendored

@ -3,3 +3,5 @@
# Packaging
.cask
.markdown-preview.html

@ -1,6 +1,7 @@
Markdown preview mode
===========================
[![MELPA Stable](http://stable.melpa.org/packages/markdown-preview-mode-badge.svg)](http://stable.melpa.org/#/markdown-preview-mode)
[![MELPA](http://melpa.org/packages/markdown-preview-mode-badge.svg)](http://melpa.org/#/markdown-preview-mode)
@ -34,6 +35,19 @@ Select your browser from `Value menu`. If it's not there, follow [EmacsWiki: Bro
In order to change preview styling, run `M-x customize-option` -> `markdown-preview-style`
and specify a URL to your favourite markdown css file.
## Client javascript
If you'd like to include additional javascript for the preview, add this to your init:
```lisp
(add-to-list 'markdown-preview-javascript "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML")
```
or, to make it async:
```lisp
(add-to-list 'markdown-preview-javascript '("http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML" . async))
```
## Websocket port
Adjustable by `M-x customize-option` -> `markdown-preview-port`.

@ -61,6 +61,9 @@
:group 'markdown-preview
:type 'string)
(defvar markdown-preview-javascript (list "http://code.jquery.com/jquery-1.11.0.min.js")
"List of javascript libs for preview.")
(defvar markdown-preview--websocket-server nil
"`markdown-preview' Websocket server.")
@ -90,6 +93,13 @@
(insert-file-contents markdown-preview--preview-template)
(if (search-forward "${MD_STYLE}" nil t)
(replace-match markdown-preview-style t))
(if (search-forward "${MD_JS}" nil t)
(replace-match
(mapconcat (lambda (x)
(concat "<script src=\"" (if (consp x) (car x) x) "\"" (if (consp x) (format " %s" (cdr x))) "></script>" ))
markdown-preview-javascript
"\n")
t))
(if (search-forward "${WS_HOST}" nil t)
(replace-match markdown-preview-host t))
(if (search-forward "${WS_PORT}" nil t)
@ -182,8 +192,7 @@
(markdown-preview--stop-idle-timer)
(let ((preview-file (concat (file-name-directory (buffer-file-name)) markdown-preview-file-name)))
(if (file-exists-p preview-file)
(delete-file preview-file)))
)
(delete-file preview-file))))
;;;###autoload
(defun markdown-preview-open-browser ()

@ -10,7 +10,7 @@
line-height: 1.2em;
}
</style>
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
${MD_JS}
<script>
(function($, undefined) {
var socket = new WebSocket("ws://${WS_HOST}:${WS_PORT}");

Loading…
Cancel
Save