1
phppp
How to make your long line code look beautiful
  • 2004/10/24 17:13

  • phppp

  • XOOPS Contributor

  • Posts: 2857

  • Since: 2004/1/25


Line line [ code] [ /code] is really annoying.
Sorry for presenting the annoying stuff to you again.
However, with this YetAnotherAnnoying, you will find that you can make it!

just follow me:

1 xoops/class/module.textsanitizer.php, line 398
change the function codeConv() with
function codeConv($text$xcode 1$image 1){
        if(
$xcode != 0){
            
$patterns "/[code](.*)[/code]/esU";
            if (
$image != 0) {
                
// image allowed
                //$replacements = "'<div class="xoopsCode"><code><pre>'.MyTextSanitizer::codeSanitizer('$1').'</pre></code></div>'";
                
$replacements "'<pre class="xoopsCode">'.MyTextSanitizer::codeSanitizer('$1').'</pre>'";
                
// hack for [code] rendering by <pre> -- phppp
                //$text =& $this->xoopsCodeDecode($text);
            
} else {
                
// image not allowed
                //$replacements = "'<div class="xoopsCode"><code><pre>'.MyTextSanitizer::codeSanitizer('$1', 0).'</pre></code></div>'";
                
$replacements "'<pre class="xoopsCode">'.MyTextSanitizer::codeSanitizer('$1', 0).'</pre>'";
                
// hack for [code] rendering by <pre> -- phppp
                //$text =& $this->xoopsCodeDecode($text, 0);
            
}
            
$text =  preg_replace($patterns$replacements$text);
        }
        return 
$text;
    }


2 at the end of your xoops/xoops.css, add:
/*xoops code rendering by phppp*/
/* The scripts are suggested to be added to each theme/style.css, styleNN.css, styleMAC.css if you prefer different styles for different themes, especially if the width is different*/
pre.xoopscode {
    
font-size12px;
    
font-familyFixedSys"Courier New",Courier,monospace;
    
background#fffff8;
    
border1px solid #6C87B0;
    
color#385a72;
    
width500px;
    
height200px;
    
margin1em;
    
overflowauto;
    
padding3px 3px 3px 3px;
}
/*xoops code rendering by phppp*/



How does it work? check the following URL you will find out the effect:
https://xoops.org.cn/modules/newbb/viewtopic.php?topic_id=1089&forum=4

2
sylvainb
Re:How to make your long line code look beautiful
  • 2004/10/24 17:47

  • sylvainb

  • Not too shy to talk

  • Posts: 168

  • Since: 2003/2/11


Hello Phppp

I certainly missed something, but I just tried your hack and can't have it to work like on your website?!

3
phppp
Re:How to make your long line code look beautiful
  • 2004/10/24 18:08

  • phppp

  • XOOPS Contributor

  • Posts: 2857

  • Since: 2004/1/25


what's your problem?
The long line still there?

4
ackbarr
Re:How to make your long line code look beautiful

do you know that the core hack is actually unneccesary in this case. All you have to do is change the style rule for div.xoopscode:

here is the style used on this site:
div.xoopsCode {    font-size12px;
    
font-familyFixedSys"Courier New",Courier,monospace;
    
background#fffff8;
    
border1px solid #6C87B0;
    
color#385a72;
    
width500px;
    
height200px;
    
margin0.5em;
    
overflowauto;
    
padding3px 3px 3px 3px;
}


Though I don't like the hardcoded 500px width. IMO it should be percentage based (like 95%), but IE 6 seems to think that 95% should be from the whole, rather than the container. grr

5
sylvainb
Re:How to make your long line code look beautiful
  • 2004/10/24 19:59

  • sylvainb

  • Not too shy to talk

  • Posts: 168

  • Since: 2003/2/11


Ok Phppp.

I fixed the problem.
In fact you said to alter xoops/xoops.css instead of themes/theme_name/style*.css, so I was a little bit confused.

Now it work like a charm.
By the way, could you tell us/me how to apply color syntax?

6
phppp
Re:How to make your long line code look beautiful
  • 2004/10/24 20:08

  • phppp

  • XOOPS Contributor

  • Posts: 2857

  • Since: 2004/1/25


@ackbarr,
I had tested the div.xoopscode class but it did not work well (can not recall what the exact problem as at this moment, but I would recheck it).
And to use the "pre", percentage based width attribute does not work with the "overflow: auto;". That's why the hardcoded width value is used and that's why (also @sylvainb in terms of where to put the pre.xoopscode class) I suggest to put the pre.xoopscode class into each individual theme style.css instead of into the xoops.css, so that you can set different values for the hardcoded "width" value

7
ackbarr
Re:How to make your long line code look beautiful

Quote:

phppp wrote:
@ackbarr,
I had tested the div.xoopscode class but it did not work well (can not recall what the exact problem as at this moment, but I would recheck it).


Would you please? I want to use this on xoops.org and dev.xoops.org so that forum posts containing source code no longer break the forum table layouts. So far I have noticed no side-effects to applying the style to div.xoopsCode directly.

8
phppp
Re:How to make your long line code look beautiful
  • 2004/10/26 0:25

  • phppp

  • XOOPS Contributor

  • Posts: 2857

  • Since: 2004/1/25


ackbarr, I have not rechcked it yet but have seen that your solution works perfectly at dev.xoops.org

When making the hack, it's almost 3 three months ago, I also worked on several other bugfixes/hacks for xoopscodes simultaneously. Might I mixed up something at that moment hence did not make the div method work.

Login

Who's Online

94 user(s) are online (78 user(s) are browsing Support Forums)


Members: 0


Guests: 94


more...

Donat-O-Meter

Stats
Goal: $100.00
Due Date: May 31
Gross Amount: $0.00
Net Balance: $0.00
Left to go: $100.00
Make donations with PayPal!

Latest GitHub Commits