[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] 99/119: serve files with htmlize Emacs fontification
From: |
Eric Schulte |
Subject: |
[elpa] 99/119: serve files with htmlize Emacs fontification |
Date: |
Mon, 10 Mar 2014 16:57:53 +0000 |
eschulte pushed a commit to branch master
in repository elpa.
commit bde88e9a22be202fe62e91ffa4aa988e07fc09c1
Author: Eric Schulte <address@hidden>
Date: Wed Jan 15 15:53:44 2014 -0800
serve files with htmlize Emacs fontification
---
examples/015-auto-mode-server.el | 28 ++++++++++++++++++++++++++++
1 files changed, 28 insertions(+), 0 deletions(-)
diff --git a/examples/015-auto-mode-server.el b/examples/015-auto-mode-server.el
new file mode 100644
index 0000000..69e993f
--- /dev/null
+++ b/examples/015-auto-mode-server.el
@@ -0,0 +1,28 @@
+;;; auto-mode-server.el --- files with fontification from the `auto-mode-alist'
+(require 'htmlize)
+
+(lexical-let ((docroot default-directory))
+ (ws-start
+ (lambda (request)
+ (with-slots (process headers) request
+ (let ((path (ws-in-directory-p
+ docroot (substring (cdr (assoc :GET headers)) 1))))
+ (if path
+ (if (file-directory-p path)
+ (ws-send-directory-list process
+ (expand-file-name path docroot) "^[^\.]")
+ ;; send htmlize version of file
+ (let ((mode (or (cdr (cl-assoc-if (lambda (re) (string-match re
path))
+ auto-mode-alist))
+ 'fundamental-mode)))
+ (ws-response-header process 200
+ '("Content-type" . "text/html; charset=utf-8"))
+ (process-send-string process
+ (with-temp-buffer
+ (insert-file-contents-literally path)
+ (funcall mode)
+ (let ((html (htmlize-buffer)))
+ (prog1 (with-current-buffer html (buffer-string))
+ (kill-buffer html)))))))
+ (ws-send-404 process)))))
+ 9015))
- [elpa] 87/119: update server stopping w/requests process field, (continued)
- [elpa] 87/119: update server stopping w/requests process field, Eric Schulte, 2014/03/10
- [elpa] 83/119: supports web sockets, Eric Schulte, 2014/03/10
- [elpa] 75/119: more web-socket implementation, Eric Schulte, 2014/03/10
- [elpa] 91/119: more tutorial, Eric Schulte, 2014/03/10
- [elpa] 94/119: example serving Org-mode files as JSON, Eric Schulte, 2014/03/10
- [elpa] 93/119: helper function to serve directory listings, Eric Schulte, 2014/03/10
- [elpa] 90/119: tutorials, Eric Schulte, 2014/03/10
- [elpa] 88/119: accept single-function handlers, Eric Schulte, 2014/03/10
- [elpa] 96/119: expand this example w/smart dir listings, Eric Schulte, 2014/03/10
- [elpa] 98/119: TODO chunked encoding, Eric Schulte, 2014/03/10
- [elpa] 99/119: serve files with htmlize Emacs fontification,
Eric Schulte <=
- [elpa] 97/119: added ws-stop-all convenience function, Eric Schulte, 2014/03/10
- [elpa] 89/119: authorization helper, Eric Schulte, 2014/03/10
- [elpa] 92/119: simpler handler in example, Eric Schulte, 2014/03/10
- [elpa] 102/119: updated content- transfer-encoding notes, Eric Schulte, 2014/03/10
- [elpa] 103/119: set Content-length when serving files, Eric Schulte, 2014/03/10
- [elpa] 95/119: better ws-send-directory-list, Eric Schulte, 2014/03/10
- [elpa] 106/119: TODO Content and Transfer encodings, Eric Schulte, 2014/03/10
- [elpa] 104/119: tweak notes, Eric Schulte, 2014/03/10
- [elpa] 108/119: test chunked/gzipped transfer/content encodings, Eric Schulte, 2014/03/10
- [elpa] 100/119: manual application of x-gzip content encoding, Eric Schulte, 2014/03/10