여기는 외부에 추가하고있는 내 wordcount 플러그인입니다.이 함수는 JavaScript 함수로 seasply .aspx 페이지에서이 함수를 실행할 때 함수의 getCount가 단어의 수를 완벽하게 반환하지만이 플러그인에서만 실행될 때 정보에 대한
tinymce.PluginManager.add('wordcount', function(editor) {
function update() {
editor.theme.panel.find('#wordcount').text(['Words: {0}', getCount()]);
}
editor.on('init', function() {
var statusbar = editor.theme.panel && editor.theme.panel.find('#statusbar')[0];
if (statusbar) {
tinymce.util.Delay.setEditorTimeout(editor, function() {
statusbar.insert({
type: 'label',
name: 'wordcount',
text: ['Words: {0}', getCount()],
classes: 'wordcount',
disabled: editor.settings.readonly
}, 0);
editor.on('setcontent beforeaddundo', update);
editor.on('keyup', function(e) {
if (e.keyCode == 32) {
update();
}
});
}, 0);
}
});
getCount = function() {
var body = editor.getBody().innerHTML;
text1 = body.replace(/<[^>]+>/g, '');
s = text1.replace(/ /g, ' ');
s = s.replace(/(^\s*)|(\s*$)/gi, "");//exclude start and end white-space
s = s.replace(/[ ]{2,}/gi, " ");//2 or more space to 1
s = s.replace(/\n /, "\n"); // exclude newline with a start spacing
return s.split(' ').length;
};
});
감사합니다 (이 숫자/특수 문자를 계산하지 않음) 문자를 계산, 그래서 나는 그것을 확인하고이 내 코드를 교체 한 : 플러그인 : "단어 수 페이스트", wordcount_cleanregex를 :/[ ]/g, wordcount_countregex :/[\ S \ u2019 \ x27 \ - \ u00C0- \ u1FFF] +/g, 여전히 coun가 아닙니다. ting &>< –
countregex에 원하는 문자를 포함해야합니다. 정규 표현식에 포함시키지 마십시오. regex101 사이트를 사용하여 정규 표현식을 사용하여 필요한 항목을 바로 얻을 수 있습니다. –
regex101에서 완벽하게 작동하지만, 왜 계산에 포함되지 않는지 모르겠다. –