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

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

Open
pmudry opened this issue Nov 8, 2022 · 7 comments
Open

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

pmudry opened this issue Nov 8, 2022 · 7 comments
Assignees

Comments

@pmudry
Copy link

pmudry commented Nov 8, 2022

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 !

@pmudry pmudry changed the title Using code blocks Markdown renders <code> clock Using code blocks in Markdown renders <code> clock Nov 8, 2022
@pmudry pmudry changed the title Using code blocks in Markdown renders <code> clock Using code blocks in Markdown renders <code> block in output Nov 8, 2022
@gjb2048 gjb2048 self-assigned this Nov 8, 2022
@gjb2048
Copy link
Collaborator

gjb2048 commented Nov 8, 2022

No idea how to solve this either.

@pmudry
Copy link
Author

pmudry commented Nov 8, 2022

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
Copy link
Collaborator

gjb2048 commented Nov 8, 2022

@gjb2048
Copy link
Collaborator

gjb2048 commented Nov 8, 2022

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

@gjb2048
Copy link
Collaborator

gjb2048 commented Mar 12, 2023

@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
Copy link
Collaborator

gjb2048 commented Mar 12, 2023

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

@gjb2048
Copy link
Collaborator

gjb2048 commented Apr 7, 2023

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

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

No branches or pull requests

2 participants