Footnote – a version of the cellTextMD function which picks up inline links as Markdown links, and also catches fonts with either ‘Oblique’ or ‘Italic’ in their name for the single-star Markdown emphasis.
// cellTextMD :: OO.Cell -> String
const cellTextMD = cell => {
const as = cell.richText.attributeRuns;
return zipWith3((txt, fnt, style) => {
const
bld = any(contains(fnt), ['Bold', 'Black']) ? (
'**'
) : '',
ital = any(contains(fnt), ['Oblique', 'Italic']) ? (
'*'
) : '',
url = style.attributes.byName('link')
.value();
return bld + ital + (
isNull(url) ? txt : ('[' + txt + '](' + url + ')')
) + ital + bld;
}, as.text(), as.font(), as.style())
.join('');
};
It uses a generic zipWith3(f, xs, ys, zs) function, which can be defined as:
// zipWith3 :: (a -> b -> c -> d) -> [a] -> [b] -> [c] -> [d]
const zipWith3 = (f, xs, ys, zs) =>
Array.from({
length: Math.min(xs.length, ys.length, zs.length)
}, (_, i) => f(xs[i], ys[i], zs[i]));
Apart from isNull() the other generic functions are given in the original listing in this thread
// isNull :: [a] | String -> Bool
const isNull = xs =>
Array.isArray(xs) || typeof xs === 'string' ? (
xs.length < 1
) : undefined;