omarkhan/coffeedoc

Using tabs for indentation causes code blocks where not wanted

Closed this issue · 5 comments

If you use tabs for indentation in your *.coffee file and write multiline coffeedoc comments like you have in your example in README.md the whole comment is converted to a <pre><code></code></pre> block.

Example:

foo = ->
    ###
    This will be a preformatted code block in the generated html
    if you happen to use tabs for indenting your *.coffee files
    ###

Take a look at the formatDocstring() function in coffeedoc.coffee. It counts the number of leading spaces before each line in the docstring, and assumes the lowest number it finds to be the indentation level. It then removes that many spaces from each line.

This will not work if you use tabs for indentation. I didn't bother putting in code for this as I don't use tabs and wasn't sure how to determine docstring indentation for cases with mixed tabs and spaces etc. If you want to contribute a patch I'll happily merge your code.

Regarding the mixed tabs and spaces issue:
I'd say this should be of no concern as it's generally considered bad practice. What's your opinion on that?

Sure. Then the formatDocstring() function just needs to figure out whether the code uses tabs or spaces, and then count them. Can you write a patch?

Actually I have no experience in working with Node.js. So building, testing etc. would be quite time-consuming for me since I'd have to look up all the stuff.

However if I haven't overlooked anything it should suffice to replace the space with the \s character class in the Regular Expressions on these lines: 149, 156, 157, 160. That would be equivalent to [ \t\r\n] which should be OK since we're never dealing with newlines here. If it sounds safer you could still use [ \t] instead.

The other thing that could be added is a warning when using mixed characters for indentation. But I think I could come up with something for that too...

Looks good. Fixed in 00c52b3