Giter Club home page Giter Club logo

moodle-filter_synhi's Introduction

Introduction

A syntax highlighter filter for Moodle with the choice of either EnlighterJS or SyntaxHighlighter as the 'engine'. The administrator has 'preview' settings to see what the look will be on example code before the saving.

When active, content with a 'code' tag or 'pre code' tags within a course, module or block will be highlighted. Specifically between the Course and Block contexts.

Features

  • Syntax Highlighting.

Screenshots

Example

System administration

Highlight preview

Usage

Prior to version 39.1.0, the 'pre' tag was accepted on its own for code to be highlighted. This proved problematic with the need to have non-code preformatted but not highlighted. To highlight code now, please use the 'code' tag, and surround with a 'pre' tag to indicate a block of code. With 'EnlighterJS', using a 'code' tag on its own indicates 'inline' code. 'SyntaxHighlighter' will highlight the code in a block regardless of if there is an enclosing 'pre' tag.

Please add any configuration attributes to the 'code' tag. Such as 'EnlighterJS - HTML Attribute Options (local)' or for SyntaxHighlighter, please look at the information on the settings page.

For example

Single line

<code data-enlighter-language="java" class="brush: java">System.out.println("SynHi");</code>

Muiltiple lines

<pre><code data-enlighter-language="java" class="brush: java">
   package test;

   public class Test {
      private final String name = "Java program";

      public static void main (String args[]) {
         Test us = new Test();
         System.out.println(us.getName());
      }

      public String getName() {
         return name;
      }
   }
</code></pre>

Free Software

The SynHi filter is 'free' software under the terms of the GNU GPLv3 License, please see 'COPYING.txt'. It contains third party 'highlighers' which are licensed differenty, see 'Highlighters'.

It can be obtained for free from:

You have all the rights granted to you by the GPLv3 license. If you are unsure about anything, then the FAQ - www.gnu.org/licenses/gpl-faq.html - is a good place to look.

If you reuse any of the code then I kindly ask that you make reference to the filter.

If you make improvements or bug fixes then I would appreciate if you would send them back to me by forking from https://github.com/gjbarnard/moodle-filter_synhi and doing a 'Pull Request' so that the rest of the Moodle community benefits.

Highlighters

Support

As SynHi is licensed under the GNU GPLv3 License it comes with NO support. If you would like support from me then I'm happy to provide it for a fee (please see my contact details above). Otherwise, the 'General plugins' forum is an excellent place to ask questions.

Sponsorships

If you'd like to sponsor, get support or fund improvements, then please do get in touch via:

Required version of Moodle

This version works with:

  • Moodle 3.9 version 2020061500.00 (Build: 20200615) and above within the 3.9 branch.
  • Moodle 3.10 version 2020110900.00 (Build: 20201109) and above within the 3.10 branch.
  • Moodle 3.11 version 2021051700.00 (Build: 20210517) and above within the 3.11 branch.
  • Moodle 4.0 version 2022041900.00 (Build: 20220419) and above within the 4.0 branch.
  • Moodle 4.1 version 2022112800.00 (Build: 20221128) and above within the 4.1 branch.
  • Moodle 4.2 version 2023042400.00 (Build: 20230424) and above within the 4.2 branch.
  • Moodle 4.3 version 2023100900.00 (Build: 20231009) and above within the 4.3 branch.

Installing Moodle links

Please ensure that your hardware and software complies with 'Requirements' in 'Installing Moodle' on:

Installation

  1. Ensure you have the version of Moodle as stated above in 'Required version of Moodle'. This is essential as the filter relies on underlying core code that is out of my control.
  2. Login as an administrator and put Moodle in 'Maintenance Mode' so that there are no users using it bar you as the administrator.
  3. Copy the extracted 'synhi' folder to the '/filter/' folder.
  4. Go to 'Site administration' -> 'Notifications' and follow standard the 'plugin' update notification.
  5. Put Moodle out of Maintenance Mode.

Upgrading

  1. Ensure you have the version of Moodle as stated above in 'Required version of Moodle'. This is essential as the filter relies on underlying core code that is out of my control.
  2. Login as an administrator and put Moodle in 'Maintenance Mode' so that there are no users using it bar you as the administrator.
  3. Make a backup of your old 'synhi' folder in '/filter/' and then delete the folder.
  4. Copy the replacement extracted 'synhi' folder to the '/filter/' folder.
  5. Go to 'Site administration' -> 'Notifications' and follow standard the 'plugin' update notification.
  6. If automatic 'Purge all caches' appears not to work by lack of display etc. then perform a manual 'Purge all caches' under 'Home -> Site administration -> Development -> Purge all caches'.
  7. Put Moodle out of Maintenance Mode.

Uninstallation

  1. Put Moodle in 'Maintenance Mode' so that there are no users using it bar you as the administrator.
  2. Go to Site administration -> Plugins -> Filters -> Manage filters.
  3. Click on 'Uninstall' and follow the on screen instructions.
  4. Put Moodle out of Maintenance Mode.

Reporting Issues

