MCPcopy
hub / github.com/cosmicpython/book / render_images

Function render_images

render-diagrams.py:29–47  ·  view source on GitHub ↗
(chapter_name)

Source from the content-addressed store, hash-verified

27
28
29def render_images(chapter_name):
30 print('Rendering images for', chapter_name)
31 raw_contents = Path(f'{chapter_name}.html').read_text()
32 parsed_html = html.fromstring(raw_contents)
33
34 for image_block in parsed_html.cssselect('.imageblock'):
35 [img] = image_block.cssselect('img')
36 image_id = img.get('src').replace('images/', '').replace('.png', '')
37 print(image_id)
38
39 parent = image_block.getparent()
40 next_sibling_pos = parent.index(image_block) + 1
41 try:
42 next_element = parent[next_sibling_pos]
43 except IndexError:
44 continue
45 if 'image-source' in next_element.classes:
46 code = next_element.cssselect('pre')[0].text
47 render_image(code, image_id)
48
49INCLUDES = [
50 'images/C4_Context.puml',

Callers 1

mainFunction · 0.85

Calls 1

render_imageFunction · 0.85

Tested by

no test coverage detected