Username:
Password:
Remember me:
Register

Back to forum: Development News


Search forums via Google


0 Users appreciate this thread.

[BBCode] CODE tag, with Syntax Highlighting
 >  >>
Started by SomeLuigi
(2012-06-25 19:59:44)
SomeLuigi (2012-06-25 19:59:44)
Ok, I'm pretty excited about this update I can't even think of a way to say hello, so I'll get right to it.

A code that 3DSPlaza hasn't had compared to other boards is a useful one: CODE.


Obviously the main purpose of it is to display source code.

It is also used for non-breaking space mechanics.

In normal HTML documents, two spaces will be compressed into one. CSS white-space: pre; or tag equivalent <pre></pre> does not break spaces, and is supposed to format as formatted in the HTML source.

So, let's take a sneak peek at the new code tag.
[code]unit Unit1; ... Some code[/code]
Source Code
unit Unit1; {$mode objfpc}{$H+} interface uses Classes, SysUtils, simpleipc, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; type { TFormMain } TFormMain = class(TForm) Button1: TButton; IPCServer: TSimpleIPCServer; IPCClient: TSimpleIPCClient; procedure Button1Click(Sender: TObject); procedure IPCServerMessage(Sender: TObject); private { private declarations } public { public declarations } end; var FormMain: TFormMain; implementation { TFormMain } procedure TFormMain.IPCServerMessage(Sender: TObject); var s: string; st: TStringStream; begin ShowMessage('Received something...'; st := TStringStream.Create(''; IPCServer.GetMessageData(st); st.Seek(0, soBeginning); s := st.ReadString(st.Size); ShowMessage(s); st.Free; end; procedure TFormMain.Button1Click(Sender: TObject); begin IPCServer.Active := true; IPCClient.Active := true; IPCServer.StartServer; IPCClient.Connect; IPCClient.SendStringMessage('Howdy!'; IPCClient.Disconnect; IPCServer.PeekMessage(1, true); end; initialization {$I unitmain.lrs} end.


See that lovely code indentation? (more info about the source: some Lazarus code I have been working on a bit. Lazarus is a "Write once, compile anywhere" deal, based on Object-Pascal, and is made to provide a cross-platform equivalent of Delphi by Borland).

Without the CODE tag, all those indentation spaces would just output as one space.

But that isn't all!

You can indicate what source code it is like so:


[code=FreePascal (Lazarus)]unit Unit1;
...[/code]
[code=FreePascal (Lazarus)]unit Unit1;
...[/code]



But that STILL isn't all! I added some basic Syntax Highlighting!

You can tell the CODE tag to highlight languages by using an asterisk, then the name (like *php).

Please note not all languages are supported, and the support is very basic.

Current supported languages/modes:

1. PHP ([code=PHP *php]<?php ?>[/code])

More to come soon (hopefully).



[code=PHP *php]Some code[/code]

[code=PHP *php]<?php

include_once($_SERVER['DOCUMENT_ROOT'] . '/lib/general.lib.php';

class TSLDBRecord {

public $data = array();
public $flag_mod = array();
public $flag_all = false;
public $cols = array();
public $mycfg = array();
public $condition = '';
public $dec = '';
public $selall = false;
public $hasmod = 'no';

public function isf($pfname) {

return isset($this->data[$pfname]);

} // n;

public function set($pfname, $pfval) {

$this->data[$pfname]=$pfval;
$this->flag_mod[$pfname]='mod';
$this->hasmod = 'yes';

} // n;

public function get($pfname) {

return $this->data[$pfname];

}

public function ism($pfname) {

return isset($this->flag_mod[$pfname]);

}

public function flagall($pfname) {

$this->flag_all = true;

}

public function flag($pfname) {

$this->flag_mod[$pfname]='mod';

}

public function unflag($pfname) {

unset($this->flag_mod[$pfname]);

}

public function myconfig($pmdb, $pmtable, $pcondition, $pdec) {

$this->mycfg['db'] = $pmdb;
$this->mycfg['table'] = $pmtable;
$this->condition = $pcondition;
$this->dec = $pdec;
}

public function save() {

$this->hasmod = 'no';

if ($this->flag_all===false) {
$scan = array_keys($this->flag_mod);
} else {
$scan = $this->cols;
$this->flag_all=false;
};

$qp = 'UPDATE ' . $this->mycfg['table'] . ' SET ';
$firstpart = 'set';
//$pi = explode('=', $this->condition);
//$pi = $pi[0];
foreach ($scan as $key => $value) {
if ($this->dec!=$value) {
if (isset($firstpart)) {
unset($firstpart);
$qpart = '';
} else {
$qpart = ', ';
};
$qpart = $qpart . $value . '="' . mysql_escape_string($this->data[$value]) . '"';
$qp = $qp . $qpart;
};
};
$qp = $qp . ' WHERE ' . $this->condition;
$a3c = a3_mysqlc($this->mycfg['db']);
mysql_query($qp) or exit(mysql_error());

if ($a3c==='yes' {
a3_mysqld();
};

}

public function load() {
$this->hasmod = 'no';
if ($this->selall==false) {
$qp = implode(', ', $this->cols);
} else {
$qp = '*';
};

$query = 'SELECT ' . $qp . ' FROM ' . $this->mycfg['table'] . ' WHERE ' . $this->condition;

$a3c = a3_mysqlc($this->mycfg['db']);
$qr = mysql_query($query) or print(mysql_error());
$res = mysql_fetch_assoc($qr);

if ($a3c==='yes' {
a3_mysqld();
};
$this->data = $res;
if ($this->selall==true) {
$this->selall = false;
foreach ($res as $key => $val) {

$this->cols[] = $key;

};
};

}

public function cfgcol($pfcol) {

$this->cols = $pfcol;

}

};

/*
Code
by
SomeLuigi
*/

?>[/code]


That's all, folks! Hope you enjoy this... and I might mention there will be a CODE tag way to disable all BBCodes inline, aswell as syntax highlight them. Enjoy

This post has been edited one or more times, the last time was:
2012-06-25 20:24:49

SomeLuigi is changing in 2015.
roxasmaker (2012-06-25 20:24:55)
lolwut?
Sup, I'm here!

Follow me on Twitter: @r0xasmaker
Leroy (2012-06-25 20:41:19)
...
[IMG]http://i61.tinypic.com/jhyjc5.png[/IMG]
Created By The One And Only SynTM! Rare And Not Being Made Anymore... MWAHAHHA
NINTENDO64 (2012-06-25 20:42:47)
Cool!
"If today were the last day of my life, would I want to do what I am about to do today?"
-Steve Jobs

DBS
Junaid (2012-06-25 21:40:44)
Epic /
Doreee (2012-06-25 21:44:26)
Uhhh
Doreee (2012-06-25 23:08:30)
Le me reading forum first time:
Fluff this, I'm not reading that
Second time:
Uhhh... 0_e What? /
Third:
I shall try to understand! >:3 -reads-
I give up in life.
Green_plesioth (2012-06-26 00:01:05)
Sheesh,could you make that at least a little simpler?
manster hanter scrubs
sandy960 (2012-06-30 00:51:57)
wait, wait, let me think . . . wth did i just read?
BioMan8 (2012-07-02 16:51:30)
Source Code
<marquee>?</marquee>

jdrelicharz (2012-07-03 03:23:13)
What is this blackmagic?


though I walk through the valley of the shadow of death I shall fear no evil

MegaBeanish (2012-07-14 20:43:07)
Lolwut? Do you have to type each one of those characters? o.o
-Lance Corporal Rodriguez (USMC)
I812 (2012-07-19 05:24:31)
...HUH? I don't get it. Is this supposed to be a language only mods know?
My PSN: Idunno543.
My NNID: EpicMudkips215.
SPOOKY GHOST CIRCLES 0o0o0
SPCOxion (2012-08-06 05:17:22)
The first time I read this, I didn't understand a thing.

Then I began learning coding, read it again.
It all made makes perfect sense.
I812 (2012-08-12 06:45:03)
I mean is This some type ov witchcraft, Is it a way to hack wapka sites? arrgh My brain hurts just by looking at it.
My PSN: Idunno543.
My NNID: EpicMudkips215.
SPOOKY GHOST CIRCLES 0o0o0
 >  >>

Log in to submit a comment

This topic's ID: 21095

Back to forum: Development News




Total registered users: 8321
New registered users today: 7
Newest registered user: ElegantVulpes

©  Copyright 2026 3DSPlaza. All Rights Reserved