Skip to content

Commit

Permalink
Fake wpautop
Browse files Browse the repository at this point in the history
  • Loading branch information
rmens committed Oct 26, 2024
1 parent 82bc49d commit 1dec4c4
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion assets/js/ttveditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@

var softLimitTitle = parseInt(ttveditorData.soft_limit_title, 10);
var hardLimitTitle = parseInt(ttveditorData.hard_limit_title, 10);

function wpautop(text) {
// Trim the text to remove leading and trailing whitespace
text = text.trim();

// Replace double line breaks with paragraph tags
text = text.replace(/\n\s*\n/g, '</p><p>');

// Wrap all content in paragraph tags
text = `<p>${text}</p>`;

// Replace single line breaks with <br> tags within paragraphs
text = text.replace(/\n/g, '<br>');

return text;
}

function base64EncodeUnicode(str) {
return btoa(unescape(encodeURIComponent(str)));
Expand All @@ -30,7 +46,7 @@
pages.forEach(function(pageContent) {
var data = {
"type": "text",
"body": pageContent,
"body": wpautop(pageContent),
"title": titleValue,
"duration": 5000,
"image": ttveditorData.image_url
Expand Down

0 comments on commit 1dec4c4

Please sign in to comment.