A field for displaying code

Permalink Browser Info Environment
Hi,
for a client i would need a field to enable users to enter code snippets (PHP, HTML and CSS) that don't get parsed of course, just for being displayed as clean text.
Would it be possible to add such a field to Block Designer?

Thank you,
Michael

Type: Discussion
Status: Resolved
okapi
View Replies:
ramonleenders replied on at Permalink Reply
ramonleenders
Hi Michael,

First of all, thanks for your interest in block designer.

About your question, would that be just a simple textarea field with no editing afterwards. So input = output? Or you need more modification than this, like an editor of some sorts? Also, you want to make a difference between coding language, or throw all this in one field?

Not knowing the answers above, I do think it's possible. We already have a simple textarea field type and a WYSIWYG field type so... why not a "code" field type with some slicker options as well? :)

Let me know what your thoughts are about this!

Kind regards,
Ramon
okapi replied on at Permalink Reply
okapi
Hi Ramon,

first of all, thank you for your speedy reply! :)
The problem is, that a simple text area does not prevent PHP code input from getting parsed. I created a simple block with just one text area field and then tried to put in a PHP code snippet - the output result was not clean text with all characters, but just some fragments of the original code. The rest, i assume, has been interpreted as executable PHP code and therefore not displayed.

Unfortunately none of the developers of related Add-Ons currently existing for Conrete5.6, namely "Highlighted Code Block" and "All in one syntax highlighter", seem to have plans to port their useful Add-Ons to Concrete5.7. At least Remo doesn't, as i have contacted him just recently, even willing to pay for porting his Add-On.

I can pretty much live without code highlighting, if there only was a way to present code as plain text. Redactor's preformatting feature is buggy and messing up the code as soon as the block is edited again, so it's unusable at the current state.

Do you think, you could (and would like to) create a "code" field as suggested, where tags and code related characters are correctly transformed into HTML entities?

Kind regards,
Michael
ramonleenders replied on at Permalink Reply
ramonleenders
Hi Michael,

Ah yes of course, it's being parsed! Long day already...

Uhm, yeah I certainly could do that. That won't be in the next 24 hours, but I will see what I can do for you this week (perhaps somewhere in the weekend). Quite loaded with other projects, so have minimum spare time in my agenda! So if you could wait for a couple of days, I will do my best to get it done ASAP! Wished a day had 48 hours haha.

Kind regards,
Ramon
okapi replied on at Permalink Reply
okapi
Ramon, you just rock!
And i totally agree with you, time has become the most precious thing in our times! It's crazy. It's not even the energy that's lacking, it's simply the amount of time for doing thing that's lacking each and every day... Of course i will happily wait for any solution you provide. Thank you so much for your kind support!

Cheers,
Michael
ramonleenders replied on at Permalink Reply
ramonleenders
Hi Michael,

Sorry for the delay in the completion of this. I've been too busy to get even started on my add-on projects. Whenever I get the change to get back to these again, I will start with this "code" field type. Sorry if you needed it in the meanwhile...

Kind regards,

Ramon
okapi replied on at Permalink Reply
okapi
Hi Ramon,

whenever you find the time to build that extension, I'm very much looking forward to it! Thank you!

Kind regards,
Michael
ramonleenders replied on at Permalink Reply 1 Attachment
ramonleenders
Hi Michael,

Here a first version of the code field type. Not sure if you need more functionality, but let me know. I made it the way I interpreted your request, hope it's how you wanted and otherwise just let me know.

Drop the "code" folder into packages/block_designer/field_types. And done! I will be updating block designer anytime soon, first want to have this field type exactly how you want it to be :)

Kind regards,

Ramon
okapi replied on at Permalink Reply
okapi
Hi Ramon,

thank you so much for your work, this is exactly what i'm currently badly needing!

This nice field type displays code with all tags and tabs and characters without modifying them in any way, and, above all, keeps it from being rendered!

What could i ask for more! Well, to be honest... of course there are advanced features, which would be very much appreciated, such as line numbers and code highlighting... but maybe it would make more sense for you to build that a separate payed Add-On...

Thank you again for this great christmas present!

Kind regards,
Michael
ramonleenders replied on at Permalink Reply
ramonleenders
Hi Michael,

Glad this is what you were looking for :)

As for code highlighting, I've thought about highlightjs.org. But that's client sided. Not sure if that's the best way to go though, as we could also do server sided. Things is if you have multiple blocks with code, you have to watch that you don't load the JS and CSS multiple times.. But well, we still can do highlighting in a next version, right?

If you have any suggestions about a highlighter, just let me know. I haven't had much time to dig deep into all this unfortunately.

Kind regards,

Ramon

concrete5 Environment Information

Installation for testing purpose only

# concrete5 Version
5.7.2

# concrete5 Packages
Block Designer (0.9.8), Page Redirect (2.0), Page Selector Attribute (2.0), ProEvents (2.0.3), Thumb Gallery (1.0).

# concrete5 Overrides
blocks/text, blocks/textblock, languages/sl_SI, languages/ru_RU, languages/fi_FI, languages/tr_TR, languages/fr_FR, languages/de_DE, languages/it_IT, languages/el_GR, languages/ja_JP, languages/da_DK, languages/nl_NL, languages/sv_SE, themes/photography

# concrete5 Cache Settings
Block Cache - On
Overrides Cache - On
Full Page Caching - Off
Full Page Cache Lifetime - Every 6 hours (default setting).

# Server Software
Apache

# Server API
cgi-fcgi

# PHP Version
5.5.19

# PHP Extensions
bcmath, calendar, cgi-fcgi, Core, ctype, curl, date, dom, ereg, exif, fileinfo, filter, ftp, gd, gettext, hash, iconv, imap, intl, json, libxml, mbstring, mcrypt, mhash, mysql, mysqli, mysqlnd, openssl, pcre, PDO, pdo_mysql, pdo_sqlite, Phar, posix, Reflection, session, SimpleXML, soap, sockets, SPL, sqlite3, standard, tokenizer, xml, xmlreader, xmlrpc, xmlwriter, xsl, zip, zlib.

# PHP Settings
max_execution_time - 160
log_errors_max_len - 1024
max_file_uploads - 20
max_input_nesting_level - 64
max_input_time - 60
max_input_vars - 1000
memory_limit - 320M
post_max_size - 200M
sql.safe_mode - Off
upload_max_filesize - 200M
mysql.max_links - 500
mysql.max_persistent - 0
mysqli.max_links - Unlimited
mysqli.max_persistent - Unlimited
pcre.backtrack_limit - 1000000
pcre.recursion_limit - 100000
session.cache_limiter - <i>no value</i>
session.gc_maxlifetime - 1440
soap.wsdl_cache_limit - 5

Browser User-Agent String

Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You may not request a refund that is not currently owned by you.