The web claims (I think on all pages I've read about Markdown and
Python) that this code should work, with some very minor variants on the topic:
```python
import os
with open(os.path.join('/home/user/apath', 'somefile')) as f:
print(f.read())
```
I just tried it in a Jupyter notebook. Changed the cell type to
Markdown, pasted the above as its contents, hit shift-enter, and it
looked just like syntax-coloured Python code.
On Sun, 26 May 2024 07:42:14 -0000 (UTC), Lawrence D'Oliveiro wrote:
I just tried it in a Jupyter notebook. Changed the cell type to
Markdown, pasted the above as its contents, hit shift-enter, and it
looked just like syntax-coloured Python code.
I've been trying some more and apparently you also have to indent the backticks and all of the code, which unfortunately makes the backticks visible ...
The web claims (I think on all pages I've read about Markdown and Python) that this code should work, with some very minor variants on the topic:
```python
import os
with open(os.path.join('/home/user/apath', 'somefile')) as f:
print(f.read())
```
However, that is not the case. At least not for me (using Python 3.12.3).
If instead I type it:
#!python
import os
with open(os.path.join('/home/user/apath', 'somefile')) as f:
print(f.read())
As an indented block (four spaces) and a shebang, THEN it works. You even
get line numbers by default.
N.b. if you don't know, you also need to generate a css file using
pygments to make this work.
Not until I started to read the markdown source code and its docs pages,
the coin dropped.
I'm posting this for other Markdown newbies that otherwise probably would spend hours trying to make it work.
Speaking of Markdown. Does anybody out there have any idea how to turn on table borders, adjust them (color/width/etc.) and such things? Currently I have to add HTML to do so, which works, but isn't very nice. I'd hate to spend an additional day or two, hunting for this info.
References:
https://pypi.org/project/Markdown/
https://python-markdown.github.io/
What markdown rendering engine are you using?
'3.6'import markdown, pygments
markdown.__version__
'2.17.2'pygments.__version__
The web claims (I think on all pages I've read about Markdown and Python) that this code should work, with some very minor variants on the topic:
```python
import os
with open(os.path.join('/home/user/apath', 'somefile')) as f:
print(f.read())
```
However, that is not the case. At least not for me (using Python 3.12.3).
If instead I type it:
#!python
import os
with open(os.path.join('/home/user/apath', 'somefile')) as f:
print(f.read())
As an indented block (four spaces) and a shebang, THEN it works. You even
get line numbers by default.
N.b. if you don't know, you also need to generate a css file using
pygments to make this work.
Not until I started to read the markdown source code and its docs pages,
the coin dropped.
I'm posting this for other Markdown newbies that otherwise probably would spend hours trying to make it work.
Speaking of Markdown. Does anybody out there have any idea how to turn on table borders, adjust them (color/width/etc.) and such things? Currently I have to add HTML to do so, which works, but isn't very nice. I'd hate to spend an additional day or two, hunting for this info.
References:
https://pypi.org/project/Markdown/
https://python-markdown.github.io/
Solved by using a different method.
Hedonist for hire... no job too easy!
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (0 / 16) |
Uptime: | 158:31:16 |
Calls: | 10,384 |
Calls today: | 1 |
Files: | 14,056 |
Messages: | 6,416,485 |