PRE tag? August 13, 2007 11:26 PM   Subscribe

Could we get a <pre> tag or something so that example code posted inline doesn't get stripped (or is there something that already works)? I ask because of this.
posted by stavrosthewonderchicken to Feature Requests at 11:26 PM (45 comments total) 1 user marked this as a favorite

Ha! That's ironic as all hell! (And no, I didn't intend that to happen, I used & lt; and & gt; and it interpreted them literally on post but not preview as angle brackets.)
posted by stavrosthewonderchicken at 11:28 PM on August 13, 2007


Oh dear, I broke Metatalk! *runs away*
posted by stavrosthewonderchicken at 11:29 PM on August 13, 2007


Thanks for
breaking the god damn page layout.  I would have to say that all your tag privileges should be removed.
posted by B(oYo)BIES at 11:31 PM on August 13, 2007


I'm against this if it means making it easier to summon the horizontal scrollbar.
posted by Many bubbles at 11:39 PM on August 13, 2007


Weird, though... I would have thought using & lt ; and such would have avoided the problem. <i>italics? </i>
posted by Many bubbles at 11:40 PM on August 13, 2007


Well, see, two things: the input textarea should not have read the & lt;pre& gt; (spaces inserted) as a literal tag in my post. So there's problem number two that just emerged. It works fine for comments, though, obviously: <pre> (using lt/gt).

Problem number one is that if you just try to put sample in a comment (as alse did in AskMe), things are stripped. This is a security thing, and fine.

But trying to use the <pre> tag to wrap the code in the comment doesn't help keep the code intact: the offending bits are still stripped.

I would have to say that all your tag privileges should be removed.

Yeah, good idea. Shoot the messenger is always excellent policy.
posted by stavrosthewonderchicken at 11:45 PM on August 13, 2007


I'm against this if it means making it easier to summon the horizontal scrollbar.

If pre is styled correctly, that won't happen. Thus (in part), my request.
posted by stavrosthewonderchicken at 11:46 PM on August 13, 2007


Well, see, two things: the input textarea should not have read the & lt;pre& gt; (spaces inserted) as a literal tag in my post.

It doesn't, but they are turned into actual angle brackets when your text is returned to you in the textarea on the preview page, because Matt doesn't bother escaping the ampersands like he should. You can avoid this bug if you hit the back button after previewing.
posted by cillit bang at 2:09 AM on August 14, 2007 [2 favorites]


Ah, right, I remember that now. I think that also used to be the case for inthread comments, but was eventually fixed.
posted by stavrosthewonderchicken at 2:45 AM on August 14, 2007


mat, #HTMLEditFormat()# is your friend. Huh. Looks like you do this on MetaTalk. :-)

Also, the solution is the <code> tag and quick little function:
(pseudocode)

while post contains '<code>'
x= pos of '<code>'
y=pos of '</code>'
if y < 1 then y=len(post)
work_start=x+len('<code>';
work_content=substring(post,1,work_start-1)
content_to_escape=substring(post,work_start,y-work_start)
content_to_escape=HTMLEditFormat(content_to_escape)
work_content=work_content & content_to_escape
if y < len(post)br> work_content=work_content & substring(post,y+1,len(post)-(y+1))
end

I'm almost positive that the ending and beginning bits of the substring will have to be fiddled with a bit, but I'm pretty sure this simple code (which if you're still using CF could be a UDF) would escape everything between the <code></code> tags. Unfortuntaely, haven't got time to test this. Heck, I should be in class *right now*. Damn you metafilter!
posted by Deathalicious at 3:10 AM on August 14, 2007


if y < len(post)br> work_content=work_content & substring(post,y+1,len(post)-(y+1))

Woot. Found another bug.
posted by Deathalicious at 3:12 AM on August 14, 2007


Code I entered was
 if y < len(post)
 work_content=work_content & 
I forgot to escape the < to &lt; and it appended a br> tag somehow.
posted by Deathalicious at 3:14 AM on August 14, 2007


1) The right thing to do would be to wrap code in <pre><code> ... </code></pre>, according to the spec.
2) Matt could probably do it all with CSS rules.
3) Deathalicious: "Woot. Found another bug." Since you're allowed to use HTML, not-escaping <s and >s is a mistake, not a bug.
posted by Plutor at 3:51 AM on August 14, 2007


