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

Syntax highlighting with fenced-code-blocks is broken #897

Open
bendavis78 opened this issue Oct 26, 2021 · 2 comments
Open

Syntax highlighting with fenced-code-blocks is broken #897

bendavis78 opened this issue Oct 26, 2021 · 2 comments

Comments

@bendavis78
Copy link

I want the following markdown code to work:

```python
if True:
    print("hello")
```

I've added a custom ASKBOT_MARKDOWN_CLASS to load fenced-code-blocks extension:

import markdown2

class Markdown(markdown2.Markdown):
    def __init__(self, *args, **kwargs):
        extras = kwargs.get('extras', list())
        extras.extend([
            'fenced-code-blocks'
        ])
        kwargs['extras'] = extras
        super().__init__(*args, **kwargs)

When writing the question with the above markdown, it does not show the preview correctly:
image

When I submit the question, it does render correctly on the first load:
image

However, when I refresh the page, the code loses newlines (and the syntax colors are oddly different):
image

@bendavis78
Copy link
Author

bendavis78 commented Oct 26, 2021

After some investigation, I found the following issues:

  1. Askbot is loading middleware askbot.middleware.spaceless.SpacelessMiddleware, which strips all whitespace from the response. This is really not needed, and is destructive, as whitespace sometimes contains valuable information. The source even has a #FIXME: why do we even have this? comment next to it. Removing this fixed the issue of newlines being stripped (you also have to modify askbot/startup_procedures.py to avoid the startup error).
  2. Askbot is doing some front-end syntax highlighting which conflicts with the back-end highlighting. I disabled this by putting the following in my skin template (at the end):
    <script type="text/javascript">
        lanai.highlightSyntax = function(){/* noop */};
    </script>
  3. The front-end preview appears to be rendered by WMD. Ideally, the preview should always reflect what the back-end will render, and should run the markdown through a backend render function in order to render the preview. I haven't found a simple way to do this, but will post here if I find a better solution.

bendavis78 added a commit to BoldIdeaInc/askbot-devel that referenced this issue Oct 26, 2021
@bendavis78
Copy link
Author

I wasn't able to find an easy solution to server-side rendering, but was able to implement it in my own fork: BoldIdeaInc@04e6422

(note: this completely replaces client-side rendering, not sure what other side effects it may have)

I don't plan on submitting a PR for that change, as I think it involves more of a design discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant