'Change font size and make text bolder in IPython.display Markdwon in JupyterLab notebook
Initially I have added heading to my JupyterLab Notebook using markdown cell:
<h1><center>For April 2021</center></h1>
then to make the date change dynamically I used Ipython.display Markdown:
m=Markdown("For {}".format(current_date))
m
For April 2021
I want to make the output look like markdown cell's output, with larger font and bold text. I got this code from google, but I don't know how to combine it with the the already existing Markdown:
Markdown('<strong>{}</strong><br/>{}'.format(date_value)>)
How to make my output like the headings in markdown cell?
Solution 1:[1]
I tried some modifications, and it worked. it can be done with single markdown object:
Markdown('<h1><center><strong>{}</strong><strong>{}</strong></center></h1>'.format('For ', MainDate))
Solution 2:[2]
This could be further simplified.
If MainDate
is a string:
Markdown(f'<h1><center><strong>For {MainDate}</strong></center></h1>')
If MainDate
is a datetime (%B
- Full Month; %Y
- Full Year):
Markdown(f'<h1><center><strong>For {MainDate.strftime("%B %Y")}</strong></center></h1>')
Full Code:
from IPython.display import Markdown
from datetime import datetime
MainDate=datetime(2021, 4, 1)
Markdown('<h1><center><strong>{}</strong><strong>{}</strong></center></h1>'.format('For ', MainDate))
For 2021-04-01 00:00:00
Markdown(f'<h1><center><strong>For {MainDate}</strong></center></h1>')
For 2021-04-01 00:00:00
Markdown(f'<h1><center><strong>For {MainDate.strftime("%B %Y")}</strong></center></h1>')
For April 2021
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Maleficent |
Solution 2 | Thomas Taylor |