Posting Source Code
Here at Automattic we’re allllll about sharing source code. We’re easy, we give it away.
Tragically, though, using WordPress.com it is really, really hard to post source code. You have to know about HTML encoding, pre and code tags, and if you want any slick highlighting you have to convert it before you post it. You have to jump through all sorts of hoops.
Isn’t this much cooler?
$features = file_get_contents( 'https://wordpress.com/features/' ); preg_match_all( '|<h3>(.*?)</h3>|is', $features, $why_wp_rocks ); foreach ( $why_wp_rocks[1] as $slick_feature ) $hotness[] = $slick_feature; var_dump( $hotness );
If you want to know how to drop that science check out this FAQ entry, it’s as easy as a blog post on a Sunday. Like , we realize this feature will probably not appeal to many people, but if you’re the type that writes about programming your blogging life should be easier now.
Here’s another editing tip: if you press Shift + Enter it gives you a single line break instead of a double one.
Happy Labor Day!
- September 3, 2007
- Features
I’ll try this one.
LikeLike
Looks like you folks labored this Labor Day weekend. I don’t do or write about programming, but I’m s-l-o-w-l-y learning about code just being here. Thanks for the links. We like you!
LikeLike
Cool feature! Nice job!
LikeLike
Great stuff! Thanks.
LikeLike
Thanks for this great feature! The thing most unpeasant about using blockquotes / code tags was that two minus-es (used as command line switches for example) got converted into a single dash. I haven’t checked yet, but I hope this is fixed with [sourcecode].
LikeLike
this is nice 🙂
LikeLike
It’s geek-o-licious.
What, no AJAX?
The scientifically impossible I do right away
The spiritually miraculous takes a bit longer
LikeLike
Ah displays very neatly, nice Matt, very nice =) Though, it’s in my opinion that I do not like the horizontal bar. I also love the header options *thumbs up*
LikeLike
Nice! 🙂
I really love you guys.
Every little thing you do makes me so happy, I know it’s silly.
Thanks.
LikeLike
cooooool I would love to try it 😉
and yea .. the editing tip… is something that I’ve been waiting for 😀
thanks
LikeLike
Exactly what I was looking for. You’re a star. Thanks.
LikeLike
Now that is cool, I might actually post some code now!!
LikeLike
Sourc-ey!! Ooops…I meant Saucy!!!!
LikeLike
Not a bad feature!! Should be handy by times… Thanks!
Erm, … but why isn’t the ‘code’ button visible in wysiwig mode? Why do we still have to switch to the ‘code’ mode? Why not having the botton in both modes?
LikeLike
Good one 😀 Cheers Matt!
LikeLike
very useful…
I said this problem in furums yesterday and now you fix it. thanx
LikeLike
Thanks for the editing tip.
I always wondered how to get a single line break.
Thanks guys.
LikeLike
wow! this is great!!! i’ll use this when I want to share my codes to others! Thanks WordPress!
LikeLike
LikeLike
Thanks a lot. This feature is definitely useful for me.
LikeLike
very cool and useful!
LikeLike
Looks nice, just a pity with the bottom scrollbar if you use larger than the default font 😦
LikeLike
I already tried latex and it was fun…thanks for sharing this code 😀
LikeLike
Thanks, sometime I used to post html code, that I had in text file located elsewhere. This will be useful.
LikeLike
Another great update, eh?
Thanks a lot. 😀
LikeLike
YES!
At last. I please you for this feature. Thanks!
LikeLike
I dont know much about source code but I learn! Thanks
LikeLike
Wow, looks really nice. Thanks!
LikeLike
Awesome! It’s a wonderful feature!!! Thanks guys!
LikeLike
simply wondarful. bless.
LikeLike
Shirt + Enter… YAY…!!
LikeLike
Guess I’m a little too young for programming but fluent in UBL – Universal Baby Language. Maybe you can add it – only very few keywords used there 🙂 .
Anyhow great.
LikeLike
I’m not one who’s going to be posing much code, but I’ve been wanting something that’ll do a single line break for ages. Thank you! You’ve now ended quite a bit of frustration
LikeLike
thanks a lot! that’s really helpful!
LikeLike
wow. thanks great matt!!
LikeLike
U guys rock!!!!
As u said, it wont appeal many…but I am glad it makes my blogging life easy.
Keep rolling.
Cheerz
Sridhar
LikeLike
Ummm, not for me…wysiwyg works just fine.Thx!
LikeLike
Hey Matt,
I’ve ran into the same problem on wordpress.
Try “:TOhtml” in vim. It exports syntax highlighting for whatever file you are editing like C, PHP, Python, bash, etc.
You may have to tweak the html a bit afterwards, but it produces great results. See: http://electronjunkie.wordpress.com/2007/06/30/sigma-delta-modulation-primer-part-ii/ for an example.
-ej
LikeLike
Go WP!
Shift + Enter also opens a link in a new window. :p
Happy Labor Day!
LikeLike
I have no reason to use this feature, but I appreciate how much ya’ll have worked to make WordPress the greatest!
Matt, how’d you get to be so cool?
LikeLike
Yep, much cooler. As someone who does blog about programming occasionally this will be helpful, thanks.
LikeLike
Woo-hoo! I was having HTML scratches to write codes before. Thanks — as usual! 😀
LikeLike
That shift+enter thing is the real winner here.
LikeLike
good
LikeLike
It’s a good idea, but it’s pathetic that it doesn’t support Perl syntax highlighting yet considering the twelve languages there.
LikeLike
If you’d like Perl support contribute it to the open source project linked in the FAQ and we can add it.
LikeLike
Oh this is great! This is really going to make life easier for me on my blog.
LikeLike
Very nice indeed. Been looking for this for quite a while. Thanks.
LikeLike
Cool!
LikeLike
very awesome.
shift+enter is a great trick, i’m surprised more people don’t know about it.
LikeLike
Thanks for this, really is need. I know XHTML and bought th Custom CSS upgrade… but never could highlight the language sintax by hand.
LikeLike
“Here’s another editing tip: if you press Shift + Enter it gives you a single line break”
Now that makes me very happy! No more writing haiku in notepad first 🙂
LikeLike
Hello Matt (from greece) !!!
Thanks for the tips and please do not stop sharing with us 😉
LikeLike
Seems perfect!
And is just what I need!
LikeLike
Sweet. I like this. Thanks Matt.
LikeLike
Very impressive. Thank you guys!
LikeLike
It always confuses me that labor day is a different day in the states, and I do not post source code all that often, but anyway: thanks, and happy labor day to you as well.
LikeLike
Just in time, I was planning on posting up some source code today. 🙂
LikeLike
You don’t support perl 😦
LikeLike
WordPress is truly the gift that keeps on giving. I should probably be embarrassed to have this much joy at a new feature. Thank you!
LikeLike
Cool!
But I think it should be great if it could have “themes”, even if there were only 2: light (the actual) and dark.
This would be good for people, like me, whom use dark themes. The source code actually draws too much attention to itself.
LikeLike
woo! 🙂
LikeLike
I’ll use this.some day. very soon 🙂 probably…
LikeLike
Woohoo — I’d even started up a self-hosted blog just so I could load plugins to do this (of course, I haven’t posted anything to it yet, just let the plain-text formatting suffice on here).
That’s too cool…
LikeLike
Another wonderful feature! Thanks a bunch! 🙂
LikeLike
It seems like HTML tags above body content level (head, body, meta, doctype, style, …) are stripped out of the posting, which renders this feature’s use for HTML somewhat limited. Fix plz kthx 😉
LikeLike
brilliance. sheer brilliance…
LikeLike
Thank you!
LikeLike
shift+enter = : )
Thanks muchly!
LikeLike
This is really helpful, actually… despite the fact that I don’t write code.
Thanks for the tips.
LikeLike
I’m going to boo in here, since I cannot understand for the life of Brian why it has to take you over a year to accommodate the large group of developers, of which you are part, to make blogging easy for us. I have craved for this feature for so long where other blogs automattically have this from the start. Now on to free CSS and paid ‘other stuff’.
LikeLike
Holy cow! About the best update since, uhh…. when was your last post?
LikeLike
Thanks for working away on labour day with the post.
LikeLike
What a great feature! My blog doesn’t deal with programming, but this is a great tool for those blogs that do.
LikeLike
Thanks for your reply. I had a look at the so-called “open source” project listed, and the javascript there is all crushed up by some kind of compressor so that it’s virtually unreadable. Do you have a reference to the uncrushed javascript or a simple way to uncompress it? Otherwise adding a Perl mode isn’t really a practical job.
LikeLike
Oops, take that back, I found the uncompressed directory.
LikeLike
cool.. i really needed it
LikeLike
This is very cool.
It woud be nice if there was a way to have the pretty display but without colours, either for languages that it didn’t recognise or when I didn’t want to use syntax highlighting.
LikeLike
Outstanding! It looks great. Nice feature.
LikeLike
Very cool, it will come in handy! But even better than the source code is Shift + Enter! I’ve been dying for that some time now…
LikeLike
thanks
LikeLike
wh000t, god thank you for this (late, but now we have it *yeah*) feature.
I hated the “replace spaces with and never edit this post ever”-shit ;);)
this feature rules! (especially for my development-blog ^^ )
regards
ShoX
p.s.: Shift+Enter …. Why I didn´t try this earlier?! *d0h* 😀
LikeLike
It sould be posted long time ago. But thanks, one right step was made by wordpress.
Shift+Enter…… never been easier to write a “” : )
LikeLike
Will you add this to v2.3 please?
LikeLike
One warning, I tried using the XML tag to post some XAML.
DON’T!!! It butchered the XAML badly, stripped out half my tags. Fortunately I write all my posts in Word prior to putting in WordPress, so I was able to go back to the original.
If it works with some of the other languages though, it could make for an extremely nice experience for the blog reader, especially the ability to copy the code.
Arcane Code
LikeLike
Fantastic, it’ really make me do not want to leave from my laptop, event to rest room.
LikeLike
Thank you. YOu are really helping us.
LikeLike
Finally!!
thanks a lot for finally implementing this!!
Will this be on wp self-hosted version also? or do I need a plugin for that.
LikeLike
Cool!!!!
LikeLike
Thanks, this is a big step forward from wrangling pre and code tags. However (a), why no Perl (you’ve got Ruby and Python!), (b) no C++?, (c), which language is recommended as “most similar” to perl, to get the right syntax highlighting, and (d), thx for the Shift+Enter, but how about not throwing away my indentations?
LikeLike
Nice – but can you please add some generic source code type for languages not listed? I’m missing “shell” for example…
LikeLike
Thanks for that last tip 😉 it will be useful!
LikeLike
That’ll be helpful. Thanks!
LikeLike