Sometimes when writing code in a blog post I want to emphasize a couple of lines in particular. Today I found out that Hugo has really nice syntax to do this in a regular markdown code-fence.
I prefer to use code-fences over the
highlight
shortcode for code blocks because I get syntax highlighting of the code within the code-fence in my editor.
Here I am emphasizing line 5
that contains the the print
statement.
import datetime
def main():
current_time = datetime.datetime.now().strftime("%H:%M")
print(f"Hello at {current_time}!")
if __name__ == "__main__":
main()
To do this I included a little extra information as part of my triple-backtick code-fence.
```python {hl_lines=[5]}
import datetime
def main():
current_time = datetime.datetime.now().strftime("%H:%M")
print(f"Hello at {current_time}!")
if __name__ == "__main__":
main()
```
To learn more check out the Hugo syntax highlighting documentation.