CrossNox / m2r2

Markdown to reStructuredText converter
https://crossnox.github.io/m2r2
MIT License
107 stars 26 forks source link

Trying to convert code block with python syntax highlighting #24

Open elinxie opened 3 years ago

elinxie commented 3 years ago

I am try to convert the following code (sample function, replacing back-ticks with apostrophes )

Markdown

''' python
def sample(args):
    return args[0]
'''

( Other docs here )

to Rst

... code-block:: python
    def sample(args):
        return args[0]

(Other docs here)

But the rst looks like this rst

```python
    def sample(args):
        return args[0]

... code-block:: python
    (Other docs here)

Do you know what is going on? I looked into your code and saw that there is the function block_code that helps convert a markdown code block to a rst code block, and I see that m2r2 supports shell or bash syntax highlighting, but for some reason it's not working with python. Do you know what is going on?

elinxie commented 3 years ago

Actually I found something funny that happens

So with Markdown

''' python
def sample(args):
    return args[0]
'''

( Other docs here )

If I had some text above the code block like below Markdown

(some text here)
''' python
def sample(args):
    return args[0]
'''

Then I get the error I showed rst

(some text here)
```python
def sample(args):
     return args[0]

... code-block:: python
    (Other docs here)

But if I add a space: Markdown

(some text here)

''' python
def sample(args):
    return args[0]
'''

Then I get the correct output rst

(some text here)

... code-block:: python
    def sample(args):
        return args[0]

    (Other docs here)

So I guess m2r2 does support python syntax highlighting however there is this bug with the space. Is this something that should be fixed?

CrossNox commented 3 years ago

I'll be looking into this next

CrossNox commented 3 years ago

@elinxie I jush pushed some tests:

Or you can see the full diff here

Those tests are passing right now, so I'm not sure I have quite understood your problem... would you be able to provide a failing test?