mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 00:11:49 +03:00
bec71d7840
refs https://github.com/TryGhost/Team/issues/2680 - Includes a new helper that is able to count HTML characters - Prevent saving portal settings when maximum length is exceeded
17 lines
630 B
JavaScript
17 lines
630 B
JavaScript
import {countDownCharacters} from './gh-count-down-characters';
|
|
import {helper} from '@ember/component/helper';
|
|
|
|
export default helper(function (params) {
|
|
let [content, maxCharacters] = params;
|
|
|
|
// Strip HTML-tags and characters from content so we have a reliable character count
|
|
content = content.replace(/<[^>]*>?/gm, '');
|
|
content = content.replace(/ /g, ' ');
|
|
content = content.replace(/&/g, '&');
|
|
content = content.replace(/"/g, '"');
|
|
content = content.replace(/</g, '<');
|
|
content = content.replace(/>/g, '>');
|
|
|
|
return countDownCharacters([content, maxCharacters]);
|
|
});
|