Merge pull request #27 from zenkiezhu/inline-css-js-support
Add inline css/js support
This commit is contained in:
commit
4ec15183fc
@ -116,14 +116,16 @@
|
|||||||
(when (timerp markdown-preview--idle-timer)
|
(when (timerp markdown-preview--idle-timer)
|
||||||
(cancel-timer markdown-preview--idle-timer)))
|
(cancel-timer markdown-preview--idle-timer)))
|
||||||
|
|
||||||
(defun markdown-preview--css-links ()
|
(defun markdown-preview--css ()
|
||||||
"Get list of styles for preview in backward compatible way."
|
"Get list of styles for preview in backward compatible way."
|
||||||
(let* ((custom-style (list markdown-preview-style))
|
(let* ((custom-style (list markdown-preview-style))
|
||||||
(all-styles
|
(all-styles
|
||||||
(mapc (lambda (x) (add-to-list 'custom-style x t)) markdown-preview-stylesheets)))
|
(mapc (lambda (x) (add-to-list 'custom-style x t)) markdown-preview-stylesheets)))
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(concat "<link rel=\"stylesheet\" type=\"text/css\" href=\"" x "\">"))
|
(if (string-match-p "^[\n\t ]*<style" x)
|
||||||
|
x
|
||||||
|
(concat "<link rel=\"stylesheet\" type=\"text/css\" href=\"" x "\">")))
|
||||||
all-styles
|
all-styles
|
||||||
"\n")))
|
"\n")))
|
||||||
|
|
||||||
@ -131,10 +133,12 @@
|
|||||||
"Get list of javascript script tags for preview."
|
"Get list of javascript script tags for preview."
|
||||||
(mapconcat
|
(mapconcat
|
||||||
(lambda (x)
|
(lambda (x)
|
||||||
(concat
|
(if (string-match-p "^[\n\t ]*<script" x)
|
||||||
"<script src=\"" (if (consp x) (car x) x) "\""
|
x
|
||||||
(if (consp x) (format " %s" (cdr x)))
|
(concat
|
||||||
"></script>"))
|
"<script src=\"" (if (consp x) (car x) x) "\""
|
||||||
|
(if (consp x) (format " %s" (cdr x)))
|
||||||
|
"></script>")))
|
||||||
markdown-preview-javascript
|
markdown-preview-javascript
|
||||||
"\n"))
|
"\n"))
|
||||||
|
|
||||||
@ -144,7 +148,7 @@ rendered copy to PREVIEW-FILE, ready to be open in browser."
|
|||||||
(with-temp-file preview-file
|
(with-temp-file preview-file
|
||||||
(insert-file-contents (expand-file-name "preview.html" markdown-preview--home-dir))
|
(insert-file-contents (expand-file-name "preview.html" markdown-preview--home-dir))
|
||||||
(when (search-forward "${MD_STYLE}" nil t)
|
(when (search-forward "${MD_STYLE}" nil t)
|
||||||
(replace-match (markdown-preview--css-links) t))
|
(replace-match (markdown-preview--css) t))
|
||||||
(when (search-forward "${MD_JS}" nil t)
|
(when (search-forward "${MD_JS}" nil t)
|
||||||
(replace-match (markdown-preview--scripts) t))
|
(replace-match (markdown-preview--scripts) t))
|
||||||
(when (search-forward "${WS_HOST}" nil t)
|
(when (search-forward "${WS_HOST}" nil t)
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
console.log('Code: ' + event.code + ' reason: ' + event.reason);
|
console.log('Code: ' + event.code + ' reason: ' + event.reason);
|
||||||
};
|
};
|
||||||
socket.onmessage = function(event) {
|
socket.onmessage = function(event) {
|
||||||
$("#markdown-body").html($(event.data).find("#content").html());
|
$("#markdown-body").html($(event.data).find("#content").html()).trigger('mdContentChange');
|
||||||
var scroll = $(document).height() * ($(event.data).find("#position-percentage").html() / 100);
|
var scroll = $(document).height() * ($(event.data).find("#position-percentage").html() / 100);
|
||||||
$("html, body").animate({ scrollTop: scroll }, 600);
|
$("html, body").animate({ scrollTop: scroll }, 600);
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user