TheSwamp

Code Red => AutoLISP (Vanilla / Visual) => Topic started by: Mark on March 25, 2013, 09:59:17 AM

Title: Code blocks
Post by: Mark on March 25, 2013, 09:59:17 AM
Can you guys please use the built-in code blocks until we can figure out why the GeSHi mod is giving us so many errors.

thanks
Title: Re: Code blocks
Post by: Jeff H on March 25, 2013, 10:19:46 AM
Do you mean the code tags without attribute for example code=csharp, etc......
Sorry was not sure what you meant.

Thanks.
Title: Re: Code blocks
Post by: Lee Mac on March 25, 2013, 10:19:53 AM
No problem Mark  :-)

To clarify, I assume you are requesting we enclose our code using:

[code]Your code here[/code]
Title: Re: Code blocks
Post by: Mark on March 25, 2013, 11:45:28 AM
Do you mean the code tags without attribute for example code=csharp, etc......
Yes, that is what I meant.

thanks
Title: Re: Code blocks
Post by: Kerry on March 25, 2013, 11:53:19 AM

I learned something

 [ nobbc ] unparsed content [ /nobbc ]
  [color=red][size=14pt]unparsed content[/size] [/color]

quote the post to help visualise
Title: Re: Code blocks
Post by: David Bethel on March 25, 2013, 01:47:41 PM

I learned something

 [ nobbc ] unparsed content [ /nobbc ]
  [color=red][size=14pt]unparsed content[/size] [/color]

quote the post to help visualise

There is also a noparse tag.

-David
Title: Re: Code blocks
Post by: Jeff H on March 26, 2013, 11:29:27 AM
Do we still need to avoid using modifiers, attributes, not sure correct name?
Title: Re: Code blocks
Post by: JohnK on April 05, 2013, 10:33:49 AM
Update: I am going to start over (redo the entire `code block' mods). ...I'm not sure if I screwed up or if its a PHP/MySql error at this point.  Something is tossing a error and the forum/server gets thousands of them a day.

Title: Re: Code blocks
Post by: JohnK on April 05, 2013, 11:05:11 AM
Pushed another attempt (rechecked my previous work and pushed it on the server again).

Title: Re: Code blocks
Post by: huiz on April 05, 2013, 11:11:32 AM
Code: [Select]
I always use code blocks. I don't know the correct syntax for colorized code when I need it so I take the simple version.
Title: Re: Code blocks
Post by: JohnK on April 05, 2013, 11:35:06 AM
huiz,
The colored code blocks were intended to be used by users to understand your code better (your choice to use them or not). The autolisp code blocks offered hyperlinks to a "man page" that offered syntax help to new users.
Title: Re: Code blocks
Post by: Kerry on April 05, 2013, 01:13:44 PM

Thanks John !
Title: Re: Code blocks
Post by: JohnK on April 05, 2013, 03:27:20 PM
:) But it's still broke though.
Title: Re: Code blocks
Post by: Kerry on April 07, 2013, 08:41:38 PM
How so ?
What sort of errors ?
Title: Re: Code blocks
Post by: JohnK on April 08, 2013, 10:45:12 AM
We are getting an error that says there is an error converting an array to string.

Code: [Select]
https://www.theswamp.org/index.php?topic=44258.0;prev_next=prev8:
Array to string conversion
File: Subs.php
Line: 2322

line 2322: $code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));

Heres the IF block (starting on line 2265, line 36 in this snip is where the error occurs):
Code: [Select]
// Don't parse the content, just skip it.
elseif ($tag['type'] == 'unparsed_equals_content')
{
// The value may be quoted for some tags - check.
if (isset($tag['quoted']))
{
$quoted = substr($message, $pos1, 6) == '"';
if ($tag['quoted'] != 'optional' && !$quoted)
continue;

if ($quoted)
$pos1 += 6;
}
else
$quoted = false;

$pos2 = strpos($message, $quoted == false ? ']' : '"]', $pos1);
if ($pos2 === false)
continue;
$pos3 = stripos($message, '[/' . substr($message, $pos + 1, strlen($tag['tag'])) . ']', $pos2);
if ($pos3 === false)
continue;

$data = array(
substr($message, $pos2 + ($quoted == false ? 1 : 7), $pos3 - ($pos2 + ($quoted == false ? 1 : 7))),
substr($message, $pos1, $pos2 - $pos1)
);

if (!empty($tag['block_level']) && substr($data[0], 0, 6) == '<br />')
$data[0] = substr($data[0], 6);

// Validation for my parking, please!
if (isset($tag['validate']))
$tag['validate']($tag, $data, $disabled);

$code = strtr($tag['content'], array('$1' => $data[0], '$2' => $data[1]));
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + strlen($tag['tag']));
$pos += strlen($code) - 1 + 2;
}
// A closed tag, with no content or value.
elseif ($tag['type'] == 'closed')
{
$pos2 = strpos($message, ']', $pos);
$message = substr($message, 0, $pos) . "\n" . $tag['content'] . "\n" . substr($message, $pos2 + 1);
$pos += strlen($tag['content']) - 1 + 2;
}
// This one is sorta ugly... :/.  Unfortunately, it's needed for flash.
elseif ($tag['type'] == 'unparsed_commas_content')
{
$pos2 = strpos($message, ']', $pos1);
if ($pos2 === false)
continue;
$pos3 = stripos($message, '[/' . substr($message, $pos + 1, strlen($tag['tag'])) . ']', $pos2);
if ($pos3 === false)
continue;

// We want $1 to be the content, and the rest to be csv.
$data = explode(',', ',' . substr($message, $pos1, $pos2 - $pos1));
$data[0] = substr($message, $pos2 + 1, $pos3 - $pos2 - 1);

if (isset($tag['validate']))
$tag['validate']($tag, $data, $disabled);

$code = $tag['content'];
foreach ($data as $k => $d)
$code = strtr($code, array('$' . ($k + 1) => trim($d)));
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos3 + 3 + strlen($tag['tag']));
$pos += strlen($code) - 1 + 2;
}
// This has parsed content, and a csv value which is unparsed.
elseif ($tag['type'] == 'unparsed_commas')
{
$pos2 = strpos($message, ']', $pos1);
if ($pos2 === false)
continue;

$data = explode(',', substr($message, $pos1, $pos2 - $pos1));

if (isset($tag['validate']))
$tag['validate']($tag, $data, $disabled);

// Fix after, for disabled code mainly.
foreach ($data as $k => $d)
$tag['after'] = strtr($tag['after'], array('$' . ($k + 1) => trim($d)));

$open_tags[] = $tag;

// Replace them out, $1, $2, $3, $4, etc.
$code = $tag['before'];
foreach ($data as $k => $d)
$code = strtr($code, array('$' . ($k + 1) => trim($d)));
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + 1);
$pos += strlen($code) - 1 + 2;
}
// A tag set to a value, parsed or not.
elseif ($tag['type'] == 'unparsed_equals' || $tag['type'] == 'parsed_equals')
{
// The value may be quoted for some tags - check.
if (isset($tag['quoted']))
{
$quoted = substr($message, $pos1, 6) == '&quot;';
if ($tag['quoted'] != 'optional' && !$quoted)
continue;

if ($quoted)
$pos1 += 6;
}
else
$quoted = false;

$pos2 = strpos($message, $quoted == false ? ']' : '&quot;]', $pos1);
if ($pos2 === false)
continue;

$data = substr($message, $pos1, $pos2 - $pos1);

// Validation for my parking, please!
if (isset($tag['validate']))
$tag['validate']($tag, $data, $disabled);

// For parsed content, we must recurse to avoid security problems.
if ($tag['type'] != 'unparsed_equals')
$data = parse_bbc($data, !empty($tag['parsed_tags_allowed']) ? false : true, '', !empty($tag['parsed_tags_allowed']) ? $tag['parsed_tags_allowed'] : array());

$tag['after'] = strtr($tag['after'], array('$1' => $data));

$open_tags[] = $tag;

$code = strtr($tag['before'], array('$1' => $data));
$message = substr($message, 0, $pos) . "\n" . $code . "\n" . substr($message, $pos2 + ($quoted == false ? 1 : 7));
$pos += strlen($code) - 1 + 2;
}


EDIT:
I needed to keep this link for myself.
http://www.roseindia.net/tutorial/php/phpbasics/PHP-Array-to-String.html
Title: Re: Code blocks
Post by: JohnK on April 19, 2013, 08:46:41 AM
*bump*
I have contacted the author of the MOD and he stated that he has a fix. w00t!

Quote
I already have a fix and will update the mod by the weekend.

Thank you.
Title: Re: Code blocks
Post by: JohnK on April 20, 2013, 09:44:18 PM
update:

The GeSHi mod has been updated on the SMF site. I will have to redo the mod on our end but at least we won't be getting all these errors. ...Thank you everyone for being so patient I know this bug has been a pain in the butt.

I will get started redoing the mod tomorrow.
Title: Re: Code blocks
Post by: JohnK on April 22, 2013, 08:00:02 AM
Code - C++: [Select]
  1. const std::string trim(const std::string& pString, const std::string& pWhitespace = " \t") /*{{{*/
  2. {
  3.     const size_t beginStr = pString.find_first_not_of(pWhitespace);
  4.     if (beginStr == std::string::npos)
  5.         // no content
  6.         return "";
  7.  
  8.     const size_t endStr = pString.find_last_not_of(pWhitespace);
  9.     const size_t range = endStr - beginStr + 1;
  10.  
  11.     return pString.substr(beginStr, range);
  12. }
  13.  
Title: Re: Code blocks
Post by: ElpanovEvgeniy on April 22, 2013, 08:13:53 AM
Please add a link [Select] to block the syntax highlighter code.
For example:
Code = C++:  [Select] (http://"")
Code = Auto/Visual Lisp:  [Select]  (http://"")
Title: Re: Code blocks
Post by: ElpanovEvgeniy on April 22, 2013, 08:21:36 AM
As Administrator, look in the settings of the theme:
"Header above GeSHi Code Container:
You can use {CODE}, {TAG} and {LANGUAGE} keywords. For reference please see cb|GeSHi-mod help."

Replace the line of code generation titles:
Code: [Select]
{CODE} - {LANGUAGE}: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a>
Title: Re: Code blocks
Post by: JohnK on April 22, 2013, 08:26:29 AM
As Administrator, look in the settings of the theme:
"Header above GeSHi Code Container:
You can use {CODE}, {TAG} and {LANGUAGE} keywords. For reference please see cb|GeSHi-mod help."

Replace the line of code generation titles:
Code: [Select]
{CODE} - {LANGUAGE}: <a href="javascript:void(0);" onclick="return smfSelectText(this);" class="codeoperation">[Select]</a>

Done.
Title: Re: Code blocks
Post by: ElpanovEvgeniy on April 22, 2013, 08:28:21 AM
Thank you!
There's much more convenient!
 :-)
Title: Re: Code blocks
Post by: JohnK on April 22, 2013, 08:33:35 AM
:-)
Title: Re: Code blocks
Post by: TheMaster on April 22, 2013, 09:23:49 AM
:-)

How about search terms that include things like angle braces, etc.?

That doesn't seem to work for me
Title: Re: Code blocks
Post by: JohnK on April 22, 2013, 09:43:02 AM
How about search terms that include things like angle braces, etc.?

That doesn't seem to work for me

I'm not sure I follow your meaning TT; `search terms'?

The `Select' doesn't work for you?
Title: Re: Code blocks
Post by: TheMaster on April 22, 2013, 01:47:41 PM
How about search terms that include things like angle braces, etc.?

That doesn't seem to work for me

I'm not sure I follow your meaning TT; `search terms'?

The `Select' doesn't work for you?

I was referring to searching, not selecting the code. 

It can't find code that contains embedded characters like angle braces in code blocks with formatting, because the search is being done (apparently) on the HTML (the 'view'), rather than on the original unformatted code (the 'model'), which is heavily-fragmented by HTML tags.

Try searching the '.NET' forum for 'GetObjects<T>', and you'll not find anything, even though there are plenty of posts with code that contains that string.



Title: Re: Code blocks
Post by: JohnK on April 22, 2013, 03:45:06 PM
...

Try searching the '.NET' forum for 'GetObjects<T>', and you'll not find anything, even though there are plenty of posts with code that contains that string.

Oh, yes; the code is heavily reformatted by GeSHi and that would make searches a problem. Here's a "how long is a string question" for you; Are there a lot of instances (in .NET, I guess) where a user could be doing a search like that or would they mostly search `GetObjects' instead?  ...Actually, I can see that happening quite a bit now that I think about it.

I know this isn't the answer your looking for, and I'm not trying to belittle the thought either, but I think that we will have to force the age-old "ask better questions" stance and force people to use better subject lines and whatnot.
Title: Re: Code blocks
Post by: TheMaster on April 22, 2013, 05:12:00 PM
...

Try searching the '.NET' forum for 'GetObjects<T>', and you'll not find anything, even though there are plenty of posts with code that contains that string.

Oh, yes; the code is heavily reformatted by GeSHi and that would make searches a problem. Here's a "how long is a string question" for you; Are there a lot of instances (in .NET, I guess) where a user could be doing a search like that or would they mostly search `GetObjects' instead?  ...Actually, I can see that happening quite a bit now that I think about it.

I know this isn't the answer your looking for, and I'm not trying to belittle the thought either, but I think that we will have to force the age-old "ask better questions" stance and force people to use better subject lines and whatnot.

Code that uses generics is fairly-common in .NET code nowadays, and the problem with angle braces specifically, is not only an problem in searches, but also when posting code snippets on brain-dead blogging platforms (like TypePad), where they are just gobbled-up.

I guess it's just one of those things.

Title: Re: Code blocks
Post by: Lee Mac on April 22, 2013, 06:04:28 PM
Thank you for your time on this Se7en, and also for adding the 'Select' option - much appreciated.

The only (very minor) issue that I've noticed with GeShi is that when copying code from code blocks, an indentation of 4-spaces is added to the front of every line, except those with leading spaces, to which only 3-spaces are added (or 4 are added and 1 existing is removed).

For example, when copying your code from Reply#17 (http://www.theswamp.org/index.php?topic=44261.msg496990#msg496990) to a code editor (Notepad++), I receive (using FF20.0.1):
Code: [Select]
    const std::string trim(const std::string& pString, const std::string& pWhitespace = " \t") /*{{{*/
    {
       const size_t beginStr = pString.find_first_not_of(pWhitespace);
       if (beginStr == std::string::npos)
           // no content
           return "";
     
       const size_t endStr = pString.find_last_not_of(pWhitespace);
       const size_t range = endStr - beginStr + 1;
     
       return pString.substr(beginStr, range);
    }
     
Note the extra 4 spaces of indentation on every line and removal of a leading space for the middle lines.

IE still copies the line numbers, but I guess this is unavoidable and simply how IE handles copying of HTML ordered lists.
Title: Re: Code blocks
Post by: JohnK on April 23, 2013, 08:31:44 AM
No problem. Thank you for the thanks.

That's weird behavior from Firefox; it's usually pretty good with encodings an whatnot (I think it's really just an encoding issue in the end). ...The server and PHP is telling your browser to use ISO-8859-1 and we could get by with just UTF-8 (wikipedia does it right?). I will snoop around the forum settings and see if I cant find anything.

Off hand: I use xombrero now-a-days; A lot of it is keyboard driven (and the bookmarks will be a big shock to you) but maybe give it a whirl. I don't seem to have near as many issuse as you guys talk about.
Title: Re: Code blocks
Post by: Lee Mac on April 23, 2013, 09:05:19 AM
It might be the use of the <pre> tag enclosing the code block which could be causing the browser to include additional spaces found in the HTML markup.

As a workaround for my site (example (http://lee-mac.com/lisp/html/5PointEllipse.html)), I avoided using the <pre> tag and instead used non-breaking space characters (&nbsp;) to replace spaces in the code - this seemed to solve the issue in FF (though of course IE still copies the line numbers).
Title: Re: Code blocks
Post by: TheMaster on April 23, 2013, 09:15:50 PM
...

Try searching the '.NET' forum for 'GetObjects<T>', and you'll not find anything, even though there are plenty of posts with code that contains that string.

Oh, yes; the code is heavily reformatted by GeSHi and that would make searches a problem. Here's a "how long is a string question" for you; Are there a lot of instances (in .NET, I guess) where a user could be doing a search like that or would they mostly search `GetObjects' instead?  ...Actually, I can see that happening quite a bit now that I think about it.

I know this isn't the answer your looking for, and I'm not trying to belittle the thought either, but I think that we will have to force the age-old "ask better questions" stance and force people to use better subject lines and whatnot.

Thanks also for your efforts.

I found that the search issue I mentioned above isn't limited to GeSHi-fication of code blocks, it also affects regular text.  It appears that the search is done against the raw HTML, so the following search term will find "GetObjects<T>", but not in code blocks:

Code - Text: [Select]
  1. GetObjects&lt;T&gt

I suppose that the search term could be encoded to make it work for regular content, but the actual issue for me is searching for something in posted code.

I guess it boils down to priorities (syntax colorization verses searchable code).  For me, unsearchable code is a deal-breaker.
Title: Re: Code blocks
Post by: Jeff H on April 23, 2013, 09:39:30 PM
Another option would be to quit using generics. :ugly:
Title: Re: Code blocks
Post by: Kerry on April 23, 2013, 09:44:27 PM

I know you're joking, but to satisfy my reflex reaction ..

bite your tongue Jeff :)
Title: Re: Code blocks
Post by: TheMaster on April 23, 2013, 10:11:50 PM
Another option would be to quit using generics. :ugly:

 :lol:
Title: Re: Code blocks
Post by: JohnK on April 24, 2013, 08:19:09 AM
Thanks also for your efforts.

I found that the search issue I mentioned above isn't limited to GeSHi-fication of code blocks, it also affects regular text.  It appears that the search is done against the raw HTML, so the following search term will find "GetObjects<T>", but not in code blocks:

Code - Text: [Select]
  1. GetObjects&lt;T&gt

I suppose that the search term could be encoded to make it work for regular content, but the actual issue for me is searching for something in posted code.

I guess it boils down to priorities (syntax colorization verses searchable code).  For me, unsearchable code is a deal-breaker.

:) ..thanks.

I agree, unsearchable things in a forum/wiki almost defeats the whole point. I will dig around in the forum admin settings area (while I still have the rights) and see if I can't find anything but I wouldn't count on anything. I suspect this is a SMF issue so snooping around their forums for fixes and whatnot may get us further.  I will get back to you in a bit.

> syntax colorization verses ...
Check out some AutoLisp code and click on a function (IF, AND, COND, etc).  I created a help doc that can be used as well.  The colors are nice, but the "links to help" was one of the real features I thought was neat. [-i.e. I have a text editor for colors.]
Title: Re: Code blocks
Post by: JohnK on April 24, 2013, 08:40:47 AM
...
I will get back to you in a bit.

There is the ability to build an "search index" (from the database itself) and use it with the searches. I did a 5 minute read on this index feature and it sounds like this index can be HUGE. We'll have to ask Mark about the HD space, migrating, updating, and whatnot on his end. He has to maintain this server not me.
Title: Re: Code blocks
Post by: Mark on April 24, 2013, 09:00:56 AM
I was reading the same thing a few days ago. Space shouldn't be a problem. I'm not sure it will index the code blocks though. That's something that needs looked at.
Title: Re: Code blocks
Post by: ribarm on August 23, 2022, 03:18:20 AM
I just want to revive this topic...
That code=cadlisp-7 seems to me now very old and IMHO needs some restoration... If you look at newly available programs like Notepad ++, or VLIDE, or BLADE, or Code Extension, or... , they all have very much better built-in tools for displaying colored code samples... Can some of those engines be used in improving that GeShi style... I've simply implemented some functions from Auto/Brics CAD by using (atoms-family) function... Yes it is for Notepad++, but for my eyes, it looks decent (especially with (vl*-xxx) functions)... If it could be used in some sort of a way, here is XML, but I don't know... I am just thinking loud - isn't www web design connected with software freebies and vs versa...
Anyway, this is now revived and so I had that feeling way long bogging my mind for a long time already...

Bye, M.R.