8 Commits
v0.6 ... v0.7

Author SHA1 Message Date
Igor Shymko
2fc9f06fdf Client javascript support: fixes #18 2016-12-05 15:40:52 +02:00
Igor Shymko
0e2edf3f48 Version bump 2016-12-05 13:38:21 +02:00
Igor Shymko
c197aa51cc Do not reload css on every message 2016-12-05 13:36:57 +02:00
Igor Shymko
c415d7e4a7 WS host/port injection fixes #14 2016-12-05 13:19:43 +02:00
Igor Shymko
c9c9bfb449 Merge pull request #19 from z4139jq/patch-1
Fix issue #15
2016-11-22 21:02:57 +02:00
Zenkie Zhu
9c10d6fb08 Fix issue #15
So we can use sindresorhus/github-markdown-css
2016-11-22 19:15:00 +08:00
Igor Shymko
a5de48c4dc Merge pull request #16 from chwarr/host-config
Default to 'local for markdown-preview-host
2016-10-04 15:13:30 +03:00
Christopher Warrington
dc3b2dfba7 Default to 'local for markdown-preview-host
* Prefer to use 'local over "127.0.0.1" to indicate localhost, as the
underlying functions use 'local for localhost.
* Adjust type to be a union of 'local and a string.
2016-10-03 22:04:06 -07:00
4 changed files with 44 additions and 22 deletions

2
.gitignore vendored
View File

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

View File

@@ -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`.

View File

@@ -5,7 +5,7 @@
;; Author: Igor Shymko <igor.shimko@gmail.com>
;; URL: https://github.com/ancane/markdown-preview-mode
;; Keywords: markdown, preview
;; Version: 0.6
;; Version: 0.7
;; Package-Requires: ((websocket "1.6") (markdown-mode "2.1") (cl-lib "0.5"))
;; This file is not part of GNU Emacs.
@@ -40,7 +40,7 @@
:prefix "markdown-preview-"
:link '(url-link "https://github.com/ancane/markdown-preview-mode"))
(defcustom markdown-preview-host "127.0.0.1"
(defcustom markdown-preview-host "localhost"
"Markdown preview websocket server address."
:group 'markdown-preview
:type 'string)
@@ -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.")
@@ -70,9 +73,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.")
@@ -86,8 +89,22 @@
"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 "${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)
(replace-match (format "%s" markdown-preview-port) t))
(buffer-string))
(browse-url preview-file)))
(defun markdown-preview--stop-websocket-server ()
@@ -152,9 +169,6 @@
(websocket-send-text websocket
(concat
"<div>"
"<span id='style'>"
markdown-preview-style
"</span>"
"<span id='position-percentage'>"
mark-position-percent
"</span>"
@@ -178,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 ()

View File

@@ -4,16 +4,16 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui">
<title>Markdown preview</title>
<link href="http://thomasf.github.io/solarized-css/solarized-dark.min.css" rel="stylesheet"></link>
<link href="${MD_STYLE}" rel="stylesheet"></link>
<style>
code.json {
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://localhost:7379");
var socket = new WebSocket("ws://${WS_HOST}:${WS_PORT}");
socket.onopen = function() {
console.log("Connection established.");
};
@@ -26,7 +26,6 @@
console.log('Code: ' + event.code + ' reason: ' + event.reason);
};
socket.onmessage = function(event) {
loadCSS($(event.data).find("#style").text());
$("#markdown-body").html($(event.data).find("#content").html());
var scroll = $(document).height() * ($(event.data).find("#position-percentage").html() / 100);
$("html, body").animate({ scrollTop: scroll }, 600);
@@ -34,17 +33,11 @@
socket.onerror = function(error) {
alert("Error: " + error.message);
};
loadCSS = function(href) {
var cssLink = $("<link rel='stylesheet' type='text/css' href='"+href+"'>");
$("link[rel='stylesheet']").remove();
$("head").append(cssLink);
};
})(jQuery);
</script>
</head>
<body>
<article id="markdown-body">
<article id="markdown-body" class="markdown-body">
<p>Markdown preview</p>
</article>
</body>