Re: Weird Stuff (Markdown, syntax highlighting and Python)

Liste des GroupesRevenir à cl python 
Sujet : Re: Weird Stuff (Markdown, syntax highlighting and Python)
De : PythonList (at) *nospam* DancesWithMice.info (dn)
Groupes : comp.lang.python
Date : 27. May 2024, 21:58:17
Autres entêtes
Organisation : DWM
Message-ID : <mailman.47.1716843512.2909.python-list@python.org>
References : 1 2
User-Agent : Mozilla Thunderbird
With reference to another reply here, the "Weird stuff" came from reading the question, finding it unclear, and only later realising that whereas most people write Markdown-formatted documents for later processing, or perhaps docstrings in Markdown-format for collection by documentation systems; here, the objective appears to be using Python to generate Markdown.
How much have you used Markdown to any serious degree, before attempting this feat?
On 26/05/24 18:28, Gilmeh Serda via Python-list wrote:
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:
There are so many "variants", the problem is not "minor"!
Markdown users learn to use their tool (again, see @Grant's question) and work within the implementation of that "variant".
Like any other non-standardised tool, the users of some particular 'version' often fail to realise that others using different versions may not enjoy the same experience. Plus-one for standardisation!
At the end of the message, the web.refs reveal use of a package which is based upon a variant of Markdown that is 20-years old(!), albeit with some updates to suit yet another variant. Neither variant-author famous for collaboration. The phrase YMMV springs to mind...
Some ten years ago, an effort was made to standardise Markup, and it ended-up being called CommonMark. Why is it not called "Standard Markdown" one might ask? Because the fellow who 'invented' Markdown objected. This very objection has likely led directly to your confusions, because the particular PyPi package is based upon that original definition...
Whereas, Markdown 3.6 is the most-recently updated Markdown search-hit on PyPi today, have you tried any of the others (which, ironically, may offer more recent and/or more standardised coverage)?
This has worked in all of the Markdown processors I have used or tried-out:
The (?reasonable) 'common-core', offers single back-ticks for code, triple back-ticks for a code-block, and the latter with or without a language specification which *usually* kicks-in syntax highlighting.

```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).
It's not Python 3 that is the problem. It is the "Markdown 3.6" package!

If instead I type it:
I've not seen the hash-bang combination in-the-wild (but YMMV!)

     #!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.
An indented-block is NOT necessarily the same as a code-block - just as "code" is not necessarily "Python".
Line numbers are great - although if a code snippet is extracted from the middle of some example code-file, the original line-numbers won't line-up with Markdown's...

N.b. if you don't know, you also need to generate a css file using
pygments to make this work.
That's not what the package's docs suggest: https://python-markdown.github.io/extensions/fenced_code_blocks/

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.
Again, heavily dependent upon the tool in-use. For example, most SSGs and doc-tools (which accept Markdown) have a .css or theming-system which enables 'decorations'.

References:
https://pypi.org/project/Markdown/
https://python-markdown.github.io/
Further reading:
https://en.wikipedia.org/wiki/Markdown
https://commonmark.org
https://pypi.org/search/?q=markdown
--
Regards,
=dn

Date Sujet#  Auteur
27 May 24 o Re: Weird Stuff (Markdown, syntax highlighting and Python)1dn

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal