Last active
December 16, 2015 01:29
-
-
Save bhyde/5355435 to your computer and use it in GitHub Desktop.
Load this into your lisp, and then goto http://localhost:8081/SyntaxHighlighter-1 for an example of using Alexgor Batchev javascript, client side, syntax highlighter via Common Lisp, Hunchentoot, cl-who, and parenscript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; -*- Mode: Common-Lisp -* | |
;;; A stand alone example of using Alex Batchev's javascript, client side, | |
;;; syntax highlighter <http://alexgorbatchev.com/SyntaxHighlighter/> | |
;;; via Common Lisp, Hunchentoot, cl-who, and parenscript. | |
(ql:quickload '(hunchentoot cl-who parenscript)) | |
(defpackage #:script-highlighter-example | |
(:use #:common-lisp #:hunchentoot #:cl-who #:parenscript)) | |
(in-package #:script-highlighter-example) | |
(setf *js-string-delimiter* #\") | |
(defvar *my-acceptor* (start (make-instance 'easy-acceptor :port 8081))) | |
; (stop *my-acceptor*) | |
(defmacro url-of-syntax-highligher-files (file) | |
(concatenate 'string | |
"http://agorbatchev.typepad.com/pub/sh/3_0_83/" | |
#+nil "http://agorbatchev.typepad.com/pub/sh/current/" ;; broken? | |
file)) | |
(import-macros-from-lisp 'url-of-syntax-highligher-files) | |
(defun add-syntax-highligher (s) | |
(with-html-output (s) | |
(flet ((javascript-file (url) | |
(with-html-output (s) | |
(:script :src url :type "text/javascript"))) | |
(css-file (url) | |
(with-html-output (s) | |
(:link :href url :rel "stylesheet" :type "text/css")))) | |
(javascript-file (url-of-syntax-highligher-files "scripts/shCore.js")) | |
(javascript-file (url-of-syntax-highligher-files "scripts/shBrushJScript.js")) | |
(css-file (url-of-syntax-highligher-files "styles/shCore.css")) | |
(css-file (url-of-syntax-highligher-files "styles/shThemeDefault.css"))) | |
(:script :type "text/javascript" | |
(str | |
(ps | |
((@ -syntax-highlighter all))))))) | |
(define-easy-handler (SyntaxHighlighter-1 :uri "/SyntaxHighlighter-1") () | |
(with-html-output-to-string (s) | |
(:html | |
(:head (:title "Syntax Highligher") | |
(add-syntax-highligher s)) | |
(:body | |
(:h2 "Example of syntax highlighting") | |
(:P "Example of Alex Batchev's " | |
(:a :href "http://alexgorbatchev.com/SyntaxHighlighter/" "Syntax Highligher")) | |
;; Highlight some Javascript, as compiled by Parenscript. | |
(:pre :class "brush:js" (str (ps (defun hi (x) (+ x 10))))))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment