Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pandoc does not set <title> despite emitting Defaulting to '<basename>' as the title. #9370

Closed
ThomasSoeiro opened this issue Jan 25, 2024 · 7 comments
Labels

Comments

@ThomasSoeiro
Copy link
Contributor

ThomasSoeiro commented Jan 25, 2024

When writing to a (custom) html template, pandoc does not set <title> despite emitting Defaulting to '<basename>' as the title.

However, I am glad with the current behaviour (i.e. warn that a title is needed + not setting the title + advice on how to set the title using pandoc). I think setting the title automatically would be too invasive (e.g. I want to set the title later using js).

template.html:

<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
      $body$
  </body>
</html>

source file:

echo hello world > test.md

convert to html:

pandoc -f commonmark -t html5 --template=template.html test.md
[WARNING] This document format requires a nonempty <title> element.
  Defaulting to 'test' as the title.
  To specify a title, use 'title' in metadata or --metadata title="...".
<!DOCTYPE html>
<html>
  <head>
    <title></title>
  </head>
  <body>
      <p>hello world</p>
  </body>
</html>
pandoc -v
pandoc 3.1.11.1
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: C:\Users\A141800\AppData\Roaming\pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.
@ThomasSoeiro ThomasSoeiro changed the title pandoc does not set <title> despite emiting Defaulting to '<basename>' as the title. pandoc does not set <title> despite emitting Defaulting to '<basename>' as the title. Jan 25, 2024
@jgm
Copy link
Owner

jgm commented Jan 25, 2024

The default template has this:

  <title>$if(title-prefix)$$title-prefix$ – $endif$$pagetitle$</title>

Do you have something similar in your custom template? You need $pagetitle$ not $title$.

@ThomasSoeiro
Copy link
Contributor Author

ThomasSoeiro commented Jan 25, 2024

I do not want pandoc to set the title, so I do not have $pagetitle$ in my template on purpose. pandoc reports Defaulting to '<basename>' as the title. anyway. I think that this is misleading, hence the report.

However, it works as expected with $pagetitle$:

$ cat template.html 
<!DOCTYPE html>
<html>
  <head>
    <title>$pagetitle$</title>
  </head>
  <body>
      $body$
  </body>
</html>
pandoc -f commonmark -t html5 --template=template.html test.md
[WARNING] This document format requires a nonempty <title> element.
  Defaulting to 'test' as the title.
  To specify a title, use 'title' in metadata or --metadata title="...".
<!DOCTYPE html>
<html>
  <head>
    <title>test</title>
  </head>
  <body>
      <p>hello world</p>
  </body>
</html>

I did not used the same machine (but should not make any difference):

$ pandoc -v
pandoc 3.1.3
Features: -server +lua
Scripting engine: Lua 5.4
User data directory: /home/manon/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

@jgm
Copy link
Owner

jgm commented Jan 26, 2024

It's true that the warning is misleading if you're not using a template that uses pagetitle. But currently pandoc doesn't have information about which variables a template includes, so there isn't a way to check.

It could be interesting to expose a function in jgm/doctemplates that would return a list of the variables in a template. (This would be trivial to write.) We could then check to see if the template contains pagetitle before emitting the warning.

@ThomasSoeiro
Copy link
Contributor Author

I have just noticed that we get a warning even if the <title> element is defined in the template. Perhaps this should be fixed as well?

template.html:

<!DOCTYPE html>
<html>
  <head>
    <title>The title is set!</title>
  </head>
  <body>
      $body$
  </body>
</html>

source file:

echo hello world > test.md

convert to html:

pandoc -f commonmark -t html5 --template=template.html test.md
[WARNING] This document format requires a nonempty <title> element.
  Defaulting to 'test' as the title.
  To specify a title, use 'title' in metadata or --metadata title="...".
<!DOCTYPE html>
<html>
  <head>
    <title>The title is set!</title>
  </head>
  <body>
      <p>hello world</p>
  </body>
</html>
pandoc -v
pandoc.exe 3.4
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: C:\Users\A141800\AppData\Roaming\pandoc
Copyright (C) 2006-2024 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

@jgm
Copy link
Owner

jgm commented Sep 13, 2024

We would have to read and parse the template on every invocation. Not worth it, in my opinion (performance price for every use just to deal with this one unusual use). Just add a pagetitle to avoid the warning?

EDIT: checking the template for the presence of a pagetitle variable, as suggested above, would also help with this. That is why I am keeping this issue open, but it would need work in doctemplates.

@ThomasSoeiro
Copy link
Contributor Author

We would have to read and parse the template on every invocation. Not worth it, in my opinion (performance price for every use just to deal with this one unusual use). Just add a pagetitle to avoid the warning?

I understand that it is not worth it. Yet, I do not want to add a variable that I do not need to silence a warning. Perhaps the warning could be reworded (e.g. state that it does not apply if <title> is already set).

EDIT: checking the template for the presence of a pagetitle variable, as suggested above, would also help with this. That is why I am keeping this issue open, but it would need work in doctemplates.

Glad to hear that, but unfortunately I am not able to help...

Thanks!

@jgm
Copy link
Owner

jgm commented Sep 13, 2024

The change to doctemplates should be easy; I'll make a note to work on that.

@jgm jgm closed this as completed in 8c14784 Sep 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants