News:

Wondering if this will always be free?  See why free is better.

Main Menu

Paragrapher

Started by Sesquipedalian, February 27, 2016, 05:59:09 PM

Previous topic - Next topic

Sesquipedalian

Link to the mod

Paragrapher

Paragrapher reformats the HTML generated from user posts so that it uses semantically correct <p></p> elements rather than <br> elements.


Features

  • Intelligently converts line breaks into paragraphs.
  • Admin can choose whether to preserve the original visual layout or to normalize it.
  • The content of [code][/code], [pre][/pre], and [php][/php] BBCodes is always left untouched.
  • Does not modify the content of posts in the database.
  • Does not interfere with the editor.
  • Does not interfere with BBCode parsing.
  • Acts on posts and personal messages within the forum, in RSS feeds, and via SSI.
  • Can be extended and integrated with other mods and custom code with very little work.

Because Paragrapher never modifies the content of any stored data, you can freely install, uninstall, or change the settings at any time without consequences.


Settings

Two admin settings are available in Administration Center ► Modification Settings ► Miscellaneous:

  • Normalize layout when formatting paragraphs: Enabling this will collapse extra lines of white space between paragraphs, resulting in more consistent formatting in the output. Leave it disabled to preserve the original visual layout.
  • Allow single line breaks to create new paragraphs: This offers three options.
    • Never: (Default) Users must always enter at least two line breaks to create a new paragraph.
    • Always: One line break will be enough to create a new paragraph.
    • Intelligently: (Recommended) Paragrapher will attempt to analyze and adapt to the author's writing style when making this decision for each post.


Extending Paragrapher

Forum admins and even other mods can easily integrate Paragrapher into their code wherever they like.

If you want Paragrapher to process a string of text stored in a variable called $str, paste the following into your code at an appropriate point in the relevant PHP file:
call_integration_hook('integrate_paragrapher_string', array(&$str));
If you have some data in an array called $foo, and you want Paragrapher to process its 'desc' element, use this:
call_integration_hook('integrate_paragrapher_post', array(&$foo, 'desc'));
If you have an multidimensional array called $bar, and you want Paragrapher to process the 'body' element of every sub-array inside $bar, use this:
call_integration_hook('integrate_paragrapher_posts', array(&$bar, 'body'));

License

Paragrapher uses code derived from WordPress, and is therefore released under the GPLv2 (or later). A copy of this license in included in the package file.


Changelog

Version 2.6:
  • Correctly handles strings with a single leading <br> element.

Version 2.5:
  • Fixes a bug where setting "Allow single line breaks to create new paragraphs" to "Intelligently" behaved like "Always" on SMF 2.1

Version 2.4:
  • Fixes an "undefined index" error when searching on SMF 2.0

Version 2.3:
  • Improves content handling for some less common HTML elements
  • Avoids creating unnecessary <p> elements inside <li>, <td>, etc.
  • Improves code efficiency

Version 2.2:
  • Posts no longer appear "un-paragraphed" after using the Quick Edit button. (Previously it was necessary to refresh the page after using Quick Edit.)
  • Ignores the content of [php][/php] BBCodes
  • Fixes a bug with handling <hr> elements
  • Improves code efficiency

Version 2.1:
  • Adds Latin Spanish translation

Version 2.0:
  • Adds a new option to control handling of single line breaks
  • Improves handling of preserved line breaks when not using the "normalize layout" option
  • Improves handling of paragraphs inside list items
  • Supports SMF 2.1
  • Rewritten to use integration hooks everywhere
    • Uses standard integration hooks on SMF 2.1
    • Creates custom integration hooks on SMF 2.0
  • Declares several generic integration hooks to enable easy integration with other mods and custom code
  • Makes some minor CSS improvements

Version 1.1:

Version 1.0.1:
  • Replaces "preserve layout" option with "normalize layout" option

Version 1.0:
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

pocttopus

Could you please send a screenshot of how this mod is working?
Thanks.

woolly bugger

Thanks, this fixed all of the tages that became visible in the members signatures after the 2.1 upgrade!

Sesquipedalian

Quote from: pocttopus on March 24, 2019, 07:10:46 AM
Could you please send a screenshot of how this mod is working?
Thanks.

Done.

Quote from: woolly bugger on March 24, 2019, 01:56:53 PM
Thanks, this fixed all of the tages that became visible in the members signatures after the 2.1 upgrade!

I'm not sure what you are referring to, nor do I understand how this mod could have solved your problem. But if it did, I'm glad it was helpful to you. :)
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

-Rock Lee-

As it is in the branch 2.0.and 2.1 I have some doubts with the language files but I leave the translations to the Latin Spanish as well.

<file name="$languagedir/Modifications.spanish_latin.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['paragrapher_normalize_layout'] = 'Normalizar la disposici&oacute;n al dar formato a los p&aacute;rrafos';]]></add>
</operation>
</file>

<file name="$languagedir/Modifications.spanish_latin-utf8.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['paragrapher_normalize_layout'] = 'Normalizar la disposición al dar formato a los párrafos';]]></add>
</operation>
</file>


Anything you will tell me...


Regards!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

Arantor

Like it. Not for all forums, but like the idea.

Sesquipedalian

Quote from: Rock Lee on March 25, 2019, 10:00:14 AM
As it is in the branch 2.0.and 2.1 I have some doubts with the language files but I leave the translations to the Latin Spanish as well.

<file name="$languagedir/Modifications.spanish_latin.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['paragrapher_normalize_layout'] = 'Normalizar la disposici&oacute;n al dar formato a los p&aacute;rrafos';]]></add>
</operation>
</file>

