10

如何合理的导出help link 成HTML

 2 years ago
source link: https://www.lujun9972.win/blog/2022/05/31/%E5%A6%82%E4%BD%95%E5%90%88%E7%90%86%E7%9A%84%E5%AF%BC%E5%87%BAhelp-link-%E6%88%90html/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.

如何合理的导出help link 成HTML

Org 文件在导出为 html 是会将 help link 导出为一个HTTP链接,例如一个

  这是一个 [[help:lazy-helm/describe-char][Help]] link

导出成HTML时会变成

  这是一个 <a href="lazy-helm/describe-char">Help</a> link

这个操作很迷,因为实际上并没有这个链接对应的页面。

一个比较合理的方法是导出时保留原文字,但当光标移动到这段文字上去时弹出相关说明。

通过 org-link-set-parameters 可以注册自己定义的链接导出函数,相关配置如下:

(defun org-link--export-help (path desc backend _)
  "Export a \"help\" type link.
PATH is a symbol name, as a string."
  (let ((info (pcase (intern path)
                ((and (pred fboundp) function) (describe-function function))
                ((and (pred boundp) variable) (describe-variable variable))
                (name (user-error "Unknown function or variable: %s" name)))))
    (quit-window)                       ;关闭新开的 help window
    (pcase backend
      ('html (format "<label title='%s'>%s</label>" info desc))
      (_ desc))))
;; 注册 help 的导出函数
(org-link-set-parameters "help"
                         :export #'org-link--export-help)

就可以导出为

这是一个 <label title='lazy-helm/describe-char is an interactive Lisp function.

It is bound to SPC h d c, M-m h d c.

(lazy-helm/describe-char)

Wrapper to ensure that ‘helm’ is loaded before calling describe-char.

'>Help</label> link

效果如下所示:

export-help-link.png

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK