tushar-rishav / code2pdf

:fax: Convert various source codes into pdf file with custom features
MIT License
348 stars 33 forks source link

Multiple files, accept stdin, avoid Qt segfaults. Solves Issue #13 #16

Closed cjwelborn closed 8 years ago

cjwelborn commented 8 years ago

Each file is highlighted separately and the final content is set to the QDocument. This takes care of Issue #13.

Instead of a filename, - may be used to pipe stdin to Code2Pdf. Stdin can only be read once, but it can be mixed in with other files.

Putting the QApplication inside of a class method was causing segfaults (reference was lost before Qt could cleanup). Moving the QApplication to the global scope fixed it. The Code2pdf class is now a subclass of QApplication.

cjwelborn commented 8 years ago

On second thought, this isn't exactly efficient. Using full=True for the HtmlFormatter means that the css classes are generated for each file. It also means that there will be multiple html, head, and body tags. The correct way is to do each file with full=False, grab the style definitions with formatter.get_style_defs(), and then build your own html page by wrapping all file content in <body>, wrapping style definitions in <head> and <style>, and then wrapping all of that in <html>. That would require more work though. A lot of things would need to be moved around. Anyway, sorry to waste your time.