I'm trying to embed the Python code into the the blog posts. I have played around the format and found there is no good support in blogger to fulfill this task. After a deep dive, I have found two ways to embed the code snippet in a good format.
One way is to use the HTML format site - http://hilite.me/. Here is a sample Python code to judge if a number is null or not.
# import numpy import numpy as np # function to judge if a number is null def is_null(x): return x != x # test samples is_null(np.nan) is_null(2)
Or you are not comfortable to use HTML, simply copy and paste the code below in the HTML view and modify it in the Compose view.
<!-- HTML --><div style="background: #f0f0f0; overflow:auto;width:auto;border:None gray;border-width:.1em .1em .1em .8em;padding:.2em .6em;"><pre style="margin: 0; line-height: 125%"><span style="color: #60a0b0; font-style: italic"># print</span> <span style="color: #007020; font-weight: bold">print</span>(<span style="color: #4070a0">"All About Python"</span>) </pre></div>
The output of the above embedding.
# modify the code here print("All About Python")
The other way is to use gist - https://gist.github.com/. Here are the steps to create the formatted code in the gist. An example of Python code is showed below.
- Sign up a account with GitHub if you don't have it
- Enter the file name with proper extension. For example, I use isnull.py as the file name
- Copy or type your code
- Select "Create public gist" and click on it. Now the code is ready to share
- Choose "Embed" and Copy the link address and paste in the blog editor in HTML mode.
To add tables to the blog, it's easier to use tableizer to format table in HTML code. It's simply to copy the table from the excel sheet to the tableizer and choose the proper font size, color, and font style. Click on the "Tableize it!" and copy the HTML, and paste it in the HTML view. An example is showed below.
Date | Open | High | Low | Close |
---|---|---|---|---|
10/18/19 | 128.34 | 129.21 | 127.38 | 129.12 |
10/27/19 | 128.21 | 129.39 | 127.1 | 129.31 |
10/26/19 | 127.31 | 128.21 | 127.03 | 128.12 |
10/25/19 | 126.41 | 127.56 | 125.98 | 127.21 |