|
|
#1 |
|
Junior Member
![]() Posts: 8
Karma: 10
Join Date: Nov 2020
Device: Pocketbook
|
title tag to h1
I have multiple epubs where the chapter titles are only inside the head title tag and nowhere else. Is there an "easy" way to convert or duplicate each title tag into a h1 tag at the beginning of a chapter?
|
|
|
|
|
|
#2 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,446
Karma: 6734148
Join Date: Nov 2009
Device: many
|
Yes, use Sigil's Find and Replace in Regex mode.
Have you ever searched using regular expressions before? The idea is to find all the text between the opening title tag (while capturing the title tag contents) to the end of the opening body tag, then creating a replacement using the full capture with the addition of h1 tag with the captured title value appended. This is also something you can easily do in a Sigil plugin if you know python, too. Last edited by KevinH; 03-16-2026 at 01:20 PM. |
|
|
|
| Advert | |
|
|
|
|
#3 |
|
Junior Member
![]() Posts: 8
Karma: 10
Join Date: Nov 2020
Device: Pocketbook
|
I have not used the regex mode before, but I will give it a try.
|
|
|
|
|
|
#4 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,446
Karma: 6734148
Join Date: Nov 2009
Device: many
|
To help get you started here are some tips:
Mode: Regex Options: Regex Options: Dot All checked Unicode Property checked Find: Code:
<title>([^<]*)</title>(.*<body[^>]*>) Code:
<title>\1</title>\2\n <h1>\1</h1>\n The Replace field tells it to use a title tag whose contents are capture 1 and then after the opening body tag, add a new line and a couple spaces and then create the h1 tag with the proper contents (capture 1). I tested this on the following html code: Code:
<?xml version="1.0" encoding="utf-8"?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops"> <head> <title>This should be heading 1</title> </head> <body> <p>*</p> </body> </html> Code:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:epub="http://www.idpf.org/2007/ops">
<head>
<title>This should be heading 1</title>
</head>
<body>
<h1>This should be heading 1</h1>
<p>*</p>
</body>
</html>
I hope this helps. KevinH Last edited by KevinH; 03-16-2026 at 04:19 PM. |
|
|
|
|
|
#5 |
|
Junior Member
![]() Posts: 8
Karma: 10
Join Date: Nov 2020
Device: Pocketbook
|
This worked like a charm, you really helped me out! Thank you!
|
|
|
|
| Advert | |
|
|
|
|
#6 |
|
Sigil Developer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 9,446
Karma: 6734148
Join Date: Nov 2009
Device: many
|
If you edit epubs often, then taking the time to learn to use regular expressions is well worth it. It is very powerful.
And for things that can't be done by regular expressions, if you know a smattering of python, you can use Python Function Replacement or create your own python Plugin for Sigil. Glad it helped. |
|
|
|
![]() |
| Thread Tools | Search this Thread |
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| <title> tag in the index_split_XXX.html files | meghane_e | Conversion | 3 | 03-25-2019 01:28 PM |
| Title node in Tag Browser | shinyplastic | Library Management | 6 | 02-24-2018 11:53 AM |
| What goes in HTML head <title> tag? | jcsalomon | ePub | 5 | 07-12-2016 02:47 PM |
| Metadata tag dc:title overwritten on transfer to Kobo Touch | Npnth | Devices | 3 | 08-31-2012 12:38 PM |
| <Title> Tag | fcoulter | ePub | 5 | 07-30-2010 07:48 PM |