In this tutorial, we'll use syntax highlighting to make C++ source code more presentable on a web page. We'll use the Free Software program Highlight to perform the syntax highlighting.
Learning Objectives:
- Define syntax highlighting.
- Define secondary notation.
- Explain exactly what Highlight is.
- Explain which operating systems Highlight is available for.
- Explain why one would want to highlight C++ code on a web page.
- Walk through an example of highlighting C++ code with Highlight, and pasting it on a web page.
The LibreOffice Impress-generated HTML slideshow for this lecture is here:
http://djere.com/lectures/node20lecture/Node20.highlighting_cpp_code_wit...
sortProject Source Code Without Syntax Highlighting:
// sortProject.cpp for Highlight Demo
#include
#include
#include
using namespace std;
int main ()
{
string originalString ("1. Charlie Parker");
struct T{
int index;
string fullName;
string fullNameCopy1;
string fullNameCopy2;
string firstName;
string lastName;
};
int a[10];
T saxophonist;
size_t period; // period = the position of the first period in the string
size_t whiteSpace;
period = originalString.find('.',0);
for(int i = 0; i
originalString.erase (originalString.begin());}
saxophonist.fullName = originalString;
saxophonist.fullNameCopy1 = saxophonist.fullName;
saxophonist.fullNameCopy2 = saxophonist.fullName;
whiteSpace = saxophonist.fullNameCopy1.find(' ',0);
for(int j = 0; j
{
saxophonist.fullNameCopy1.erase (saxophonist.fullNameCopy1.begin());
}
saxophonist.lastName = saxophonist.fullNameCopy1;
int firstNameSize = saxophonist.fullName.size() - saxophonist.lastName.size();
saxophonist.fullNameCopy2.erase (firstNameSize, saxophonist.lastName.size());
//lastName = fullNameCopy;
saxophonist.firstName = saxophonist.fullNameCopy2;
cout cout cout
return 0;
}
sortProject Source Code With Syntax Highlighting:
// sortProject.cpp for Highlight Demo #include <iostream> #include <string> #include <vector> using namespace std; int main () { string originalString ("1. Charlie Parker"); struct T{ int index; string fullName; string fullNameCopy1; string fullNameCopy2; string firstName; string lastName; }; int a[10]; T saxophonist; size_t period; // period = the position of the first period in the string size_t whiteSpace; period = originalString.find('.',0); for(int i = 0; i < period+2;i++){ originalString.erase (originalString.begin());} saxophonist.fullName = originalString; saxophonist.fullNameCopy1 = saxophonist.fullName; saxophonist.fullNameCopy2 = saxophonist.fullName; whiteSpace = saxophonist.fullNameCopy1.find(' ',0); for(int j = 0; j < whiteSpace+1;j++) { saxophonist.fullNameCopy1.erase (saxophonist.fullNameCopy1.begin()); } saxophonist.lastName = saxophonist.fullNameCopy1; int firstNameSize = saxophonist.fullName.size() - saxophonist.lastName.size(); saxophonist.fullNameCopy2.erase (firstNameSize, saxophonist.lastName.size()); //lastName = fullNameCopy; saxophonist.firstName = saxophonist.fullNameCopy2; cout << saxophonist.fullName << endl; cout << saxophonist.lastName << endl; cout << saxophonist.firstName << endl; return 0; }