Click here to Skip to main content
16,017,248 members
Articles / Editor
Tip/Trick

Workarounds for Code Project's Text Editor

Rate me:
Please Sign up or sign in to vote.
5.00/5 (5 votes)
24 Sep 2016CPOL2 min read 20.7K   2   6
Although the text editor from the site is very powerful, sometimes... well if you use it, you know what I mean ;)

Having trouble writing or posting articles? These articles aim to gather together tips and tricks from authors and mentors to help you write great articles.

Introduction

Code Project (CP) is one of my favourite sites in the net. It is amazing how the team works under pressure speed solving problems or includes new features based on suggestions. But they are still humans, what means, they can't solve everything at once.

That's why some annoying things are still there, troubling the daily routine of the site.

Background

One source for tiny (or not so tiny) headaches is the article editor. There already are some very nice explanations about the editor and site formatting here in CP. Some I find good are:


But I keep seeing articles / tips / Q&A items having troubles with the code snippets.

For my explanation, I am using SQL code snippets extracted from Use SQL Server to Manage Completely DB Backups on Mirrored Databases. I have chosen this article, because it has had both the problems I am going to explain. If the article still is live, you can have a look to the versions history.

Issue 1: Copy and Paste Code from an Already Formatted Source

I would reckon that the author copied his code in his SQL environment (which is already formatted), when pasting here the colors of SQL environment were codified to HTML with the result...

<font color="#0000ff" face="Consolas" size="2"> 
<font color="#0000ff" face="Consolas" size="2"> 
<font color="#0000ff" face="Consolas" size="2"> 
EXEC</font></font></font>

How to insert code correctly is covered in OriginalGriff's tip in a professional way, but there is another possibility to avoid this using a simple workaround... paste it first in a pure plain text editor and then copy again. For Windows users, the best would be to use the Notepad.
In other words, copy in SQL and paste in Notepad, then copy in Notepad and paste in CP-Editor.

Doing this and choosing the correct language (Anshul's tip) in your code format (for this example "SQL") will give the result:

SQL
EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure'xp_cmdshell', 1
RECONFIGURE
GO
-- Show
EXEC sp_configure 'xp_cmdshell'

Issue 2: Escaped Quotes Mess the Format Coloring Everything as String

As we all know, sometimes when working with string / text, we have to escape some special symbols like [ \, ", ', : ] using another backslash before the special symbol [ \\, \", \', \: ]. This seems to drive the editor crazy and fool it with the result that it thinks everything afterwards is a string and formats it using the color purple.

Getting back to the previous SQL article as an example...

SQL
iF @Folder_Path LIKE '%' + '\'
SET @Folder_Path = substring(@Folder_Path, 1, len(@Folder_Path) - len('\'))
 
--Create a temp table to hold the results.
 
IF OBJECT_ID('tempdb..#DirectoryTree') IS NOT NULL
DROP TABLE #DirectoryTree;
 
CREATE TABLE #DirectoryTree (
id INT IDENTITY(1,1)
,fullpath VARCHAR(2000)
,subdirectory NVARCHAR(512)
,depth INT
,isfile BIT);

or using another format, like C#:

C#
int Pos = file.LastIndexOf("\\");
if (Pos != null)
{
   // doing things here
}

// some other stuff here

Path = Folder_Path + '\' + subdirectory
if (Path == null)
{ 
   return;
}

// do other things

This can be simply solved by adding a comment with the same special symbol at the end of the line producing the chaos. Please note that the comment symbol must be appropriate for the programming language.

Using this workaround would give us the result:

SQL
iF @Folder_Path LIKE '%' + '\'  --'
SET @Folder_Path = substring(@Folder_Path, 1, len(@Folder_Path) - len('\')) --'
 
--Create a temp table to hold the results.
 
IF OBJECT_ID('tempdb..#DirectoryTree') IS NOT NULL
DROP TABLE #DirectoryTree;
 
CREATE TABLE #DirectoryTree (
id INT IDENTITY(1,1)
,fullpath VARCHAR(2000)
,subdirectory NVARCHAR(512)
,depth INT
,isfile BIT);

and...

C#
int Pos = file.LastIndexOf("\\");  //"
if (Pos != null)
{
   // doing things here
}

// some other stuff here

Path = Folder_Path + '\' + subdirectory  //'
if (Path == null)
{ 
   return;
}

// do other things

I know that this will become obsolete at some time because CP will have solved the bug, but in the meanwhile... I hope it helps you.

History

  • 4th September, 2016 - v1.0 - Initial creation

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Engineer
Germany Germany
I come from Spain. After making a lot of silly things during the studies, I wanted to correct me and to make something positive with my life, so I asked for (and got) an “Erasmus” scholarship to go to Germany. After obtaining a placement to make my Thesis in a Firm of Automation and Software development, I reached the double Degree in Electronics’ Engineering and Informatic. I worked a time with VC++ 6, many years with industry PLC and robot programming, done backbone IT for something related to car electronics and production, back to my roots in C++ and PLC Programming again and currently working as system architect for my division.

I contrinue trying to learn more C# in my spare time (which is even less than before, God bless my kids)

Comments and Discussions

 
GeneralMy vote of 5 Pin
Espen Harlinn1-Jan-21 12:12
professionalEspen Harlinn1-Jan-21 12:12 
QuestionFixes Pin
Chris Maunder4-Mar-19 9:07
cofounderChris Maunder4-Mar-19 9:07 
GeneralMy vote of 5 Pin
Mehedi Shams17-Oct-16 12:33
Mehedi Shams17-Oct-16 12:33 
GeneralRe: My vote of 5 Pin
Nelek18-Oct-16 0:30
protectorNelek18-Oct-16 0:30 
QuestionNice Post! Pin
Vincent Maverick Durano24-Sep-16 21:26
professionalVincent Maverick Durano24-Sep-16 21:26 
AnswerRe: Nice Post! Pin
Nelek24-Sep-16 22:42
protectorNelek24-Sep-16 22:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.