rt icon indicating copy to clipboard operation
rt copied to clipboard

Preserve formatting when inserting articles

Open btb opened this issue 4 years ago • 14 comments

Articles with Text or WikiText fields can display wiki/html formatting with no problem, but it is currently not possible to insert the article into a ticket reply with the formatting intact. This patch (when MessageBoxRichText is enabled) allows these custom fields to be rendered into a ticket message using the same standard ShowCustomField* elements as when viewing the article. This also means that tags other than those in @SCRUBBER_ALLOWED_TAGS will be scrubbed.

The article's Name and the custom field titles (if enabled) are formatted as html headings. Multi-value fields are rendered as html lists.

btb avatar Aug 29 '19 00:08 btb

Note that this is not the same as the issue addressed by “Add option to disable escaping HTML in articles (I#32374).” That only allows html tags themselves to be printed into your messages as code, not have their formatting actually rendered. as in: https://forum.bestpractical.com/t/4-4-4-beta2-possible-issue-with-new-unescaped-html-feature/33673

The intended function of that option is unclear to me so it isn't implemented here. (it is ignored when using MessageBoxRichText) - if we wanted to preserve the end result, we'd be escaping the html in this case, so that option seems to be clearly mis-named.

btb avatar Aug 29 '19 00:08 btb

thank you very much. you save my time. I'm testing...

Negatifff avatar Aug 29 '19 11:08 Negatifff

Hi there,

Thanks for this! It almost works for me. For some reason I am gettting doubled spaces when an article is inserted. There seem to be extra "br" tags inserted, for example, between list items; at the end of paragraphs; and any place it feels like.

Here is one article as it appears in source view in Articles:

<h2>Submitting Good Reports</h2>

<p>The first step in getting a problem solved is providing a good description of the issue. The better the description, the more promptly the issue can be addressed.<br />
Whether you use the web form, or e-mail, a problem report should <b>always</b> include the following information:</p>

<ul><li>The <b>name of the machine</b> where you are running the command, and any other computers that were involved</li>
<li>The full <b>name of the command</b> you are running, including the path to the command and all <b>options and arguments</b></li>
<li>The <b>login name of the user</b> running the command, particularly if jobs are run as a "project user", not under a personal account</li>
<li><b>Any output</b>, particularly error messages</li>
<li><b>What is not working</b> (i.e., what you expected to get from the command and what you actually received)</li>
<li>The <b>current environment</b> (on the servers, this can be shown with the output from the commands "<tt>module list ; env | sort</tt>")</li>
<li>For network issues, please include the <b>IP address</b> of the computer you are using (under Windows, run "<b><tt>ipconfig /all</b></tt>" from a command prompt; under Linux, run "<b><tt>ifconfig -a</tt></b>").</li>
</ul>

<p>It is almost impossible to troubleshoot an issue without this basic information.</p>

Once inserted into a ticket, it becomes this - apparently converting whitespace from the source into breaks?

<p>&nbsp;</p>

<h2>Submitting Good Reports</h2>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>The first step in getting a problem solved is providing a good description of the issue. The better the description, the more promptly the issue can be addressed.<br />
<br />
Whether you use the web form, or e-mail, a problem report should <strong>always</strong> include the following information:</p>

<p>&nbsp;</p>

<p>&nbsp;</p>

<ul>
	<li>The <strong>name of the machine</strong> where you are running the command, and any other computers that were involved</li>
	<br />
	<li>The full <strong>name of the command</strong> you are running, including the path to the command and all <strong>options and arguments</strong></li>
	<br />
	<li>The <strong>login name of the user</strong> running the command, particularly if jobs are run as a &quot;project user&quot;, not under a personal account</li>
	<br />
	<li><strong>Any output</strong>, particularly error messages</li>
	<br />
	<li><strong>What is not working</strong> (i.e., what you expected to get from the command and what you actually received)</li>
	<br />
	<li>The <strong>current environment</strong> (on the servers, this can be shown with the output from the commands &quot;module list ; env | sort&quot;)</li>
	<br />
	<li>For network issues, please include the <strong>IP address</strong> of the computer you are using (under Windows, run &quot;<strong>ipconfig /all</strong>&quot; from a command prompt; under Linux, run &quot;<strong>ifconfig -a</strong>&quot;).</li>
	<br />
	<br />
	&nbsp;
</ul>

<p>&nbsp;</p>

<p>&nbsp;</p>

<p>It is almost impossible to troubleshoot an issue without this basic information.</p>

Note: yes, that "disable escaping" option does in fact seem to be named backwards. I'm the one who posted that comment you link to, harhar. As you can see, I never got a response of any kind - so I very much appreciate you doing this!

robmunsch avatar Nov 07 '19 21:11 robmunsch

Hi there,

Thanks for this! It almost works for me. For some reason I am gettting doubled spaces when an article is inserted. There seem to be extra "br" tags inserted, for example, between list items; at the end of paragraphs; and any place it feels like.

Hi Rob, Is that field of type "Text" or "WikiText"? if it's WikiText, I recommend not mixing HTML in with it, because then you have two different renderers competing/adding to each other. If you want your HTML to render purely as HTML, use type "Text"

btb avatar Nov 07 '19 23:11 btb

Oh strange - when I set it as a Text field, it had no formatting at all. I assumed I had to use WikiText. I'll set it back to Text and see if maybe I did something else to it.

Edit: no effect. The type was changed to Text; i then went to the article in question, Modify, re-saved it - and the same thing happens on insertion, exactly the same way.

robmunsch avatar Nov 08 '19 15:11 robmunsch

Update: I've tested with my plaintext articles, that I use to insert canned responses. They are also now showing multiple extra line breaks where they were formatted correctly before. For instance, a plain text article with two paragraphs that used to show up like:

This is the first paragraph

And this is the second

Now has multiple blank lines between paragraphs, which I can see in source view as:

This is the first paragraph.<br />
<br />
<br />
<br />
And this is the second

Edit: I should also mention that in the Articles view, they appear normal. It's only the function that inserts them into a ticket that is adding all these extra breaks, and I haven't been able to figure out why.

robmunsch avatar Nov 08 '19 16:11 robmunsch

Any updates on this? Has anyone else experienced this issue?

robmunsch avatar Dec 04 '19 17:12 robmunsch

@btb Still there? Any news? Anything I can do to help you test? I'd really love to be able to use this.

robmunsch avatar Jan 27 '20 22:01 robmunsch

Sorry, I'll try to grab some time soon to take another look.

btb avatar Jan 30 '20 20:01 btb

There is the branch 4.4/respect-article-escape-html-in-includearticle which addresses this issue.

craigkai avatar Jan 31 '20 17:01 craigkai

It doesn't, actually. Misleading description and not documented hugely well by BP. What that option does is allow literal HTML code to be printed as-is when inserted, instead of scrubbing it. The result is akin to using a "code" block tag on a post. It doesn't interpret the HTML - it just leaves it to be printed literal. Believe me, I banged my head against that for a while wondering what I was doing wrong.


From: Craig Kaiser [email protected] Sent: Friday, January 31, 2020 12:02 PM To: bestpractical/rt [email protected] Cc: Munsch, Rob [email protected]; Manual [email protected] Subject: [External] Re: [bestpractical/rt] Preserve formatting when inserting articles (#283)

There is the branch 4.4/respect-article-escape-html-in-includearticlehttps://github.com/bestpractical/rt/tree/4.4/respect-article-escape-html-in-includearticle which addresses this issue.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHubhttps://github.com/bestpractical/rt/pull/283?email_source=notifications&email_token=AKDS44MGY2445EQA6DPBX33RARKT7A5CNFSM4IRY3WT2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKPJW4A#issuecomment-580819824, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AKDS44PZYNEH7XW2XQFKD2DRARKT7ANCNFSM4IRY3WTQ.

robmunsch avatar Feb 03 '20 15:02 robmunsch

4.4/respect-article-escape-html-in-includearticle is a bug fix for the previous branch that added the include HTML feature. Testing your example from above I see the following:

Article page: article_content

Ticket update page: update

Is this the expected behavior?

craigkai avatar Feb 03 '20 16:02 craigkai

Ooookay. On the BP forums, I was told I misunderstood that function and it was working as intended.....

I'm not sure what I'm looking at, however. Do you mean you used my text as a test on your own installation of that bugfix branch, and that's the result of inserting the article into a ticket? If so, then yes: it looks correctly formatted.

robmunsch avatar Feb 03 '20 17:02 robmunsch

Ooookay. On the BP forums, I was told I misunderstood that function and it was working as intended.....

There was a bug, so the feature did not work correctly. The new branch addresses that bug.

I'm not sure what I'm looking at, however. Do you mean you used my text as a test on your own installation of that bugfix branch, and that's the result of inserting the article into a ticket? If so, then yes: it looks correctly formatted.

Correct! I took your example from this thread and added it to the content of an article, then used the insert article feature on ticket update to insert the HTML content.

craigkai avatar Feb 03 '20 17:02 craigkai