Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to convert code block with python syntax highlighting #24

Open
elinxie opened this issue Feb 5, 2021 · 3 comments
Open

Trying to convert code block with python syntax highlighting #24

elinxie opened this issue Feb 5, 2021 · 3 comments
Assignees
Labels
followed-up To mark issues that are awaiting follow up.

Comments

@elinxie
Copy link

elinxie commented Feb 5, 2021

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
Copy link
Author

elinxie commented Feb 5, 2021

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
Copy link
Owner

I'll be looking into this next

@CrossNox CrossNox self-assigned this Jun 24, 2021
@CrossNox
Copy link
Owner

@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?

@CrossNox CrossNox added the followed-up To mark issues that are awaiting follow up. label Jun 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
followed-up To mark issues that are awaiting follow up.
Projects
None yet
Development

No branches or pull requests

2 participants