Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2009-01-29 22:25:53

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

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

#2 2009-01-29 22:44:31

the_ghost
Plugin Author
From: Minsk, The Republic of Belarus
Registered: 2007-07-26
Posts: 907
Website

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

#3 2009-01-29 23:03:17

driz
Member
From: Huddersfield, UK
Registered: 2008-03-18
Posts: 441
Website

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

#4 2009-01-30 00:01:57

jm
Plugin Author
From: Missoula, MT
Registered: 2005-11-27
Posts: 1,746
Website

Re: Adding a class to <code>

It’s a limitation in Textile, so you could do one of the following:

  1. Limit your CSS to just code elements with whatever class name you need – code.<className> {}
  2. Use HTML @notextile.. <pre><code class=”“>…
  3. 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

Board footer

Powered by FluxBB