Code Rendering Test Article
This article tests the rendering of various code blocks in article pages.
Python Example
Here's a Python function that calculates factorial:
PYTHON
1
2
3 """Calculate the factorial of a number."""
4
5
6 == 0:
7 return 1
8
9 return *
10
11 # Test the function
12
13
JavaScript/TypeScript Example
Here's a TypeScript class for a simple counter:
TYPESCRIPT
1
2
12
13 : void
16
17 : number
20
21 : void
24 }
25
26 // Usage example
27 const counter = ;
28 ;
29 counter.;
30 ;
Rust Example
Here's a Rust implementation of a simple struct:
RUST
1
2
6
7
20
21
SQL Example
Here's a SQL query to find the top 5 users by post count:
SQL
1
2 SELECT
3 u.id,
4 u.username,
5 u.email,
6 COUNT(p.id) as post_count
7 FROM
8 users u
9 LEFT JOIN
10 posts p ON u.id = p.user_id
11 WHERE
12 u.created_at >= '2023-01-01'
13 GROUP BY
14 u.id, u.username, u.email
15 ORDER BY
16 post_count DESC
17 LIMIT 5;
Inline Code Examples
You can also use inline code like `console.log("Hello")` or `def hello(): pass`.
Math with Code
Here's a mathematical formula with code:
The formula for compound interest is:
Where:
- A = final amount
- P = principal amount
- r = annual interest rate
- t = time in years
Here's how to implement it in Python:
PYTHON
1
2
3 """Calculate compound interest."""
4 return * **
5
6 # Example: $1000 at 5% interest for 3 years
7 =
8
Conclusion
This article demonstrates that code blocks are properly rendered in articles with syntax highlighting for various programming languages.