Code Documentation

Code Snippets

In this part, we'll explore how to display code snippets in your presentations using Markdown syntax. Whether you're giving a technical presentation, a code review, or want to share some code examples, Marp and Marpit provide some great tools for displaying code snippets in a clean and readable format.


Basic Syntax

Before we start, it's important to understand the basic syntax for including code in Markdown. To create a code block, indent each line of the code by four spaces or one tab. Alternatively, you can wrap the code in backticks (`) for inline code.

Example

....print("Hello world!");
print("Hello world!");

or

When you use the `print()` function in python ...

When you use the print() function in python ...


Fenced Code Blocks

While the basic syntax works well for small snippets of code, it can quickly become unwieldy for longer blocks. That's where Marp and Marpit come in. Using the backtick (`) or tilde (~) characters, you can create fenced code blocks that preserve the original formatting and highlight the syntax.

```language
code
```

Example:

```csharp
public int Area(int a, int b);
```

img

After the opening backtick or tilde, you can customize this using a code language specifier. For example, you could use javascript for JavaScript code or python for Python code.


Code Samples

```javascript
console.log("Hello World")
```

img

or

```python
def search_products(product_list, search_term):
    return [product for product in product_list if search_term in product['name']]
```

img