Yes, sound weird. But I'm trying to make a text editor inside the browser. I've seen some programs use it. Like wordpress and unet. But I'm not sure if they use a custom one or not.
However, this topic explains why geshi won't work in textarea:
Why isn't textarea an input[type="textarea"]?
I simply get the code of the colors. Just wondering if there's a way around this. I've tried searching but I was without luck.
<textarea><?php geshi_highlight($source, 'php'); ?></textarea>
edit::the variable $source contains php code.
Output is basically the span style that geshi outputs.
That kind of formatting does not work in a textarea, that's one its properties. You probably want to make some HTML contentEditable, but it won't work quickly out of the box, there needs to be a mechanism where an alteration triggers new highlighting. And that would probably involve a lot of traffic to and from the server, to the point of it not being a viable solution. You probably would end up using a javascript syntax highlighter like http://jush.sourceforge.net/ or others, and I haven't actually seen a 'live' syntax highlighter editor in the wild yet (as in: only plain textareas with a syntax-highlighted 2nd box), but then again I've never been searching for it.... I like my editors local ;).
Related
I'm struggling with following issue: I want to include some code examples on my page. They are mostly php, but also html and js.
My best option is to use some of js-based syntax highlighters. I choose SyntaxHighlighter, because so many people recommend this on SO and other sites.
But what about output escaping in twig? Of course default escaping is causing code to show beatifully escaped, but this doesn't work properly. Using |raw to make this work results in other - obvious - issue: it breaks page if html is presented, or breaks scripts if javascript is presented.
Another issue is that all the outputs that I need escaped are mixed, eg:
(some text, with html formatting)
<code class="someclass">
(block of code)
</code>
(some another text)
<code class="anotherclass">
(another block of code)
</code>
Having all these fact I thought - let's write our own filter for Twig! That sounds great, but even if I was able to make it run, I coudn't make it work the way I want.
They I thought - why should I reinvent the wheel? Twig and Symfony2 are out for years, probably someone else already solved this problem, and did it good, secure way.
I'm looking for one of four things:
Custom twig filter to handle this issue, or
Better syntax coloring script, that will handle output escaped by Twig, or
Some other solution, or
Any useful hint.
Have a look at this manual:
http://isometriks.com/geshi-symfony2-and-twig-extensions
It worked for me.
I need to send a rich formated html with lots of css in it.. The problem with mail is that only inline css works.. and i can use that for some part of the mail. the rest is in need to highlight some codes.. which changes for every email.. what i need is some syntax highlighter that can really glow the different codes like c, c++, java, php etc with syntax colors. And i need to do that in php. What is the best server side syntax highlighter can be used.
Or else is there anyway to email a webpage completely with full css support.
Check this out: http://www.sitepoint.com/highlight-source-code-php/
There is this project on GitHub, written in Python, which takes an HTML document and converts all the styles to inline CSS. There is a web page which shows it working.
If you know Python, or know someone who does, you could probably port it to PHP without much difficulty.
I found it by Googling "convert css to inline" - it is the first result, if you look further down the results, you may find a PHP based solution.
PHP source code can be highlighted by using the highlight_string() function - I'm sure other languages provide similar functionality, and there are also projects like this one.
I used something called emogrifier which is written in PHP and it works cool.
I've used Notepad++ for PHP editing with HTML tags echoed out. Notepad++ had always highlighted, and interacted with the HTML, CSS, Javascript, and PHP code all in the same document.
The latest versions seem to only highlight PHP code only, and all the rest of the code be it HTML, CSS, Javscript just gets greyed out, and bunched together.
Here's the screenshot of how the html and javascript look. Switching the language from the menu bar to PHP, HTML, or Javascript doesn't change anything though.
Is there any way to enable this feature again?
Looking at the screenshot, it seems your markup is all in a string that's being echoed out. In that case, Notepad++ is acting normally, highlighting the entire string as a PHP string.
Remember that you don't need to use echo to print HTML. You can embed PHP in HTML (or HTML in PHP) by using PHP's opening and closing delimiters to break out and back in to PHP code anywhere in your files (see the manual). If you close your PHP code with ?> rather than use echo ", and open it back up at the end of the string with <?php instead of ";, your HTML should highlight as HTML again.
Thankfully, no.
I ran into this 'problem' too. Then after an hour of trying to enable this 'feature' I realized: hey, at this point, I should be using templates anyway.
After some consideration I've come to the conclusion that Notepad++ shouldn't do this, to encourage good coding practices.
I'm only embarrassed that it took me so long to realize that it was no longer my editor's job to make my code readable, but mine.
GLHF
im using tinymce for my text editor, i wanted a code highlighting feature for one of the buttons on the toolbar, but i wanted a simple one like the one stackoverflow uses, deos anybody know of anything out there, or deos tinymce have something like this build in :)) thanks for the support!
p.s. im using the jquery tinymce
Stackoverflow uses the markup language Markdown. Server-side it's "rendered" by MarkdownSharp (C# implementation, but there are PHP ports as well). The client-side text editor is WMD.
Syntax highlighting is done using code-prettify.
See https://meta.stackexchange.com/questions/10369/which-tools-and-technologies-build-the-stack-exchange-network.
You probably won't be able to easily fold this into TinyMCE. You're either using Markdown, or a WYSIWYG text editor. Both at the same time is a contradiction.
I can't seem to find a js RTE that will play friendly with snippets of php intertwined in it. I want a mini CMS for the backend of a number of sites. The views have some snippets of php here and there
Are there any RTE's that will leave the php alone, and even show it mixed with the nice formatting?
TinyMCE kills the tags even when entered in html mode and switched back and forth. FCKEdit seems to keep the code intact if pasted into source mode, but it isn't shown in the editing side, so if someone deletes an element with some php in it, bop, it's gone.
And none of the editors like creating nicely indented code, that would be a nice plus as well, but probably over the top to ask, heh.
The Javascript rich text editors make use of the browsers' in-built DesignMode or ContentEditable features in order to implement in-line HTML editing, and these do not support embedded PHP tags.
The solution would have to convert these to some other form, which is not going to get mushed by the browser's HTML editor, then convert them back to PHP tags upon submission.
It could be done. I don't know of any that do, however.
As for creating nicely indented code, it is a similar issue. The browsers munge it in their in-line HTML editors.
I had a similar question a few weeks back:
Textarea that can do syntax highlighting on the fly?
This may be the right thing for you:
http://marijn.haverbeke.nl/codemirror/
They even have mixed PHP and HTML highlighting.