diff options
Diffstat (limited to 'app/javascript/mastodon/utils')
-rw-r--r-- | app/javascript/mastodon/utils/html.js | 3 | ||||
-rw-r--r-- | app/javascript/mastodon/utils/numbers.js | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/app/javascript/mastodon/utils/html.js b/app/javascript/mastodon/utils/html.js index 0b646ce58..5159df9db 100644 --- a/app/javascript/mastodon/utils/html.js +++ b/app/javascript/mastodon/utils/html.js @@ -1,6 +1,5 @@ export const unescapeHTML = (html) => { const wrapper = document.createElement('div'); - html = html.replace(/<br \/>|<br>|\n/g, ' '); - wrapper.innerHTML = html; + wrapper.innerHTML = html.replace(/<br\s*\/?>/g, '\n').replace(/<\/p><p>/g, '\n\n').replace(/<[^>]*>/g, ''); return wrapper.textContent; }; diff --git a/app/javascript/mastodon/utils/numbers.js b/app/javascript/mastodon/utils/numbers.js new file mode 100644 index 000000000..fdd8269ae --- /dev/null +++ b/app/javascript/mastodon/utils/numbers.js @@ -0,0 +1,10 @@ +import React, { Fragment } from 'react'; +import { FormattedNumber } from 'react-intl'; + +export const shortNumberFormat = number => { + if (number < 1000) { + return <FormattedNumber value={number} />; + } else { + return <Fragment><FormattedNumber value={number / 1000} maximumFractionDigits={1} />K</Fragment>; + } +}; |