Nicely formatted source code

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-03 21:06:02

An ordered list does a decent job. Opera doesn't copy the line numbers with it, but I think other browsers might do.

Here are my trials, but none of this does what I want:

<table>
  <tr>
    <td style="vertical-align: top;">
      <pre style="margin: 0px; -moz-user-select: none;"><img src="eol.png"/></pre>
    </td>
    <td style="background-image: url('eol.png'); background-position: right top; background-repeat: repeat-y;">
      <pre style="white-space: pre-wrap; margin: 0px;">This is a        long text         having weird whitespace content that has to be word wrapped even though</pre>
    </td>
  </tr>
  <tr>
    <td style="vertical-align: top;">
      <pre style="margin: 0px; -moz-user-select: none;"><img src="eol.png"/></pre>
    </td>
    <td>
      <pre style="white-space: pre-wrap; margin: 0px;">it is preformatted.</pre>
    </td>
  </tr>
</table>

<div>
  <div>
    <div>
      <pre style="float: left; margin: 0px;">1 </pre>
      <pre style="white-space: pre-wrap; margin: 0px;">This is a        long text         having weird whitespace content that has to be word wrapped even though</pre>
    </div>
    <div>
      <pre style="float: left; margin: 0px;">2 </pre>
      <pre style="white-space: pre-wrap; margin: 0px;">it is preformatted.</pre>
    </div>
  </div>
</div>

<pre style="white-space: pre-wrap">The Server runs under the Ubuntu Linux Server Edition (x86-64) operating system. Installing the Server under other versions of Ubuntu Linux (such as th     e Desktop Edition) should not be a problem. 

Installing the Server under other Linux distributions may be different and may need more hand tuning th an what is described here. Other operating systems such as Windows, Mac OS X, etc. are not tested and most likely will not work out of the box.

Give this a whirl. Javascript code prettifier I know you mentioned no javascript, but unless you do it server side, I'm not sure how you are going to avoid it. What language are you trying to format?

  1. Give style to the code using highlight_string()
  2. Explode / break the text by line
  3. Add the number of line at the start of each line using <input type="text" value="# of line" disable>

Something like:

$file = highlight_string(file_get_contents("some_code.php"),true);
$file = explode("<br />",$file);

foreach ($file as $n=>&$line)
    $line = "<input type='text' disabled='disabled' value='$n' />".$line;

echo join("<br />",$file);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!