Open lucemia opened 7 months ago
https://github.com/samuelcolvin/mkdocs-run-
The configuration that makes the code examples runnable in your MkDocs setup is the inclusion of an external JavaScript file specifically designed for making code blocks interactive:
extra_javascript:
- 'extra/fluff.js'
- 'https://samuelcolvin.github.io/mkdocs-run-code/run_code_main.js'
In this part of your MkDocs configuration, the run_code_main.js
script from the URL https://samuelcolvin.github.io/mkdocs-run-code/run_code_main.js
is particularly important. This script is part of the mkdocs-run-code plugin or a similar setup, which enables the functionality to run Python code directly from the MkDocs pages in the browser. This JavaScript file, when included in your MkDocs site, interacts with code blocks (typically within specific HTML elements) to make them interactive, allowing users to execute the code examples shown in your documentation.
Ensure that you have set up everything necessary for the mkdocs-run-code
plugin or the respective tool you're using, as this involves more than just including the JavaScript file. This might include additional setup on the server hosting the documentation or configuring specific options for how the code should be run and displayed. If mkdocs-run-code
is what you're using, you should also ensure that it's properly installed and configured as part of your MkDocs plugins.
from datetime import datetime
from pydantic import BaseModel, PositiveInt
class User(BaseModel):
id: int # (1)!
name: str = 'John Doe' # (2)!
signup_ts: datetime | None # (3)!
tastes: dict[str, PositiveInt] # (4)!
external_data = {
'id': 123,
'signup_ts': '2019-06-01 12:22', # (5)!
'tastes': {
'wine': 9,
b'cheese': 7, # (6)!
'cabbage': '1', # (7)!
},
}
user = User(**external_data) # (8)!
print(user.id) # (9)!
#> 123
print(user.model_dump()) # (10)!
"""
{
'id': 123,
'name': 'John Doe',
'signup_ts': datetime.datetime(2019, 6, 1, 12, 22),
'tastes': {'wine': 9, 'cheese': 7, 'cabbage': 1},
}
"""