[phpBB]代码语法高亮模块 Codebox Plus

回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

[phpBB]代码语法高亮模块 Codebox Plus

帖子 523066680 »

模块 对应 PHPBB 3.0.x
模块 对应 PHPBB 3.1.x
安装后在 ACP > 自定 选项卡中开启
遇到的问题:
  1. 默认代码是折叠起来的,在扩展选项卡中(如果是第一次安装模块,需要刷新后才出现这个选项卡),将Display expanded 设为是
  2. 默认字体为monospace,但是系统没有安装的话就会显示成别的字体。推荐字体:consolas, 修改位置:
    includes/geshi/geshi.php:458行
    var $overall_style = 'font-family:consolas;';
  3. 默认代码字体太小,同样是458行,添加font-size选项 修改示例:
    var $overall_style = 'font-family:consolas; font-size: 15px';
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Re: [phpBB]代码语法高亮模块 Codebox Plus - 左侧行号缩进的修改

帖子 523066680 »

(默认的缩进太多了)
/wwwroot/ext/o0johntam0o/codeboxplus/event/main_listener.php
240行:
$geshi->set_line_style('margin-left:20px;', false);
改成
$geshi->set_line_style('margin-left:10px;', false);
或者其他更小的值

此时代码和行号又显得太近了
$geshi->set_code_style('border-bottom: dotted 1px #cccccc;', false);
改为
$geshi->set_code_style('margin-left:5px; border-bottom: dotted 1px #cccccc;', false);
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

显示效果 - 展开时为完全展开、收缩时带滚动条

帖子 523066680 »

How to add scrollbar on codebox - Codebox Plus
Re: [RC] Codebox Plus Post by o0johntam0o
打开
  • .\ext\o0johntam0o\codeboxplus\event\main_listener.php
找到
  • $re .= '<div><div style="display: ' . (($lang != 'NULL' && !$this->expanded) ? 'none' : 'inline') . ';">';
替换为
  • $re .= '<div><div style="display: ' . (($lang != 'NULL' && !$this->expanded) ? 'none' : 'block') . '; height: 150px; overflow:hidden;">';
在论坛模块管理的codebox plus选项中设置默认展开代码,即可看到带滚动条的代码框。
但是点击展开、收缩后代码框又变成没有滚动条的模式,这个问题还未解决

================================ 华丽分割线 =================================
2016-08-09
问题已解决
  1. 找到
    /ext/o0johntam0o/codeboxplus/event/main_listener.php

    代码: 全选

    $re?.=?'<div><div?style="display:?'?.?(($lang?!=?'NULL'?&&?!$this->expanded)???'none'?:?'inline')?.?';">';?
    替换为:

    代码: 全选

    $re?.=?'<div><div?style="display:?'?.?(($lang?!=?'NULL'?&&?!$this->expanded)???'block;height:auto;?max-height:?210px;?overflow:auto'?:?'inline')?.?';">';
  2. 找到
    /ext/o0johntam0o/codeboxplus/styles/all/template/script.js

    代码: 全选

        if (e.style.display == 'none')
        {
            e.style.display = 'inline';
        }
        else
        {
            e.style.display = 'none';
        } 
    替换为

    代码: 全选

        if (e.style.display == 'inline')
        {
            e.style.display = 'block';
        }
        else
        {
            e.style.display = 'inline';
        }  
collapse.gif
(112.66 KiB) 已下载 2545 次
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

相关的替换代码

帖子 523066680 »

ext/o0johntam0o/codeboxplus/migrations/v200.php

代码: 全选

		if ($bbcode_id <= BBCODE_LIMIT)
		{
			$this->db->sql_query('INSERT INTO ' . $this->table_prefix . 'bbcodes ' . $this->db->sql_build_array(
				'INSERT',
				array(
					'bbcode_tag'			=> 'Codebox=',
					'bbcode_id'				=> (int) $bbcode_id,
					'bbcode_helpline'		=> '',
					'display_on_posting'	=> 0,
					'bbcode_match'			=> '[Codebox={SIMPLETEXT1} file={SIMPLETEXT2}]{TEXT}[/Codebox]',
					'bbcode_tpl'			=> '<div class="codebox" title="{L_CODEBOX_PLUS_TITLE}" data-language="{SIMPLETEXT1}" data-filename="{SIMPLETEXT2}"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code>{TEXT}</code></div>',
					'first_pass_match'		=> '!\[codebox\=([a-zA-Z0-9-+.,_ ]+) file\=([a-zA-Z0-9-+.,_ ]+)\](.*?)\[/codebox\]!ies',
					'first_pass_replace'	=> '\'[codebox=${1} file=${2}:$uid]\'.str_replace(array("\\r\\n", \'\\"\', \'\\\'\', \'(\', \')\'), array("\\n", \'"\', \''\', \'&#40;\', \'&#41;\'), \'${3}\').\'[/codebox:$uid]\'',
					'second_pass_match'		=> '!\[codebox\=([a-zA-Z0-9-+.,_ ]+) file\=([a-zA-Z0-9-+.,_ ]+):$uid\](.*?)\[/codebox:$uid\]!s',
					'second_pass_replace'	=> '<div class="codebox" title="{L_CODEBOX_PLUS_TITLE}" data-language="${1}" data-filename="${2}"><p>{L_CODE}{L_COLON} <a href="#" onclick="selectCode(this); return false;">{L_SELECT_ALL_CODE}</a></p><code>${3}</code></div>'
				)
			));
		}
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

