File tree Expand file tree Collapse file tree 4 files changed +15
-6
lines changed
crates/mdbook-html/src/html Expand file tree Collapse file tree 4 files changed +15
-6
lines changed Original file line number Diff line number Diff line change @@ -77,6 +77,8 @@ pub(crate) struct Element {
7777 pub ( crate ) attrs : Attributes ,
7878 /// True if this tag ends with `/>`.
7979 pub ( crate ) self_closing : bool ,
80+ /// True if this was raw HTML written in the markdown.
81+ pub ( crate ) was_raw : bool ,
8082}
8183
8284impl Element {
@@ -87,6 +89,7 @@ impl Element {
8789 name,
8890 attrs : Attributes :: new ( ) ,
8991 self_closing : false ,
92+ was_raw : false ,
9093 }
9194 }
9295
@@ -618,6 +621,7 @@ where
618621 name,
619622 attrs,
620623 self_closing : tag. self_closing ,
624+ was_raw : true ,
621625 } ;
622626 fix_html_link ( & mut el) ;
623627 self . push ( Node :: Element ( el) ) ;
@@ -842,6 +846,11 @@ where
842846 for heading in headings {
843847 let node = self . tree . get ( heading) . unwrap ( ) ;
844848 let el = node. value ( ) . as_element ( ) . unwrap ( ) ;
849+ // Don't modify tags if they were manually written HTML. The
850+ // user probably had some intent, and we don't want to mess it up.
851+ if el. was_raw {
852+ continue ;
853+ }
845854 let href = if let Some ( id) = el. attr ( "id" ) {
846855 format ! ( "#{id}" )
847856 } else {
Original file line number Diff line number Diff line change @@ -64,6 +64,6 @@ <h2 id="style"><a class="header" href="#style">Style</a></h2>
6464.bar { background-color : green }
6565</ style >
6666< h2 id ="manual-headers "> < a class ="header " href ="#manual-headers "> Manual headers</ a > </ h2 >
67- < h2 id ="my header "> < a class =" header " href ="#my header " > < a href =" # foo "> My Header</ a > </ a > </ h2 >
67+ < h2 id ="my header "> < a href ="#foo "> My Header</ a > </ h2 >
6868
69- < h3 id =" another-header " > < a class =" header " href =" #another-header " > Another header</ a > </ h3 >
69+ < h3 > Another header</ h3 >
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ <h1 id="html-definition-lists"><a class="header" href="#html-definition-lists">H
22< p > Test for definition lists manually written in HTML.</ p >
33< dl >
44
5- < dt id =" some-tag " > < a class =" header " href =" #some-tag " > Some tag</ a > </ dt >
5+ < dt > Some tag</ dt >
66
77
88< dd > Some defintion</ dd >
99
1010
11- < dt class ="myclass " id ="myid "> < a class ="header " href =" #myid " > < a class =" option-anchor " href ="#foo "> Another definition</ a > </ a > </ dt >
11+ < dt class ="myclass " id ="myid "> < a class ="option-anchor " href ="#foo "> Another definition</ a > </ dt >
1212
1313
1414< dd class ="def-class "> A definition.</ dd >
Original file line number Diff line number Diff line change @@ -2,13 +2,13 @@ <h1 id="html-definition-lists"><a class="header" href="#html-definition-lists">H
22< p > Test for definition lists manually written in HTML.</ p >
33< dl >
44
5- < dt id =" some-tag " > < a class =" header " href =" #some-tag " > Some tag</ a > </ dt >
5+ < dt > Some tag</ dt >
66
77
88< dd > Some defintion</ dd >
99
1010
11- < dt class ="myclass " id ="myid "> < a class ="header " href =" #myid " > < a class =" option-anchor " href ="#foo "> Another definition</ a > </ a > </ dt >
11+ < dt class ="myclass " id ="myid "> < a class ="option-anchor " href ="#foo "> Another definition</ a > </ dt >
1212
1313
1414< dd class ="def-class "> A definition.</ dd >
You can’t perform that action at this time.
0 commit comments