| Conditions | 6 | 
| Total Lines | 35 | 
| Code Lines | 19 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 0 | ||
| 1 | #!/usr/bin/env python | ||
| 19 | def figure(elem, doc): | ||
| 20 | """ | ||
| 21 | Transform a div element into a figure element. | ||
| 22 | |||
| 23 | Arguments | ||
| 24 | --------- | ||
| 25 | elem | ||
| 26 | The pandoc element | ||
| 27 | doc | ||
| 28 | The pandoc document | ||
| 29 | |||
| 30 | Returns | ||
| 31 | ------- | ||
| 32 | Figure or None. | ||
| 33 | """ | ||
| 34 | if ( | ||
| 35 | doc.api_version >= (1, 23) | ||
| 36 | and isinstance(elem, Div) | ||
| 37 | and "figure" in elem.classes | ||
| 38 | and "caption" in elem.attributes | ||
| 39 | ): | ||
| 40 | try: | ||
| 41 | caption = convert_text(elem.attributes["caption"]) | ||
| 42 | del elem.attributes["caption"] | ||
| 43 |             elem.classes.remove("figure") | ||
| 44 | return Figure( | ||
| 45 | *elem.content, | ||
| 46 | caption=Caption(Plain(*caption[0].content)), | ||
| 47 | identifier=elem.identifier, | ||
| 48 | classes=elem.classes, | ||
| 49 | attributes=elem.attributes, | ||
| 50 | ) | ||
| 51 | except Exception as error: # noqa: B902 | ||
| 52 |             debug(f"[WARNING] pandoc-figure: {error}") | ||
| 53 | return None | ||
| 54 | |||
| 91 |