emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `:export' attribute?: Re: Experimental public branch for inline spec


From: Max Nikulin
Subject: Re: `:export' attribute?: Re: Experimental public branch for inline special blocks
Date: Sat, 16 Mar 2024 21:07:23 +0700
User-agent: Mozilla Thunderbird

On 15/03/2024 23:26, Juan Manuel Macías wrote:
Tomorrow I will make a new commit with your code.

An update with a couple of bugs fixed. Now it is possible to specify different export rules for a backend and all its derivatives:

(ignore
 (pp
  (let ((rules
         (org-export--inline-special-block-make-backend-list
          (org-split-string "latex/ html./ html+= ascii+ *"))))
    (mapcar (lambda (backend)
              (let ((hierarchy
                     (org-export--backend-hierarchy backend)))
                (list backend
                      (org-export--inline-special-block-export-decision
                       rules hierarchy))))
            '(odt latex beamer html md ascii)))))

((odt content)
 (latex nil)
 (beamer nil)
 (html nil)
 (md full)
 (ascii full))

----

(defun org-export--inline-special-block-make-backend-list
    (rules)
  (let (result)
    (dolist (spec rules)
      (if (string-match

"\\`\\([-_a-zA-Z0-9]*\\)\\(?:\\([/+*]\\)\\([=.]\\)?\\|\\([=.]\\)\\([/+*]\\)?\\)?\\'"
           spec)
          (let ((name (match-string 1 spec))
                (inherit (or (match-string 3 spec)
                             (match-string 4 spec)))
                (what (or (match-string 2 spec)
                          (match-string 5 spec))))
            (push (cons
                   (if (string-equal "" name) '@ (intern name))
                   (cons (or (not inherit) (string-equal inherit "="))
                         (if what (string-to-char what) ?+)))
                  result))
        (message "invalid :export specification %S" spec)))
    (nreverse result)))

(defun org-export--backend-hierarchy (backend)
  "Result may be cached in INFO."
  (let ((hierarchy))
    (when (not (symbolp backend))
      (setq backend (org-export-backend-name backend)))
    (while backend
      (push backend hierarchy)
      (setq backend (org-export-backend-parent
                     (org-export-get-backend backend))))
    hierarchy))

(defun org-export--inline-special-block-export-decision
    (rule-list hierarchy)
  (let ((hierarchy (cons '@ hierarchy))
        (decision ?+))
    (while (and hierarchy rule-list)
      (let* ((rule (pop rule-list))
             (tail (memq (car rule) hierarchy)))
        (when (and tail
                   (or (not (cdr tail)) ; Current backend.
                       (cadr rule))) ; Inherits.
          (setq hierarchy (cdr tail))
          (setq decision (cddr rule)))))
    (pcase decision
      (?+ 'full)
      (?* 'content)
      (?/ nil)
      (_ 'full))))





reply via email to

[Prev in Thread] Current Thread [Next in Thread]