Multi-Language Notebook Demo
Multi-Language Notebook Demo
This demonstrates real-world cell-level language detection using VSCode metadata format.
Multi-Language Jupyter Notebook Demo
This notebook demonstrates support for multiple programming languages and raw text cells.
This is a raw cell containing unformatted text.
Raw cells are useful for:
- Documentation fragments
- Configuration snippets
- Plain text notes
- Template content
They are displayed exactly as typed, without any formatting or execution.
Python Example
Let's start with a Python code cell:
# Python code with various features
import numpy as np
import pandas as pd
def fibonacci(n):
"""Generate Fibonacci sequence up to n terms"""
if n <= 0:
return []
elif n == 1:
return [0]
else:
sequence = [0, 1]
for i in range(2, n):
sequence.append(sequence[i-1] + sequence[i-2])
return sequence
# Generate and display Fibonacci sequence
fib_numbers = fibonacci(10)
print(f"First 10 Fibonacci numbers: {fib_numbers}")
print(f"Sum: {sum(fib_numbers)}")
# Create a DataFrame
df = pd.DataFrame({'fibonacci': fib_numbers})
print("\nDataFrame:")
print(df.head())
First 10 Fibonacci numbers: [0, 1, 1, 2, 3, 5, 8, 13, 21, 34]
Sum: 88
DataFrame:
fibonacci
0 0
1 1
2 1
3 2
4 3
JavaScript Example
Here's a JavaScript code cell:
// JavaScript code with modern features
const data = [1, 2, 3, 4, 5];
// Arrow function with array methods
const processData = (arr) => {
return arr
.map(x => x * 2)
.filter(x => x > 5)
.reduce((sum, x) => sum + x, 0);
};
// Async function example
async function fetchData() {
try {
const result = processData(data);
console.log(`Processed result: ${result}`);
return result;
} catch (error) {
console.error('Error processing data:', error);
}
}
// Execute the function
fetchData();
[0;36m Cell [0;32mIn[4], line 1[0;36m[0m [0;31m // JavaScript code with modern features[0m [0m ^[0m [0;31mSyntaxError[0m[0;31m:[0m invalid syntax
Configuration Example:
server:
host: localhost
port: 8080
database:
url: postgresql://user:pass@localhost/db
pool_size: 10
logging:
level: INFO
format: '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
R Example
Statistical analysis with R:
# R code for statistical analysis
library(ggplot2)
# Create sample data
set.seed(42)
data <- data.frame(
x = rnorm(100, mean = 0, sd = 1),
y = rnorm(100, mean = 0, sd = 1)
)
# Calculate correlation
correlation <- cor(data$x, data$y)
cat("Correlation between x and y:", correlation, "\n")
# Summary statistics
summary(data)
# Simple linear model
model <- lm(y ~ x, data = data)
print(summary(model))
SQL Example
Database query example:
-- SQL query example
SELECT
u.id,
u.username,
u.email,
COUNT(p.id) as post_count,
AVG(p.score) as avg_score
FROM users u
LEFT JOIN posts p ON u.id = p.user_id
WHERE u.created_at >= '2023-01-01'
GROUP BY u.id, u.username, u.email
HAVING COUNT(p.id) > 5
ORDER BY avg_score DESC
LIMIT 10;
-- Create index for optimization
CREATE INDEX idx_posts_user_created
ON posts(user_id, created_at);
Summary
This notebook demonstrates:
- Raw cells displayed as code blocks without execution prompts
- Multiple programming languages displaying properly formatted code
- All cell types - code, markdown, and raw cells work correctly
- Authentic Jupyter styling with proper input/output prompts
Raw cells now appear identical to code blocks but without the In [n]: prompt, making them perfect for documentation and configuration examples.
How Cell-Level Languages Work
This notebook demonstrates the following language detection features:
1. VSCode Metadata Format
Individual cells can specify their language using VSCode's metadata format:
"metadata": {
"vscode": {
"languageId": "javascript"
}
}2. Language Indicators
Each cell shows its detected language in the bottom-right corner:
- Raw cells: Always show
raw(regardless of VSCode metadata) - JavaScript cells: Show
javascript(from VSCode metadata) - SQL cells: Show
sql(from VSCode metadata) - Python cells: Show
python(notebook kernel default)
3. Priority Order
The language detection follows this hierarchy:
- VSCode metadata (
cell.metadata.vscode.languageId) - Raw cells always override to show
raw - Other metadata formats (
languageId,language) - Magic commands (
%%javascript,%%bash, etc.) - Notebook kernel language (fallback)
4. No Syntax Highlighting
Note that we show language indicators but don't apply syntax highlighting, keeping the code clean and readable without artificial coloring.