Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
Pages: 1
Adding a class to <code>
On my site I have some JS code highlighting! The issue is it requires me to declare in the form of a class what type of code it is, so for an example html code would be like this:
<code class=“html”><pre>
MY CODE
</pre></code>
How do I go about doing this, as I want to use textile, but also be able to add my class, I tried doing it but then Textile either wraps it all in a <p> tag or worse makes the tag with the class part of the code!
Any ideas?
~ Cameron
Offline
Re: Adding a class to <code>
bc(html). class will be set to "html"
Look for textile reference
Last edited by the_ghost (2009-01-29 22:45:38)
Providing help in hacking ATM! Come to courses and don’t forget to bring us notebook and hammer! What for notebook? What a kind of hacker you are without notebok?
Offline
Re: Adding a class to <code>
That adds a class to both the Pre and the Code tag! What (for arguments sake) would I do if I only want to add it to the code tag?
Last edited by driz (2009-01-29 23:35:20)
~ Cameron
Offline
Re: Adding a class to <code>
It’s a limitation in Textile, so you could do one of the following:
- Limit your CSS to just code elements with whatever class name you need –
code.<className> {}
- Use HTML @notextile.. <pre><code class=”“>…
- Use JS:
function addCodeClass(class)
{
var pre = document.getElementsByTagName('pre');
if (pre)
{
for (var i = 0; i < pre.length; i++)
{
var code = pre[i].getElementsByTagName('code')[0];
if (code)
code.className = class;
}
}
}
Also, your example is invalid HTML. code
is an inline element; pre
is a block element.
Last edited by jm (2009-01-30 00:03:32)
Offline
Pages: 1