Markdown
- Dart course
- Intermediate
- Lesson 108/116
- 5 min
Learn documentation formatting with Markdown.
Markdown
Doc comments support Markdown. Headings use #, bold **, italics * and code blocks ```.
dartdoc converts them to HTML. Example: ## Heading, **important**, `code`. This makes documentation rich and readable.
Use - dashes for lists and single backticks for inline code. Format sparingly, not excessively.
A Markdown example
Markdown inside a doc comment: first line /// # Calculation, a blank line, then /// This function does **fast** addition.
For a code example open a block with three backticks: /// ```dart ... /// ```. dartdoc renders it as syntax-highlighted HTML.
A blank /// line acts as a paragraph break; it improves readability.
Practice A Markdown doc comment
Write int multiply(int a, int b) => a * b;. Add a doc comment above it: first line /// # Multiplication, second line /// **fast** operation.. In main call print(multiply(3, 4)).
Starter code
// Write the multiply function and its markdown doc comment
void main() {
// print the result of multiply(3, 4)
}Sample solution
/// # Multiplication
/// **fast** operation.
int multiply(int a, int b) => a * b;
void main() {
print(multiply(3, 4));
}Expected output
12
Questions and answers
Review the lesson questions together with their answers. To test yourself, solve the lesson interactively.
1 Markdown formats
| Term | Meaning |
|---|---|
# Heading |
Heading |
**bold** |
Bold |
*italic* |
Italic |
`code` |
Code |
2 How is bold text marked in Markdown?
- {bold}
- <<bold>>
- **bold** Correct answer
- //bold//
Explanation: text wrapped in ** becomes bold.
3 Markdown heading
/// ____ Hesaplama
/// # Hesaplama
Explanation: # is a level-one heading.