2016-08-24 1 views
0

TinyMCE 텍스트 편집기에 입력 한 단어 수를 계산하기 위해 플러그인 wordcount를 추가했습니다.TinyMCE : wordcount 플러그인이 단어로 특수 문자를 계산하지 않습니다.

plugins: "wordcount", 
wordcount_cleanregex: /[.(),;:!?%#$?\x27\x22_+=\\/\-]*/g 

문자와 숫자를 세고 있지만 특수 문자를 부여 할 때는 계산되지 않습니다.

for e.g ---- 
Hi I am 18 year old  (for this it is giving me count 6) 
Hi I am ## year old  (for this it is giving me count 5) 

내가해야 할 일이 있습니다. wordcount_cleanregex 설정으로

%#$ from wordcount_cleanregex , but it didn't work. 

답변

0

문제가 아니라 오히려 wordcount_countregex 설정으로 : 나는 제거하려 기본 하나를 보면

https://www.tinymce.com/docs/plugins/wordcount/#wordcount_countregex

당신이 왜 그 건너 뛰는 볼 것 문자입니다. 여기에 정확한 정규식은 다음과 같습니다 당신이 정규식을 조정할 경우

https://regex101.com/r/wL4fL1/1

당신이 단어와 같은 ## 카운트를 얻을 수 있습니다.

가에 관계없이 구성 설정의 수행됩니다 wordcount 플러그인 내에서 수행되는 몇 가지 핵심 청소가있다. TinyMCE에에서이 같이 보입니다 4.4.1 :

if (tx) { 
     tx = tx.replace(/\.\.\./g, ' '); // convert ellipses to spaces 
     tx = tx.replace(/<.[^<>]*?>/g, ' ').replace(/&nbsp;|&#160;/gi, ' '); // remove html tags and space chars 

     // deal with html entities 
     tx = tx.replace(/(\w+)(&#?[a-z0-9]+;)+(\w+)/i, "$1$3").replace(/&.+?;/g, ' '); 
     tx = tx.replace(cleanre, ''); // remove numbers and punctuation 

     var wordArray = tx.match(countre); 
     if (wordArray) { 
      tc = wordArray.length; 
     } 
    } 

을 ... 그래서 몇 가지 핵심 일들이 여전히 관계없이 wordcount_cleanregexwordcount_countregex에 넣어 어떤 콘텐츠에서 제거됩니다. 이 핵심 동작을 변경하려면 플러그인의 소스 코드를 수정해야합니다.

+0

감사합니다 (이 숫자/특수 문자를 계산하지 않음) 문자를 계산, 그래서 나는 그것을 확인하고이 내 코드를 교체 한 : 플러그인 : "단어 수 페이스트", wordcount_cleanregex를 :/[ ]/g, wordcount_countregex :/[\ S \ u2019 \ x27 \ - \ u00C0- \ u1FFF] +/g, 여전히 coun가 아닙니다. ting &>< –

+0

countregex에 원하는 문자를 포함해야합니다. 정규 표현식에 포함시키지 마십시오. regex101 사이트를 사용하여 정규 표현식을 사용하여 필요한 항목을 바로 얻을 수 있습니다. –

+0

regex101에서 완벽하게 작동하지만, 왜 계산에 포함되지 않는지 모르겠다. –

0

여기는 외부에 추가하고있는 내 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(/&nbsp;/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; 

}; 
});