Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / NewStats: 3,194,215 members, 7,953,795 topics. Date: Friday, 20 September 2024 at 06:41 AM |
Nairaland Forum / Science/Technology / Programming / Programming Your Own Code Syntax Highlighter (2320 Views)
I Have A Very Import Question On Python Syntax / Syntax Error: Unexpected End Of File: Php / Javascript Function Declaration Syntax: Var... (2) (3) (4)
Programming Your Own Code Syntax Highlighter by Nobody: 9:10am On Mar 01, 2016 |
Yeah, that's pretty much how it's done...forgive me for going into the code first i love diving a lot. That highlights basic html tags plus javascript comments. Regular Expressions are used to achieve things like this, RegExp can also be used to filter banned words from a site, e.g: if "Daniel" was a banned word on Nairaland it wouldn't show up, or can be programmed to show another word, maybe "DanielTheGeek" That would be achieved this way:
There are many more interesting things that can be done with RegExp, like auto correcting words and auto-capitalization of words. We have what we call flags in RegExp programming logic the [size=22pt]g[/size] which stands for global will target the specified letters anywhere it is used.
the [size=22pt]i[/size] flag will ignore the casing of letters
We have another flag the [size=22pt]m[/size] flag, do your research and tell me what it does. Even though it is cool and creative making your own code syntax highlighter from scratch, supporting a vast array of programming languages and config files will be too much work, except that's your specialisation. So i recommend using ready made libraries for these tedious tasks, they were made to reduce the work time and load, most users won't even know you're using a framework/plugin...they'd just be like, waooh! cool!. Go ahead and grab cool libraries like highlight.js, which supports almost all the languages you know of, if not all. https://highlightjs.org/download/ Goodluck. [size=22pt]Modified[/size] [size=22pt]Maybe we should recommend highlight.js for Seun, do you all agree?[/size] 1 Like |
Re: Programming Your Own Code Syntax Highlighter by danidee10(m): 9:28am On Mar 01, 2016 |
I swear nairaland needs a better swear-word filter users easily beat the system by just adding more letters to the word 2 Likes |
Re: Programming Your Own Code Syntax Highlighter by asalimpo(m): 10:31am On Mar 01, 2016 |
Cool. So syntax highlighting is frontend stuff? Seun, needs to declass the word na.ked as foul. 'unclad' is simply too clumsy to use. 1 Like |
Re: Programming Your Own Code Syntax Highlighter by Nobody: 10:37am On Mar 01, 2016 |
asalimpo: It can be used anyhow, frontend alone for static websites but dynamic sites like Naira land only had to implement few more things. The click event can be used with buttons in comment boxes. But basically you don't need any interaction with the server before highlighting syntax. |
(1) (Reply)
Share Your Programming Tips / Mobile Electronic Voting System / Who wants Free Crytocurrecy Buy and Sell Script?
(Go Up)
Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health religion celebs tv-movies music-radio literature webmasters programming techmarket Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10) Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 34 |