Skip to content

Single-line comments in C# carry over to the next line #22

@simon-nicalis

Description

@simon-nicalis
  • Create a new text page with syntaxhighlighter enabled
  • Paste the following text using CTRL + Shift + V:
```lang:cs;;private void Function()
{
    int number = 10; // Single-line comment
    string str = "Hello";
}```

Observe the single-line comment highlight carries over to the next line and in fact never ends.
The same thing happens when you insert <br> tag using Shift + Enter
It looks like highlight.js cannot deal with <br> tags, and expects \n character to end a line.

I was able to fix this locally with the following code_replace function in filter.php:

    private function code_replace($mgrp) {
        return
            '<pre><code' . ($mgrp[2] ? ' class="lang-' . $mgrp[3] .'"' : '') . '>' .
                str_replace(['<p>', '</p>', '<br>'], ['', "\n", "\n"], $mgrp[4]) .
            '</code></pre>';
    }

Here is a screenshot of the issue:
image

Here is the text in Atto editor:
image

Here is the generated markup in Atto editor:
image

Why would I use CTRL + Shift + V to insert text? Because if I just use CTRL + V, depending on where I copied the text from it will include additional markup like extra <pre> tags, colors, etc. and I just want to insert the text.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions