Join GitHub today
GitHub is home to over 36 million developers working together to host and review code, manage projects, and build software together.
Sign upHtml generation leaves out the first character from python imports #84
Comments
BurntSushi
added
the
bug
label
Jan 14, 2016
This comment has been minimized.
This comment has been minimized.
|
That is a strange bug indeed! I haven't reproduced it yet, but I wonder, is the HTML correct and this is just a styling issue? Or is the first character actually dropped from the output altogether? (Either would be weird!) |
This comment has been minimized.
This comment has been minimized.
|
I am not sure, yet haven't taken a look at the code. Here is the html of that screenshot And it is actually stripping the first character of each line, the html shows that it is being stripped and not just a styling issue. Now , you made me curious let me take a look why that is happening and do a PR. |
This comment has been minimized.
This comment has been minimized.
|
Okay, found the bug. It's here https://github.com/BurntSushi/pdoc/blob/master/pdoc/templates/html.mako#L41 It basically tries to get the indent of the first line, but since the first line is an empty line the indent is 1 and not the expected 0. So, on line 41 basically says give me every single line from source code but starting from the I am not sure why it needs to get the indent though, so am afraid of removing that thinking it might mess something else. However, if you remove line 41 then it should work. |
This comment has been minimized.
This comment has been minimized.
|
@IAlwaysBeCoding the reason why it's mucking with indents is if the code is indented, then it doesn't look so good to just put that in I think I'd probably recommend fixing the indent code. That is, compute the indent based on the first non-empty line instead of the first line. (There may be other cases where this fails, but I'd be happy with that simple fix for now!) |
This comment has been minimized.
This comment has been minimized.
|
@BurntSushi Oh okay! Then in that case, we can do a really quick fix. Just check if the first line just contains white space, if so then set the base indent to 0 if not then set it to whatever the base indent is. Let me do a quick pull request. That should fix that for now for that edge case and leave the indended functionality behind like it was. |
This comment has been minimized.
This comment has been minimized.
|
How about: base_indent = 0
for line in line:
if len(line.strip()) > 0:
base_indent = len(indent.match(lines[0]).group(0))
break |
This comment has been minimized.
This comment has been minimized.
|
I had this in mind,literally I was 30 seconds away from finishing the pull request. What do you think base_indent = 0 if lines[0].isspace() else base_indent
|
This comment has been minimized.
This comment has been minimized.
|
@IAlwaysBeCoding Well, what happens if there are two preceding empty lines? :P Might as well just find the first non-empty line and base the indent off of that. (I'm not sure if you're worried about performance or not, but if you are, you shouldn't be. :-)) |
This comment has been minimized.
This comment has been minimized.
|
@BurntSushi I am confused though, like for example on my sublime editor. I can't really run any python if the first line has any spaces as indentation starting out because I get the |
This comment has been minimized.
This comment has been minimized.
|
@IAlwaysBeCoding I think I'm just thinking about other places, like methods, but I think their code blocks are probably trimmed anyway. Nevertheless, I think I prefer the more robust way of doing it (find first non-empty line) for now. Please feel free to submit a PR with it. :-) Thanks! |
IAlwaysBeCoding
referenced this issue
Jan 14, 2016
Merged
Remove html stripping bug from html.mako #86
This comment has been minimized.
This comment has been minimized.
|
Okay, I submitted a pull request. If there is anything else you would like changed let me know. Anyways, I think am going to be playing a lot more with pdoc from now on. Great project though! |
IAlwaysBeCoding commentedJan 14, 2016
So, I found an odd bug. Don't really know how to fix it , but I know how to get around it.
Here is a screenshot:
https://imgur.com/w6Z5Ro3
Example:
Will produce source code without the first character, only if the first line is blank. To fix this, just make sure the first line isn't blank, and will produce the correct output.
Also, just wanted to say that your project is FREAKING amazing. I am thinking of using it for stitching together something simple that I can use to upload my documentation to gitbook.com . Sphinx is kinda too big, although is great it doesn't work well with Markdown. Plus, I saw that your project also processes any markdown too in doc strings which is super useful. Thanks for this god-send project, just what I was looking for .