public inbox archive for pandoc-discuss@googlegroups.com
 help / color / mirror / Atom feed
* YAML metadata block + HTML input file
@ 2021-12-07 19:09 Gregory D. Weber
       [not found] ` <91104b9d67992600aa9acc26fa32b2cfcde60056.camel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: Gregory D. Weber @ 2021-12-07 19:09 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

I'm having trouble with an HTML to HTML conversion using a template and YAML
metadata block.  Pandoc does not seem to recognize the YAML block in the HTML
input file, and then reports an error due to the missing $title$ variable.  If
the error is mine, I'd like to know what I did wrong here:

$ pandoc --version
pandoc 2.5
Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
......

$ pandoc --template=template.html -o output.html input.html
[WARNING] This document format requires a nonempty <title> element.
  Please specify either 'title' or 'pagetitle' in the metadata,
  e.g. by using --metadata pagetitle="..." on the command line.
  Falling back to 'input'

A.  These are my files:

1.  template.html

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="UTF-8"/>
      <title>$title$</title>
    </head>

    <body>
      <h1>$title$</h1>
      <div>$body$</div>
    </body>
</html>

2.  input.html

---
title: Hello
---
<form id="form1"
  <p>Salvete, sodales.</p>
</form>

3.  output.html

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="UTF-8"/>
      <title></title>
    </head>

    <body>
      <h1></h1>
      <div>--- title: Hello ---
Salvete, sodales.</div>
    </body>
</html>

B.  So far, I'm able to work around this by putting the metadata variables in
their own file, *without* the "---" above and below, and using the --metadata-
file option.  And this seems to work also for ordinary template variables like
$speaker$, which are not metadata variables like $title$ -- though I don't
understand the distinction too clearly:

$ pandoc --template=template.html -o output2.html --metadata-file=input3.yaml
input2.html

1.  template.html

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="UTF-8"/>
      <title>$title$</title>
    </head>

    <body>
      <h1>$title$</h1>
      <div>Dixit $speaker$: $body$</div>
    </body>
</html>

1.  input3.html

<form id="form1"
  <p>Salvete, sodales.</p>
</form>

2.  input3.yaml

title: Hello
speaker: Marcus

3.  output2.html

<!DOCTYPE html>
<html lang="en">
    <head>
      <meta charset="UTF-8"/>
      <title>Hello</title>
    </head>

    <body>
      <h1>Hello</h1>
      <div>Dixit Marcus: Salvete, sodales.</div>
    </body>
</html>

(This is the desired and actual output.)



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: YAML metadata block + HTML input file
       [not found] ` <91104b9d67992600aa9acc26fa32b2cfcde60056.camel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-12-07 20:19   ` John MacFarlane
       [not found]     ` <yh480kczm82mn9.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  0 siblings, 1 reply; 5+ messages in thread
From: John MacFarlane @ 2021-12-07 20:19 UTC (permalink / raw)
  To: Gregory D. Weber, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw


Since YAML metadata is a markdown extension, you can't include
it in HTML input.

Using an external metadata file is fine, or you can use the
--metadata command line option.

Note that template variables are set automatically from
metadata when present.

