For a function this small there isn't really much to refactor. Parsing markdown has been done thousands of times already and there are libraries that do this perfectly.
Extra bonus points for renaming the function. This would be my first improvement. Even if you left the function as is and just renamed it to describe its purpose that's a huge improvement in my book.
I would first start thinking about what this function actually does.
For me the name
lineChecker
is a little bit misleading because it looks like the function actually parses strings to html.This is what I came up with:
For a function this small there isn't really much to refactor. Parsing markdown has been done thousands of times already and there are libraries that do this perfectly.
Cool puzzle nonetheless.
Adding the types makes sense.
Only the else if else statement could be replaced. My suggestion based on your example
edited
I'd suggest putting the line argument in the function first, as line is more important and
isFirstLine
can have a default valuetrue i just copy paste it and didn't read the arguments.
Extra bonus points for renaming the function. This would be my first improvement. Even if you left the function as is and just renamed it to describe its purpose that's a huge improvement in my book.
The renaming idea + introducing types is great!
To me, the method seems to be more of a
print
than aparse
method (but I don't have the full context, just saw it in isolation).