TopShelfCraft / Wordsmith

A plugin for Craft CMS to help you manage and manipulate text.
Other
30 stars 20 forks source link

Paragraph chop includes additional leading paragraph #7

Closed rogerdawkins closed 6 years ago

rogerdawkins commented 6 years ago

I have used chop(limit=2, unit='p') but the returned string includes an additional leading paragraph tag. I checked the source data and that is clean.

Looking at the code in libs/hacksaw.php around line 88 the problem is caused by...

            $return = "<p>";
            foreach ($paragraphs as $key => $paragraph)
            {
                $return .= "<p>" . $paragraph;
                if ($key < $paragraphsCount)
                {
                    $return .= "</p>";
                }
            }
            $return .= $append . "</p>";

The $return variable is set to a paragraph tag but then inside the foreach loop each paragraph has a paragraph tag added as well resulting in two p tags at the start. Changing the first line to

$return = "";

would fix it.

michaelrog commented 6 years ago

@rogerdawkins good catch! Could you PR that to the 3.x.dev branch?

michaelrog commented 6 years ago

Thanks @rogerdawkins!!!