Help - Search - Members - Calendar
Full Version: Post a block of code in an article?
Movable Type Community Forum > Additional Resources > Tips and Tricks
EllenM1
Hi, I want to be able to post blocks of code in articles, just like this:
CODE
<b>THIS IS SOME CODE</b>


How are people doing this in MoveableType?
crys
At the moment I put the code in <pre> tags and the search & replace < -> &lt; + > -> &gt; -- I've got a text filter plug-in almost done that uses
CODE
[code] [b]
type tags though including translating the contents of [ code ] tags to display the code.
stepan
Instead of search-and-replace, you can use Quick Escape to escape HTML for you. biggrin.gif
bmk
I've been using brad's macro plugin for this:

CODE
<MTMacroDefine pattern="m/\[code\](.+?)\[\/code\]/si">
<pre><MTMacroMatch position="1" encode_html="1"></pre>
</MTMacroDefine>


Then surround your code with code tags:
CODE
[CODE]


CODE
[/CODE]
EllenM1
Thanks for all the very helpful suggestions. So with these types of escaped characters, when someone copies and pastes the code, do they get the < and >symbols, or do they get all the escape codes that create them? I mean - can they use it, or do they pretty much have to go in and fix it all?

I know that when you use a text field to type code in, it can be copied and pasted just fine.
EllenM1
Oh, I think I've got it: first run the code thru that accessify page, then just surround it with a < textarea > tag, and you're done?
gramcracker
That's one way to do it, Ellen. And putting it in a textarea tag makes it easily selectable, too, which is nice.
morgantj
Ah, I was trying to do this one time... I couldn't figure it out, so I ended up taking a screenshot! This is great, thank you.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2009 Invision Power Services, Inc.