[Mentoring] Code Formatting Blank Screen

When I mentored a few students, I wanted to use highlight.js to add code formatting to my Python code by pasting it into a blank page like this:

<pre><code class="language-python hljs">
[CODE HERE]
</pre></code>

Then I ran the hljs.highlightAll function on the code and pasted the highlighted (by HTML) code back into the mentoring session. The code preview works fine, but after pressing “Send”, the screen went blank. It stayed like this when I refreshed, left, and reentered the page.

How do I solve this issue and should I open this on GitHub?

Console:

Why not use this:

```language
your code here
```

This will end up using highlight.js (as that is what we use on the platform, if I remember correctly) without having to deal with the filtering of the HTML tags that may be going on with the comment processing on the platform.

IIRC (it’s been a minute), the mentoring feedback area uses GitHub Flavored Markdown for codeblocks, not <pre> tags. That means for Python you would do the following (text followed by codeblock):



It is helpful to include a docstring to let others reading your code know what the function intends to do. Suggest something like:

```python

def score(x, y):
  """Score a dart throw given coord_x & coord_y on dart board.
  
  :param x: int or float - position on the x-axis
  :param y: int or float - position on the y-axis
  :return: int - score for the coordinates, given the scoring described below.
  
  Scoring circles:
  Outside radius 10:      0
  Within a radius 5 - 10: 1
  Within a radius 1-5:    5
  Within a radius 0-1:    10
  """
    distance = math.sqrt(x**2 + y**2)
    if distance <= 1:
        result = 10
    elif distance <= 5:
        result = 5
    elif distance <= 10:
        result = 1
    elif distance > 10:
        result = 0
    return result```


Which would then render in the mentoring UI like (screengrab of darkmode on website):

Here’s the relevant bit in the GHFMD docs, and more details here.

Since certain HTML tags are stripped or ignored by the markdown processor, its not clear that using <pre><code> is supported in the mentoring UI.

1 Like

:smile:

You were replying as I was! Thanks for that.

1 Like

What should I do if I wanted to give hints and allow the student to reveal the answer in a details/summary code block?

Also, if I already sent the message, how do I change it because there is a blank screen?

OK, I now realized that works. Because I have always been using the “preview” feature and it never shows the colouring. Should this be a feature request?

<details> tags are allowed:


_Below is something hidden behind a details tag, so that you can look at it when you are ready._


<details>
  <summary>Spoiler warning</summary>
  
  Spoiler text. Note that it's important to have a space after the summary tag. You should be able to write any markdown you want inside the `<details>` tag... just make sure you close `<details>` afterward.
  
  ```python
  print("Hi there! I'm a code block!"); ```
  

</details>


will render as:


Below is something hidden behind a details tag, so that you can look at it when you are ready.

Spoiler warning

Spoiler text. Note that it’s important to have a space after the summary tag. You should be able to write any markdown you want inside the <details> tag… just make sure you close <details> afterward.

print("Hi there! I'm a code block!");


Quick Screengrabs of the UI:

Closed

Open

One or two [returns] between the html tags and any markdown tags tho, or it breaks.

Also, if I already sent the message, how do I change it because there is a blank screen?

You will need to open the session and send another message, and/or edit the one you’ve sent.

Ok, thanks! I think I kept missing the new-lines when I did it!

I can’t open the session because clicking it produces a blank screen, so I can’t edit it.

Did you regain access to the session since you posted this, or is this still an outstanding issue?

1 Like

It’s working. Thank you very much!

(Sorry for the late reply)

1 Like

You can mark the solution as the solution to your question and then this topic will show up as resolved.