Village Pump:Home/Syntax Highlighting ( archived 2009-06-18 ): Difference between revisions

→‎Whitespace: Replaced code and pre blocks with lang blocks. WHITESPACE highlighting works?!
(→‎Whitespace: Replaced code and pre blocks with lang blocks. WHITESPACE highlighting works?!)
Line 146:
==Whitespace==
If anyone ever feels like putting whitespace code on here (unlikely but possible) they may have trouble highlighting it:
<code lang= whitespace><nowiki>
 
</nowiki></codelang>
Taking out the nowiki tags eliminates the code:
<code lang= whitespace>
 
</codelang>
Not sure if that can be fixed or not. --[[User:Mwn3d|Mwn3d]] 18:58, 23 January 2009 (UTC)
 
: I guess it comes from the code removing those superfluous (in other languages) lines at the beginning and end (e.g. instead of the ugly
<lang c>int main()
<pre>
<c>int main()
{
}</clang>
</pre>
: you can write a more reasonable
<prelang c>
<code c>
int main()
{
}
</codelang>
</pre>
: without getting empty lines at the beginning/end.
: Note that in Whitespace, every non-whitespace character is a comment, so you can simply write any non-whitespace stuff at the beginning/end:
<codelang whitespace>
code:
end
</codelang>
: (note that this probably isn't a valid whitespace program; I just randomly added spaces/tabs).
: However, last friday, whitespace got nicely colored (tabs were bright red and spaces bright blue, IIRC). Now it's just white. Looking at the generated HTML, it seems classes "re2" (space) and "re3" (tab) are responsible for whitespace hilighting. Setting the background property for them should re-enable whitespace highlighting. --[[User:Ce|Ce]] 11:57, 26 January 2009 (UTC)
:: I've now found a trick to get Whitespace highlighting without any (visible) text around it: Use the Unicode character U+FEFF (ZERO WIDTH NO-BREAK SPACE) to mark the start/end of the code:
<codelang whitespace>

Line 192 ⟶ 188:

</codelang>
:: Note that U+FEFF renders as absolutely nothing, and is not whitespace as defined by Whitespace (although it ''is'' whitespace according to Unicode), and therefore should be ignored as "comment" by whitespace interpreters (I didn't test that, though). It apparently also isn't considered whitespace by the start/end line removing code, therefore it's not removed. --[[User:Ce|Ce]] 15:22, 26 January 2009 (UTC)
 
: Whitespace hightlighting now works as expected. I updated the code in this section to reflect the new lang tag, and I'm amazed that it works, myself... --[[User:Short Circuit|Short Circuit]] 08:09, 30 January 2009 (UTC)
 
==Another problem with eating whitespace characters==