代码框默认高度

帖子 523066680 »

默认是不带滚动条直接全部收缩或者全部显示的,在三楼设置了滚动条显示。代码高度也是后期添加的。

main_listener.php

代码: 全选

$re .= '<div><div style="display: ' . (($lang != 'NULL' && !$this->expanded) ? 'block;height:auto; max-height: 210px; overflow:auto' : 'inline') . ';">';
修改max-height
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

去掉脚注

帖子 523066680 »

去掉Code框底下的脚注:
Geshi @ Codebox Plus Extension

(我也觉得不太厚道

还是main_listener.php
找到

代码: 全选

$re .= '<div class="codebox_plus_footer">' . $this->user->lang['CODEBOX_PLUS_GESHI'] . ' &copy; ' . $this->user->lang['CODEBOX_PLUS_TITLE'] . '</div></div>';
把这一行用双斜杠注释掉,加一行

代码: 全选

		$re .= '</div>';
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

全选复制时,出现空格缩进或者编号

帖子 523066680 »

问题
1. 全选复制时,出现空格缩进或者编号
2. 如果首行有缩进,保存发布后就丢失了

作为强迫症,发现这个问题的我感觉要死了。作者已经很多个月没上线,github也没有登录迹象,该模块已经被告知处于遗弃阶段。
发了邮件出去 。。。等待回复
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

修改 dos / bat / cmd 语法高亮

帖子 523066680 »

调这个颜色好烦。
--- dosSRC.php	2015-11-27 21:48:34.000000000 +0800
+++ dosNEW.php 2016-10-08 17:29:00.000000000 +0800
@@ -123,4 +123,4 @@
- 1 => 'color: #00b100; font-weight: bold;',
- 2 => 'color: #000000; font-weight: bold;',
- 3 => 'color: #b1b100; font-weight: bold;',
- 4 => 'color: #0000ff; font-weight: bold;'
+ 1 => 'color: #000000; font-weight: bold;', /* control: if for exit goto */
+ 2 => 'color: #000000; font-weight: normal;', /* ... */
+ 3 => 'color: #7a0874; font-weight: bold;', /* normal command */
+ 4 => 'color: #0000ff; font-weight: bold;' /* device: con nul com1 ... */
@@ -129,3 +129,3 @@
- 1 => 'color: #808080; font-style: italic;',
- 2 => 'color: #b100b1; font-style: italic;',
- 3 => 'color: #33cc33;'
+ 1 => 'color: #880000; font-style: italic;', /* rem */
+ 2 => 'color: #880000; font-style: italic;', /* :: */
+ 3 => 'color: #008800; font-weight: bold;' /* ^ escape */
@@ -148 +148 @@
- 0 => 'color: #33cc33;',
+ 0 => 'color: #000000; font-weight: bold;', /* %, !, () .. */
@@ -154 +154 @@
- 0 => 'color: #b100b1; font-weight: bold;',
+ 0 => 'color: #7a0874; font-weight: bold;', /* :loop tags */
@@ -156,2 +156,2 @@
- 2 => 'color: #448888;',
- 3 => 'color: #448888;'
+ 2 => 'color: #336666; font-weight: bold;', /* varname color in !! */
+ 3 => 'color: #448888; font-weight: bold;' /* varname color in %% */
dos_php.txt
(8.36 KiB) 已下载 70 次
头像
523066680
Administrator
Administrator
帖子: 573
注册时间: 2016年07月19日 12:14
联系:

Re: [phpBB]代码语法高亮模块 Codebox Plus

帖子 523066680 »

1. 翻译修改:
/ext/o0johntam0o/codeboxplus/language/zh_cmn_hans/codebox_plus.php
'CODEBOX_PLUS_SELECT' => '[代码高亮]',

2. 重复了3楼的操作。

3. 在管理界面的扩展选项卡中,Codebox Plus Extension 的 Display expanded 项 改为否。然后可以看到伸展/收缩效果。
回复

在线用户

正浏览此版面之用户: 没有注册用户 和 0 访客