Home / Companies / HuggingFace / Blog / Post Details
Content Deep Dive

From doctest to runnable Markdown

Blog post from HuggingFace

Post Details
Company
Date Published
Author
Tarek Ziadé
Word Count
1,460
Language
-
Hacker News Points
-
Summary

Python's principle that documentation examples should be executable has evolved with the introduction of runnable code blocks in Markdown by Hugging Face. This feature, incorporated into the doc-builder project, allows examples to function as both documentation and tests without needing separate formats. Historically, Python's doctest enabled examples in documentation to double as regression tests, but it became cumbersome as projects grew due to the need for setup, teardown, and complex assertions within examples. In contrast, Hugging Face's approach treats Markdown snippets as standard Python code, which integrates seamlessly with pytest, enabling examples to be tested automatically while keeping documentation clean and readable. This modern method maintains the integrity of documentation by ensuring examples remain valid and functional, which is particularly valuable for large projects with extensive documentation and code examples, such as the Transformers library. The feature aims to prevent documentation drift and ensure examples are reliable by continuously testing them, aligning with the original objective of executable documentation.