Browse Source

Do not reload css on every message

pull/23/head
Igor Shymko 6 years ago
parent
commit
c197aa51cc
  1. 5
      markdown-preview-mode.el
  2. 9
      preview.html

5
markdown-preview-mode.el

@ -88,6 +88,8 @@
(preview-file (concat dir-of-buffer-to-preview markdown-preview-file-name)))
(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 "${WS_HOST}" nil t)
(replace-match markdown-preview-host t))
(if (search-forward "${WS_PORT}" nil t)
@ -157,9 +159,6 @@
(websocket-send-text websocket
(concat
"<div>"
"<span id='style'>"
markdown-preview-style
"</span>"
"<span id='position-percentage'>"
mark-position-percent
"</span>"

9
preview.html

@ -4,7 +4,7 @@
<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;
@ -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,12 +33,6 @@
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>

Loading…
Cancel
Save