from docutils import nodes
from docutils.parsers.rst import directives

CODE = """\
<iframe width="%(width)d" height="%(height)d"
scrolling="no" frameborder="no"
src="https://w.soundcloud.com/player/?url=http://api.soundcloud.com/tracks/%(sid)s">
</iframe>
"""

def soundcloud(name, args, options, content, lineno,
				contentOffset, blockText, state, stateMachine):
	""" Restructured text extension for inserting SoundCloud embedded music """
	string_vars = {
		'sid': content[0],
		'width': 600,
		'height': 160,
		'extra': ''
	}
	extra_args = content[1:]  # Because content[0] is ID
	extra_args = [ea.strip().split("=") for ea in extra_args]  # key=value
	extra_args = [ea for ea in extra_args if len(ea) == 2]  # drop bad lines
	extra_args = dict(extra_args)
	if 'width' in extra_args:
		string_vars['width'] = extra_args.pop('width')
	if 'height' in extra_args:
		string_vars['height'] = extra_args.pop('height')

	return [nodes.raw('', CODE % string_vars, format='html')]



soundcloud.content = True
directives.register_directive('soundcloud', soundcloud)
@@ -255,16 +255,17 @@
 e%3E%0A%22%22%22%0A%0A
+%0A
 def soun
@@ -313,12 +313,23 @@
 no,%0A
-%09%09%09%09
+               
 cont
@@ -372,17 +372,20 @@
 chine):%0A
-%09
+    
 %22%22%22 Rest
@@ -452,17 +452,20 @@
 sic %22%22%22%0A
-%09
+    
 string_v
@@ -472,18 +472,24 @@
 ars = %7B%0A
-%09%09
+        
 'sid': c
@@ -499,18 +499,24 @@
 ent%5B0%5D,%0A
-%09%09
+        
 'width':
@@ -521,18 +521,24 @@
 ': 600,%0A
-%09%09
+        
 'height'
@@ -544,18 +544,24 @@
 ': 160,%0A
-%09%09
+        
 'extra':
@@ -568,12 +568,18 @@
  ''%0A
-%09%7D%0A%09
+    %7D%0A    
 extr
@@ -627,17 +627,20 @@
 %5D is ID%0A
-%09
+    
 extra_ar
@@ -702,17 +702,20 @@
 y=value%0A
-%09
+    
 extra_ar
@@ -779,17 +779,20 @@
 d lines%0A
-%09
+    
 extra_ar
@@ -813,17 +813,20 @@
 a_args)%0A
-%09
+    
 if 'widt
@@ -835,34 +835,40 @@
  in extra_args:%0A
-%09%09
+        
 string_vars%5B'wid
@@ -898,17 +898,20 @@
 width')%0A
-%09
+    
 if 'heig
@@ -933,10 +933,16 @@
 gs:%0A
-%09%09
+        
 stri
@@ -991,9 +991,12 @@
 ')%0A%0A
-%09
+    
 retu
@@ -1050,18 +1050,16 @@
 tml')%5D%0A%0A
-%0A%0A
 soundclo
@@ -1131,8 +1131,9 @@
 ndcloud)
+%0A

Fix Flake 8 issues