import showdown from 'showdown';
const converter = new showdown.Converter({
  emoji: true,
  tables: true,
  noHeaderId: true,
  strikethrough: true,
  simplifiedAutoLink: true,
  parseImgDimensions: true,
  literalMidWordUnderscores: true
});

export const toHtml = (text: string, trimPTag?: boolean): string => {
  const html:string = converter.makeHtml(text);
  
  if (trimPTag) {
    return html
      .split(/<\/?p>\n?/g)
      .filter(item => !!item)
      .join('<br>');
  }
  return html;
};
