@@ -407,7 +407,7 @@ def get_chapters(doc, options=None, serialize_options=None):
407407
408408 context = ImporterContext (options )
409409
410- def _serialize_chapter (idx , els , is_frontmatter ):
410+ def _serialize_chapter (idx , els , is_frontmatter ):
411411 s = serialize .serialize_elements (doc , els , options = serialize_options )
412412
413413 if s .startswith (six .b ('<div/>' )):
@@ -418,17 +418,29 @@ def _serialize_chapter(idx, els, is_frontmatter):
418418 chapter_title = ''
419419
420420 if not is_frontmatter :
421- if body [0 ].tag in ['h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ]:
421+ if body [0 ].tag in ['h1' , 'h2' , 'h3' , 'h4' , 'h5' , 'h6' ]:
422+ need_classes = True if body [0 ].tag == 'h1' else False
423+
422424 body [0 ].tag = 'h1'
423425 # get text content of first header
424426 chapter_title = body [0 ].text_content ().strip ()
425427 # clears it up and set new content
426428 # this is when we have different html tags in the header
427429 # this also clears attributes
428-
430+
431+ _style = body [0 ].attrib .get ('style' , None )
432+ _class = body [0 ].attrib .get ('class' , None )
433+
429434 body [0 ].clear ()
430435
431436 body [0 ].text = chapter_title
437+
438+ if need_classes :
439+ if _style :
440+ body [0 ].set ('style' , _style )
441+
442+ if _class :
443+ body [0 ].set ('class' , _class )
432444 else :
433445 if idx > 0 :
434446 title = etree .Element ('h1' )
0 commit comments