Skip to content

Instantly share code, notes, and snippets.

@sunnygleason
Last active April 25, 2017 18:14
Show Gist options
  • Save sunnygleason/31165fa4c4507f9e1ba4f70684a575e0 to your computer and use it in GitHub Desktop.
Save sunnygleason/31165fa4c4507f9e1ba4f70684a575e0 to your computer and use it in GitHub Desktop.
PubNub HTML Sanitizer BLOCK JavaScript
export default (request) => {
const xhr = require('xhr');
const query = require('codec/query_string');
const userId = 'YOUR_USER';
const apiKey = 'YOUR_API_KEY';
const outputType = 'plain-text';
let apiUrl = 'https://neutrinoapi.com/html-clean';
let params = {
'user-id': userId,
'api-key': apiKey,
'content': request.message.payload,
'output-type': outputType
};
apiUrl = apiUrl + '?' + query.stringify(params);
return xhr.fetch(apiUrl).then((response) => {
request.message.clean_html = response.body;
request.message.original_html = request.message.payload;
delete request.message.payload;
return request.ok();
}).catch(err => {
console.error(err);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment