Currently there is no way to reedit a code block without editing the html source... e.g. change the language, turn the gutter off, or change anything else about it. I know that that was a flaw in the original plugin code, but it would be great if you could get that working!

CommentFileSizeAuthor
#4 wysiwyg_syntaxhl.tar_.gz10.27 KBmeecect

Comments

meecect’s picture

Version: 6.x-1.1 » 6.x-1.x-dev
Assigned: Unassigned » meecect

Yes, I would love to have this feature as well. I'm sure it's possible because other tiny plugins have the ability to do it. I'll begin working on it right away.

meecect’s picture

Status: Active » Needs review

This is implemented in the latest dev branch, as soon as it auto builds.

http://ftp.drupal.org/files/projects/wysiwyg_syntaxhl-6.x-1.x-dev.tar.gz

Please see if it fixes the issue.

mrfelton’s picture

Status: Needs review » Needs work

Not working for me. If I click in a bit of text that already has the syntaxhl applied to it, then the syntaxhl button gets a black border, as if to say that tinymce recognises that this bit of text already has it applied. However, clicking on the button just brings up a brand new code edit popup - no code already in there, and none of my settings.

meecect’s picture

StatusFileSize
new10.27 KB

You probably don't have the current code. Is there a CHANGELOG.txt in your module folder, because I added it at the same time. The dev branch releases only build every 12 hours and I only put new code in branches, not in head. I don't want to push a new release yet though because there is still a bug outstanding. I've attached a tar ball; Can you try it?

mrfelton’s picture

The file you just pasted on this thread unzips into /vol/dev/drupal/contributions/modules/wysiwyg_syntaxhl and I can get to it. I just downloaded the latest -dev, whioch has today's date and the CHANGELOG.txt file in it. Now, the syntax highlighter doesn't work at all! I get the popup, but there are no languages in it. The button doesn't even highlight anymore when putting the cursor in an existing code block!

mrfelton’s picture

Actually, the button does highlight if I create a NEW code block and then put the cursor in that - but doesn't for any of my pre existing code blocks. The other problems I described above are still true.

meecect’s picture

Can you tell me the version of os/browser/drupal you are testing with?

mrfelton’s picture

Ubuntu, Firefox, Drupal 6.14, garland theme. No errors in firebug.

meecect’s picture

As far as the issue of not recognizing code blocks that were created before this module, it was partly by design, but I could certainly change it.

In fact we can make the syntax button 'activate' on any PRE element, which would mean you could theoretically change plain ol pre tags into code syntax highlighted boxes. What do you think about that?

mrfelton’s picture

I have written numerous articles using the syntax highlighter, and it will be a royal pain in the ass if this new version doesn't recognise the old ones. I like the idea of associating all pre elements with the syntax highlighter button. +1 from me on that.

meecect’s picture

I've nearly got it;

It now recognizes old syntax blocks, as well as normal pre's. The one downside is that if you edit an old code block, and save the node, you will get the new behavior, which is to convert the pre tags to {}-macro blocks.

Of course, that also means we may not initially have any good way to change syntax blocks back into plain pre's.

Will that work for you?

When I'm done, I'll tag a beta release to make testing easier so we don't have to wait for the dev auto builds or pass around tarballs.

meecect’s picture

Status: Needs work » Needs review

ok, I think it's working. I still have a few problems:

- in ie, it sometimes messes up whitespace (it removes it when it shouldn't).

- if I dynamically add the tiny_mce_popup.js script, safari sometimes bombs out when the dialog opens. This is a known issue with safari, apparently. my current workaround for that currently is to just load it statically, like:

  <script type="text/javascript" src="/sites/all/libraries/tinymce/jscripts/tiny_mce/tiny_mce_popup.js"></script>

in dialog.htm

Note that that only works if that is where your tinymce happens to be (although it should be there).

If you'd like to test, just check out the DRUPAL-6--1 branch where the current changes are. Sample command for that is:

cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d wysiwyg_syntaxhl -r DRUPAL-6--1 contributions/modules/wysiwyg_syntaxhl

mrfelton’s picture

Status: Needs review » Needs work

progress. Not quite there yet...

1) Still doesn't recognise old code blocks. Here is an example of the HTML of one of my old blocks

<pre class="brush: bash;fontsize: 100; first-line: 1; ">[swf file="some-flash-file.swf"] &lt;- wrong
[swf file="flash/some-flash-file.swf"] &lt;- correct
</pre>