SHITCOCK>

posted by quonsar at 4:04 AM on August 14, 2007


Wow, I just came over here to MeTa to post a request that HTML characters be more intelligently converted in AskMe answers, and here someone has beaten me to the punch. It is exceptionally annoying to have to convert every left and right angle bracket to its HTML entity.
posted by Civil_Disobedient at 4:37 AM on August 14, 2007


See? This is why we can't have nice things.
posted by Smart Dalek at 4:44 AM on August 14, 2007


<falls_down_on_knees_and_begs_for_this_feature>please!&lt/falls...
posted by grumblebee at 5:06 AM on August 14, 2007


So much for that bad joke. Anyway, this has been my number 1 feature request for years. Those of us who code would deeply benefit by being about to display code accurately in askme. Fixing the PRE tag so that it doesn't doublespace would be a great start.
posted by grumblebee at 5:08 AM on August 14, 2007


#include <stdio.h>

int main(int argc, char **argv)
{
for (int i = 0; i < 100; i++)
puts ("Code can be posted just fine with <PRE>");
return 0;
}
posted by Rhomboid at 5:24 AM on August 14, 2007


This has come up before. The conclusion was that if you're so clever that you're posting code to this site, you should be clever enough to figure out how to post it correctly.
posted by smackfu at 5:26 AM on August 14, 2007


Also, using something like pastebin buys you line numbering and syntax highlighting. It would be silly for every site to reimplement this functionality.
posted by Rhomboid at 5:28 AM on August 14, 2007 [1 favorite]


heh. i go away for awhile and come back and nothing's changed. stavros is still running around breaking shit.
posted by lonefrontranger at 5:33 AM on August 14, 2007


The conclusion was that if you're so clever that you're posting code to this site, you should be clever enough to figure out how to post it correctly.

Sorry, but if that were the case (which I don't believe it was) that's just bullshit. There are simple things that are lazily and inconsistently broken that would help people who are trying to help out other people on AskMe to post code snippets, and it's not out of line to suggest that they might be fixed.
posted by stavrosthewonderchicken at 5:34 AM on August 14, 2007


Yeah, rhomboid's got it. I don't know why I supported this stupid idea unecessary drain on Matt's time in the first place.
posted by Plutor at 5:34 AM on August 14, 2007


Plus if you post your problemmatic/non-working code fragment with pastebin then responders can make modifications to your snippet which you can view in 'diff' format on the site.
posted by Rhomboid at 5:42 AM on August 14, 2007


I didn't know about pastebin. Thanks.

I still think PRE without double-spaces would be a good feature here. I doubt it would take long to code.
posted by grumblebee at 5:56 AM on August 14, 2007


I fixed the code in the original question.
posted by jessamyn (staff) at 6:04 AM on August 14, 2007


metafilter.pastebin.com

Some explanatory text on the posting page may be a good idea.
posted by blag at 6:05 AM on August 14, 2007


I fixed the code in the original question.

Thanks, jessamyn.
posted by stavrosthewonderchicken at 6:24 AM on August 14, 2007


metafilter.pastebin.com

Some explanatory text on the posting page may be a good idea.


Some explanatory text right here might be a good idea. I (for one welcome) have no idea whatsoever what that is, or how it solves the problem at hand.
posted by stavrosthewonderchicken at 6:35 AM on August 14, 2007


I guess we were overdue for this again:

May 7, 2004
Sep 7, 2005
March 28, 2006
Oct 31, 2006

And the official last response from mathowie was "You could just post a link to a txt file on your server."
posted by smackfu at 6:46 AM on August 14, 2007


Oops, missed at least one more:
June 29, 2006
posted by smackfu at 6:48 AM on August 14, 2007


And the official last response from mathowie was "You could just post a link to a txt file on your server."

Awesome. Was that before or after Metafilter became Matt's day job?
posted by stavrosthewonderchicken at 7:02 AM on August 14, 2007


</snark>

Actually, let me apologize pre-emptively for 'there are simple things that are lazily and inconsistently broken...' that I said above.

I'm actually not totally certain that allowing code inline can be made simple, security-wise. But the long list of requests for this functionality posted by smackfu (and thank you, even if you were trying to imply that this latest thread is redundant -- I disagree, because if it's possible and not been done, Matt has said in the past that he just forgets to do shit sometimes that has been requested, so this is useful, hopefully) suggests either a) it's hard or b) slack.
posted by stavrosthewonderchicken at 7:10 AM on August 14, 2007


