Hi Mark,
I have been working upon your grammark checker and have been trying to expand its features. However, I have been having some difficulty in fully understanding your code especially how you tried to clean up raw text input and analyze it. Below is a sample.
parse : function (rawText) { var withLineBreaks, simpleQuotes, noSuggestions, placeholder; withLineBreaks = rawText.replace(/<br(.*?)>/g, 'LINEBREAK'); withLineBreaks = withLineBreaks.replace(/<p(.*?)>/gi, 'PARAGRAPHSTART'); simpleQuotes = withLineBreaks.replace(/[\u2018\u2019]/g, "'").replace(/[\u201C\u201D]/g, '"'); noSuggestions = String(simpleQuotes).replace(/<span class="suggestion">(.*?)<\/span>/gi, ''); this.sanitized = String(noSuggestions).replace(/<[^>]+>/gm, ''); this.noLineBreaks = this.sanitized.replace(/PARAGRAPHEND/g, ' '); this.noLineBreaks = this.noLineBreaks.replace(/PARAGRAPHSTART/g, ' '); this.noLineBreaks = this.noLineBreaks.replace(/LINEBREAK/g, ' '); placeholder = this.noLineBreaks.replace(/[\-\/#!\"$%\^&\*:{}=\-_
~()]/g, '');
this.spacedPunctuation = placeholder.replace(/[.,;]/g, ' .');
this.semicolonsAndPeriods = this.noLineBreaks.replace(/[,-/#!"$%^&*:{}=-_~()]/g, ''); this.sentences = this.semicolonsAndPeriods.replace(/[?;]/g, '.'); this.sentenceCount = this.sentences.trim().split(/[\.]/g).length - 1; this.noPunctuation = ' ' + this.sentences.replace(/[\.]/g, '').toLowerCase() + ' '; this.words = this.noPunctuation.trim().split(/\s+/); this.wordCount = this.words.length; },
...
highlight: function (analysisType) { // todo -- what about getting the latest text? var i, match, suggestion, uppercase; this.highlighted = this.sanitized; this.highlighted = this.highlighted.split('LINEBREAK').join('<br>'); this.highlighted = this.highlighted.split('PARAGRAPHSTART').join('<br><br>'); this.highlighted = this.highlighted.replace(/\n{2}/g, ' </p><p>'); this.highlighted = this.highlighted.replace(/\n/g, ' <br />'); this.highlighted = this.highlighted.replace(/\n/g, ' <br />'); this.highlighted = this.highlighted.replace(' ', ' '); type.get(analysisType); i = 0; for (i = 0; i < this.matches.length; i++) { match = this.matches[i]; suggestion = ''; if (type.data.corrections[match] !== undefined) { suggestion = '<span class="suggestion">' + type.data.corrections[match] + '</span>'; } this.highlighted = this.highlighted.split(' ' + match + ' ').join(' <mark>' + suggestion + match + '</mark> '); this.highlighted = this.highlighted.split(' ' + match + '.').join(' <mark>' + suggestion + match + '</mark>.'); this.highlighted = this.highlighted.split(' ' + match + ',').join(' <mark>' + suggestion + match + '</mark>,'); this.highlighted = this.highlighted.split(' ' + match + ';').join(' <mark>' + suggestion + match + '</mark>;'); this.highlighted = this.highlighted.split('"' + match + ',').join('"<mark>' + suggestion + match + '</mark>,'); this.highlighted = this.highlighted.split('"' + match + '"').join('"<mark>' + suggestion + match + '</mark>"'); this.highlighted = this.highlighted.split('<br>' + match + ' ').join('<br><mark>' + suggestion + match + '</mark> '); uppercase = match.substr(0, 1).toUpperCase() + match.substr(1); this.highlighted = this.highlighted.split(' ' + uppercase + ' ').join(' <mark>' + suggestion + uppercase + '</mark> '); this.highlighted = this.highlighted.split(' ' + uppercase + '.').join(' <mark>' + suggestion + uppercase + '</mark>.'); this.highlighted = this.highlighted.split(' ' + uppercase + ',').join(' <mark>' + suggestion + uppercase + '</mark>,'); this.highlighted = this.highlighted.split(' ' + uppercase + ';').join(' <mark>' + suggestion + uppercase + '</mark>;'); this.highlighted = this.highlighted.split('"' + uppercase + ',').join('"<mark>' + suggestion + uppercase + '</mark>,'); this.highlighted = this.highlighted.split('"' + uppercase + '"').join('"<mark>' + suggestion + uppercase + '</mark>"'); this.highlighted = this.highlighted.split('<br>' + uppercase + ' ').join('<br><mark>' + suggestion + uppercase + '</mark> '); }
So far, I have successfully made it catch double-negatives and others.
I will be very glad if you can help me out as a professional coder. Forgive me if I sound really stupid but I am just a amateur coder.