2

为org-mode增加video link导出html video tag

 3 years ago
source link: https://www.lujun9972.win/blog/2020/01/09/%E4%B8%BAorg-mode%E5%A2%9E%E5%8A%A0video-link%E5%AF%BC%E5%87%BAhtml-video-tag/index.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

为org-mode增加video link导出html video tag

org导出html的一个难点就是内嵌视频,基本上需要通过内嵌html的方式来插入视频,像下面这样:

#+begin_export html
<video class="wp-video-shortcode" width="640" height="360" preload="metadata" controls="controls"><source type="video/mp4" src="./Baby唱小金鱼.mp4" /></video>
#+end_export

但是这种方式太繁琐了,不如直接自定义一个video link,在导出成html时帮我自动生成video tag片段.如下所示:

(defun org-video-link-export (path desc backend)
  (let ((ext (file-name-extension path)))
    (cond
     ((eq 'html backend)
      (format "<video preload='metadata' controls='controls'><source type='video/%s' src='%s' /></video>" ext path))
     ;; fall-through case for everything else
     (t
      path))))

(org-link-set-parameters "video" :export 'org-video-link-export)

(org-export-string-as "video:xxx.mp4" 'html t)
<p>
<video preload='metadata' controls='controls'><source type='video/mp4' src='xxx.mp4' /></video></p>

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK