Converting HTML from an email to Markdown?

Wondering if anyone has done this. The goal is to print the body of the email channel to our slack / mattermost.

I'm currently trying to convert turndown to a single file with webpack so our YouTrack Workflow can consume it, but no luck yet.

0
3 comments

Hello,

I'm Lena from the YouTrack Team. 

Please try to use the `Prefer plain text for ticket descriptions` option in the mailbox integration → post-processing section. 

https://www.jetbrains.com/help/youtrack/cloud/inbound-message-handling.html#email-channel-post-processing

When enabled, YouTrack uses the plain-text version of the message for the ticket description whenever the incoming message contains a plain-text version of the email. If the plain-text version is not available, the content from the HTML version of the message is wrapped in HTML tags, stored in Markdown syntax, and used for the description instead.

 

0

I might actually turn on the text-only version just because it's simpler and it works 99% of the time, thank you so much for this great suggestion!

But I got it working after all anyway, so if anybody needs to include arbitrary JS modules in their YouTrack Workflows, this webpack config might be of help. So in this particular case, getting Turndown to work as a commonjs module:

Here's the webpack.config.js that takes the src/turndown.js file and its dependencies, bundles it into a js blob that can be pasted as a custom workflow:

const webpack = require('webpack');

module.exports = {
  entry: ['./src/turndown.js'],
  output: {
    filename: 'turndown.js',
    library: {
      type: 'commonjs'
    }
  },
  mode: 'production',
  target: 'node',
  plugins: [
    new webpack.DefinePlugin({
      'setTimeout': 'undefined',
      'clearTimeout': 'undefined',
      'setInterval': 'undefined',
      'clearInterval': 'undefined',
      'process.browser': 'undefined',
    })
  ]
}

Since some of the dependencies source contained reference to timers and a process.browser object which are not implemented for Workflows, these are omitted in the configuration file using webpack's plugin interface.

A quirk of the result is that I had to include the file the following way:

const td = require('my-workflows/turndown').default;

Not sure what that is about, but it works.

0

Hi,

I'm happy to hear that the option works for you, and thank you for sharing your solution as well! 

0

Please sign in to leave a comment.