Re: Code that contains </code> (easy)
by tye (Sage) on Aug 05, 2003 at 21:23 UTC
|
print "Use </", "code>";
print "Use <\/code>";
print "Use </c$,ode>";
print "Use </"."code>";
my $code="code";
print "Use </$code>";
...
- tye | [reply] [d/l] |
|
|
| [reply] |
|
|
I don't want to change the actual content of the code just so that it displays ok in a Perl Monks writeup! Lets try <pre> tags instead of <code>...
#!/usr/bin/perl
use strict;
print "Put your code in <CODE></CODE> tags!\n";
OK that works, but you have to do something to the tags (at first I used <i></i>, then changed to < at aristotle's suggestion). | [reply] [d/l] [select] |
|
|
| [reply] |
|
|
You don't want to change the code so you prefer to change the < (in the code) to <?? And how is this not changing the code? A smaller change would be to add a \ before the / or the >.
And you aren't bothered that people can't download the code simply any longer? If you end up with even slightly long lines in your code, then others certainly will be bothered by you using PRE tags instead of CODE tags.
- tye
| [reply] [d/l] [select] |
|
|
Re: Code that contains </code>
by jeffa (Bishop) on Aug 06, 2003 at 14:28 UTC
|
Most of the time, i can get away with using <pre> tags
and escaping < like so:
<pre>
#!/usr/bin/perl
use strict;
print "Put your code in <CODE></CODE> tags!\n";
</pre>
This yields:
#!/usr/bin/perl
use strict;
print "Put your code in <CODE></CODE> tags!\n";
It's not an ideal solution, but if your snippet is small
enough, it'll get ya by. ;)
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] [d/l] |
•Re: Code that contains </code>
by merlyn (Sage) on Aug 05, 2003 at 21:42 UTC
|
print "</co</co
de><code>de>";
update:
Or at least, that should have worked, but a /code..code pair inserts extra blank lines for me. Stupid rendering engine. Where do I point at to fix that? The HTML looks like:
<pre><tt class="code"><font size="-1">
print "</co</co
</font></tt></pre>
<tt><font size="-1">de><co</font></tt><pre><tt class="code"><fon
+t size="-1">de>de>";
</font></tt></pre>
so it looks like the Everything2 engine is adding extra newlines inside the PRE element. Bad. I was trying to print:
print "</co</code><code>de>";
-- Randal L. Schwartz, Perl hacker
Be sure to read my standard disclaimer if this is a reply. | [reply] [d/l] [select] |
|
|
so it looks like the Everything2 engine is adding extra newlines inside the PRE element.
What you're seeing is the rather poorly documented behavior of <pre> when there's a newline somewhere between the tags.
No, that's me on crack dust.
| [reply] |
|
|
<pre>line1\nli</pre><pre>ne2\nline3</pre>
or
<p>line1\nli</p><p>ne2\nline3</p>
(where \n is a real newline), the middle close+open don't just disappear:
line1
li ne2
line3
I see two blocks with a blank line between them.
CODE tags where there is a newline in the code become a block. CODE tags that contain no newlines do not become a block. So a close+open is invisible if there are no newlines in either chunk of code. A close+open cannot become invisible for a block unless we special-case it. That would surprise people who expect them to work like other block tags.
- tye | [reply] [d/l] [select] |
|
|
| [reply] |
|
|
Re: Code that contains </code>
by Mr. Muskrat (Canon) on Aug 05, 2003 at 20:41 UTC
|
Simplest answer: Don't use code tags in your code ;-)
It's a little screwy looking but you simply need to break apart the closing code tag.
<code>my $code = '<code></code</code><code>>';</code> results in: my $code = '<code></code>'; exhibits break in multi-line code blocks :(
| [reply] [d/l] [select] |