MediaWiki:Common.js: Difference between revisions

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


   if ($("#show-article-wrapper-entry").length) {
   if ($("#show-article-wrapper-entry").length) {
    // Your existing formatParagraphs function
     function formatParagraphs(text) {
     function formatParagraphs(text) {
       var paragraphs = text.split("\n").filter(function (p) {
       return text
        return p.trim() !== "";
        .split("\n")
      });
        .filter((p) => p.trim() !== "")
      return paragraphs
         .map((p) => "<p>" + p.trim() + "</p>")
         .map(function (p) {
          return "<p>" + p.trim() + "</p>";
        })
         .join("");
         .join("");
     }
     }


     // Check if ".article-description" exists and format its text
     $(
    if ($(".article-description").length) {
      "#show-article .article-description, #show-article .article-reflection"
      var descriptionText = $(".article-description").text();
    ).each(function () {
       var formattedDescription = formatParagraphs(descriptionText);
       // Skip if already has <p> children (means it's formatted)
       $(".article-description").html(formattedDescription); // Set the formatted text
       if ($(this).children("p").length > 0) return;
    }


    // Check if ".article-reflection" exists and format its text
       const rawText = $(this).text();
    if ($(".article-reflection").length) {
       $(this).html(formatParagraphs(rawText));
       var reflectionText = $(".article-reflection").text();
     });
      var formattedReflection = formatParagraphs(reflectionText);
       $(".article-reflection").html(formattedReflection); // Set the formatted text
     }
   }
   }


Navigation menu