Before reporting an issue, please ensure that you are running the current version for your release of Moodle. It is essential that you are operating the required version of Moodle as stated at the top - this is because the filter relies on core functionality that is out of its control.

I operate a policy that I will fix all genuine issues for free. Improvements are at my discretion. I am happy to make bespoke customisations / improvements for a negotiated fee.

It is essential that you provide as much information as possible, the critical information being the contents of the filter's version.php file. Other version information such as specific Moodle version, theme name and version also helps. A screen shot can be really useful in visualising the issue along with any files you consider to be relevant.

Report issues on: https://github.com/gjbarnard/moodle-filter_synhi/issues

Version Information

See Changes.md

Refs

iframe resize: https://stackoverflow.com/questions/9975810/make-iframe-automatically-adjust-height-according-to-the-contents-without-using

Developed and maintained by

G J Barnard MSc. BSc(Hons)(Sndw). MBCS. CEng. CITP. PGCE.

moodle-filter_synhi's People

Contributors

gjb2048 avatar twhitehead avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Forkers

twhitehead sudile

moodle-filter_synhi's Issues

The EnlighterJS engine turns inline elements to block elements

Noticed all my inline elements are being turned into block elements by the EnlightnerJS engine as shown in this screenshot from our moodle (clearly I didn't want ssh broken out into its own line each time!)

moodle-issue

From the manual, the first argument passed to the EnlightnerJS.init is a selector for block elements, and the second for inline elements. This plugin calls EnlightnerJS.init with the same pre (block) and code (inline) selector specification for both

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

I expect this is can be resolved by simply only specifying the block elements (pre) for the first and only the inline elements (code) for the second

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

The markup is broken, highlighting will be wrong.

Describe the bug
In the admin settings (/admin/settings.php?section=filter_synhi_settings) the preview is broken and the error message "The markup is broken, highlighting will be wrong." is displayed

To Reproduce
Steps to reproduce the behaviour:

  1. Update to version 39.1.0 (2020073106)
  2. Go to admin settings (/admin/settings.php?section=filter_synhi_settings)

Expected behaviour
a working preview using any engine

Screenshots
image

Versions (please complete the following information):

  • Moodle: 4.1.1 or 3.11
  • Filter: 39.1.0
  • Browser and version: Edge Version 111.0.1661.54 (Official build) (64-bit) on Ubuntu 22.04 LTS

Moodle question type CLOZE is interpreted with SynHi

Using a quiz with the qquestion type CLOZE ((https://docs.moodle.org/400/en/Embedded_Answers_(Cloze)_question_type) with the following code (see example 1 in the link) results in a broken question. The question is interpreted as a source code and is thus highlighted:

Match the following cities with the correct state:
* San Francisco: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Tucson: {1:MULTICHOICE:California#Wrong~%100%Arizona#OK}
* Los Angeles: {1:MULTICHOICE:=California#OK~Arizona#Wrong}
* Phoenix: {1:MULTICHOICE:%0%California#Wrong~=Arizona#OK}
The capital of France is {1:SHORTANSWER:%100%Paris#Congratulations!
~%50%Marseille#No, that is the second largest city in France (after
Paris).~*#Wrong answer. The capital of France is Paris, of course.}.

Instead of this:
cloze_synhi-off

The question gets interpreted as source code
cloze_synhi-on

non latin characters before the code block break highlighting

Describe the bug
using non latin characters such as ä ö ü ß breaks code highlighting

To Reproduce
Steps to reproduce the behaviour:

  1. create label with the following HTML
<h3>Umlaut breaks highlighting</h3>
<p>code highlighting breaks when using non latin characters: ä ü ß ö - each character cuts makes one char of the not to be highlichted code tag appear</p>
<pre><code>
# This is a Python program that calculates the sum of two numbers
num1 = 5
num2 = 10
sum = num1 + num2
print("The sum of", num1, "and", num2, "is:", sum)
</code>
</pre>

The code and pre tag are highlighted as well. The more umlauts you insert, the more characters of the parts after the code are displayed, i.e. the closing tags (code and pre) are highlighted and break the subsequent HTML.

Expected behaviour
The code highlighting should end at "sum)"

Screenshots
image

Versions (please complete the following information):

  • Moodle: 4.1.1 and 3.11
  • Filter: 39.1.0
  • Browser: Edge Version 111.0.1661.54 (Official build) (64-bit) on Ubuntu 22.04 LTS

missing thirdpartylibs.xml

When including an external library in your plugin, you must include a thirdpartylibs.xml file that includes the name, location and license of the library.
More information on this is here:
https://docs.moodle.org/dev/Plugin_files#thirdpartylibs.xml
And here:
https://docs.moodle.org/dev/Plugin_with_third_party_libraries

One of the other advantages of using this is that Moodle's codechecker automatically ignores any files included in the location specificed in the thirdpartylibs.xml file.

Please note - this is typically a blocker for approval in the plugins db.

also - this will also allow you to drop this line in your travis config:
https://github.com/gjb2048/moodle-filter_synhi/blob/master/.travis.yml#L31

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

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 !

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.