Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

Is there a way to pipe html to gedit witout losing the spacing.

I am trying with: echo "'+html5template+'" | gedit

The output is like this:

<!DOCTYPE html><html><head><title></title></head><body></body></html>

But I need it to be like this:

<!DOCTYPE html>
<html>
      <head>
            <title></title>
      </head>
      <body>
      </body>
 </html>

The script look like this:

doctype='<!DOCTYPE html>'
html_start='<html>'
header_start='<head>'
header_end='</head>'
body='<body></body>'
html_end='</html>'

meta_data=''

#get page title
meta_data += '<title>'+self.builder.get_object("page_title_entry").get_text()+'</title>'

#build the html template
html5template=doctype+html_start+header_start+meta_data+header_end+body+html_end

#open template with gedit
Popen('echo "'+html5template+'" | gedit', shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=False)
share|improve this question

1 Answer 1

up vote 1 down vote accepted

You don't create any spacing in your Python code, your output is exactly what your Python code creates.

To get the spacing you want you can for example replace

html5template=doctype+html_start+header_start+meta_data+header_end+body+html_end

with

indent='    '    
html5template='\n'.join((doctype,
                        html_start,
                        indent + header_start,
                        indent + indent + meta_data,
                        indent + header_end,
                        indent + body,
                        html_end
                        ))
share|improve this answer
    
Of course, it was just so simple :) Thanks!! –  Voidcode Jul 7 '12 at 0:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.