Files

96 lines
2.2 KiB
Markdown
Raw Permalink Normal View History

2026-05-26 08:39:57 +00:00
# Markdown Code
## Inline Code
For a function or short code snippet within a paragraph, wrap it with backticks (`` ` ``).
**Example:**
`printf()` function
`printf()` function
## Special Character Escaping
**How to display backticks:**
Use double backticks to wrap single backticks:
`` Use `backticks` to wrap code ``
**Rendered result:**
Use `backticks` to wrap code
Use multiple backticks to wrap:
``` ``Code with double backticks`` ```
## Code Blocks
### Indented Code Blocks
A code block can be created with **4 spaces** or one **Tab** at the start of each line.
**Syntax:**
Normal text paragraph
This is an indented code block
Four spaces before each line
Preserves original formatting
Continue normal text
**Important:Indented code blocks require blank lines before and after**
### Fenced Code Blocks (Triple Backticks)
You can also wrap code with `` ``` `` and optionally specify a language.
```python
print("hello world!")
```
## Notes
- Requires 8 spaces indentation when used inside lists.
## Language Identification & Syntax Highlighting
Add a language identifier after triple backticks to enable syntax highlighting.
**Common language identifiers:**
- `javascript` / `js` JavaScript
- `python` / `py` Python
- `html` HTML
- `css` CSS
- `sql` SQL
- `json` JSON
- `xml` XML
- `yaml` / `yml` YAML
- `bash` / `shell` Shell script
- `java` Java
- `cpp` / `c++` C++
- `csharp` / `c#` C#
- `php` PHP
- `ruby` / `rb` Ruby
- `go` Go
- `rust` Rust
- `typescript` / `ts` TypeScript
### Code Diff (Difference Comparison)
Used to show added, deleted, or modified code, common in version control.
**Diff syntax:**
```diff
function calculateTotal(items) {
- let total = 0;
+ let total = 0.0;
for (let item of items) {
- total += item.price;
+ total += parseFloat(item.price);
}
+ // Keep two decimal places
+ total = Math.round(total * 100) / 100;
return total;
}
```
**Git-style diff:**
```diff
@@ -1,5 +1,8 @@
function greetUser(name) {
- console.log("Hello " + name);
+ if (!name) {
+ throw new Error("Name is required");
+ }
+ console.log(`Hello, ${name}!`);
}
```