Refactor code and add unit test for code blocks in list items