![]() |
#1 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: May 2023
Device: Kindle
|
Detecting tags in header
Hello,
When converting an EPUB to PDF, in the custom "Header Template" section, I would like to use JavaScript in order to show the closest text of a given tag type, say, whatever is the value o the closest <h2>. In order to do that, I tried to enhance the JavaScript example provided in the documentation, for example: <header> ... <div></div> <script> var thisDiv = document.currentScript.parentNode.querySelector("d iv"); var first = document.getElementsByTagName('h2').firstChild[0]; thisDiv.innerHTML = "" + first.innerHTML </script> ... </header> But the problem with that code, is that the DOM has not been evaluated at the time where I try to grab the H2 content. And the normal JavaScript tricks to overcome this problem (adding "defer" or "module" to the <script> tag, or putting it all inside the document's load event), also don't seem to work. So, my question is: Only the predefined variables such as _SECTION_ or _TOP_LEVEL_SECTION_ are available in the header script? Is it not possible to grab the value of the "closest()" text of a specific tag type? |
![]() |
![]() |
![]() |
#2 |
creator of calibre
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 45,345
Karma: 27182818
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
|
Headers and footers are evaluated in dummy HTML files they dont have access to book content. If you want to get title information use _SECTION_
|
![]() |
![]() |
Advert | |
|
![]() |
#3 |
Junior Member
![]() Posts: 5
Karma: 10
Join Date: May 2023
Device: Kindle
|
OK, I understand.
Thanks for the answer. |
![]() |
![]() |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Are too many single-use tags (in tags-like field(s)) bad for Calibre's performance? | 01100001 | Library Management | 10 | 09-21-2022 09:39 AM |
In epub converting calibre auto split file in header. Why not create toc from header. | The_book | Conversion | 7 | 11-06-2020 09:09 AM |
Parsing tags from a bibliographic entry and/or getting tags from Library of Congress | kirk8677 | Library Management | 2 | 05-27-2020 06:48 PM |
How to sync MacOs Finder Tags with Calibre Tags | EmilThelonius | Calibre | 13 | 09-11-2019 12:53 PM |
Amazon Tags - Popular tags vs Unique tags. | chrisanthropic | Writers' Corner | 6 | 09-19-2011 11:18 PM |