Source Code Highlighting
Posted: Fri Feb 01, 2019 9:08 pm
Hi, I am new to WYSIWYG but been exploring it extensively and it seems excellent so far! I have used a number of different editors in the past.
My only issue is that there appears to be no way of adding a <code> tag and the html object does not quite do the job. Let me explain:
I run a website where I need to have blocks of C++ code. Normally the <pre> and <code> tags work quite well but they do not do syntax highlighting. However there are a few .js scripts available to do it for you, so what I have done:
- Created a Master Page with a file publisher object where I specify the JavaScript files I need plus run a function to parse the code (I am using highlight.js)
- Added an HTML object to a page with <pre><code> before my source code sample and </code></pre> afterwards.
When I preview the above it works well with the code highlighting correctly with Visual Studio colouring - perfect!
So now the next step was to create a resuable method that I could quickly call upon when writing pages e.g. I just want to insert a bit of code at a point. So I created a block from my HTML and can reuse it quite easily BUT here is where the issue is:
The HTML object has a set size to it and this does not correspond to the size of the actual text (the source code). So subsequent page elements can write over the top of the source code text. This is a real pain as for each bit of source code I add I have to manually size the html object to what I should think it is and then keep tweaking it until it is right, a real PITA. The HTML box gives the option to use a div tag for positioning and various other options but none work - what I really need is one that just allows me to insert the html in the position I specify and let the normal htrml flow sort out the positioning however I am away WYSIWG does not work that way.
So I wondered if there is anything else I could try?
My only issue is that there appears to be no way of adding a <code> tag and the html object does not quite do the job. Let me explain:
I run a website where I need to have blocks of C++ code. Normally the <pre> and <code> tags work quite well but they do not do syntax highlighting. However there are a few .js scripts available to do it for you, so what I have done:
- Created a Master Page with a file publisher object where I specify the JavaScript files I need plus run a function to parse the code (I am using highlight.js)
- Added an HTML object to a page with <pre><code> before my source code sample and </code></pre> afterwards.
When I preview the above it works well with the code highlighting correctly with Visual Studio colouring - perfect!
So now the next step was to create a resuable method that I could quickly call upon when writing pages e.g. I just want to insert a bit of code at a point. So I created a block from my HTML and can reuse it quite easily BUT here is where the issue is:
The HTML object has a set size to it and this does not correspond to the size of the actual text (the source code). So subsequent page elements can write over the top of the source code text. This is a real pain as for each bit of source code I add I have to manually size the html object to what I should think it is and then keep tweaking it until it is right, a real PITA. The HTML box gives the option to use a div tag for positioning and various other options but none work - what I really need is one that just allows me to insert the html in the position I specify and let the normal htrml flow sort out the positioning however I am away WYSIWG does not work that way.
So I wondered if there is anything else I could try?