"Gregory D. Weber" <spottedmetal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> I'm having trouble with an HTML to HTML conversion using a template and YAML
> metadata block.  Pandoc does not seem to recognize the YAML block in the HTML
> input file, and then reports an error due to the missing $title$ variable.  If
> the error is mine, I'd like to know what I did wrong here:
>
> $ pandoc --version
> pandoc 2.5
> Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
> ......
>
> $ pandoc --template=template.html -o output.html input.html
> [WARNING] This document format requires a nonempty <title> element.
>   Please specify either 'title' or 'pagetitle' in the metadata,
>   e.g. by using --metadata pagetitle="..." on the command line.
>   Falling back to 'input'
>
> A.  These are my files:
>
> 1.  template.html
>
> <!DOCTYPE html>
> <html lang="en">
>     <head>
>       <meta charset="UTF-8"/>
>       <title>$title$</title>
>     </head>
>
>     <body>
>       <h1>$title$</h1>
>       <div>$body$</div>
>     </body>
> </html>
>
> 2.  input.html
>
> ---
> title: Hello
> ---
> <form id="form1"
>   <p>Salvete, sodales.</p>
> </form>
>
> 3.  output.html
>
> <!DOCTYPE html>
> <html lang="en">
>     <head>
>       <meta charset="UTF-8"/>
>       <title></title>
>     </head>
>
>     <body>
>       <h1></h1>
>       <div>--- title: Hello ---
> Salvete, sodales.</div>
>     </body>
> </html>
>
> B.  So far, I'm able to work around this by putting the metadata variables in
> their own file, *without* the "---" above and below, and using the --metadata-
> file option.  And this seems to work also for ordinary template variables like
> $speaker$, which are not metadata variables like $title$ -- though I don't
> understand the distinction too clearly:
>
> $ pandoc --template=template.html -o output2.html --metadata-file=input3.yaml
> input2.html
>
> 1.  template.html
>
> <!DOCTYPE html>
> <html lang="en">
>     <head>
>       <meta charset="UTF-8"/>
>       <title>$title$</title>
>     </head>
>
>     <body>
>       <h1>$title$</h1>
>       <div>Dixit $speaker$: $body$</div>
>     </body>
> </html>
>
> 1.  input3.html
>
> <form id="form1"
>   <p>Salvete, sodales.</p>
> </form>
>
> 2.  input3.yaml
>
> title: Hello
> speaker: Marcus
>
> 3.  output2.html
>
> <!DOCTYPE html>
> <html lang="en">
>     <head>
>       <meta charset="UTF-8"/>
>       <title>Hello</title>
>     </head>
>
>     <body>
>       <h1>Hello</h1>
>       <div>Dixit Marcus: Salvete, sodales.</div>
>     </body>
> </html>
>
> (This is the desired and actual output.)
>
>
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/91104b9d67992600aa9acc26fa32b2cfcde60056.camel%40gmail.com.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: YAML metadata block + HTML input file
       [not found]     ` <yh480kczm82mn9.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
@ 2021-12-07 21:02       ` Martin Hepp
       [not found]         ` <76E923B2-4D96-4654-8D11-B5B2A261C21F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
  2021-12-07 23:57       ` Gregory D. Weber
  1 sibling, 1 reply; 5+ messages in thread
From: Martin Hepp @ 2021-12-07 21:02 UTC (permalink / raw)
  To: pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: Gregory D. Weber

