[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-source-highlight] Processing escape sequences

From: Lorenzo Bettini
Subject: Re: [Help-source-highlight] Processing escape sequences
Date: Mon, 22 Feb 2010 12:21:48 +0100
User-agent: Thunderbird (X11/20090817)

Dario Teixeira wrote:

I am using the Source-highlight library to perform a fairly straightforward
syntax highlighting task: given a string containing the source-code, and
another with the language definition, I want to return a string with the
highlighted version of source-code expressed in a custom "foobar" outlang.
In pseudo-C++, something like the code below:  (forget optimisations for now)

string highlight (string src, string langdef)
        istringstream in (src);
        ostringstream out;
        SourceHighlight hiliter ("foobar.outlang");
        hiliter.highlight (in, out, langdef);
        return out.str ();

In rough terms, this works.  There is however one big problem: any use of
escaping directives within the "src" (like "\n") is being processed, instead
of being written verbatim into the output string.  Is there any way to turn
off this behaviour?

Thanks in advance!
Best regards,
Dario Teixeira

Dear Dario

I'm not sure I understand what the final result should be, but in the outlang file you can specify some regular expression based translations. For instance, in latex.outlang you have

"_" "$\\_$"
"{" "\\{"
"}" "\\}"
"<" "\\textless{}"
">" "\\textgreater{}"
"&" "\\&"
"\\" "\\textbackslash{}"
"^" "\\textasciicircum{}"
"~" "\\textasciitilde{}"
"\n" " \\\\\n"
" " "\\ "
"\t" "\\ \\ \\ \\ \\ \\ \\ \\ "
"%" "\\%"
"#" "\\#"
"$" "\\$"
"|" "$|$"
"---" "-\\/-\\/-"
"--" "-\\/-"
"\"" "\"{}" # avoids problems with some inputenc

in html_notfixed.outlang

"\n" "<br>\n"
"  " "&nbsp; "
'^ ' "&nbsp;" # a space at the beginning of a line
"\t" "&nbsp; &nbsp; &nbsp; &nbsp; "

so probably you should be able to achieve your goal in your foobar.outlang file.

Please, let me know whether this solves this issue


Lorenzo Bettini, PhD in Computer Science, DI, Univ. Torino
ICQ# lbetto, 16080134     (GNU/Linux User # 158233)

reply via email to

[Prev in Thread] Current Thread [Next in Thread]