dotemacs

My Emacs configuration
git clone git://git.entf.net/dotemacs
Log | Files | Refs | LICENSE

org-roam-export.el (2840B)


      1 ;;; org-roam-export.el --- Org-roam org-export tweaks -*- coding: utf-8; lexical-binding: t; -*-
      2 
      3 ;; Copyright © 2020-2022 Jethro Kuan <jethrokuan95@gmail.com>
      4 
      5 ;; Author: Jethro Kuan <jethrokuan95@gmail.com>
      6 ;; URL: https://github.com/org-roam/org-roam
      7 ;; Keywords: org-mode, roam, convenience
      8 ;; Version: 2.2.2
      9 ;; Package-Requires: ((emacs "26.1") (org "9.4") (org-roam "2.1"))
     10 
     11 ;; This file is NOT part of GNU Emacs.
     12 
     13 ;; This program is free software; you can redistribute it and/or modify
     14 ;; it under the terms of the GNU General Public License as published by
     15 ;; the Free Software Foundation; either version 3, or (at your option)
     16 ;; any later version.
     17 ;;
     18 ;; This program is distributed in the hope that it will be useful,
     19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
     20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     21 ;; GNU General Public License for more details.
     22 ;;
     23 ;; You should have received a copy of the GNU General Public License
     24 ;; along with GNU Emacs; see the file COPYING.  If not, write to the
     25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
     26 ;; Boston, MA 02110-1301, USA.
     27 
     28 ;;; Commentary:
     29 ;;
     30 ;; This package provides the necessary changes required to make org-export work out-of-the-box.
     31 ;;
     32 ;; To enable it, run:
     33 ;;
     34 ;;    (require 'org-roam-export)
     35 ;;
     36 ;; The key issue Org's export-to-html functionality has is that it does not respect the ID property, which
     37 ;; Org-roam relies heavily on. This patches the necessary function in ox-html to export ID links correctly,
     38 ;; pointing to the correct place.
     39 ;;
     40 ;;; Code:
     41 (require 'ox-html)
     42 
     43 (defun org-roam-export--org-html--reference (datum info &optional named-only)
     44   "Org-roam's patch for `org-html--reference' to support ID link export.
     45 See `org-html--reference' for DATUM, INFO and NAMED-ONLY."
     46   (let* ((type (org-element-type datum))
     47          (user-label
     48           (org-element-property
     49            (pcase type
     50              ((or `headline `inlinetask) :CUSTOM_ID)
     51              ((or `radio-target `target) :value)
     52              (_ :name))
     53            datum))
     54          (user-label
     55           (or user-label
     56               (when-let ((path (org-element-property :ID datum)))
     57                 ;; see `org-html-link' for why we use "ID-"
     58                 ;; (search for "ID-" in ox-html.el)
     59                 (concat "ID-" path)))))
     60     (cond
     61      ((and user-label
     62            (or (plist-get info :html-prefer-user-labels)
     63                (memq type '(headline inlinetask))))
     64       user-label)
     65      ((and named-only
     66            (not (memq type '(headline inlinetask radio-target target)))
     67            (not user-label))
     68       nil)
     69      (t
     70       (org-export-get-reference datum info)))))
     71 
     72 (advice-add 'org-html--reference :override #'org-roam-export--org-html--reference)
     73 
     74 (provide 'org-roam-export)
     75 ;;; org-roam-export.el ends here