Click here to Skip to main content
14,326,118 members

Workarounds for Code Project's Text Editor

Rate this:
5.00 (4 votes)
Please Sign up or sign in to vote.
5.00 (4 votes)
24 Sep 2016CPOL
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:

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...

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#:

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:

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...

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)

Share

About the Author

Nelek
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 have worked a time with VC++ 6, after that I was over 8 years busy with industry PLC and roboter programming. Now I am working on something related to car electronics and production.

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

Comments and Discussions

 
QuestionFixes Pin
Chris Maunder4-Mar-19 9:07
adminChris Maunder4-Mar-19 9:07 
GeneralMy vote of 5 Pin
Mehedi Shams17-Oct-16 12:33
memberMehedi 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
mveVincent 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.

Tip/Trick
Posted 24 Sep 2016

Tagged as

Stats

11.3K views
2 bookmarked