@@ -106,32 +106,22 @@ def get_file_soup(self):
106106
107107 def get_chapter_title (self ):
108108 '''
109- Retrieve chapter title based on the text of <h1 > or
109+ Retrieve chapter title based on the text of <title > or
110110 taking a guess from the file name
111111 (i.e. front-cover.xhtml -> "Front Cover")
112112
113113 Special characters in the title are escaped before
114114 the ch_title varible is returned.
115115 '''
116116
117- h1 = self .soup .find_all ('h1' )
118-
119- if len (h1 ) == 1 :
120- ch_title = self .soup .h1 .get_text ()
121-
122- elif len (h1 ) > 1 :
123- print ("[WARNING] {} has multiple h1 tags"
124- .format (self .contents [self .index ]))
125- ch_title = h1 .pop (0 ).get_text ()
117+ title_node = self .soup .title
126118
119+ if (title_node is not None ) and \
120+ (title_node .string is not None ):
121+ ch_title = title_node .string
127122 else :
128- # Strip extension from file name
129- basename = self .contents [self .index ].split ('.' )[0 ]
130-
131- # Replace hypens with spaces (if any)
123+ basename = os .path .splitext (self .contents [self .index ])[0 ]
132124 title_words = basename .replace ('-' , ' ' )
133-
134- # Create a titlecased version of title words
135125 ch_title = title_words .title ()
136126
137127 return html .escape (ch_title )
0 commit comments