* handling as special special block in derived export @ 2022-01-19 13:52 Matt Price 2022-01-19 17:18 ` John Kitchin 2022-01-19 20:56 ` Berry, Charles 0 siblings, 2 replies; 7+ messages in thread From: Matt Price @ 2022-01-19 13:52 UTC (permalink / raw) To: Org Mode [-- Attachment #1: Type: text/plain, Size: 907 bytes --] I am trying ot figure out if I can create a simplified syntax for a particular special block in a derived HTML exporter. I'm trying to produce HTML like this: <div class="r-stack> <img data-fragment="fade-out" src="...."/> <img data-fragment="fade-in" src="..."/></div> The derived backend (org-re-reveal) already has an #+ATTR_REVEAL that an make the data-fragment attributes, so it's not hard to produce the desired outpu: #+begin_r-stack #+ATTR_REVEAL: :frag appear[[imglink1]] #+ATTR_REVEAL: :frag appear[[imglink2]]#+end_r-stack However, I'd really like to add a less verbose syntax, like this: #+begin_r-stack :frag (appear appear)[[imglink1]][[imglink2]]#+end_r-stack My question is: will the exporter preserve information from these header-like arguments, and is there a mechanism I can use in a custom ~special-block-function~ to make use of htem? Thanks for your help as always! Matt [-- Attachment #2: Type: text/html, Size: 3182 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: handling as special special block in derived export 2022-01-19 13:52 handling as special special block in derived export Matt Price @ 2022-01-19 17:18 ` John Kitchin 2022-01-20 15:21 ` Matt Price 2022-01-19 20:56 ` Berry, Charles 1 sibling, 1 reply; 7+ messages in thread From: John Kitchin @ 2022-01-19 17:18 UTC (permalink / raw) To: Matt Price; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 2301 bytes --] I am not sure this is quite what you are looking for. You could use a macro like this. {{{r-stack(((src1 . fade-out) (src2 . fade-in) (src3 . fade-out)))}}} * code :noexport: #+macro: r-stack (eval (r-stack $1)) #+BEGIN_SRC emacs-lisp (defun r-stack (src-alist) "SRC-alist will be a string containing a list of (src . data-fragment) src is a url or filename data-fragment Returns a string for export." (let ((src (read src-alist))) (format "#+BEGIN_EXPORT html <div class=\"r-stack\"> %s </div> ,#+END_EXPORT" (string-join (cl-loop for (src . data-fragment) in src collect (format " <img data-fragment=\"%s\" src=\"%s\"/>" data-fragment src)) "\n")))) (r-stack "((src1 . fade-out) (src2 . fade-in) (src3 . fade-out))") #+END_SRC #+RESULTS: : #+BEGIN_EXPORT html : <div class="r-stack"> : <img data-fragment="fade-out" src="src1"/> : <img data-fragment="fade-in" src="src2"/> : <img data-fragment="fade-out" src="src3"/> : </div> : #+END_EXPORT You could also make a link do that. John ----------------------------------- Professor John Kitchin (he/him/his) Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Wed, Jan 19, 2022 at 9:42 AM Matt Price <moptop99@gmail.com> wrote: > I am trying ot figure out if I can create a simplified syntax for a > particular special block in a derived HTML exporter. > > I'm trying to produce HTML like this: > > <div class="r-stack> <img data-fragment="fade-out" src="...."/> <img data-fragment="fade-in" src="..."/></div> > > The derived backend (org-re-reveal) already has an > > #+ATTR_REVEAL that an make the data-fragment attributes, so it's not hard to produce > the desired outpu: > > #+begin_r-stack > #+ATTR_REVEAL: :frag appear[[imglink1]] > #+ATTR_REVEAL: :frag appear[[imglink2]]#+end_r-stack > > However, I'd really like to add a less verbose syntax, like this: > > #+begin_r-stack :frag (appear appear)[[imglink1]][[imglink2]]#+end_r-stack > > My question is: will the exporter preserve information from these header-like arguments, and is > there a mechanism I can use in a custom ~special-block-function~ to make use of htem? > > Thanks for your help as always! > > Matt > > [-- Attachment #2: Type: text/html, Size: 5119 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: handling as special special block in derived export 2022-01-19 17:18 ` John Kitchin @ 2022-01-20 15:21 ` Matt Price 2022-01-20 16:12 ` John Kitchin 0 siblings, 1 reply; 7+ messages in thread From: Matt Price @ 2022-01-20 15:21 UTC (permalink / raw) To: John Kitchin; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 3107 bytes --] On Wed, Jan 19, 2022 at 12:18 PM John Kitchin <jkitchin@andrew.cmu.edu> wrote: > I am not sure this is quite what you are looking for. You could use a > macro like this. > > > > {{{r-stack(((src1 . fade-out) (src2 . fade-in) (src3 . fade-out)))}}} > > * code :noexport: > > #+macro: r-stack (eval (r-stack $1)) > > #+BEGIN_SRC emacs-lisp > (defun r-stack (src-alist) > "SRC-alist will be a string containing a list of (src . data-fragment) > src is a url or filename > data-fragment > > Returns a string for export." > (let ((src (read src-alist))) > (format "#+BEGIN_EXPORT html > <div class=\"r-stack\"> > %s > </div> > ,#+END_EXPORT" > (string-join > (cl-loop for (src . data-fragment) in src > collect > (format " <img data-fragment=\"%s\" src=\"%s\"/>" > data-fragment src)) > "\n")))) > > > (r-stack "((src1 . fade-out) (src2 . fade-in) (src3 . fade-out))") > #+END_SRC > > #+RESULTS: > : #+BEGIN_EXPORT html > : <div class="r-stack"> > : <img data-fragment="fade-out" src="src1"/> > : <img data-fragment="fade-in" src="src2"/> > : <img data-fragment="fade-out" src="src3"/> > : </div> > : #+END_EXPORT > > You could also make a link do that. > Huh. This wasn't at all what I was thinking but it may be a much better way than I'd htought of. A link seems like it would be a great solution, especially if I could figure out how to get the :follow function to open an individual ~src~ path. Would you use "looking-at" to get the right candidate, or can you think of a way to get completion candidates for a function that opens the file? I'm looking at your eamples in https://kitchingroup.cheme.cmu.edu/blog/2016/11/04/New-link-features-in-org-9 but can't quite follow the code. Thank so mjch for this really interesting solution. > > John > > ----------------------------------- > Professor John Kitchin (he/him/his) > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > > > > On Wed, Jan 19, 2022 at 9:42 AM Matt Price <moptop99@gmail.com> wrote: > >> I am trying ot figure out if I can create a simplified syntax for a >> particular special block in a derived HTML exporter. >> >> I'm trying to produce HTML like this: >> >> <div class="r-stack> <img data-fragment="fade-out" src="...."/> <img data-fragment="fade-in" src="..."/></div> >> >> The derived backend (org-re-reveal) already has an >> >> #+ATTR_REVEAL that an make the data-fragment attributes, so it's not hard to produce >> the desired outpu: >> >> #+begin_r-stack >> #+ATTR_REVEAL: :frag appear[[imglink1]] >> #+ATTR_REVEAL: :frag appear[[imglink2]]#+end_r-stack >> >> However, I'd really like to add a less verbose syntax, like this: >> >> #+begin_r-stack :frag (appear appear)[[imglink1]][[imglink2]]#+end_r-stack >> >> My question is: will the exporter preserve information from these header-like arguments, and is >> there a mechanism I can use in a custom ~special-block-function~ to make use of htem? >> >> Thanks for your help as always! >> >> Matt >> >> [-- Attachment #2: Type: text/html, Size: 6750 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: handling as special special block in derived export 2022-01-20 15:21 ` Matt Price @ 2022-01-20 16:12 ` John Kitchin 2022-01-21 2:46 ` Matt Price 0 siblings, 1 reply; 7+ messages in thread From: John Kitchin @ 2022-01-20 16:12 UTC (permalink / raw) To: Matt Price; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 4107 bytes --] It depends on what the src things look like. You might be able to just call ffap or some variant of it. Here is an example of the follow part that works for a file and url for me. #+BEGIN_SRC emacs-lisp (org-link-set-parameters "rstack" :follow (lambda (path) (ffap (or (ffap-url-at-point) (ffap-file-at-point))))) #+END_SRC #+RESULTS: | :follow | (lambda (path) (ffap (or (ffap-url-at-point) (ffap-file-at-point)))) | [[rstack:(("./screenshots/date-20-01-2022-time-10-36-54.png" . fade-out) (src2 . fade-in) ("https://google.com" . fade-out))]] John ----------------------------------- Professor John Kitchin (he/him/his) Doherty Hall A207F Department of Chemical Engineering Carnegie Mellon University Pittsburgh, PA 15213 412-268-7803 @johnkitchin http://kitchingroup.cheme.cmu.edu On Thu, Jan 20, 2022 at 10:21 AM Matt Price <moptop99@gmail.com> wrote: > > > On Wed, Jan 19, 2022 at 12:18 PM John Kitchin <jkitchin@andrew.cmu.edu> > wrote: > >> I am not sure this is quite what you are looking for. You could use a >> macro like this. >> >> >> >> {{{r-stack(((src1 . fade-out) (src2 . fade-in) (src3 . fade-out)))}}} >> >> * code :noexport: >> >> #+macro: r-stack (eval (r-stack $1)) >> >> #+BEGIN_SRC emacs-lisp >> (defun r-stack (src-alist) >> "SRC-alist will be a string containing a list of (src . data-fragment) >> src is a url or filename >> data-fragment >> >> Returns a string for export." >> (let ((src (read src-alist))) >> (format "#+BEGIN_EXPORT html >> <div class=\"r-stack\"> >> %s >> </div> >> ,#+END_EXPORT" >> (string-join >> (cl-loop for (src . data-fragment) in src >> collect >> (format " <img data-fragment=\"%s\" src=\"%s\"/>" >> data-fragment src)) >> "\n")))) >> >> >> (r-stack "((src1 . fade-out) (src2 . fade-in) (src3 . fade-out))") >> #+END_SRC >> >> #+RESULTS: >> : #+BEGIN_EXPORT html >> : <div class="r-stack"> >> : <img data-fragment="fade-out" src="src1"/> >> : <img data-fragment="fade-in" src="src2"/> >> : <img data-fragment="fade-out" src="src3"/> >> : </div> >> : #+END_EXPORT >> >> You could also make a link do that. >> > > Huh. This wasn't at all what I was thinking but it may be a much better > way than I'd htought of. > > A link seems like it would be a great solution, especially if I could > figure out how to get the :follow function to open an individual ~src~ > path. Would you use "looking-at" to get the right candidate, or can you > think of a way to get completion candidates for a function that opens the > file? I'm looking at your eamples in > https://kitchingroup.cheme.cmu.edu/blog/2016/11/04/New-link-features-in-org-9 > but can't quite follow the code. > > Thank so mjch for this really interesting solution. > >> >> John >> >> ----------------------------------- >> Professor John Kitchin (he/him/his) >> Doherty Hall A207F >> Department of Chemical Engineering >> Carnegie Mellon University >> Pittsburgh, PA 15213 >> 412-268-7803 >> @johnkitchin >> http://kitchingroup.cheme.cmu.edu >> >> >> >> On Wed, Jan 19, 2022 at 9:42 AM Matt Price <moptop99@gmail.com> wrote: >> >>> I am trying ot figure out if I can create a simplified syntax for a >>> particular special block in a derived HTML exporter. >>> >>> I'm trying to produce HTML like this: >>> >>> <div class="r-stack> <img data-fragment="fade-out" src="...."/> <img data-fragment="fade-in" src="..."/></div> >>> >>> The derived backend (org-re-reveal) already has an >>> >>> #+ATTR_REVEAL that an make the data-fragment attributes, so it's not hard to produce >>> the desired outpu: >>> >>> #+begin_r-stack >>> #+ATTR_REVEAL: :frag appear[[imglink1]] >>> #+ATTR_REVEAL: :frag appear[[imglink2]]#+end_r-stack >>> >>> However, I'd really like to add a less verbose syntax, like this: >>> >>> #+begin_r-stack :frag (appear appear)[[imglink1]][[imglink2]]#+end_r-stack >>> >>> My question is: will the exporter preserve information from these header-like arguments, and is >>> there a mechanism I can use in a custom ~special-block-function~ to make use of htem? >>> >>> Thanks for your help as always! >>> >>> Matt >>> >>> [-- Attachment #2: Type: text/html, Size: 8695 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: handling as special special block in derived export 2022-01-20 16:12 ` John Kitchin @ 2022-01-21 2:46 ` Matt Price 0 siblings, 0 replies; 7+ messages in thread From: Matt Price @ 2022-01-21 2:46 UTC (permalink / raw) To: John Kitchin; +Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 6277 bytes --] On Thu, Jan 20, 2022 at 11:12 AM John Kitchin <jkitchin@andrew.cmu.edu> wrote: > It depends on what the src things look like. You might be able to just > call ffap or some variant of it. Here is an example of the follow part that > works for a file and url for me. > > #+BEGIN_SRC emacs-lisp > (org-link-set-parameters > "rstack" > :follow (lambda (path) > (ffap (or (ffap-url-at-point) > (ffap-file-at-point))))) > #+END_SRC > > #+RESULTS: > | :follow | (lambda (path) (ffap (or (ffap-url-at-point) > (ffap-file-at-point)))) | > > > [[rstack:(("./screenshots/date-20-01-2022-time-10-36-54.png" . fade-out) > (src2 . fade-in) ("https://google.com" . fade-out))]] > > > This is what I have so far. I'm pretty happy with it; it's quite concise, and will fill in default values for the fade in and out instructions. When I asked my question, I left out an optional second parameter that these stacking images can take -- a "fragment-index" number. I'm trying to figure out a way to add that additional info into the link without making it (a) unnecessarily long, esp for the majority of cases where I won't use that index; or (b) impossible to read. I guess I could make each list element a plist instead? Like ((:s ~/image.png :i 4 :f fade-in-then-out))? Anyway, here's my code: (defun r-stack-follow (path) (let* ((srcs (read path )) (completions (-map (lambda (src) (car src)) srcs) ) (chosen (completing-read "Follow link to: " completions))) (if (ffap-url-p chosen) (browse-url chosen) (find-file-ace-window chosen)))) (defun r-stack-export (path desc backend) (cond ((eq 'html backend) (let ((srcs (read path))) (format "<div class=\"r-stack\">\n%s</div>\n" (string-join (cl-loop for index from 1 for (src . data-fragment) in srcs collect (format " <img class=\"fragment %s\" src=\"%s\"/>" (or data-fragment (cond ((eql 1 index) "fade-out") ((eql (length srcs) index) "fade-in") (t "fade-in-then-out"))) src)) "\n")))))) (org-link-set-parameters "r-stack" :follow 'r-stack-follow :export 'r-stack-export :face '(:foreground "red") :help-echo "Click me for a message.") > John > > ----------------------------------- > Professor John Kitchin (he/him/his) > Doherty Hall A207F > Department of Chemical Engineering > Carnegie Mellon University > Pittsburgh, PA 15213 > 412-268-7803 > @johnkitchin > http://kitchingroup.cheme.cmu.edu > > > > On Thu, Jan 20, 2022 at 10:21 AM Matt Price <moptop99@gmail.com> wrote: > >> >> >> On Wed, Jan 19, 2022 at 12:18 PM John Kitchin <jkitchin@andrew.cmu.edu> >> wrote: >> >>> I am not sure this is quite what you are looking for. You could use a >>> macro like this. >>> >>> >>> >>> {{{r-stack(((src1 . fade-out) (src2 . fade-in) (src3 . fade-out)))}}} >>> >>> * code :noexport: >>> >>> #+macro: r-stack (eval (r-stack $1)) >>> >>> #+BEGIN_SRC emacs-lisp >>> (defun r-stack (src-alist) >>> "SRC-alist will be a string containing a list of (src . data-fragment) >>> src is a url or filename >>> data-fragment >>> >>> Returns a string for export." >>> (let ((src (read src-alist))) >>> (format "#+BEGIN_EXPORT html >>> <div class=\"r-stack\"> >>> %s >>> </div> >>> ,#+END_EXPORT" >>> (string-join >>> (cl-loop for (src . data-fragment) in src >>> collect >>> (format " <img data-fragment=\"%s\" src=\"%s\"/>" >>> data-fragment src)) >>> "\n")))) >>> >>> >>> (r-stack "((src1 . fade-out) (src2 . fade-in) (src3 . fade-out))") >>> #+END_SRC >>> >>> #+RESULTS: >>> : #+BEGIN_EXPORT html >>> : <div class="r-stack"> >>> : <img data-fragment="fade-out" src="src1"/> >>> : <img data-fragment="fade-in" src="src2"/> >>> : <img data-fragment="fade-out" src="src3"/> >>> : </div> >>> : #+END_EXPORT >>> >>> You could also make a link do that. >>> >> >> Huh. This wasn't at all what I was thinking but it may be a much better >> way than I'd htought of. >> >> A link seems like it would be a great solution, especially if I could >> figure out how to get the :follow function to open an individual ~src~ >> path. Would you use "looking-at" to get the right candidate, or can you >> think of a way to get completion candidates for a function that opens the >> file? I'm looking at your eamples in >> https://kitchingroup.cheme.cmu.edu/blog/2016/11/04/New-link-features-in-org-9 >> but can't quite follow the code. >> >> Thank so mjch for this really interesting solution. >> >>> >>> John >>> >>> ----------------------------------- >>> Professor John Kitchin (he/him/his) >>> Doherty Hall A207F >>> Department of Chemical Engineering >>> Carnegie Mellon University >>> Pittsburgh, PA 15213 >>> 412-268-7803 >>> @johnkitchin >>> http://kitchingroup.cheme.cmu.edu >>> >>> >>> >>> On Wed, Jan 19, 2022 at 9:42 AM Matt Price <moptop99@gmail.com> wrote: >>> >>>> I am trying ot figure out if I can create a simplified syntax for a >>>> particular special block in a derived HTML exporter. >>>> >>>> I'm trying to produce HTML like this: >>>> >>>> <div class="r-stack> <img data-fragment="fade-out" src="...."/> <img data-fragment="fade-in" src="..."/></div> >>>> >>>> The derived backend (org-re-reveal) already has an >>>> >>>> #+ATTR_REVEAL that an make the data-fragment attributes, so it's not hard to produce >>>> the desired outpu: >>>> >>>> #+begin_r-stack >>>> #+ATTR_REVEAL: :frag appear[[imglink1]] >>>> #+ATTR_REVEAL: :frag appear[[imglink2]]#+end_r-stack >>>> >>>> However, I'd really like to add a less verbose syntax, like this: >>>> >>>> #+begin_r-stack :frag (appear appear)[[imglink1]][[imglink2]]#+end_r-stack >>>> >>>> My question is: will the exporter preserve information from these header-like arguments, and is >>>> there a mechanism I can use in a custom ~special-block-function~ to make use of htem? >>>> >>>> Thanks for your help as always! >>>> >>>> Matt >>>> >>>> [-- Attachment #2: Type: text/html, Size: 12138 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: handling as special special block in derived export 2022-01-19 13:52 handling as special special block in derived export Matt Price 2022-01-19 17:18 ` John Kitchin @ 2022-01-19 20:56 ` Berry, Charles 2022-01-20 14:42 ` Matt Price 1 sibling, 1 reply; 7+ messages in thread From: Berry, Charles @ 2022-01-19 20:56 UTC (permalink / raw) To: Matt Price; +Cc: Org Mode Matt, > On Jan 19, 2022, at 5:52 AM, Matt Price <moptop99@gmail.com> wrote: > > However, I'd really like to add a less verbose syntax, like this: > > #+begin_r-stack :frag (appear appear) > [[imglink1]] > [[imglink2]] > #+end_r-stack > > My question is: will the exporter preserve information from these header-like arguments, and is > there a mechanism I can use in a custom ~special-block-function~ to make use of htem? > Not as you have it there, but #+header: :frag (appear appear) #+begin_r-stack [[imglink1]] [[imglink2]] #+end_r-stack parses as (special-block (:type "r-stack" :begin 727 :end 815 :contents-begin 775 :contents-end 801 :post-blank 0 :post-affiliated 759 :header (":frag (appear appear)") :mode nil :granularity element :parent nil)) if that helps. Chuck ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: handling as special special block in derived export 2022-01-19 20:56 ` Berry, Charles @ 2022-01-20 14:42 ` Matt Price 0 siblings, 0 replies; 7+ messages in thread From: Matt Price @ 2022-01-20 14:42 UTC (permalink / raw) Cc: Org Mode [-- Attachment #1: Type: text/plain, Size: 1521 bytes --] On Wed, Jan 19, 2022 at 3:56 PM Berry, Charles <ccberry@health.ucsd.edu> wrote: > Matt, > > > On Jan 19, 2022, at 5:52 AM, Matt Price <moptop99@gmail.com> wrote: > > > > However, I'd really like to add a less verbose syntax, like this: > > > > #+begin_r-stack :frag (appear appear) > > [[imglink1]] > > [[imglink2]] > > #+end_r-stack > > > > My question is: will the exporter preserve information from these > header-like arguments, and is > > there a mechanism I can use in a custom ~special-block-function~ to make > use of htem? > > > > Not as you have it there, but > > #+header: :frag (appear appear) > #+begin_r-stack > [[imglink1]] > [[imglink2]] > #+end_r-stack > > > parses as > > (special-block > (:type "r-stack" :begin 727 :end 815 :contents-begin 775 :contents-end > 801 :post-blank 0 :post-affiliated 759 :header > (":frag (appear appear)") > :mode nil :granularity element :parent nil)) > > if that helps. > Ah, thank you. I had never used #+header: before. THis helps a little, but I guess the parser works from the inside out. That is, the special block contents are already parsed before the block itself. As a result, I don't see how to add classes to the contents on the basis of the block headers. Also, it doesn't seem trivial to identify the "direct children" of the block, the way one might in javaScript with, say, ~document.querySelectorAll()~.or just ~elem.children()~. So I'm not convinced my initial impulse to solve the problem this way will be fruitful. > > Chuck > [-- Attachment #2: Type: text/html, Size: 2278 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2022-01-21 2:47 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2022-01-19 13:52 handling as special special block in derived export Matt Price 2022-01-19 17:18 ` John Kitchin 2022-01-20 15:21 ` Matt Price 2022-01-20 16:12 ` John Kitchin 2022-01-21 2:46 ` Matt Price 2022-01-19 20:56 ` Berry, Charles 2022-01-20 14:42 ` Matt Price
Code repositories for project(s) associated with this public inbox https://git.savannah.gnu.org/cgit/emacs/org-mode.git This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).