Thread: title tag to h1
View Single Post
Old 03-16-2026, 04:16 PM   #4
KevinH
Sigil Developer
KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.KevinH ought to be getting tired of karma fortunes by now.
 
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[^>]*>)
Replace:
Code:
<title>\1</title>\2\n  <h1>\1</h1>\n
The Find field above tells it to select everything from the starting title tag to the end of starting body tag, while capturing the contents of the title tag into the first capture field and everything else into the second capture field.

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>
And after doing a find and replace you end up with the following:

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>
So this or something much like it should do the trick.

I hope this helps.

KevinH

Last edited by KevinH; 03-16-2026 at 04:19 PM.
KevinH is offline   Reply With Quote