<file name="$languagedir/Modifications.spanish_latin-utf8.php" error="skip">
<operation>
<search position="end" />
<add><![CDATA[
$txt['paragrapher_normalize_layout'] = 'Normalizar la disposición al dar formato a los párrafos';]]></add>
</operation>
</file>


Anything you will tell me...


Regards!

Thanks again, Rock Lee. I've added your translations to version 2.1 of Paragrapher.

There was no need to include translated changes to the Modifications language file. That stuff only appears in the upgrade_SMF20.xml because that file is used to remove changes when upgrading from Paragrapher 1.x to 2.x. But thanks for taking the time to be so thorough! :)

Quote from: Arantor on March 25, 2019, 06:40:54 PM
Like it. Not for all forums, but like the idea.

Thanks. I agree that this isn't for every forum. It all depends on who the target demographic is. I mostly use this mod for forums where users may not be tech-savvy enough to know the formatting conventions of the Internet and how they differ from those of paper-based documents.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Biology Forums

What happens in the situation the user wants two or more line breaks? Does The mod add an empty <p></p> tag in between?

Sesquipedalian

Quote from: Study Force on March 26, 2019, 01:24:00 AM
What happens in the situation the user wants two or more line breaks? Does The mod add an empty <p></p> tag in between?

That depends on the "Normalize layout when formatting paragraphs" setting. If the "Normalize layout" setting is disabled, the extra <br> tags will be wrapped in a <div></div> in order to preserve them. If the "Normalize layout" setting is enabled, the extra <br> tags will be stripped out.

Since both the "Normalize layout when formatting paragraphs" setting and the "Allow single line breaks to create new paragraphs" setting are disabled by default, the visual layout of posts will appear unchanged after the mod is first installed.

The admin can test the effects of each setting without making any permanent changes to the forum's content at all. If you try one setting for a while, and then you or your users decide that you/they don't like it, you can simply turn it back off and everything will go back to normal.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

-Rock Lee-

Quote from: Sesquipedalian on March 25, 2019, 08:10:22 PM
Thanks again, Rock Lee. I've added your translations to version 2.1 of Paragrapher.

There was no need to include translated changes to the Modifications language file. That stuff only appears in the upgrade_SMF20.xml because that file is used to remove changes when upgrading from Paragrapher 1.x to 2.x. But thanks for taking the time to be so thorough! :)

That's the doubt I had but that's why I take my time calmly and translate everything, if you have to do it well :P, right?


Regards!
¡Regresando como cual Fenix! ~ Bomber Code
Ayudas - Aportes - Tutoriales - Y mucho mas!!!

njtweb

Trying to figure out what the use for this mod is? Is it for lazy people who just don't want to hit the enter key when typing?

Arantor

It's more for people who get confused around how many line breaks they actually need and who don't exactly get how bbcode works.

njtweb

Ok, got it. There is a very small group of my traffic that actually know what BBCode is and how to use it. 99% of the time they contact me asking to add attachments, embed images etc.

Sesquipedalian

Quote from: Arantor on March 26, 2019, 09:28:43 AM
It's more for people who get confused around how many line breaks they actually need and who don't exactly get how bbcode works.

That, and for people like me who care about having consistently formatted content and semantically correct HTML on their sites. :)
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

Sesquipedalian

Quote from: Rock Lee on March 26, 2019, 09:07:27 AM
That's the doubt I had but that's why I take my time calmly and translate everything, if you have to do it well :P, right?

Agreed and much appreciated. :)
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

RGMears

I am using this Mod.
When I look at the page code (view source) it is doing something peculiar:
After an <hr /> tag the text for the next bit of content displays, regardless how long it is.
Then there is a </p> tag. But there is no opening <p> tag.

Sesquipedalian

Can you provide me with a copy of the raw text of the post that causes this, RGMears? You can send it to me via a private message.
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

RGMears

Thanks for the reply Sesquipedalian,

By raw text do you mean what is typed in the BBCode editor pane?
Or copy the html from Page Source?
Or both?

I might mention it does this on multiple posts, wherever an
was inserted in the BBCode.


Sesquipedalian

Quote from: RGMears on June 30, 2020, 05:11:38 PM
By raw text do you mean what is typed in the BBCode editor pane?

Yes. :)
I promise you nothing.

Sesqu... Sesqui... what?
Sesquipedalian, the best word in the English language.

RGMears

Here are two examples. One without images:
You can add "tags" to your posts simply by typing the word you want in the box beside [size=16pt][font=arial][b]Tags:[/b][/font][/size]
If the word is already used it will appear in a dropdown below the text box. If it's already there, select it. If your word is somehow different, keep typing.
[hr]
The [u]Tags[/u] section, accessible through the top menu (between [u]Messages[/u] and [u]Bookmarks[/u]), displays words which have been added as tags. Tapping on a "tag" displays a list of Posts so tagged.

And one with images:
Yes there are. And maybe you don't want to see them all.
You can select which boards you want to see on your Profile page.
Under Profile, select Modify Profile >
Ignore Boards Options ...
... tap on the box beside boards you [b]don't[/b] want to see.
[attachment=3,msg71]
Scroll to the bottom and tap Change profile. The top level Category will remain but the boards under it do not display.
[hr]
Conversely, you can tap the [color=magenta]title of the Category[/color] or the [color=magenta]beige icon[/color] with the "-" (minus sign) to collapse it.
[attachment=1,msg71]
[hr]
Tapping on the closed [color=magenta]title[/color] or the [color=magenta]beige icon[/color] with a "+" (plus sign) will reopen the category.
[attachment id=2 msg=71]

Advertisement: