Skip to content

Commit

Permalink
html2myst: handle admonitions specially.
Browse files Browse the repository at this point in the history
  • Loading branch information
jessicah committed Aug 30, 2024
1 parent 89b1d3d commit de97004
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions html2myst/html2myst.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,22 @@ def process_declaration(self, element):
else:
return nodes.Block(f'{{cpp:function}} {declaration}')

def process_admonition_block(self, container, element):
for child in element.children:
if has_class(child, 'title'):
continue
elif has_class(child, 'graphic'):
container += self.process_admonition_block(container, child)
elif child.name == 'div' and has_class(child, 'text'):
for grandchild in child.children:
container += self.process_block(grandchild)
elif child.name == 'img' and has_class(child, 'icon'):
continue
else:
print(fg.li_red, 'ADMONITION: UNKNOWN BLOCK')
print(child, reset)
continue

# not 100% sure on the return type...
def process_block(self, element):
if element.name == 'p':
Expand All @@ -204,19 +220,8 @@ def process_block(self, element):
kind = ''.join([cls for cls in element['class'] if cls != 'admonition'])

admonition = nodes.BlockContainer(f'{{admonition}} {title}\n:class: {kind}')
# what about other children?
for child in element.select(':scope p, :scope pre, :scope div'):
if child.name == 'div':
print(fg.li_yellow, 'Admonition with unknown div child, skipping:', reset)
print(child)
pass
block = self.process_block(child)
admonition += block
for child in element.children:
if child.name == 'p' or child.name == 'pre' or child.name == 'div':
pass
else:
print(fg.li_red, 'Unhandled admonition child type:', fg.li_yellow, child.name, reset)

self.process_admonition_block(admonition, element)
return admonition
if element.name == 'pre':
if has_class(element, 'cpp'):
Expand Down

0 comments on commit de97004

Please sign in to comment.