I got the syntax highlighting with highlighjs working. But I had to add new code block BBcode elements, i.e. [codebox][/codebox] and [c][/c]. And they work a bit different than the default code block. But I like the way this one is setup to be collapsed and expand to the full code when needed.
The main issue is it will take a bit more work and testing to figure out how to replace the default code blocks with the new setup, and requires editing of some php files and template/theme files. So I'll have to do this on the dev server and see if it even works first, plus test it thoroughly and test reparsing the already posted code.
Example new code block, done like this [c=lua]--some lua code[/c] or [codebox=lua]--some lua code[/codebox]
Code: [show] | [select all]
As opposed to the default code block, which doesn't always auto detect the language correctly and has no way to manually set it:
Code: Select all
local NAME = 'I2CETLua.extensions.string'
local CLASS_NAME = '[string]'
local NAME = 'I2 Cheat Engine Lua string Extension'
local VERSION = '1.0.1'
require('I2CETLua.helpers')
----
---- Returns true if a string is empty, or nil if notOrNil is false.
----
---- string.isEmpty(str)
---- string.isEmpty(str, notOrNil)
---- str:isEmpty()
---- str:isEmpty(notOrNil)
----
---- Parameters:
---- str : string :
---- The string to check.
---- notOrNil (optional): boolean : default : false
---- Set to true to only check if the string is empty.
---- Return:
---- boolean :
---- true if the string is empty, or nil if notOrNil is false.
function string.isEmpty(str, notOrNil)
if notOrNil then
return str == ''
else
if type(str) == 'string' or type(str) == 'nil' then
return str == nil or str == ''
end
end
end
----
---- Returns a parsed string, using the data table passed (tbl).
---- Using the format of "${Some_Key}" with table { Some_Key = 'key value' }.
----
---- string.interp(str, tbl)
---- str:interp(tbl)
----
---- Parameters:
---- str : string :
---- The string to parse.
---- tbl : table :
---- The data table to use for parsing.
---- Return:
---- string :
---- The parsed string.
function string.interp(str, tbl)
checkArgType(str, 1, 'string')
checkArgType(tbl, 2, 'table')
local function lookup(key) return tbl[key:sub(3, -2)] or key end
return str:gsub('($%b{})', lookup)
end
----
---- Returns a padded string.
---- For left padding use positive numbers, and for right padding use negative numbers.
----
---- string.pad(str, len)
---- string.pad(str, len, s_char)
---- str:pad(len)
---- str:pad(len, s_char)
----
---- Parameters:
---- str : string :
---- The string to pad.
---- len : number : integer
---- The total length of the string with padding.
---- s_char (optional): string : character : default : ' ' (space)
---- The string character to use for padding.
---- Return:
---- string :
---- The padded string.
function string.pad(str, len, s_char)
checkArgType(str, 1, 'string')
checkArgType(len, 2, 'number')
checkInteger(len, 2)
if not s_char or s_char == ' ' then
---- if s_char is a space then format could be used with "%(len)s"
local fmt = string.format('%%%ds', len)
return fmt:format(str)
else
checkArgType(s_char, 3, 'string')
if #s_char ~= 1 then
local msg = string.format("bad argument #%d to '%s' (%s expected, got %s %s)",
3, debug.getinfo(1).name, 'string with length 1', 'string with length', #s_char)
error(msg, 2)
end
if len > 0 then
return string.rep(s_char, len - #str)..str
elseif len < 0 then
len = math.abs(len)
return str..string.rep(s_char, len - #str)
end
end
return str
end
local function titleCase(str, s_char, removeSeperator, camelCase)
checkArgType(str, 1, 'string', 2)
local patt = '%S+' -- match every thing but spaces ( ).
local char = ' '
if s_char == '_' then
patt = '[^_]+' -- match every thing but underscores (_).
char = '_'
elseif s_char == '-' then
patt = '[^-]+' -- match every thing but dashes (-).
char = '-'
elseif s_char == '.' then
patt = '[^\\.]+' -- match every thing but periods (.).
char = '.'
elseif s_char == 'p' then
patt = '%P+' -- match every thing but punctuation (.).
char = '.'
end
local ret = ''
for word in str:gfind(patt) do
if #ret > 0 and not removeSeperator then ret = ret..char end
local first = word:sub(1, 1):upper()
if #ret < 1 and camelCase then
first = first:lower()
end
ret = ret..first..word:sub(2):lower()
end
if #ret < 1 then ret = str end
return ret
end
----
---- Returns a title cased string.
---- i.e. 'some string to title case' -> 'Some String To Title Case'.
----
---- string.titleCase(str)
---- string.titleCase(str, s_char)
---- string.titleCase(str, s_char, removeSeperator)
---- str:titleCase()
---- str:titleCase(s_char)
---- str:titleCase(s_char, removeSeperator)
----
---- Parameters:
---- str : string :
---- The string to title case.
---- s_char (optional): string : character : default : ' ' (space)
---- The string character that separates the words.
---- removeSeperator (optional): boolean : default : false
---- Set to true to remove the separator when parsing the string.
---- Return:
---- string :
---- The title cased string.
function string.titleCase(str, s_char, removeSeperator)
checkArgType(str, 1, 'string')
return titleCase(str, s_char, removeSeperator)
end
----
---- Returns a camel cased string.
---- i.e. 'some string to camel case' -> 'someStringToCamelCase'.
----
---- string.camelCase(str)
---- string.camelCase(str, s_char)
---- str:camelCase()
---- str:camelCase(s_char)
----
---- Parameters:
---- str : string :
---- The string to camel case.
---- s_char (optional): string : character : default : ' ' (space)
---- The string character that separates the words.
---- Return:
---- string :
---- The camel cased string.
function string.camelCase(str, s_char)
checkArgType(str, 1, 'string')
return titleCase(str, s_char, true, true)
end
----
---- Returns a stripped string, removes white space from both ends of the string.
----
---- string.strip(str)
---- str:strip()
----
---- Parameters:
---- str : string :
---- The string to strip.
---- Return:
---- string :
---- The stripped string.
function string.strip(str)
checkArgType(str, 1, 'string')
return str:gsub('^%s*(.-)%s*$', '%1')
end
----
---- Returns a table of strings, after splitting the string based on the delimiter.
----
---- string.split(str)
---- string.split(str, delimiter)
---- str:split()
---- str:split(delimiter)
----
---- Parameters:
---- str : string :
---- The string to split.
---- delimiter : string :
---- The delimiter to use for splitting.
---- Return:
---- table :
---- A table of the split strings.
function string.split(str, delimiter)
checkArgType(str, 1, 'string')
checkArgType(delimiter, 2, 'string')
if not str:match(delimiter) then return end
local patt = '(.-)'
if delimiter == '.' then
patt = patt..'%'..delimiter
else
patt = patt..delimiter
end
result = {}
for match in (str .. delimiter):gmatch(patt) do
table.insert(result, match)
end
return result
end
Let me know what you guys think, do you like the old version better. I do plan to figure out how to allow you to select a theme for the syntax highlighting but currently it's not setup that way. You can get an idea of what themes are available here https://highlightjs.org/static/demo/
EDIT:
Added cea and modded lua language definitions.
Code: [show] | [select all]
EDIT:
So it looks like I got the default code blocks working pretty good. You might need to purge the browser's cashe to see it right. But I even seemed to get the language auto detect working a little better.