File tree Expand file tree Collapse file tree 8 files changed +67
-1
lines changed
crates/mdbook-html/src/html Expand file tree Collapse file tree 8 files changed +67
-1
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 @@ -157,6 +157,10 @@ fn definition_lists() {
157157 . check_main_file (
158158 "book/definition_lists.html" ,
159159 file ! [ "markdown/definition_lists/expected_disabled/definition_lists.html" ] ,
160+ )
161+ . check_main_file (
162+ "book/html_definition_lists.html" ,
163+ file ! [ "markdown/definition_lists/expected_disabled/html_definition_lists.html" ] ,
160164 ) ;
161165}
162166
Original file line number Diff line number Diff line change @@ -62,4 +62,8 @@ <h2 id="style"><a class="header" href="#style">Style</a></h2>
6262</ style >
6363< style media ="(width < 500px) ">
6464.bar { background-color : green }
65- </ style >
65+ </ style >
66+ < h2 id ="manual-headers "> < a class ="header " href ="#manual-headers "> Manual headers</ a > </ h2 >
67+ < h2 id ="my header "> < a href ="#foo "> My Header</ a > </ h2 >
68+
69+ < h3 > Another header</ h3 >
Original file line number Diff line number Diff line change @@ -92,3 +92,9 @@ const x = 'some *text* inside';
9292<style media=" (width < 500px )" >
9393.bar { background-color: green }
9494</style>
95+
96+ ## Manual headers
97+
98+ <h2 id=" my header" ><a href=" #foo" >My Header</a></h2>
99+
100+ <h3>Another header</h3>
Original file line number Diff line number Diff line change 1+ < h1 id ="html-definition-lists "> < a class ="header " href ="#html-definition-lists "> HTML definition lists</ a > </ h1 >
2+ < p > Test for definition lists manually written in HTML.</ p >
3+ < dl >
4+
5+ < dt > Some tag</ dt >
6+
7+
8+ < dd > Some defintion</ dd >
9+
10+
11+ < dt class ="myclass " id ="myid "> < a class ="option-anchor " href ="#foo "> Another definition</ a > </ dt >
12+
13+
14+ < dd class ="def-class "> A definition.</ dd >
15+
16+ </ dl >
Original file line number Diff line number Diff line change 1+ < h1 id ="html-definition-lists "> < a class ="header " href ="#html-definition-lists "> HTML definition lists</ a > </ h1 >
2+ < p > Test for definition lists manually written in HTML.</ p >
3+ < dl >
4+
5+ < dt > Some tag</ dt >
6+
7+
8+ < dd > Some defintion</ dd >
9+
10+
11+ < dt class ="myclass " id ="myid "> < a class ="option-anchor " href ="#foo "> Another definition</ a > </ dt >
12+
13+
14+ < dd class ="def-class "> A definition.</ dd >
15+
16+ </ dl >
Original file line number Diff line number Diff line change 11# Summary
22
33- [ Definition lists] ( ./definition_lists.md )
4+ - [ HTML definition lists] ( ./html_definition_lists.md )
Original file line number Diff line number Diff line change 1+ # HTML definition lists
2+
3+ Test for definition lists manually written in HTML.
4+
5+ <dl >
6+ <dt>Some tag</dt>
7+ <dd>Some defintion</dd>
8+ <dt class="myclass" id="myid"><a class="option-anchor" href="#foo">Another definition</a></dt>
9+ <dd class="def-class">A definition.</dd>
10+ </dl >
You can’t perform that action at this time.
0 commit comments