Create a static site generator from scratch. Translating Markdown text to HTML for webpage rendering.
A static site generator takes raw content files (like Markdown and images) and turns them into a static website (a mix of HTML and CSS files).
-
Markdown Parsing:
- Converts Markdown text into structured blocks (e.g., paragraphs, headings, lists, and code blocks).
- Supports inline formatting such as bold, italic, code, links, and images.
-
HTML Node Generation:
- Converts parsed Markdown into HTML nodes using
HTMLNode,LeafNode, andParentNodeclasses. - Supports attributes like
hreffor links andsrc/altfor images.
- Converts parsed Markdown into HTML nodes using
-
Text Node Splitting:
- Splits text into
TextNodeobjects based on Markdown syntax. - Handles nested formatting (e.g., bold and italic within the same text).
- Splits text into
-
Image and Link Extraction:
- Extracts images and links from Markdown text using regex-based utilities.
-
Testing:
- Comprehensive unit tests for all major components:
- Markdown block splitting (
splitblocks.py). - Text node splitting and formatting (
splitnode.py). - HTML node generation (
htmlnode.py). - Markdown image and link extraction (
extract_markdown.py).
- Markdown block splitting (
- Tests ensure proper handling of edge cases, malformed Markdown, and nested structures.
- Comprehensive unit tests for all major components:
To execute the main script:
main.shTo run all unit tests:
test.sh- Lint check with Ruff: Run
ruff check src/to check lint the code.
Reference: ruff linter
- Formatting with Ruff: Run
ruff format src/orruff check src/ --fixto run code formatting.
Reference: ruff formatter
- Note: pyproject.toml is a legacy file that defines the rules for linting and formatting inside src/ for black, isort, and some initial ruff configuration
- The ruff.toml is mostly the default settings except for the linelength is adjusted 120.
The project uses GitHub Actions to:
- Run tests with pytest.
- Perform linting with Ruff.
- Check code formatting with Black.