markdown-ext.lisp (1557B)
1 (in-package #:miniblog.markdown-ext) 2 3 ;;; Extension flags, enable all by default 4 (defparameter *youtube-embeds* 1) 5 6 ;;; Embed youtube videos 7 ;;; Based on 3bmd-youtube 8 ;;; 9 ;;; !yt[id] 10 ;;; !yt[id|width=100,height=200,allowfullscreen] 11 12 (defrule yt-param-value 13 (and "=" 14 (+ (and (! "]") (! ",") character))) 15 (:destructure (e v) 16 (declare (ignore e)) 17 (text v))) 18 19 (defrule yt-param 20 (and (or "|" ",") 21 (+ (and (! "=") (! "]") (! ",") character)) 22 (? yt-param-value)) 23 (:destructure (delim name value) 24 (declare (ignore delim)) 25 (cons (text name) value))) 26 27 (define-extension-inline *youtube-embeds* youtube-embed 28 (and "!yt[" 29 (* (and (! "]") (! "|") character)) 30 (? (+ yt-param)) 31 "]") 32 (:destructure (s id params e) 33 (declare (ignore s e)) 34 (append 35 (list :youtube-embed (text id)) 36 params))) 37 38 (defmethod print-tagged-element ((tag (eql :youtube-embed)) stream rest) 39 (let ((id (car rest)) 40 (params (cdr rest))) 41 (format stream 42 (concatenate 43 'string 44 "<div class=\"yt-container\">" 45 "<iframe src=\"https://www.youtube-nocookie.com/embed/~a\" " 46 "frameborder=\"0\" class=\"yt-video\" " 47 "~{~a~^ ~}" 48 "></iframe>" 49 "</div>") 50 id 51 (mapcar (lambda (x) 52 (format nil "~a~@[=\"~a\"~]" (car x) (cdr x))) 53 params))))