playgroundbooks / playgroundbook

Tool for Swift Playground books
https://ashfurrow.com/blog/swift-playground-books/
MIT License
259 stars 17 forks source link

Removes extraneous newlines. #22

Closed ashfurrow closed 8 years ago

ashfurrow commented 8 years ago

Fixes #20.

Regexes gave me trouble for stripping lines like

//: Some markdown.

I originally used squeeze("\n") but that strips consecutive newlines in code, which is not good (I added a test for that). So my solution was to split based on a regex that used \n* and then join. The problem is that this adds a newline before any matched components, so I make sure to remove newlines preceding //: comments after that check. Let me know what you think, I'm sure there's a better solution.

ashfurrow commented 8 years ago

@rpowelll Are you available to look this over? No worries at all, I know you're busy!

rhysforyou commented 8 years ago

It might be a good idea to add a test to ensure we're not stripping newlines from inside comment blocks as well since in Markdown those can be syntactically significant. My general rule is to over-test any time you use regular expressions since they tend to be fragile and introduce regressions.

ashfurrow commented 8 years ago

That's a good idea!

rhysforyou commented 8 years ago

👍 looks good