-
Notifications
You must be signed in to change notification settings - Fork 14
/
youtube.lisp
54 lines (48 loc) · 1.6 KB
/
youtube.lisp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
;-------------------------------------------------------------------------------
; Embed youtube videos
; Author: Lukasz Janyst <lukasz@jany.st>
;
; !yt[id]
; !yt[id|width=100,height=200,allowfullscreen]
;-------------------------------------------------------------------------------
(defpackage #:3bmd-youtube
(:use :cl :esrap :3bmd-ext)
(:export #:*youtube-embeds*))
(in-package #:3bmd-youtube)
(defrule yt-param-value
(and "="
(+ (and (! "]") (! ",") character)))
(:destructure (e v)
(declare (ignore e))
(text v)))
(defrule yt-param
(and (or "|" ",")
(+ (and (! "=") (! "]") (! ",") character))
(? yt-param-value))
(:destructure (delim name value)
(declare (ignore delim))
(cons (text name) value)))
(define-extension-inline *youtube-embeds* youtube-embed
(and "!yt["
(* (and (! "]") (! "|") character))
(? (+ yt-param))
"]")
(:destructure (s id params e)
(declare (ignore s e))
(append
(list :youtube-embed (text id))
params)))
(defmethod print-tagged-element ((tag (eql :youtube-embed)) stream rest)
(let ((id (car rest))
(params (cdr rest)))
(format stream
(concatenate
'string
"<iframe src=\"https://www.youtube.com/embed/~a\" "
"frameborder=\"0\" "
"~{~a~^ ~}"
"></iframe>")
id
(mapcar (lambda (x)
(format nil "~a~@[=\"~a\"~]" (car x) (cdr x)))
params))))