sharpchi / moodle-filter_syntaxhighlighter

14 stars 10 forks source link

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

Open simon-nicalis opened 1 year ago

simon-nicalis commented 1 year ago

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.

oncer commented 1 year ago

@sharpchi is this repository still actively maintained? Considering there was no response to this PR, and the last commit was more than a year ago.