gjbarnard / moodle-filter_synhi

Syntax highlighter
GNU General Public License v3.0
2 stars 2 forks source link

Using code blocks in Markdown renders <code> block in output #8

Open pmudry opened 1 year ago

pmudry commented 1 year ago

Hi !

When using the Moodle markdown text processor, code blocks are rendered correctly but they include the <code> tag.

Example :

# Test

```scala

// Person.scala
class Person(var lastName: String,
             var firstName: String,
             var age:
             Int, var height: Int = -1) {
}

```

Is rendered as :

image

The problem is probably because the Markdown preprocessor first creates a <pre> tag in which a <code> tag is embedded. I don't know how to solve this however.

Cheers !

gjb2048 commented 1 year ago

No idea how to solve this either.

pmudry commented 1 year ago

I digged a bit into the problem. The HTML output by Moodle from the Markdown is as follows :

<pre><code class="scala">class Car() {
    var color : String = ""
    var maxSpeed : Int = -1
    var model : String = ""

    def getStringRepresentation(): String ={
        s"$model $color, vitesse max $maxSpeed km/h"
    }
}
</code></pre>

I tried modifying toolbox.php line 241 to

'theinit' => "EnlighterJS.init('synhi pre', 'synhi code', {theme: '".$config->enlighterjsstyle."', indent : 4});" 

to

'theinit' => "EnlighterJS.init('synhi pre code.scala', 'synhi code', {theme: '".$config->enlighterjsstyle."', indent : 4});" 

Doing so, the class text is removed properly. However, highlighting is no longer working properly (dark background) and I fear having side-effects. Does this help a bit ?

I would love to help you find a solution but I have no idea how to develop Moodle plugins...

gjb2048 commented 1 year ago

NTS: https://github.com/EnlighterJS/documentation/blob/master/development/Methods_and_API.md#init

gjb2048 commented 1 year ago

@pmudry Sure there is a rule that no 'code' in 'pre', so if so then filter out.

gjb2048 commented 1 year ago

@pmudry Still not sure how to fix this. Is it not the issue with the markdown? Aside from the Moodle code, what is the ideal logic / solution?

gjb2048 commented 1 year ago

@pmudry Humm, what if the 'pre' tag was stripped when combined with a 'code' tag before being highlighted.

gjb2048 commented 1 year ago

@pmudry Please upgrade to the next release 39.1.1 and this should be fixed.