File tree Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Expand file tree Collapse file tree 2 files changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -220,7 +220,13 @@ class _RelativeUrlRewriter extends html_parsing.TreeVisitor {
220220 super .visitElement (element);
221221
222222 // check current element
223- if (element.localName == 'a' ) {
223+ if (element.localName == 'a' &&
224+ element.attributes.length == 1 &&
225+ element.attributes.containsKey ('name' ) &&
226+ element.attributes['name' ]! .isNotEmpty &&
227+ element.nodes.isEmpty) {
228+ // allow name anchor without any other attribute or content
229+ } else if (element.localName == 'a' ) {
224230 _updateUrlAttributes (element, 'href' );
225231 } else if (element.localName == 'img' ) {
226232 _updateUrlAttributes (element, 'src' , raw: true );
Original file line number Diff line number Diff line change @@ -27,6 +27,16 @@ void main() {
2727 '</ul>\n ' ,
2828 );
2929 });
30+
31+ test ('named anchor' , () {
32+ expect (
33+ markdownToHtml ('<a name="abc"></a>' ), '<p><a name="abc"></a></p>\n ' );
34+ });
35+
36+ test ('named anchor with other content' , () {
37+ expect (markdownToHtml ('<a name="abc" other="1"></a>' ), '<p></p>\n ' );
38+ expect (markdownToHtml ('<a name="abc">x</a>' ), '<p>x</p>\n ' );
39+ });
3040 });
3141
3242 group ('Valid custom base URL' , () {
You can’t perform that action at this time.
0 commit comments