Skip to content

Commit

Permalink
Add Audio snippet and drop action
Browse files Browse the repository at this point in the history
Also add ogg extension to Video drop action.
  • Loading branch information
infininight committed Jul 2, 2018
1 parent a7b8756 commit 7822e77
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 3 deletions.
51 changes: 51 additions & 0 deletions DragCommands/Insert Audio.tmDragCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>command</key>
<string>#!/usr/bin/env ruby20

if ENV['TM_DROPPED_FILE'] =~ /(?i)\.mp4$/
mimetype = 'mp4'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.mp3$/
mimetype = 'mp3'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.og[ga]$/
mimetype = 'ogg'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.webm$/
mimetype = 'webm'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.flac$/
mimetype = 'flac'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.wave?$/
mimetype = 'wav'
end

puts &lt;&lt;~TAG
&lt;audio controls&gt;
&lt;source src="#{ENV['TM_DROPPED_FILE']}" type="audio/#{mimetype}"${TM_XHTML}&gt;

&lt;p&gt;Your browser doesn't support HTML5 audio. Here is
a &lt;a href="#{ENV['TM_DROPPED_FILE']}"&gt;link to the audio&lt;/a&gt; instead.&lt;/p&gt;
&lt;/audio&gt;
TAG
</string>
<key>draggedFileExtensions</key>
<array>
<string>mp4</string>
<string>mp3</string>
<string>ogg</string>
<string>oga</string>
<string>webm</string>
<string>flac</string>
<string>wav</string>
<string>wave</string>
</array>
<key>name</key>
<string>Insert Audio</string>
<key>output</key>
<string>insertAsSnippet</string>
<key>scope</key>
<string>text.html</string>
<key>uuid</key>
<string>01D7DB7F-0A1E-4086-9277-562FD85A58CC</string>
</dict>
</plist>
7 changes: 4 additions & 3 deletions DragCommands/Insert Video.tmDragCommand
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

if ENV['TM_DROPPED_FILE'] =~ /(?i)\.mp4$/
mimetype = 'mp4'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.ogv$/
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.og[gv]$/
mimetype = 'ogg'
elsif ENV['TM_DROPPED_FILE'] =~ /(?i)\.webm$/
mimetype = 'webm'
Expand All @@ -28,10 +28,11 @@ TAG
</string>
<key>draggedFileExtensions</key>
<array>
<string>mov</string>
<string>ogv</string>
<string>mp4</string>
<string>ogg</string>
<string>ogv</string>
<string>webm</string>
<string>mov</string>
</array>
<key>input</key>
<string>selection</string>
Expand Down
21 changes: 21 additions & 0 deletions Snippets/Audio.tmSnippet
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>content</key>
<string>&lt;audio controls&gt;
&lt;source src="${1:example.mp3}" type="audio/${1/(?i).*?(?:\.((mp4)|(mp3)|(webm)|(og[ga])|(flac)|(wave?)))?$/(?2:mp4)(?3:mp3)(?4:webm)(?5:ogg)(?6:flac)(?7:wav)(?1::unknown)/}"${TM_XHTML}&gt;
&lt;p&gt;Your browser doesn't support HTML5 audio. Here is
a &lt;a href="${1:example.mp3}"&gt;link to the audio&lt;/a&gt; instead.&lt;/p&gt;
&lt;/audio&gt;</string>
<key>name</key>
<string>Audio</string>
<key>scope</key>
<string>text.html - B:meta.tag - B:text.html meta.embedded</string>
<key>tabTrigger</key>
<string>audio</string>
<key>uuid</key>
<string>8C826982-F460-43FA-BA31-476EE410F101</string>
</dict>
</plist>
1 change: 1 addition & 0 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
<array>
<string>64F212E5-545D-4D36-A243-B452B10EC678</string>
<string>------------------------------------</string>
<string>8C826982-F460-43FA-BA31-476EE410F101</string>
<string>4462A6B8-A08A-11D9-A5A2-000D93C8BE28</string>
<string>4905D47B-A08B-11D9-A5A2-000D93C8BE28</string>
<string>3E008E42-A5C9-11D9-9BCD-000D93C8BE28</string>
Expand Down

0 comments on commit 7822e77

Please sign in to comment.