Editor discards empty anchor tags specified with ID instead of NAME

ASSIGNED
Assigned to

Status

()

Core
Editor
ASSIGNED
14 years ago
8 years ago

People

(Reporter: Mike Cowperthwaite, Assigned: glazou)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(2 attachments)

(Reporter)

Description

14 years ago
In Composer and the HTML Mail editor, it is not possible to include an anchor 
that has an ID instead of a NAME.  This is true for pasting text with such an 
anchor from the browser, or when using Insert|HTML or editing the HTML view in 
Composer.

Steps to reproduce:
In Composer: 
1) open a new window, or open an existing file.  Go to HTML Source tab.  Put 
cursor at some reasonable point in the <body> -- e.g. within text.
2) type:    <a id="foo"></a>
3) go to HTML Tags tab
4) return to HTML Source tab

Actual results:
After step 3, there is no visible placeholder (either [A] or the anchor) where 
the tag was entered.
After step 4, the tag that was entered is no longer present

Expected results: placeholder should be visible on HTML Tags view, preferably as 
the anchor; tag text should continue to be present.

A non-empty tag:   <a id="bar">BAR</a>   is maintained in the source; the 
placeholder is [A] rather than the anchor symbol, altho a link to #bar will work 
as expected.
An empty tag with name:   <a name="ok"></a>   is maintained, and its placeholder 
is the anchor.

Same results are seen using Insert|HTML, in both Composer and in HTML mail.  
(To view the HTML source in mail, select the entire text and then Insert|HTML.)

Opening a file in composer that contains an empty, ID-spec'd anchor works as 
expected, except that [A] is displayed on the Tags view rather than the anchor 
symbol. Also note: after such a file has been opened, if Insert|Link is 
selected, the dropdown list of possible links includes both the id-specified and 
the name-specified anchors.
(Reporter)

Comment 1

14 years ago
Created attachment 151535 [details]
Test data file

Alternate path to reproduce:
Open this attachment in Mozilla browser
Select all text, and copy to clipboard
Open new composer window
Paste copied text in
Go to HTML Source tab

Actual results: the empty <a id="foo"></a> tag (eight line of text) is not
present
Expected results: it oughtta be!
QA Contact: bugzilla → editor
Assignee: mozeditor → nobody
(Assignee)

Comment 2

8 years ago
confirmed, taking.
Assignee: nobody → daniel
Status: NEW → ASSIGNED
OS: Windows 2000 → All
Hardware: x86 → All
(Assignee)

Comment 3

8 years ago
This is because nsHTMLEditRules consider an empty a element that has no name
attribute as removable (sigh).
(Assignee)

Comment 4

8 years ago
Created attachment 463136 [details] [diff] [review]
proposed fix

This fix is not optimal since we should really revamp all this part of the editor: if removing useless elements makes sense for the editor in Thunderbird, it does not make sense in a lot of cases in the Markup editor. But since this
bug severely affects editability of HTML5 anchors (using IDs and not names any
more), I suggest we don't wait so here's a trivial fix for the bug.
Attachment #463136 - Flags: review?(neil)

Comment 5

8 years ago
Comment on attachment 463136 [details] [diff] [review]
proposed fix

Could you also add a test for this, please?  Thanks!
Attachment #463136 - Flags: review?(neil) → review+
You need to log in before you can comment on or make changes to this bug.