sharpchi / moodle-filter_syntaxhighlighter

14 stars 10 forks source link

more robust highlight.js when using Atto editor #7

Closed oncer closed 4 years ago

oncer commented 4 years ago

When inserting code in Atto editor, useless HTML tags like <p></p> or <br> are created, messing with the way highlight.js works. One common problem were single-line comments in C# or C++, where end-of-line was only detected in hljs on a "true" line break \n, but not at the
tag. I'm using a simple javascript (textify.js) to replace the contents of the <code> tag with its text contents, effectively stripping away all HTML tags with their plaintext representation. I've also moved the regex substitution of paragraphs with line-breaks to the Javascript - this is still necessary when e.g. line-height is large enough so a paragraph stop is converted to two instead of one line-break line in the text representation.

I've also updated highlight.js itself with a more recent version.

oncer commented 4 years ago

I suggest to use this instead, it turned out to be a better approach: https://github.com/sharpchi/moodle-filter_syntaxhighlighter/pull/8