MediaWiki:Common.js: Difference between revisions

Jump to navigation Jump to search
no edit summary
No edit summary
No edit summary
 
Line 1,856: Line 1,856:
   }
   }


   if ($("#show-article-wrapper-entry").length) {
  // paragraph-formatting block
   if (jQuery("#show-article-wrapper-entry").length) {
     function formatParagraphs(text) {
     function formatParagraphs(text) {
       return text
       // split on newlines, drop empty lines, wrap each in <p>
        .split("\n")
      var parts = String(text || "").split("\n");
         .filter((p) => p.trim() !== "")
      var out = [];
         .map((p) => "<p>" + p.trim() + "</p>")
      for (var i = 0; i < parts.length; i++) {
        .join("");
         var p = parts[i].replace(/^\s+|\s+$/g, "");
         if (p) out.push("<p>" + p + "</p>");
      }
      return out.join("");
     }
     }


     $(
     jQuery(
       "#show-article .article-description, #show-article .article-reflection"
       "#show-article .article-description, #show-article .article-reflection"
     ).each(function () {
     ).each(function () {
       // Skip if already has <p> children (means it's formatted)
       var $el = jQuery(this);
       if ($(this).children("p").length > 0) return;
       if ($el.children("p").length > 0) return; // already formatted by PageForms
 
       var rawText = $el.text();
       const rawText = $(this).text();
       $el.html(formatParagraphs(rawText));
       $(this).html(formatParagraphs(rawText));
     });
     });
   }
   }

Navigation menu