Pasting formatted code into AskMe response? June 29, 2006 2:49 PM   Subscribe

Is there a way to paste formatted (e.g. indented) code into an AskMe response? If not, could such a feature be added? It would really help out threads like this.
posted by grumblebee to Feature Requests at 2:49 PM (46 comments total)

Hm. I was typing in the blockquote tag...
sort of like this
...if you see what I mean.
posted by Robert Angelo at 2:51 PM on June 29, 2006


You can use the <pre> tags:
 indented text
  at
   different
    levels
But as you can see there is some unflattering spacing going on.

Matt, you ever hunt down why "pre" gets all bloaty?
posted by NinjaTadpole at 2:55 PM on June 29, 2006


Previously requested: "Code feature for ask.mefa?

The answer seems to be, use the <pre> taq with <br> where you want line breaks, instead of just hitting enter.
posted by Chuckles at 2:55 PM on June 29, 2006


Yeah, a bit of thinking would have told me, but I checked the source.
Inside the "pre" the line is split with <br> as well as linebreaks, as it is everywhere else, unfortunately inside this tag it means the spacing is applied twice.

Is this a known bug on the list? Can we help you to sort it out?

posted by NinjaTadpole at 2:58 PM on June 29, 2006


Barring a more elegant solution, you can always use a simple post-processing step to replace your tabs/spaces with &nbsp; characters.

if(foo) {
    //bar time
    bar;
    while(baz) {
        //rothko
    }
}
posted by cortex at 3:02 PM on June 29, 2006


(And pre automatically creates line breaks where you have line breaks, and mefi comments take breaks on line breaks too—it's not a bug so much as a misfeature. And, yeah, if it's not insane to do a conditional check when storing/displaying comments, it'd be nice to see that get fixed.)
posted by cortex at 3:04 PM on June 29, 2006


The worst is posting HTML. Escaping sucks.
posted by smackfu at 3:05 PM on June 29, 2006


See also.
posted by boo_radley at 3:09 PM on June 29, 2006


Is this a known bug on the list?

This is known in the sense that there have been 3 or 4 metatalk posts about it at least. here are some more. I know there are older ones, but I can't find them. (there is no way to search only fpp content, right? It makes it really hard to find stuff like this.) I don't know if they're on any list.
posted by advil at 3:10 PM on June 29, 2006


Actually, yeah, I could ignore the adding br tags inside of pre tags to solve this.
posted by mathowie (staff) at 3:18 PM on June 29, 2006


Yay!
posted by NinjaTadpole at 3:18 PM on June 29, 2006


hot! also how is comment editing coming?
posted by boo_radley at 3:36 PM on June 29, 2006


And how about fixing the link styles for IE in Projects?

...
"are we nearly there yet?"
posted by NinjaTadpole at 3:51 PM on June 29, 2006


I'm busy with a new subsite, that should launch in the next 24 hours.
posted by mathowie (staff) at 4:50 PM on June 29, 2006


!
posted by brundlefly at 5:00 PM on June 29, 2006


I'm busy with a new subsite, that should launch in the next 24 hours.

MetaXXX, for users to upload their grainy homemade porn, I'll wager. That or a jobs board.
posted by jack_mo at 5:02 PM on June 29, 2006


oh shut up!!!
posted by boo_radley at 5:02 PM on June 29, 2006


*prepares classified for "art film" recruiting, just to cover bases*
posted by cortex at 5:03 PM on June 29, 2006


*reads jack_mo's comment as "granny homemade porn," shudders*
posted by brundlefly at 5:04 PM on June 29, 2006


MeDr: Yes, I am a doctor.
posted by boo_radley at 5:10 PM on June 29, 2006


A YouTube for porn!
posted by soundofsuburbia at 5:17 PM on June 29, 2006


Actually, yeah, I could ignore the adding br tags inside of pre tags to solve this.

I think the actual problem is that you're not removing the line break character when you insert a BR tag. You could simply remove them universally, which I'm guessing would be easier than having a special policy for PRE tags.

I'm busy with a new subsite, that should launch in the next 24 hours.

!
posted by cillit bang at 6:28 PM on June 29, 2006


How I prepare code for posting, after long and painful experience:
  • replace all opening HTML brackets with &lt;
  • replace all linebreaks with <br>
  • wrap with <pre> Which should work...
    sub import {    my $pkg = shift;    @_ = @Config::EXPORT unless @_;    my @funcs = grep $_ ne '%Config', @_;    my $export_Config = @funcs < @_ ? 1 : 0;    no strict 'refs';    my $callpkg = caller(0);    foreach my $func (@funcs) {	die sprintf qq{"%s" is not exported by the %s module\n},	    $func, __PACKAGE__ unless $Export_Cache{$func};	*{$callpkg.'::'.$func} = \&{$func};    }    *{"$callpkg\::Config"} = \%Config if $export_Config;    return;}

posted by AmbroseChapel at 6:42 PM on June 29, 2006


So, write a macro for that ... but there are two problems even when you've done that:
  • Preview can still mess it up -- see how I got the &lt; to come out? I had to do that by typing &amp;lt; of course. But if you click the preview button? The &amp; becomes an & and your &lt; turns into an actual < So don't Preview! Or if you do, check the "live" preview below very carefully. This stuff is not fun, even for me, and I play with this kind of code all day long.
  • Once you've done it, your code looks like hell and is impossible to read. So now write a macro that's the reverse of the previous one.
posted by AmbroseChapel at 6:49 PM on June 29, 2006


Going for the triple, but as I said before, I reckon the way they do it at Perlmonks is the best. Their code also wraps really long lines which is another problem with PRE. If not that, could someone write a greasemonkey script/extension?
posted by AmbroseChapel at 6:51 PM on June 29, 2006


The solution I'd really like is having one of those rich HTML editors all around, at least something richer than just bold, italics & link. It's a pain to have to manually code blockquote, bullets, etc.
posted by scalefree at 7:25 PM on June 29, 2006


screw the indents. bring on the metapr0nz.
posted by ninjew at 7:29 PM on June 29, 2006


I'm busy with a new subsite, that should launch in the next 24 hours.
Prepares recipes.
posted by tellurian at 7:29 PM on June 29, 2006


I hope it's something that keeps track of my credit card number. That's what Meta's missing.
posted by graventy at 8:00 PM on June 29, 2006


fights crime!
posted by boo_radley at 9:03 PM on June 29, 2006


The answer is in my favorites. It's about 80% done, hopefully hitting 100% by tomorrow morn.
posted by mathowie (staff) at 10:00 PM on June 29, 2006


music?
posted by puke & cry at 10:06 PM on June 29, 2006


Well, he's got a bunch of stuff about parenting and investing favorited. Thus the new project must be a site for people who make large amounts of money trading babies and young children on the black market.
posted by Rhomboid at 10:12 PM on June 29, 2006


*cough*
posted by carsonb at 10:13 PM on June 29, 2006


!!!!!
posted by carsonb at 10:13 PM on June 29, 2006


Jinkies.
posted by cillit bang at 10:20 PM on June 29, 2006


it's the RIAA on the line.... FOR YOU
posted by Rhomboid at 10:24 PM on June 29, 2006


Matt are you made from malaria because I am delerious with happiness over here.
posted by cortex at 10:44 PM on June 29, 2006



sub import {
my $pkg = shift;
@_ = @Config::EXPORT unless @_;

my @funcs = grep $_ ne '%Config', @_;
my $export_Config = @funcs < @_ ? 1 : 0;br>
no strict 'refs';
my $callpkg = caller(0);
foreach my $func (@funcs) {
die sprintf qq{"%s" is not exported by the %s module\n},
$func, __PACKAGE__ unless $Export_Cache{$func};
*{$callpkg.'::'.$func} = \&{$func};
}

*{"$callpkg\::Config"} = \%Config if $export_Config;
return;
}

I've always used the <code> tags, but I can see now that they don't preserve tabs. Odd. Never noticed that before...
posted by unixrat at 10:49 PM on June 29, 2006




*faints*
posted by brundlefly at 11:17 PM on June 29, 2006


Is this where I say it should have a different colour scheme than AskMe?
posted by ninjew at 11:58 PM on June 29, 2006


reload your CSS. it's almost black now.
posted by mathowie (staff) at 11:58 PM on June 29, 2006


Is HTML a problem? Why not just use blockquote /blockquote tags?
Like this. I can't help it. Old school.
This could help?
Or the UL /UL tags
    this allows you to
  • add bullets (LI /LI)
  • or levels
  • to the conversation
posted by Surfurrus at 12:45 PM on June 30, 2006


Because that would only provide a leading tab, at certain times other white space is worth preserving too. For example:
                                   |\       R1                          |  \in ---/\/\/\---o------o-----o------|amp >------ out               |      |     |      |  /               \     --    --      |/               /     \/    /\               \     --    --            R2 /      | D1  | D2               |      |     |              ---    ---   ---
posted by Chuckles at 12:52 PM on June 30, 2006


I usually just replace all spaces with &nbsp;, use Preview to see how it will look, then use the browser's Back button to get my pre-preview text back before clicking Post Comment.

It works, but it's a PITA.
posted by flabdablet at 5:43 AM on July 1, 2006


« Older DC Meetup   |   Is there a problem with the AskMe RSS Feed? Newer »

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