Refactoring from nodebb-plugin-markdown