Z-blogSyntaxHighlighter long code cannot wrap a line (based on jquery) _ jquery-js tutorial

Source: Internet
Author: User
This article mainly introduces how long code z-blogSyntaxHighlighter cannot wrap (jquery ), if you need a highlight plug-in using SyntaxHighlighter syntax, you may have encountered a problem where the Code does not display line breaks. This problem cannot be solved on the Internet, it has been bothering me for a long time. Today we have solved it. The solution is actually simple. Let's talk about it below...

Solution:

Open the shcoredefault.css file, find the definition of. syntaxhighlighter textarea, and add word-break: break-all! Important; it's OK, which means to force line feed display of the Code.

Since each person calls different css, you can modify the css as needed.

Test found that version 3.08 is invalid. You can refer to the following method.

Because my blog is mainly about code sharing, a lot of code is very long. Most of the time, I manually wrap a line.

But today we can't stand it. Find a solution from the Internet.

1. css modification:

In the folder: zb_system \ ADMIN \ ueditor \ third-party \ SyntaxHighlighter

Add css in the file shcoredefault.pack.css:

body .syntaxhighlighter .line{  white-space: pre-wrap !important;} .syntaxhighlighter{width:100%!important;margin:.3em 0 .3em 0!important;position:relative!important;overflow:auto!important;background-color:#f5f5f5!important;border:1px solid #ccc!important;word-break:break-all;}

2. Jquery code:

$(function () { // Line wrap back var shLineWrap = function () {  $('.syntaxhighlighter').each(function () {   // Fetch   var $sh = $(this),    $gutter = $sh.find('td.gutter'),    $code = $sh.find('td.code')    ;   // Cycle through lines   $gutter.children('.line').each(function (i) {    // Fetch    var $gutterLine = $(this),     $codeLine = $code.find('.line:nth-child(' + (i + 1) + ')')     ;    //alert($gutterLine);    // Fetch height    var height = $codeLine.height() || 0;    if (!height) {     height = 'auto';    }    else {     height = height += 'px';     //alert(height);    }    // Copy height over    $gutterLine.attr('style', 'height: ' + height + ' !important'); // fix by Edi, for JQuery 1.7+ under Firefox 15.0    console.debug($gutterLine.height(), height, $gutterLine.text(), $codeLine);   });  }); }; // Line wrap back when syntax highlighter has done it's stuff var shLineWrapWhenReady = function () {  if ($('.syntaxhighlighter').length === 0) {   setTimeout(shLineWrapWhenReady, 10);  }  else {   shLineWrap();  } }; // Fire shLineWrapWhenReady();});

The above code is long code. Let's see if all of them have line breaks ??

Now, the height of the row number can be the same as that of the Code.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.