WS host/port injection fixes #14

Igor Shymko 7 years ago
parent c9c9bfb449
commit c415d7e4a7

@ -40,11 +40,10 @@
:prefix "markdown-preview-"
:link '(url-link ""))
(defcustom markdown-preview-host 'local
(defcustom markdown-preview-host "localhost"
"Markdown preview websocket server address."
:group 'markdown-preview
:type '(choice (const :tag "localhost" local)
(string :tag "Custom host")))
:type 'string)
(defcustom markdown-preview-port 7379
"Markdown preview websocket server port."
@ -71,9 +70,9 @@
(defvar markdown-preview--remote-clients nil
"List of `markdown-preview' websocket remote clients.")
(defvar markdown-preview--preview-url
(defvar markdown-preview--preview-template
(concat (file-name-directory load-file-name) "preview.html")
"Location of `markdown-preview' html.")
"Location of `markdown-preview' html template file.")
(defvar markdown-preview--idle-timer nil
"Preview idle timer.")
@ -87,8 +86,13 @@
"Open the markdown preview in the browser."
(let* ((dir-of-buffer-to-preview (file-name-directory (buffer-file-name)))
(preview-file (concat dir-of-buffer-to-preview markdown-preview-file-name)))
(if (not (file-exists-p preview-file))
(copy-file markdown-preview--preview-url preview-file))
(with-temp-file preview-file
(insert-file-contents markdown-preview--preview-template)
(if (search-forward "${WS_HOST}" nil t)
(replace-match markdown-preview-host t))
(if (search-forward "${WS_PORT}" nil t)
(replace-match (format "%s" markdown-preview-port) t))
(browse-url preview-file)))
(defun markdown-preview--stop-websocket-server ()

@ -13,7 +13,7 @@
<script src=""></script>
(function($, undefined) {
var socket = new WebSocket("ws://localhost:7379");
var socket = new WebSocket("ws://${WS_HOST}:${WS_PORT}");
socket.onopen = function() {
console.log("Connection established.");