[Top][All Lists]

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

Re: Raw Org AST snippets for "impossible" markup

From: Max Nikulin
Subject: Re: Raw Org AST snippets for "impossible" markup
Date: Thu, 9 Dec 2021 21:56:16 +0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.14.0

On 09/12/2021 14:01, Juan Manuel Macías wrote:
John Kitchin writes:

Have you seen
https://github.com/tj64/org-dp? It seems to do a lot with creating and
manipulating org elements. It might either be handy or lead to some

Interesting package. Thanks for sharing.

Either I missed something or its purpose is completely different. It maps Org markup to Org markup. I am experimenting with fragments that should allow to get something that is really tricky or even impossible with established syntax, so it has to run immediately before exporters.

It gave me an idea, also borrowing part of Maxim's code, but evaluating
in this case the path. To continue playing with links... The goal is
to obtain a link with this structure `[[quote-lang:lang][quote]]':

#+BEGIN_SRC emacs-lisp :results silent
    :display 'full
    :export (lambda (path desc bck)
             (let* ((bck org-export-current-backend)
                    (attr (list (format
                                 ":environment foreigndisplayquote :options 
                    (info (org-export-get-environment
                           bck nil nil)))
                 `(quote-block (:attr_latex ,attr)
                 bck info)))))

Looking into your code I have realized that it should be implemented using filter, not through :export property of links. Maybe without working proof of concept with link exporters, this session of monkey-typing would not be successful.

#+begin_src elisp :results silent
  (defun orgia-element-replace (current new destructive?)
    (if (eq current new)
      (let* ((lst? (and (listp new) (not (symbolp (car new)))))
             (new-lst (if lst?
                          (if destructive? (nconc new) (reverse new))
                        (list new))))
        (dolist (element new-lst)
          (org-element-insert-before element current)))
      (org-element-extract-element current)

  (defun orgia--transform-link (data)
    (if (not (string-equal "orgia" (org-element-property :type data)))
      (let* ((path (org-element-property :path data)))
        (if (not (eq ?\( (aref path 0)))
            (or path (org-element-contents data))
          (read path)))))

  (defun orgia-parse-tree-filter (data _backend info)
    (org-element-map data 'link
      (lambda (data)
        (orgia-element-replace data (orgia--transform-link data) t))
      info nil nil t)

#+begin_src elisp :results silent
(add-to-list 'org-export-filter-parse-tree-functions #'orgia-parse-tree-filter)

  (org-link-set-parameters "orgia")

#+begin_src elisp
(org-export-string-as "An <orgia:(\"in\" (italic () \"ter\"))>word" 'html t)

: <p>
: An in<i>ter</i>word</p>

reply via email to

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