convert long paragraph short - Free Download Convert A Long Paragraph To Short Paragraphs - Paragraphier

Free Download Convert A Long Paragraph To Short Paragraphs – Paragraphier

Posted on

This time I will share jQuery Plugin and tutorial about Convert A Long Paragraph To Short Paragraphs – Paragraphier, hope it will help you in programming stack.

convert long paragraph short - Free Download Convert A Long Paragraph To Short Paragraphs - Paragraphier
File Size: 4.29 KB
Views Total: 1411
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

Paragraphier is a tiny jQuery based app for writers that converts/splits a long paragraph to short paragraphs for better readability.

Type the number of sentences per paragraph and click the Convert button. That’s it.

How to use it:

1. Create a textarea element to accept long paragraphs.

1 <textarea id="text" rows="5"></textarea>

2. Create a select element from which you can select the amount of sentences per paragraph.

1 <select id="sentences">
2   <option value="2">2</option>
3   <option value="4">4</option>
4   <option value="6">6</option>
5 </select>

3. Load the necessary jQuery JavaScript library at the end of the document.

1 <script src="/path/to/cdn/jquery.slim.min.js"></script>

4. The main JavaScript (jQuery script) to enable the long paragraph converter.

01 function paragrphier(){
02  
03   let text = $('#text').val();
04   let sentences = $("#sentences option:selected" ).val();
05  
06   const expectedSentenceCount = sentences;
07   let overallCount = 0;
08   let sentenceCount = 0;
09   let previousIndex = 0;
10  
11   const totalFullStops = (text.match(/,/g) || []).length;
12  
13    
14   $('#sentenceCount').html('Total Number Sentences: '+ totalFullStops);
15  
16   let newText = '';
17  
18   for(let i = 0; i < text.length; i++){
19     let value = text.charAt(i);
20  
21     if(sentenceCount == expectedSentenceCount){
22       newText += text.substring(previousIndex, i) + '</br></br>';
23       previousIndex = i;
24       sentenceCount = 0;
25  
26       if((totalFullStops - overallCount) < expectedSentenceCount ){
27       newText += text.substring(previousIndex, (text.length)) + '</br></br>';
28       }
29     }
30  
31     if(value === '.'){
32       sentenceCount += 1;
33       overallCount += 1;
34     }
35  
36  
37   }
38    
39    
40   $('#outputText').html(newText);
41    
42 }

5. Create a convert button on the page.

1 <button onclick="paragrphier()">Paragraphy</button>

6. Create an empty container to hold the output.

1 <div id="outputText">
2 </div>