Re: [NTG-context] Dynamic document variables from metadata

2022-01-02 Thread Thangalin via ntg-context
Thank you, Hans.

Updates are in place:

https://github.com/DaveJarvis/keenwrite/releases
https://github.com/DaveJarvis/keenwrite-themes/releases

On Sun, Jan 2, 2022 at 3:11 AM Hans Hagen  wrote:

> On 1/2/2022 2:54 AM, Thangalin via ntg-context wrote:
> > Happy New Year!
> >
> > How would you implement a mechanism that takes arbitrary XHTML 
> > tags and produces document variables? Consider:
> >
> >  
> >
> > After running XML setups, the following would write "Nature":
> >
> >  \documentvariable{journal}
> >
> > The tricky part is doing this without pre-defining them. Here's a short,
> > self-contained example to help demonstrate:
> >
> > |\startbuffer[xdoc]> name="author"/> 
> > \stopbuffer \startxmlsetups xml:xhtml
> > \xmlsetsetup{\xmldocument}{*}{-}
> > \xmlsetsetup{\xmldocument}{html|body}{xml:*}
> > \xmlsetsetup{\xmldocument}{head}{xml:meta} \stopxmlsetups
> > \xmlregistersetup{xml:xhtml} \startxmlsetups xml:html
> > % "author" is a special setup, not generalized
> > \xmlfilter{#1}{/head/meta[@name='author']/command(xml:author)} % What
> > goes here to make this dynamic?
> > %\xmlfilter{#1}{/head/meta[@name='journal']/command(xml:journal)}
> > \xmlflush{#1} \stopxmlsetups \startxmlsetups xml:author
> > \setupdocument[author={\xmlatt{#1}{content}}]
> > \setupdocument[metadata:author={\xmlatt{#1}{content}}]
> > \setupinteraction[author={\documentvariable{author}}] \stopxmlsetups %
> > How can this be generalized? %\startxmlsetups xml:journal
> > %\setupdocument[journal={\xmlatt{#1}{content}}] %\stopxmlsetups
> > \startxmlsetups xml:body \startdocument Author:
> > \documentvariable{author} \par Journal: \documentvariable{journal}
> > \stopdocument \stopxmlsetups \xmlprocessbuffer{main}{xdoc}{}|
> \startxmlsetups xml:setdocumentvariable
>\setupdocument[\xmlatt{#1}{name}={\xmlatt{#1}{content}}]
> \stopxmlsetups
>
> \startxmlsetups xml:author
>\setupdocument[author={\xmlatt{#1}{content}}]
>\setupdocument[metadata:author={\xmlatt{#1}{content}}]
>\setupinteraction[author={\documentvariable{author}}]
> \stopxmlsetups
>
> \startxmlsetups xml:html
>\xmlfilter{#1}{/head/meta/command(xml:setdocumentvariable)}
>\xmlfilter{#1}{/head/meta[@name='author']/command(xml:author)}
>\startdocument
>\xmlflush{#1}
>\stopdocument
> \stopxmlsetups
>
>
>
> -
>Hans Hagen | PRAGMA ADE
>Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
> tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
> -
>
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


Re: [NTG-context] Dynamic document variables from metadata

2022-01-02 Thread Hans Hagen via ntg-context

On 1/2/2022 2:54 AM, Thangalin via ntg-context wrote:

Happy New Year!

How would you implement a mechanism that takes arbitrary XHTML  
tags and produces document variables? Consider:


     

After running XML setups, the following would write "Nature":

     \documentvariable{journal}

The tricky part is doing this without pre-defining them. Here's a short, 
self-contained example to help demonstrate:


|\startbuffer[xdoc]   name="author"/>  
\stopbuffer \startxmlsetups xml:xhtml 
\xmlsetsetup{\xmldocument}{*}{-} 
\xmlsetsetup{\xmldocument}{html|body}{xml:*} 
\xmlsetsetup{\xmldocument}{head}{xml:meta} \stopxmlsetups 
\xmlregistersetup{xml:xhtml} \startxmlsetups xml:html
% "author" is a special setup, not generalized 
\xmlfilter{#1}{/head/meta[@name='author']/command(xml:author)} % What 
goes here to make this dynamic? 
%\xmlfilter{#1}{/head/meta[@name='journal']/command(xml:journal)} 
\xmlflush{#1} \stopxmlsetups \startxmlsetups xml:author 
\setupdocument[author={\xmlatt{#1}{content}}] 
\setupdocument[metadata:author={\xmlatt{#1}{content}}] 
\setupinteraction[author={\documentvariable{author}}] \stopxmlsetups % 
How can this be generalized? %\startxmlsetups xml:journal 
%\setupdocument[journal={\xmlatt{#1}{content}}] %\stopxmlsetups 
\startxmlsetups xml:body \startdocument Author: 
\documentvariable{author} \par Journal: \documentvariable{journal} 
\stopdocument \stopxmlsetups \xmlprocessbuffer{main}{xdoc}{}|

\startxmlsetups xml:setdocumentvariable
  \setupdocument[\xmlatt{#1}{name}={\xmlatt{#1}{content}}]
\stopxmlsetups

\startxmlsetups xml:author
  \setupdocument[author={\xmlatt{#1}{content}}]
  \setupdocument[metadata:author={\xmlatt{#1}{content}}]
  \setupinteraction[author={\documentvariable{author}}]
\stopxmlsetups

\startxmlsetups xml:html
  \xmlfilter{#1}{/head/meta/command(xml:setdocumentvariable)}
  \xmlfilter{#1}{/head/meta[@name='author']/command(xml:author)}
  \startdocument
  \xmlflush{#1}
  \stopdocument
\stopxmlsetups



-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
   tel: 038 477 53 69 | www.pragma-ade.nl | www.pragma-pod.nl
-
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___


[NTG-context] Dynamic document variables from metadata

2022-01-01 Thread Thangalin via ntg-context
Happy New Year!

How would you implement a mechanism that takes arbitrary XHTML  tags
and produces document variables? Consider:



After running XML setups, the following would write "Nature":

\documentvariable{journal}

The tricky part is doing this without pre-defining them. Here's a short,
self-contained example to help demonstrate:

\startbuffer[xdoc]


  
  



\stopbuffer
\startxmlsetups xml:xhtml
  \xmlsetsetup{\xmldocument}{*}{-}
  \xmlsetsetup{\xmldocument}{html|body}{xml:*}
  \xmlsetsetup{\xmldocument}{head}{xml:meta}\stopxmlsetups
\xmlregistersetup{xml:xhtml}
\startxmlsetups xml:html
  % "author" is a special setup, not generalized
  \xmlfilter{#1}{/head/meta[@name='author']/command(xml:author)}

  % What goes here to make this dynamic?
  %\xmlfilter{#1}{/head/meta[@name='journal']/command(xml:journal)}

  \xmlflush{#1}\stopxmlsetups
\startxmlsetups xml:author
  \setupdocument[author={\xmlatt{#1}{content}}]
  \setupdocument[metadata:author={\xmlatt{#1}{content}}]
  \setupinteraction[author={\documentvariable{author}}]\stopxmlsetups
% How can this be generalized?%\startxmlsetups xml:journal
  %\setupdocument[journal={\xmlatt{#1}{content}}]%\stopxmlsetups
\startxmlsetups xml:body
  \startdocument
Author: \documentvariable{author}

\par

Journal: \documentvariable{journal}
  \stopdocument\stopxmlsetups
\xmlprocessbuffer{main}{xdoc}{}


Thank you!
___
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___