[-- Attachment #1: Type: text/plain, Size: 5265 bytes --]

It would be possible, and actually pretty useful, to represent YAML meta-data in HTML, either directly as a JSON dictionary in a script element, or better, as JSON-LD, see

https://json-ld.org/

As for the vocabulary, one could use

https://schema.org/PropertyValue

This would allow round-tripping meta-data at least between HTML and Markdown.

Even better, JSON-LD meta-data from HTML documents (e.g. schema.org markup) could be represented as a YAML header block in Markdown.

If anybody is willing to add respective support to the readers and writers involved, I can offer to craft respective JSON-LD templates and YAML renderings.

Best wishes
Martin


---------------------------------------
martin hepp
www:  http://www.heppnetz.de/
email: mhepp-bdq14YP6qtRg9hUCZPvPmw@public.gmane.org


> Am 07.12.2021 um 21:20 schrieb John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>:
> 
> 
> Since YAML metadata is a markdown extension, you can't include
> it in HTML input.
> 
> Using an external metadata file is fine, or you can use the
> --metadata command line option.
> 
> Note that template variables are set automatically from
> metadata when present.
> 
> "Gregory D. Weber" <spottedmetal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
> 
>> I'm having trouble with an HTML to HTML conversion using a template and YAML
>> metadata block.  Pandoc does not seem to recognize the YAML block in the HTML
>> input file, and then reports an error due to the missing $title$ variable.  If
>> the error is mine, I'd like to know what I did wrong here:
>> 
>> $ pandoc --version
>> pandoc 2.5
>> Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
>> ......
>> 
>> $ pandoc --template=template.html -o output.html input.html
>> [WARNING] This document format requires a nonempty <title> element.
>>  Please specify either 'title' or 'pagetitle' in the metadata,
>>  e.g. by using --metadata pagetitle="..." on the command line.
>>  Falling back to 'input'
>> 
>> A.  These are my files:
>> 
>> 1.  template.html
>> 
>> <!DOCTYPE html>
>> <html lang="en">
>>    <head>
>>      <meta charset="UTF-8"/>
>>      <title>$title$</title>
>>    </head>
>> 
>>    <body>
>>      <h1>$title$</h1>
>>      <div>$body$</div>
>>    </body>
>> </html>
>> 
>> 2.  input.html
>> 
>> ---
>> title: Hello
>> ---
>> <form id="form1"
>>  <p>Salvete, sodales.</p>
>> </form>
>> 
>> 3.  output.html
>> 
>> <!DOCTYPE html>
>> <html lang="en">
>>    <head>
>>      <meta charset="UTF-8"/>
>>      <title></title>
>>    </head>
>> 
>>    <body>
>>      <h1></h1>
>>      <div>--- title: Hello ---
>> Salvete, sodales.</div>
>>    </body>
>> </html>
>> 
>> B.  So far, I'm able to work around this by putting the metadata variables in
>> their own file, *without* the "---" above and below, and using the --metadata-
>> file option.  And this seems to work also for ordinary template variables like
>> $speaker$, which are not metadata variables like $title$ -- though I don't
>> understand the distinction too clearly:
>> 
>> $ pandoc --template=template.html -o output2.html --metadata-file=input3.yaml
>> input2.html
>> 
>> 1.  template.html
>> 
>> <!DOCTYPE html>
>> <html lang="en">
>>    <head>
>>      <meta charset="UTF-8"/>
>>      <title>$title$</title>
>>    </head>
>> 
>>    <body>
>>      <h1>$title$</h1>
>>      <div>Dixit $speaker$: $body$</div>
>>    </body>
>> </html>
>> 
>> 1.  input3.html
>> 
>> <form id="form1"
>>  <p>Salvete, sodales.</p>
>> </form>
>> 
>> 2.  input3.yaml
>> 
>> title: Hello
>> speaker: Marcus
>> 
>> 3.  output2.html
>> 
>> <!DOCTYPE html>
>> <html lang="en">
>>    <head>
>>      <meta charset="UTF-8"/>
>>      <title>Hello</title>
>>    </head>
>> 
>>    <body>
>>      <h1>Hello</h1>
>>      <div>Dixit Marcus: Salvete, sodales.</div>
>>    </body>
>> </html>
>> 
>> (This is the desired and actual output.)
>> 
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/91104b9d67992600aa9acc26fa32b2cfcde60056.camel%40gmail.com.
> 
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/yh480kczm82mn9.fsf%40johnmacfarlane.net.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/76E923B2-4D96-4654-8D11-B5B2A261C21F%40gmail.com.

[-- Attachment #2: Type: text/html, Size: 13060 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: YAML metadata block + HTML input file
       [not found]     ` <yh480kczm82mn9.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
  2021-12-07 21:02       ` Martin Hepp
@ 2021-12-07 23:57       ` Gregory D. Weber
  1 sibling, 0 replies; 5+ messages in thread
From: Gregory D. Weber @ 2021-12-07 23:57 UTC (permalink / raw)
  To: John MacFarlane, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw

On Tue, 2021-12-07 at 12:19 -0800, John MacFarlane wrote:
> Since YAML metadata is a markdown extension, you can't include
> it in HTML input.
> 

Understood, thanks.

I was trying to use HTML source because the file contained <form> and
<canvas> elements, which, when the input file was turned into markdown,
were rendered as formatted code instead of being copied straight through.

However, I've been able to fix this with proper indenting, ```{=html5},
and --from=markdown-smart.

It is working well now, with markdown source files, and I don't need the
extra YAML files!



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: YAML metadata block + HTML input file
       [not found]         ` <76E923B2-4D96-4654-8D11-B5B2A261C21F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
@ 2021-12-08  2:44           ` John MacFarlane
  0 siblings, 0 replies; 5+ messages in thread
From: John MacFarlane @ 2021-12-08  2:44 UTC (permalink / raw)
  To: Martin Hepp, pandoc-discuss-/JYPxA39Uh5TLH3MbocFFw; +Cc: Gregory D. Weber


Easy to do this already.
A template variable `meta-json` gets set in all the writers,
so you just need to put this somewhere in your HTML template.

Martin Hepp <mfhepp-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:

> It would be possible, and actually pretty useful, to represent YAML meta-data in HTML, either directly as a JSON dictionary in a script element, or better, as JSON-LD, see
>
> https://json-ld.org/
>
> As for the vocabulary, one could use
>
> https://schema.org/PropertyValue
>
> This would allow round-tripping meta-data at least between HTML and Markdown.
>
> Even better, JSON-LD meta-data from HTML documents (e.g. schema.org markup) could be represented as a YAML header block in Markdown.
>
> If anybody is willing to add respective support to the readers and writers involved, I can offer to craft respective JSON-LD templates and YAML renderings.
>
> Best wishes
> Martin
>
>
> ---------------------------------------
> martin hepp
> www:  http://www.heppnetz.de/
> email: mhepp-bdq14YP6qtRg9hUCZPvPmw@public.gmane.org
>
>
>> Am 07.12.2021 um 21:20 schrieb John MacFarlane <jgm-TVLZxgkOlNX2fBVCVOL8/A@public.gmane.org>:
>> 
>> 
>> Since YAML metadata is a markdown extension, you can't include
>> it in HTML input.
>> 
>> Using an external metadata file is fine, or you can use the
>> --metadata command line option.
>> 
>> Note that template variables are set automatically from
>> metadata when present.
>> 
>> "Gregory D. Weber" <spottedmetal-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> writes:
>> 
>>> I'm having trouble with an HTML to HTML conversion using a template and YAML
>>> metadata block.  Pandoc does not seem to recognize the YAML block in the HTML
>>> input file, and then reports an error due to the missing $title$ variable.  If
>>> the error is mine, I'd like to know what I did wrong here:
>>> 
>>> $ pandoc --version
>>> pandoc 2.5
>>> Compiled with pandoc-types 1.17.5.4, texmath 0.11.2.2, skylighting 0.7.7
>>> ......
>>> 
>>> $ pandoc --template=template.html -o output.html input.html
>>> [WARNING] This document format requires a nonempty <title> element.
>>>  Please specify either 'title' or 'pagetitle' in the metadata,
>>>  e.g. by using --metadata pagetitle="..." on the command line.
>>>  Falling back to 'input'
>>> 
>>> A.  These are my files:
>>> 
>>> 1.  template.html
>>> 
>>> <!DOCTYPE html>
>>> <html lang="en">
>>>    <head>
>>>      <meta charset="UTF-8"/>
>>>      <title>$title$</title>
>>>    </head>
>>> 
>>>    <body>
>>>      <h1>$title$</h1>
>>>      <div>$body$</div>
>>>    </body>
>>> </html>
>>> 
>>> 2.  input.html
>>> 
>>> ---
>>> title: Hello
>>> ---
>>> <form id="form1"
>>>  <p>Salvete, sodales.</p>
>>> </form>
>>> 
>>> 3.  output.html
>>> 
>>> <!DOCTYPE html>
>>> <html lang="en">
>>>    <head>
>>>      <meta charset="UTF-8"/>
>>>      <title></title>
>>>    </head>
>>> 
>>>    <body>
>>>      <h1></h1>
>>>      <div>--- title: Hello ---
>>> Salvete, sodales.</div>
>>>    </body>
>>> </html>
>>> 
>>> B.  So far, I'm able to work around this by putting the metadata variables in
>>> their own file, *without* the "---" above and below, and using the --metadata-
>>> file option.  And this seems to work also for ordinary template variables like
>>> $speaker$, which are not metadata variables like $title$ -- though I don't
>>> understand the distinction too clearly:
>>> 
>>> $ pandoc --template=template.html -o output2.html --metadata-file=input3.yaml
>>> input2.html
>>> 
>>> 1.  template.html
>>> 
>>> <!DOCTYPE html>
>>> <html lang="en">
>>>    <head>
>>>      <meta charset="UTF-8"/>
>>>      <title>$title$</title>
>>>    </head>
>>> 
>>>    <body>
>>>      <h1>$title$</h1>
>>>      <div>Dixit $speaker$: $body$</div>
>>>    </body>
>>> </html>
>>> 
>>> 1.  input3.html
>>> 
>>> <form id="form1"
>>>  <p>Salvete, sodales.</p>
>>> </form>
>>> 
>>> 2.  input3.yaml
>>> 
>>> title: Hello
>>> speaker: Marcus
>>> 
>>> 3.  output2.html
>>> 
>>> <!DOCTYPE html>
>>> <html lang="en">
>>>    <head>
>>>      <meta charset="UTF-8"/>
>>>      <title>Hello</title>
>>>    </head>
>>> 
>>>    <body>
>>>      <h1>Hello</h1>
>>>      <div>Dixit Marcus: Salvete, sodales.</div>
>>>    </body>
>>> </html>
>>> 
>>> (This is the desired and actual output.)
>>> 
>>> 
>>> -- 
>>> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>>> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>>> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/91104b9d67992600aa9acc26fa32b2cfcde60056.camel%40gmail.com.
>> 
>> -- 
>> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
>> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
>> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/yh480kczm82mn9.fsf%40johnmacfarlane.net.
>
> -- 
> You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
> To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/76E923B2-4D96-4654-8D11-B5B2A261C21F%40gmail.com.

-- 
You received this message because you are subscribed to the Google Groups "pandoc-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pandoc-discuss+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org
To view this discussion on the web visit https://groups.google.com/d/msgid/pandoc-discuss/m2czm7izmj.fsf%40MacBook-Pro-2.hsd1.ca.comcast.net.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-12-08  2:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-07 19:09 YAML metadata block + HTML input file Gregory D. Weber
     [not found] ` <91104b9d67992600aa9acc26fa32b2cfcde60056.camel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-12-07 20:19   ` John MacFarlane
     [not found]     ` <yh480kczm82mn9.fsf-pgq/RBwaQ+zq8tPRBa0AtqxOck334EZe@public.gmane.org>
2021-12-07 21:02       ` Martin Hepp
     [not found]         ` <76E923B2-4D96-4654-8D11-B5B2A261C21F-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2021-12-08  2:44           ` John MacFarlane
2021-12-07 23:57       ` Gregory D. Weber

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 NNTP newsgroup(s).