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

Content added Content deleted
(→‎Whitespace: Replaced code and pre blocks with lang blocks. WHITESPACE highlighting works?!)
Line 146: Line 146:
==Whitespace==
==Whitespace==
If anyone ever feels like putting whitespace code on here (unlikely but possible) they may have trouble highlighting it:
If anyone ever feels like putting whitespace code on here (unlikely but possible) they may have trouble highlighting it:
<code lang=whitespace><nowiki>
<lang whitespace>


</nowiki></code>
</lang>
Taking out the nowiki tags eliminates the code:
Taking out the nowiki tags eliminates the code:
<code lang=whitespace>
<lang whitespace>


</code>
</lang>
Not sure if that can be fixed or not. --[[User:Mwn3d|Mwn3d]] 18:58, 23 January 2009 (UTC)
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
: 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()
{
{
}</c>
}</lang>
</pre>
: you can write a more reasonable
: you can write a more reasonable
<pre>
<lang c>
<code c>
int main()
int main()
{
{
}
}
</code>
</lang>
</pre>
: without getting empty lines at the beginning/end.
: 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:
: Note that in Whitespace, every non-whitespace character is a comment, so you can simply write any non-whitespace stuff at the beginning/end:
<code whitespace>
<lang whitespace>
code:
code:
end
end
</code>
</lang>
: (note that this probably isn't a valid whitespace program; I just randomly added spaces/tabs).
: (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)
: 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:
:: 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:
<code whitespace>
<lang whitespace>


Line 192: Line 188:


</code>
</lang>
:: 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)
:: 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==
==Another problem with eating whitespace characters==