class mdfy.elements.code.MdCode(code: str, inline: bool = False, syntax: str = '')[source]

Bases: MdElement

Represents Markdown code or code block.

code

The code string.

Type:

str

inline

Determines if the code should be represented as inline or block.

Type:

bool

syntax

The programming language syntax for the code block.

Type:

str

Examples

>>> code = MdCode("print('Hello World!')", inline=True)
>>> print(code)
`print('Hello World!')`
>>> code = MdCode("print('Hello World!')", inline=False, syntax="python")
>>> print(code)
```python
print('Hello World!')
```
__str__() str[source]

Returns a string representation of the code in Markdown format.

Returns:

String representation of the code.

Return type:

str

Warning

If the code is None, it will log a warning and set the code to an empty string.