Skip to content

Instantly share code, notes, and snippets.

@mykeels
Created January 29, 2018 21:41
Show Gist options
  • Select an option

  • Save mykeels/82011b3fe9d6c40d9d8b9ca24ebe2a80 to your computer and use it in GitHub Desktop.

Select an option

Save mykeels/82011b3fe9d6c40d9d8b9ca24ebe2a80 to your computer and use it in GitHub Desktop.
Array.prototype.distinct = function (fn) {
if (typeof (fn) == 'string') {
var key = '' + fn;
fn = function (a) { return a[key]; }
}
else fn = fn || function (a) { return a; }
var arr = this;
return arr.reduce(function (a, b) {
return a.map(fn).indexOf(fn(b)) < 0 ? a.concat(b) : a;
}, []);
}
$('blockquote').filter(function () {
return !$(this).parent('blockquote').length
}).toArray().map(function (elem) {
let text = []
function getPrevText($el) {
if ($el.children('font[size="6"]').length) {
text.unshift('# ' + $el.text().trim())
}
else if ($el.children('font[size="4"]').length) {
text.unshift('## ' + $el.text().trim())
}
else {
if ($el.children('strong').length) {
text.unshift('### ' + $el.text().trim())
}
else {
text.unshift($el.text())
}
if (text.length < 10) {
return getPrevText($el.prev())
}
}
return text
}
text.push($(elem).text())
return getPrevText($(elem).prev())
}).reduce((a, b) => a.concat(b)).distinct().map(text => text.trim()).filter(Boolean)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment