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: Tue, 19 Mar 2024 21:54:12 +0700
User-agent: Mozilla Thunderbird

On 19/03/2024 02:42, Juan Manuel Macías wrote:
As I mentioned in a past email, these days I will be somewhat busy, but
I will try to keep up to date with your comments. Although it may take a
while to respond.

Would you mind against new thread as an umbrella for next bunch of topics? Current one becomes too large from my point of view.

For a while a couple of questions related to :export to think on.

I am afraid that :export will cause confusion with :exports for source code blocks. Its name differs by just "s" but possible values have nothing common.

Another issue is more general and should apply e.g. to HTML attributes as well. Consider

--- 8< ---
#+options: inline-special-block-aliases:(("kbd" :export "html*" :html-tag kbd))
@kbd{Default} and @kbd[:export "latex*"]{LaTeX}
--- >8 ---

It exports to

    <p>\nDefault and <kbd class="kbd">LaTeX</kbd></p>

I would expect that "html*" is inherited from the parent declaration and "latex*" does not override it, so

    <p>\nDefault and LaTeX</p>

On the other hand it should be possible to specify that declared earlier rules should be taken into consideration. E.g. "#" might stop further processing:

--- 8< ---
#+options: inline-special-block-aliases:(("kbd" :export "html*" :html-tag kbd))
@kbd{Default} and @kbd[:export "latex* #"]{LaTeX}
--- >8 ---

makes

    <p>\nDefault and <kbd class="kbd">LaTeX</kbd></p>

result valid.

In the meanwhile I have realized that there is no point in the list of parsed rules. You may consider code organized in a bit different way. I hope, just a single extra line in these helpers is required to support "#".

(defun org-export--parse-export-rule
    (spec)
  (and (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))))
         (cons
          (if (string-equal "" name) '@ (intern name))
          (cons (or (not inherit) (string-equal inherit "="))
                (pcase (and what (string-to-char what))
                  ((or ?+ (pred null)) 'full)
                  (?* 'content)
                  (?/ nil)))))))
;; (org-export--parse-export-rule "html+=")

(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))
;; (org-export--backend-hierarchy 'md)

(defun org-export--inline-special-block-export-decision
    (spec-list hierarchy &optional default-rule)
  "Returns (backend inherit . what).
so use `cddr' to get decision."
  (let ((decision '(@ t . full))
        (hierarchy (cons '@ hierarchy)))
    (while (and hierarchy spec-list)
      (let* ((rule (org-export--parse-export-rule (pop spec-list)))
             (tail (and rule (memq (car rule) hierarchy))))
        (if (not rule)
            (message "invalid :export specification %S" (car spec-list)))
        (when (and tail
                   (or (not (cdr tail)) ; Current backend.
                       (cadr rule))) ; Inherits.
          (setq hierarchy (cdr tail))
          (setq decision rule))))
    (if (and default-rule (memq (car default-rule) hierarchy))
        default-rule
      decision)))

----

(ignore
 (pp
  (let ((rules (org-split-string "latex/ html./ html+= ascii+ *")))
    (mapcar (lambda (backend)
              (let ((hierarchy
                     (org-export--backend-hierarchy backend)))
                (list backend
                      (cddr
                       (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))





reply via email to

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