preview port and style customization

This commit is contained in:
Igor Shymko 2014-09-15 22:39:14 +03:00
parent 2b6034b5c1
commit bbc80511e2
2 changed files with 23 additions and 7 deletions

View File

@ -34,4 +34,11 @@ Select your browser from `Value menu`. If it's not there, follow [EmacsWiki: Bro
[Solarized-dark](http://thomasf.github.io/solarized-css/)
In order to change preview styling, run `M-x customize-option` -> `markdown-preview-style`
and specify your favourite markdonw css URI.
## Websocket port
Adjustable by `M-x customize-option` -> `markdown-preview-port`.
## El-get recipe included

View File

@ -27,17 +27,26 @@
(require 'websocket)
(require 'markdown-mode)
(defgroup markdown-preview-mode nil
(defgroup markdown-preview nil
"Markdown preview mode"
:group 'text
:prefix "mdpm:")
:prefix "mdpm:"
:link '(url-link "https://github.com/ancane/markdown-preview-mode"))
(defcustom markdown-preview-port 7379
"Markdown preview websocket server port"
:group 'markdown-preview
:type 'integer)
(defcustom markdown-preview-style "http://thomasf.github.io/solarized-css/solarized-dark.min.css"
"Markdown preview style URI"
:group 'markdown-preview
:type 'string)
(defvar mdpm:websocket-port 7379)
(defvar mdpm:websocket-server nil)
(defvar mdpm:local-client nil)
(defvar mdpm:remote-clients nil)
(defvar mdpm:preview-url (concat (file-name-directory load-file-name) "preview.html"))
(defvar mdpm:style "http://thomasf.github.io/solarized-css/solarized-dark.min.css")
(defun mdpm:open-browser-preview ()
(browse-url mdpm:preview-url))
@ -58,7 +67,7 @@
(when (not mdpm:websocket-server)
(setq mdpm:websocket-server
(websocket-server
mdpm:websocket-port
markdown-preview-port
:on-message (lambda (websocket frame)
(mapc (lambda (ws)
(websocket-send-text ws
@ -76,7 +85,7 @@
(when (not mdpm:local-client)
(setq mdpm:local-client
(websocket-open
(format "ws://localhost:%d" mdpm:websocket-port)
(format "ws://localhost:%d" markdown-preview-port)
:on-error (lambda (ws type err)
(message "error connecting"))
:on-close (lambda (websocket)
@ -93,7 +102,7 @@
(concat
"<div>"
"<span id='style'>"
mdpm:style
markdown-preview-style
"</span>"
"<div id='content'>"
(buffer-substring-no-properties (point-min) (point-max))