Перейти к публикации
View in the app

A better way to browse. Learn more.

Дизайн и модификация Invision Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

bb-code + geshi

Опубликовано:

И так. Geshi - набор классов и функций для красивого отображения различных языков программирования.

Архив

 

 

Php файл bb-code.

Строго не судите т.к. это мои первые шаги (я сам программист c, c++, asm).

 

<?php

class bbcode_cppcode extends bbcode_parent_class implements bbcodePlugin
{

/**
 * Constructor
 *
 * @access	public
 * @param	object		Registry object
 * @return	void
 */
public function __construct( ipsRegistry $registry )
{
	$this->currentBbcode	= 'cppcode';

	parent::__construct( $registry );

}

public function preDbParse( $txt )
{
	return parent::preDbParse( $txt );
}

public function preDisplayParse( $txt )
{
	return parent::preDisplayParse( $txt );
}

/**
 * Do the actual replacement
 *
 * @access	protected
 * @param	string		$txt	Parsed text from database to be edited
 * @return	string				BBCode content, ready for editing
 */
protected function _replaceText( $txt )
{
	$_tags = $this->_retrieveTags();

	foreach( $_tags as $_tag )
	{

		$open_tag	= '[' . $_tag;
		$close_tag	= '[/' . $_tag . ']';

		while( ( $this->end_pos = stripos( $txt, $close_tag, $this->end_pos ) ) !== false )
		{

			$this->cur_pos	= $this->end_pos;	

			while( $this->cur_pos > 0 )
			{

				$this->cur_pos = $this->cur_pos - 1;

				if( $this->cur_pos < 0 )
				{
					break;
				}

				if( stripos( $txt, $open_tag, $this->cur_pos ) === $this->cur_pos )
				{

					$open_length	= strlen($open_tag);

					$_content	= substr( $txt, ($this->cur_pos + $open_length + strlen($_option) + 1));

					$txt = substr_replace( $txt, $this->_buildOutput( $_content), $this->cur_pos, (stripos( $txt, $close_tag, $this->cur_pos ) + strlen($close_tag) - $this->cur_pos) );

					break;
				}
			}

			$this->end_pos += 1;

			if( $this->end_pos > strlen($txt) )
			{					
				$this->end_pos	= 0;
				break;
			}
		}
	}

	return $txt;
}


/**
 * Raw options string
 *
 * @access	private
 * @param	string		$string		The options submitted with the post as a string
 * @return	array					Key => value Option pairs
 */
private function _extractSurgicallyTehOptions( $options='' )
{


	return $finalOpts;
}


/**
 * Build the actual output to show
 *
 * @access	private
 * @param	integer		$option		Font size
 * @param	string		$content	Text
 * @return	string					Content to replace bbcode with
 */
private function _buildOutput( $content)
{
	// Include the GeSHi library//
	require_once('***************/includes/geshi.php'); 
	//// Define some source to highlight, a language to use
	// and the path to the language files//
	;
	 $lang = 'cpp';
	 $geshi = new GeSHi($content, $lang);

	return  $geshi->parse_code(); 
}
}

 

 

Ввожу у себя на формуе:

[cppcode]
#include <iostream>
using namespace std;
[/cppcode] 

 

Цвет, отступы распознает, но

получаю:

<br />

#include <iostream><br />

using namespace std;<br />

 

Хотя отдельно php скрипт пашет без проблем. Как быть?

Рекомендованные сообщения

Опубликовано:
но получаю:

 

Это от того что Geshi кодирует спецсимволы в хтмл сущности, потом строка еще раз проходит через форумный кодировщик. Получается спецсимволы кодируются два раза. Надо либо в геши отключить, либо декодировать на выходе из него - htmlspecialchars_decode( return $geshi->parse_code() );

Опубликовано:
  • Автор

Попробую потыкаться в настройках.

Проблема еще не устранена.

 

 

И так код:

#include <iosream>
using namespace std;
void main()
{
cout<<endl;
}

 

Без декодирования (как было в 1ом сообщении):

<br />
#include <iosream><br />
using namespace std;<br />
void main()<br />
{<br />
cout<<endl;<br />
}<br />

 

С:

<br />
#include <iosream>

using namespace std;<br />
void main()<br />
{<br />
cout<<endl;<br />
}<br />

Изменено пользователем DJ_Vasek

Создайте аккаунт или войдите в него для комментирования

Сейчас на странице 0

  • Нет пользователей, просматривающих эту страницу.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.