Pastebin!

I was trying to recall one of those code syntax highlight sites.

Here's what I was thinking:

- if you select a technology category for your question, a small note and link to pastebin will show up on the posting page saying if you have any code to share, post it there and link to it.

- if you're reading a question posted in a tech category, the text below the comment form will offer a link to pastebin and suggest you use it if you are sharing code.
posted by mathowie (staff) at 8:01 AM on August 14, 2007 [1 favorite]


and I've never been able to do it because it's hard to do all the necessary HTML escaping within only certain submissions.
posted by mathowie (staff) at 8:03 AM on August 14, 2007


People post code in all sorts of weird places actually, so the pastebin link might need to be a little more ubiquitous than that [schematics &c.] but otherwise it's a great idea. I usually use pasta which has the excellent side effect of posting your code to del.icio.us so you can find it again.
posted by jessamyn (staff) at 8:22 AM on August 14, 2007


The source code is here.
posted by blue_beetle at 9:05 AM on August 14, 2007


pastebin would be hell of hot, Matt.
posted by boo_radley at 9:07 AM on August 14, 2007




We should start a movement to bring back the <xmp> tag. (Seriously. It's incredibly useful.)
posted by Crabby Appleton at 2:13 PM on August 14, 2007


Are we confident that Pastebin is going to be around for a long time? I'm a little concerned about Google searches turning up old ask.me questions with answers that have defunct Pastebin links.

It's a better solution than linking to your own space, though. I think in most cases personal webspace only lasts a few years before someone changes ISPs or whatever.
posted by zixyer at 6:36 PM on August 14, 2007


- if you select a technology category for your question, a small note and link to pastebin will show up on the posting page saying if you have any code to share, post it there and link to it.

- if you're reading a question posted in a tech category, the text below the comment form will offer a link to pastebin and suggest you use it if you are sharing code.
Instead, how about a checkbox on the preferences page that adds a link to pastebin (or equivalent) below each and every comment box? The interface stays consistent, coders get easy access anytime they want to post some code (even if you didn't foresee a reason they'd need to in a given category,) and non-coders never even have to see it. I do share zixyer's concern about the longevity of third-party sites, though.
posted by contraption at 9:42 PM on August 14, 2007


<br> lookit mah tagz: <aitchteemell><br> </aitchteemell>
We should start a movement to bring back the <xmp> tag. (Seriously. It's incredibly useful.)

I was just thinking about that. As seen above, adds br tags for all your linebreaks and my unclosed aitchteemell tag got auto-closed. Poopy.
posted by juv3nal at 3:11 PM on August 15, 2007


Plutor: Deathalicious: "Woot. Found another bug." Since you're allowed to use HTML, not-escaping <s and >s is a mistake, not a bug.
I still think what I found is an error. A lot of people who aren't familiar with tags are still going to use the less than or greater than signs, and
It is clear to see that 3 < 4
You idiot
Should not become
It is clear to see that 3 < 4br>
You idiot
That's not a mistake. That's an error.
posted by Deathalicious at 5:57 PM on August 15, 2007


« Older Has this 1994 Cheney interview been posted?   |   Tag Families Newer »

You are not logged in, either login or create an account to post comments