2) Clicking the button on a code block does indeed bring the popup with the text already in it, but the options (butter, light etc) are not set to that of the code block...
a) No gutter - not remembered
b) Light - not remembered
c) collapse - not remembered
d) highlight - turned '4' into '[4]'
e) language - ok
f) first line - reset to 1
g) font size - reset to 100%

progress though... nice work.

meecect’s picture

Status: Needs work » Needs review

I just committed some changes to the DRUPAL-6--1 branch, please check it out and give it a spin. On my system, it is working fine now for the example you suggested. I have also created a 'sample.html' file in the module root that has some standard examples so we can test from some known starting position (although please try it out on your other nodes that will have more examples of what may be found in the wild). The sample.html has three cases:

a {} style block

a preexisting pre block based on your example

a plain pre

Note, the button should activate (border drawn around it) for all those cases. Actually it should have been doing this for some time now, because it's the simplest part of the whole thing and was implemented a few revisions ago...it just checks to see if your cursor is in a pre tag or not and the code is stripped right out of the sample plugin tinymce provided.

If something basic like that doesn't work for you, then you must be having a cache issue of some sort.

BTW, I tested this on firefox 3 in ubuntu 9.04

Here is the sample html I have been using to test (from sample.html):

<p>Testing.</p><p>Newly entered syntax block:</p><p>{syntaxhighlighter brush: php;fontsize: 100; first-line: 1;}&lt;?php

print $this;

// this block was entered with the tinymce editor
// if it was entered with the editor plugin it gets 
// a class "wysiwyg-syntaxhl class
// on Save, the editor looks for pre tags
// with that class and will convert it to 
// the '{}' macro's on save

?&gt;{/syntaxhighlighter}</p><p>Old syntax block:</p><pre class="brush: bash;fontsize: 100; first-line: 1;">[swf
file="some-flash-file.swf"] &lt;- wrong
[swf file="flash/some-flash-file.swf"] &lt;- correct

# this block was already syntax highlighted in 'pre' format
# so it doesn't get the wysiwyg-syntaxhl special class.  If you save
# the node without invoking the popup, it will remain intact.
# If you edit it with the popup, it will then get the wysiwyg-syntaxhl class.  
# When saved, all pre's that have the wysiwyg-syntaxhl class are converted to 
# the macro format with {}'s
# Note: you can edit this text in the tinyMCE editor and not trigger
# the conversion, it will only get converted to the {} format if you click the syntax button and 
# invoke the popup 
</pre><p>

Just a regular pre block:

</p><pre>some
text                         with            white
space</pre><p>&nbsp;</p><p>If you enable the 'path' option in the wysiwyg profile section, you
can investigate the preceding pre boxes easily.&nbsp; Just put your cursor
in the box you want to check and look at the path.&nbsp; You should see
something like:</p><p>Path: pre.wysiwyg-syntaxhl brush: php;fontsize: 100; first-line: 1;</p><p>-for pre's that were created by converting macro {} to pre boxes, or for newly inserted syntax boxes from the popup.</p><p>&nbsp;or</p><p>Path: pre.brush: bash;fontsize: 100; first-line: 1;</p><p>-for syntax boxes that pre-existed in the node, and still use the pre format instead of the macro {} tags</p><p>or</p><p>Path: pre</p><p>-for regular pre tags that might pre-exist.</p><p>&nbsp;</p><p>Note: The syntax highlight button should 'activate' (button should get a border) if you place the cursor in ANY pre element.&nbsp; I am only checking for whether the element is a &lt;pre&gt;, that's it.</p>

meecect’s picture

BTW, do you have performance enabled, like javascript consolidation? Make sure those are off, or you reset your drupal cache before testing.

mrfelton’s picture

I had all the performance stuff turned off. I am testing in Firefox 3.5 ubuntu... I'll give the new code a spin in the next hour so. Thanks for your work on this, gonna be great when this is working properly!

mrfelton’s picture

Status: Needs review » Reviewed & tested by the community

Seems to be working nicely... Very cool. One thought... what do you think about being able to highlight any text and turn it into syntax highlighted text (not just pre elements)? Not sure if that would work or not - didn't give it much thought, just an idea.

What you have here is great though. Thanks again.

meecect’s picture

I think that would be pretty easy to implement, because right now, when a selection is made I just check to make sure the selection is a pre tag and then get all of it's content to populate the popup. In the general case, I would just need to code the 'if-not-pre' case and then process the highlighted section. Internet explorer will likely give me fits though. It just decides willy-nilly to force html validation when getting and setting values, so we'll probably have lots of whitespace and html encoding issues. It doesn't work very well right now in ie, but I can't be arsed to fix it. Screw ie.

Feel free to create a new issue for it though and I'll do it when I get time.

meecect’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.