Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 106 additions & 2 deletions content/components/code.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class HelloWorld {

## Names

You can add more text after the programming language to set the name of your code example. The text can be anything as long as its all in one line.
Add a title after the programming language to set the name of your code example. The text can be anything as long as its all in one line.

```javascript Code Block Example
const hello = "world";
Expand All @@ -68,7 +68,7 @@ const hello = "world";

## Line Highlighting

You can highlight specific lines in your code blocks by adding a special comment after the language identifier. Use curly braces `{}` and specify line numbers or ranges separated by commas.
Highlight specific lines in your code blocks by adding a special comment after the language identifier. Use curly braces `{}` and specify line numbers or ranges separated by commas.

```javascript Line Highlighting Example {1,3-5}
const greeting = "Hello, World!";
Expand All @@ -88,6 +88,110 @@ sayHello();
```
````

## Expandable

If you have a long code block and `[expandable]` after your title to make it close and expand.

```python library.py [expandable]
from datetime import datetime, timedelta
from typing import Dict, List, Optional
from dataclasses import dataclass

@dataclass
class Book:
title: str
author: str
isbn: str
checked_out: bool = False
due_date: Optional[datetime] = None

class Library:
def __init__(self):
self.books: Dict[str, Book] = {}
self.checkouts: Dict[str, List[str]] = {} # patron -> list of ISBNs

def add_book(self, book: Book) -> None:
if book.isbn in self.books:
raise ValueError(f"Book with ISBN {book.isbn} already exists")
self.books[book.isbn] = book

def checkout_book(self, isbn: str, patron: str, days: int = 14) -> None:
if patron not in self.checkouts:
self.checkouts[patron] = []

book = self.books.get(isbn)
if not book:
raise ValueError("Book not found")

if book.checked_out:
raise ValueError("Book is already checked out")

if len(self.checkouts[patron]) >= 3:
raise ValueError("Patron has reached checkout limit")

book.checked_out = True
book.due_date = datetime.now() + timedelta(days=days)
self.checkouts[patron].append(isbn)

def return_book(self, isbn: str) -> float:
book = self.books.get(isbn)
if not book or not book.checked_out:
raise ValueError("Book not found or not checked out")

late_fee = 0.0
if datetime.now() > book.due_date:
days_late = (datetime.now() - book.due_date).days
late_fee = days_late * 0.50

book.checked_out = False
book.due_date = None

# Remove from patron's checkouts
for patron, books in self.checkouts.items():
if isbn in books:
books.remove(isbn)
break

return late_fee

def search(self, query: str) -> List[Book]:
query = query.lower()
return [
book for book in self.books.values()
if query in book.title.lower() or query in book.author.lower()
]

def main():
library = Library()

# Add some books
books = [
Book("The Hobbit", "J.R.R. Tolkien", "978-0-261-10295-4"),
Book("1984", "George Orwell", "978-0-452-28423-4"),
]

for book in books:
library.add_book(book)

# Checkout and return example
library.checkout_book("978-0-261-10295-4", "patron123")
late_fee = library.return_book("978-0-261-10295-4")
print(f"Late fee: ${late_fee:.2f}")

if __name__ == "__main__":
main()
```

````md
```javascript Expandable Example [expandable]
const greeting = "Hello, World!";
function sayHello() {
console.log(greeting);
}
sayHello();
```
````

## Code Groups

Want to display multiple code examples in one code box? Check out the Code Group docs:
Expand Down
34 changes: 17 additions & 17 deletions docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,21 @@
{
"group": "Editing",
"icon": "pen-paintbrush",
"pages": ["development", "web-editor"]
},
"settings/global",
{
"group": "Navigation",
"icon": "map",
"pages": [
"development",
"web-editor"
"navigation/overview",
"navigation/pages",
"navigation/divisions",
"navigation/versions",
"navigation/localization",
"navigation/config-upgrade"
]
},
"settings/global",
"settings/navigation",
"migration"
]
},
Expand Down Expand Up @@ -71,12 +79,11 @@
"settings/custom-domain",
"settings/seo",
"settings/broken-links",
"settings/versioning",
"settings/add-members",
"settings/authentication",
"settings/github",
"settings/gitlab",
"settings/ci",
"settings/ci",
"settings/preview-deployments"
]
},
Expand All @@ -86,10 +93,7 @@
{
"group": "Custom Scripts",
"icon": "code",
"pages": [
"advanced/custom/css",
"advanced/custom/js"
]
"pages": ["advanced/custom/css", "advanced/custom/js"]
},
{
"group": "Custom Subdirectory",
Expand Down Expand Up @@ -133,9 +137,7 @@
{
"group": "Extensions",
"icon": "plug",
"pages": [
"advanced/widget/chat"
]
"pages": ["advanced/widget/chat"]
},
{
"group": "REST API",
Expand Down Expand Up @@ -246,9 +248,7 @@
"groups": [
{
"group": "Changelog",
"pages": [
"changelog/overview"
]
"pages": ["changelog/overview"]
}
]
}
Expand Down Expand Up @@ -363,4 +363,4 @@
"publicApiKey": "pk_76a6caa274e800f3ceff0b2bc6b9b9d82ab8"
}
}
}
}
Loading