I was wondering if anyone had got the built-in HTML drag commands for <img> and <css> to work in Textmate 1b5?
Currently if I drag a html or PDF file from the project window into a HTML file I'm working on it will create a <a href=""> link, but if I drag an image file or css file onto the HTML file, Textmate will insert the raw source of the dragged file.
Any ideas where I am going wrong? I am using the following drag commands (built-in):
<img> File Types: png, PNG, jpeg, JPEG, jpg, JPG, gif, GIF Commands: img=$TM_DROPPED_FILE alt=`echo $img | perl -pe 's/^(.*/)?(.*?)(..*)?$/$2/g' | tr '_-' ' '` sips -g pixelWidth -g pixelHeight $img | awk '/pixelWidth/ { w=$2 } /pixelHeight/ { h=$2 } END { printf("<img src="'"$img"'" width="%d" height="%d" alt="${0:'"$alt"'}" />", w, h) }'
<css> File Types: css echo "<link href="$TM_DROPPED_FILE" rel="stylesheet" type="text/css" />"
Apologies if this has already been covered.
Mike
On Mar 29, 2005, at 16:49, Michael wrote:
I was wondering if anyone had got the built-in HTML drag commands for <img> and <css> to work in Textmate 1b5?
It works for me. What's not apparent from the bundle editor is that currently the extension of the file in which you drop the image is used to figure out which drag command to execute.
In the future this will be changed to instead rely on the scope, but for now the HTML file should have one of these extensions: html, htm, rhtml, shtml, phtml, php, php3, php4, php5, inc, cfm, cfml, dbm, dbml.
You can edit the drag command outside TextMate if you're using another extension for your files.
Currently if I drag a html or PDF file from the project window into a HTML file I'm working on it will create a <a href=""> link, but if I drag an image file or css file onto the HTML file, Textmate will insert the raw source of the dragged file.
Hmm... judging from this, your document does have the proper extension. Which extension does the dragged CSS or image file have?
On 29 Mar 2005, at 16:46, Allan Odgaard wrote:
On Mar 29, 2005, at 16:49, Michael wrote:
I was wondering if anyone had got the built-in HTML drag commands for <img> and <css> to work in Textmate 1b5?
It works for me. What's not apparent from the bundle editor is that currently the extension of the file in which you drop the image is used to figure out which drag command to execute.
In the future this will be changed to instead rely on the scope, but for now the HTML file should have one of these extensions: html, htm, rhtml, shtml, phtml, php, php3, php4, php5, inc, cfm, cfml, dbm, dbml.
You can edit the drag command outside TextMate if you're using another extension for your files.
Currently if I drag a html or PDF file from the project window into a HTML file I'm working on it will create a <a href=""> link, but if I drag an image file or css file onto the HTML file, Textmate will insert the raw source of the dragged file.
Hmm... judging from this, your document does have the proper extension. Which extension does the dragged CSS or image file have?
.css and .jpg
Interestingly this morning after re-launching Textmate when I drag and drop an image I get:
Error 4: no file was specified Try 'sips --help' for help using this tool <img src="" width="0" height="0" alt="" />
but still get the source of a css file when dragged and dropped.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On Mar 30, 2005, at 12:34, Michael wrote:
Interestingly this morning after re-launching Textmate when I drag and drop an image I get:
Error 4: no file was specified
I just noticed that the $TM_DROPPED_FILE variable (and $img) should have been quoted in the drag command (in case the file path contains a space), though I'd think this would give another error code.
Could you try to change the drag command simply to: echo $TM_DROPPED_FILE
That should then output the path dropped (relative to the directory of the file).
On 30 Mar 2005, at 14:48, Allan Odgaard wrote:
On Mar 30, 2005, at 12:34, Michael wrote:
Interestingly this morning after re-launching Textmate when I drag and drop an image I get:
Error 4: no file was specified
I just noticed that the $TM_DROPPED_FILE variable (and $img) should have been quoted in the drag command (in case the file path contains a space), though I'd think this would give another error code.
Could you try to change the drag command simply to: echo $TM_DROPPED_FILE
That should then output the path dropped (relative to the directory of the file).
Thanks: that works - with just the path to the file being inserted. How do I modify it so that when I drag an image file to a document I get:
<img src="path_to_image" width="actual_pixels" height="actual_pixels" alt="" />
and for css:
<link href="path_to_css" rel="stylesheet" type="text/css" media="my_choice"/>
Cheers,
Mike
On Mar 30, 2005, at 16:05, Michael wrote:
Could you try to change the drag command simply to: echo $TM_DROPPED_FILE
Thanks: that works - with just the path to the file being inserted.
Does it use the command then both for your image and CSS? or did you make the change for both drag commands?
How do I modify it so that when I drag an image file to a document I get: <img src="path_to_image" width="actual_pixels" height="actual_pixels" alt="" />
and for css:
<link href="path_to_css" rel="stylesheet" type="text/css" media="my_choice"/>
Well... that's really what the default stuff should have done ;)
For CSS try then to change the drag command to: printf '<link href="%s" rel="stylesheet" type="text/css" media="my_choice"/>\n' "$TM_DROPPED_FILE"
And let me know if that works.
On 30 Mar 2005, at 15:21, Allan Odgaard wrote:
On Mar 30, 2005, at 16:05, Michael wrote:
Could you try to change the drag command simply to: echo $TM_DROPPED_FILE
Thanks: that works - with just the path to the file being inserted.
Does it use the command then both for your image and CSS? or did you make the change for both drag commands?
I only modified the image drag command, and when I tried to drag a css file it still inserted the source of the file, but after trying the drag command listed below for css it works fine - thanks.
Any suggestions for the image drag command?
How do I modify it so that when I drag an image file to a document I get: <img src="path_to_image" width="actual_pixels" height="actual_pixels" alt="" />
and for css:
<link href="path_to_css" rel="stylesheet" type="text/css" media="my_choice"/>
Well... that's really what the default stuff should have done ;)
For CSS try then to change the drag command to: printf '<link href="%s" rel="stylesheet" type="text/css" media="my_choice"/>\n' "$TM_DROPPED_FILE"
And let me know if that works.
On Mar 30, 2005, at 16:30, Michael wrote:
Does it use the command then both for your image and CSS? or did you make the change for both drag commands?
I only modified the image drag command, and when I tried to drag a css file it still inserted the source of the file, but after trying the drag command listed below for css it works fine - thanks.
Any suggestions for the image drag command?
Well, try to restore it to:
img="$TM_DROPPED_FILE" alt=`echo $img | perl -pe 's/^(.*/)?(.*?)(..*)?$/$2/g' | tr '_-' ' '` sips -g pixelWidth -g pixelHeight "$img" | awk '/pixelWidth/ { w=$2 } /pixelHeight/ { h=$2 } END { printf("<img src="'"$img"'" width="%d" height="%d" alt="${0:'"$alt"'}" />", w, h) }'
If this fails, try one thing at a time, e.g. just: sips -g pixelWidth -g pixelHeight "$TM_DROPPED_FILE"
Btw: if you have an IRC client, msg me on #textmate / FreeNode, that's a bit easier than this...
Hi, I'm reviving this somewhat old thread on dragging images (and css) into an open html file. I'm unable to get an <img> tag when I try to drag an image into an open html file, I get only the very long binary write-out.
I've tried playing with the snippet as per this thread (dated March '05). I'm using 1.09b with a refreshed svn checkout (as of 5/25/05).
Just for the fun of it, I just removed all my local bundles ~/Library/ Application Support/Textmate in case some setting I'd created was overwriting the new bundles (I may be confused on how this works, but I think it's like this)
I have: img=$TM_DROPPED_FILE alt=`echo $img | perl -pe 's/^(.*/)?(.*?)(..*)?$/$2/g' | tr '_-' ' '` echo -n "![${1:$alt}]($TM_DROPPED_FILE)"
as the Drag command in the bundle editor. (under Markdown/Insert <img> tag) Applying to these file types: png, PNG, jpeg, JPEG, jpg, JPG, gif, GIF
This hasn't worked for me on the last couple of betas, and I've neglected to take the time to figure out if it was something I did or was the result of the new beta development. Since I haven't heard anyone mention it, I'm guessing I frigged w/ something at one time.
I just tried: sips -g pixelWidth -g pixelHeight "$TM_DROPPED_FILE" in place of the drag command above, but I still get binary output instead of an <img> tag w/ the path. Is it possible I have one drag command taking precedence over the one I'm looking at?
--OK, I just listed only drag commands and found there was also a Latex img drag command. I've tried removing the latex bundle, restarting, trying the drag command. Then replacing latex, removing markdown bundle and trying drag command. Still no go.
Does anyone have any suggestions?
Thanks in advance, Ben
On Mar 30, 2005, at 6:41 AM, Allan Odgaard wrote:
On Mar 30, 2005, at 16:30, Michael wrote:
Any suggestions for the image drag command?
Well, try to restore it to:
img="$TM_DROPPED_FILE" alt=`echo $img | perl -pe 's/^(.*/)?(.*?)(..*)?$/$2/g' | tr '_-' ' '` sips -g pixelWidth -g pixelHeight "$img" | awk '/pixelWidth/ { w= $2 } /pixelHeight/ { h=$2 } END { printf("<img src="'"$img"'" width="%d" height="%d" alt="${0:'"$alt"'}" />", w, h) }'
If this fails, try one thing at a time, e.g. just: sips -g pixelWidth -g pixelHeight "$TM_DROPPED_FILE"
Btw: if you have an IRC client, msg me on #textmate / FreeNode, that's a bit easier than this...
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
On May 25, 2005, at 2:53 PM, Ben Parzybok wrote:
Hi, I'm reviving this somewhat old thread on dragging images (and css) into an open html file. I'm unable to get an <img> tag when I try to drag an image into an open html file, I get only the very long binary write-out.
I just tried it, and it works fine for me. Are you sure the image you are dragging has one of the extensions that are handled by the drag? I renamed the extension of a jpg image to jpe, and it got loaded as binary data instead, but when its extension was jpg, it worked as expected. Also, if the spelling was Jpg, then it was not recognized either. Also, are you certain the language for the file is html?
I have: img=$TM_DROPPED_FILE alt=`echo $img | perl -pe 's/^(.*/)?(.*?)(..*)?$/$2/g' | tr '_-' ' '` echo -n "![${1:$alt}]($TM_DROPPED_FILE)"
This is what I have: img="$TM_DROPPED_FILE" alt=`perl <<<$img -pe 's/^(.*/)?(.*?)(..*)?$/$2/g; y/_-/ /'` sips -g pixelWidth -g pixelHeight "$img" | awk '/pixelWidth/ { w=$2 } /pixelHeight/ { h=$2 } END { printf("<img src="'"$img"'" width="%d" height="%d" alt="${0:'"$alt"'}" />", w, h) }'
as the Drag command in the bundle editor. (under Markdown/Insert <img> tag) Applying to these file types: png, PNG, jpeg, JPEG, jpg, JPG, gif, GIF
So, unless your file has as extension EXACTLY one of those, it will not work.
--OK, I just listed only drag commands and found there was also a Latex img drag command. I've tried removing the latex bundle, restarting, trying the drag command. Then replacing latex, removing markdown bundle and trying drag command. Still no go.
This should not affect things, the latex drag command should work only if the language is latex.
Does anyone have any suggestions?
Thanks in advance, Ben
Haris
Hi Haris, Thanks for your reply.
I just tried it, and it works fine for me. Are you sure the image you are dragging has one of the extensions that are handled by the drag? I renamed the extension of a jpg image to jpe, and it got loaded as binary data instead, but when its extension was jpg, it worked as expected. Also, if the spelling was Jpg, then it was not recognized either. Also, are you certain the language for the file is html?
My file extensions are correct, i've tried .png, .jpg and .gif with the same results. However I did have the language set to PHP. Trying HTML (PHP) resulted in the same binary output.
Interestingly the drag command does work for href links.
OK, I just duplicated my drag <a> command and re-entered the code for the img drag command
img="$TM_DROPPED_FILE" alt=`perl <<<$img -pe 's/^(.*/)?(.*?)(..*)?$/$2/g; y/_-/ /'` sips -g pixelWidth -g pixelHeight "$img" | awk '/pixelWidth/ { w= $2 } /pixelHeight/ { h=$2 } END { printf("<img src="'"$img"'" width= "%d" height="%d" alt="${0:'"$alt"'}" />", w, h) }'
and reset the file extensions and it worked. The one thing that was different was the scope field, which I guess I don't understand yet. It used to be: text.html.markdown and now it's just: text.html
Also I should note that the drag command that's working is now under the HTML heading (because I duplicated the drag <a> command that was there) and not under the Markdown heading in the bundle editor.
-Ben
On May 25, 2005, at 22:44, Ben Parzybok wrote:
The one thing that was different was the scope field, which I guess I don't understand yet.
The scope is where the command should be active (i.e. the language).
If you have enabled the Language Definition bundle then try e.g. to place the caret on a string in PHP in HTML, then press ctrl-shift-T (a command that shows the current scope as a tooltip), it should show: text.html.basic source.php.embedded.html string.double-quoted.php
This is the scope that the caret is in, and you can limit settings, styles, and bundle items to work only for a given scope.
So scopes are very much like CSS selectors -- also, when you enter the scope, TextMate performs pattern matching, so you don't have to enter all of it, e.g. you could just enter: “string” and the (in this case) drag command would only be used, when you drag stuff onto strings.
For something like a drag command you'd just set the first part of the scope, i.e. text.html versus text.latex or source.css. This btw means that if you have <style>...</style> in a HTML file, dragging stuff to that section will get the appropriate drag command scoped to source.css, where dragging to outside this section will result in the commands scoped to text.html.
There should be coverage of this in the release notes (for 1.1b6).
On May 25, 2005, at 4:37 PM, Allan Odgaard wrote:
So scopes are very much like CSS selectors -- also, when you enter the scope, TextMate performs pattern matching, so you don't have to enter all of it, e.g. you could just enter: “string” and the (in this case) drag command would only be used, when you drag stuff onto strings.
Very cool, I'm finally beginning to understand what's been happening b5 - b9 -- Thanks Alan. -b
On 30 Mar 2005, at 15:54, Allan Odgaard wrote:
On Mar 30, 2005, at 12:34, Michael wrote:
[...] Interestingly this morning after re-launching Textmate when I drag and drop an image I get:
Which reminds me, editing the drag commands currently does require a restart before the changes take effect, sorry.
Thanks for the image drag command - this now works. I had guessed that a re-launch was required for changes to take effect - but thanks for the confirmation.
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
* Michael [2005-03-29 09:51]:
I was wondering if anyone had got the built-in HTML drag commands for <img> and <css> to work in Textmate 1b5?
Currently if I drag a html or PDF file from the project window into a HTML file I'm working on it will create a <a href=""> link, but if I drag an image file or css file onto the HTML file, Textmate will insert the raw source of the dragged file.
Any ideas where I am going wrong? I am using the following drag commands (built-in):
This totally doesn't answer your question, but I've noticed in some cases I'll get an img tag, other cases the binary code. Unfortunately I've always been rushed and not had a chance to examine the context. I have the default (built-in) commands as well... I suspect it's based on the context - file type or location in file, or something...