Click here to Skip to main content
15,882,113 members
Please Sign up or sign in to vote.
2.65/5 (3 votes)
Hello to all

I want to know how to make code editor with color markup utility to be used on a webpage. example of such utility is ACE CLOUD9 EDITOR

the main query is how i can markup code with different colors? what technique i should use. I guess it happens with the help of css not sure... but how can i assign colors to fragments of code

for example when we write code in visual studio or turbo C or any modern text editor like Notepad++ it provides nice colors to the code according to its associated file extension. How can one achieve same on a webpage without using any API.

IMPROVED QUESTION:

my motive to ask this question is to know how every character or keyword of code is blinded to different colors as shown on following code examples

C
/* Hello World code with syntax highlighted using different colors*/
#include <stdlib.h>
#include <stdio.h>

int main()
{
    printf("Hello World\n");
    return 0;
}



/* Hello World code without syntax highlighter*/
#include
#include

int main()
{
printf("Hello World\n");
return 0;
}
Posted
Updated 2-Apr-14 18:08pm
v2
Comments
Sergey Alexandrovich Kryukov 2-Apr-14 21:45pm    
Did you try to find anything? It could be easy. Searching in CodeProject along would give you some answer faster than typing this question...
—SA
Sergey Alexandrovich Kryukov 2-Apr-14 21:53pm    
Did you try to find anything? It could be easy...
—SA
Hitesh Rohilla 3-Apr-14 0:12am    
Hello Sergey i don't just want editable area that can be done very simply. what i want is to know how multicolored text markup or technically "SYNTAX HIGHLIGHTING" can be achieve. i know many plugins for doing this but want to know what's behind the code that make this happen. i have updated subject as well as clear my intention in body of question along with two example code. both codes are same but one is with colored highlights and another is simple text.
Hitesh Rohilla 5-Apr-14 23:50pm    
However i didn't get solution yet this is what my common sens or experience says. If i get capability to use regex or grep to style an HTML page in a css this task will be very easy and this will the logical solution.
Hitesh Rohilla 5-Apr-14 23:52pm    
I just found this http://stackoverflow.com/questions/8903313/using-regular-expression-in-css

1 solution

The simplest approach is really very simple, but doing it all from scratch just means a lot of work.

Here is the idea: don't use a "regular" text box. You can make any block HTML element, such as div or paragraph, typeable, by using the attribute contenteditable. And other HTML content (tags with formatting attributes, such as classes, font colors, etc) could be added via commands modifying innerHTML of any element. I already answered this question, with rudimentary code samples:
http://www.codeproject.com/Answers/682802/How-can-i-insert-different-letters-with-different#answer1[^],
http://www.codeproject.com/Answers/684812/changing-the-style-of-every-character-within-any-c#answer1[^].

—SA
 
Share this answer
 
v3

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900