Opened 9 years ago
Closed 7 years ago
#33712 closed defect (bug) (wontfix)
Press This: Multiple paragraphs in source text are quoted as a single paragraph
Reported by: | rachelmcr | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2 |
Component: | Press This | Keywords: | needs-patch |
Focuses: | javascript | Cc: |
Description
When using Press This to quote multiple paragraphs from a source article, the text is reduced to a single paragraph (no line or paragraph breaks) in the editor. Other formatting such as links are also removed — I can understand removing some of the source formatting, but I'd expect Press This to at least maintain paragraph breaks from the source text.
Attachments (2)
Change History (9)
#2
@
9 years ago
- Focuses javascript added
- Keywords needs-patch added
- Version changed from 4.3 to 4.2
For a JS wizard, this is coming from the bookmarklet https://core.trac.wordpress.org/browser/tags/4.3.1/src/wp-admin/js/bookmarklet.js#L24
We're using window.getSelection
right now. I think we could use Range.toString()
to preserve line breaks?
#3
@
9 years ago
There are two ways this can be done:
- We can make "pseudo" paragraphs.
window.getSelection().toString()
returns the text with line breaks which follow the visible layout. We can replace\n\n
with<p>
and\n
with<br>
, or just run it through wpautop(). This will approximate the original layout but will not use any of the HTML, so if there is a link in the selection, only the linked text will be shown. The advantage is that this will produce very clean, minimal, safe HTML from the selection.
- We can get the selected range and "extract" the HTML. This will bring all sorts of tags and attributes, so will have to run it through pretty restrictive kses filter. In many cases this will also contain divs which don't work well in the editor. At first look this seems better, but the selection will have to be filtered/cleaned quite a lot to make it suitable for the editor.
Note: See
TracTickets for help on using
tickets.
The attached screenshots show how the three paragraphs at the end of the WordPress 4.3 announcement become a single paragraph with Press This.