• Weird Stuff (Markdown, syntax highlighting and Python)

    From Gilmeh Serda@21:1/5 to All on Sun May 26 06:28:51 2024
    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/

    --
    Gilmeh

    "Reality is that which, when you stop believing in it, doesn't go away".
    -- Philip K. Dick

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Gilmeh Serda on Sun May 26 07:42:14 2024
    On Sun, 26 May 2024 06:28:51 GMT, Gilmeh Serda 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:

    ```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.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gilmeh Serda@21:1/5 to Lawrence D'Oliveiro on Sun May 26 08:59:44 2024
    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, which, well, is ugly. Perhaps there is a setting for it
    somewhere, not sure.

    It smells as if JN has code that corrects the behavior, whereas plain
    Python hasn't.

    I think I prefer the other method without the backticks. It's cleaner and
    more to the point of what it does.


    Cheers,
    --
    Gilmeh

    Rule #1: The Boss is always right. Rule #2: If the Boss is wrong, see Rule
    #1.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Lawrence D'Oliveiro@21:1/5 to Gilmeh Serda on Sun May 26 21:01:12 2024
    On Sun, 26 May 2024 08:59:44 GMT, Gilmeh Serda wrote:

    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 ...

    I didn’t need to do that.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dn@21:1/5 to Gilmeh Serda via Python-list on Tue May 28 08:58:17 2024
    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

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gilmeh Serda@21:1/5 to Grant Edwards on Mon May 27 22:47:22 2024
    On Mon, 27 May 2024 14:41:15 -0400 (EDT), Grant Edwards wrote:

    What markdown rendering engine are you using?

    $ python
    Python 3.12.3 (main, Apr 23 2024, 09:16:07) [GCC 13.2.1 20240417] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    import markdown, pygments
    markdown.__version__
    '3.6'
    pygments.__version__
    '2.17.2'

    I've been thinking maybe it's some weird text encoding issue. I can use
    the indented-by-four-spaces-and-a-shebang for now, it's no big deal.

    --
    Gilmeh

    Satellite Safety Tip #14: If you see a bright streak in the sky coming at
    you, duck.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Thomas Passin@21:1/5 to Gilmeh Serda via Python-list on Mon May 27 14:08:55 2024
    On 5/26/2024 2:28 AM, 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:

    ```python

    import os

    with open(os.path.join('/home/user/apath', 'somefile')) as f:
    print(f.read())
    ```

    There are different flavors of Markdown, so that might be a factor so
    far as details of the block are concerned.

    What do you mean by it not "working"? What do you see and what did you
    expect to see? What did you see different when you used the next example?

    How did you generate the output HTML file?

    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/


    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Gilmeh Serda@21:1/5 to All on Tue May 28 18:49:06 2024
    Solved by using a different method.

    --
    Gilmeh

    Hedonist for hire... no job too easy!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From dn@21:1/5 to Gilmeh Serda via Python-list on Thu May 30 09:59:24 2024
    On 29/05/24 06:49, Gilmeh Serda via Python-list wrote:

    Solved by using a different method.

    Hedonist for hire... no job too easy!

    This combination of sig-file and content seems sadly ironic.


    How about CONTRIBUTING to the community by explaining 'the solution' to
    people who may find a similar problem - in the similar manner to the
    various members who have helped YOU, voluntarily (and despite the
    paucity of source-information and response)?

    --
    Regards,
    =dn

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)