mirror of
https://github.com/rust-lang/mdBook.git
synced 2025-12-27 10:16:09 -05:00
Merge pull request #2913 from ehuss/html-definition-lists
Don't modify headers or dt if the tag is manually written HTML
This commit is contained in:
@@ -77,6 +77,8 @@ pub(crate) struct Element {
|
||||
pub(crate) attrs: Attributes,
|
||||
/// True if this tag ends with `/>`.
|
||||
pub(crate) self_closing: bool,
|
||||
/// True if this was raw HTML written in the markdown.
|
||||
pub(crate) was_raw: bool,
|
||||
}
|
||||
|
||||
impl Element {
|
||||
@@ -87,6 +89,7 @@ impl Element {
|
||||
name,
|
||||
attrs: Attributes::new(),
|
||||
self_closing: false,
|
||||
was_raw: false,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -618,6 +621,7 @@ where
|
||||
name,
|
||||
attrs,
|
||||
self_closing: tag.self_closing,
|
||||
was_raw: true,
|
||||
};
|
||||
fix_html_link(&mut el);
|
||||
self.push(Node::Element(el));
|
||||
@@ -842,6 +846,11 @@ where
|
||||
for heading in headings {
|
||||
let node = self.tree.get(heading).unwrap();
|
||||
let el = node.value().as_element().unwrap();
|
||||
// Don't modify tags if they were manually written HTML. The
|
||||
// user probably had some intent, and we don't want to mess it up.
|
||||
if el.was_raw {
|
||||
continue;
|
||||
}
|
||||
let href = if let Some(id) = el.attr("id") {
|
||||
format!("#{id}")
|
||||
} else {
|
||||
|
||||
@@ -157,6 +157,10 @@ fn definition_lists() {
|
||||
.check_main_file(
|
||||
"book/definition_lists.html",
|
||||
file!["markdown/definition_lists/expected_disabled/definition_lists.html"],
|
||||
)
|
||||
.check_main_file(
|
||||
"book/html_definition_lists.html",
|
||||
file!["markdown/definition_lists/expected_disabled/html_definition_lists.html"],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -62,4 +62,8 @@ const x = 'some *text* inside';
|
||||
</style>
|
||||
<style media="(width < 500px)">
|
||||
.bar { background-color: green }
|
||||
</style>
|
||||
</style>
|
||||
<h2 id="manual-headers"><a class="header" href="#manual-headers">Manual headers</a></h2>
|
||||
<h2 id="my header"><a href="#foo">My Header</a></h2>
|
||||
|
||||
<h3>Another header</h3>
|
||||
@@ -92,3 +92,9 @@ const x = 'some *text* inside';
|
||||
<style media="(width < 500px)">
|
||||
.bar { background-color: green }
|
||||
</style>
|
||||
|
||||
## Manual headers
|
||||
|
||||
<h2 id="my header"><a href="#foo">My Header</a></h2>
|
||||
|
||||
<h3>Another header</h3>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
<h1 id="html-definition-lists"><a class="header" href="#html-definition-lists">HTML definition lists</a></h1>
|
||||
<p>Test for definition lists manually written in HTML.</p>
|
||||
<dl>
|
||||
|
||||
<dt>Some tag</dt>
|
||||
|
||||
|
||||
<dd>Some defintion</dd>
|
||||
|
||||
|
||||
<dt class="myclass" id="myid"><a class="option-anchor" href="#foo">Another definition</a></dt>
|
||||
|
||||
|
||||
<dd class="def-class">A definition.</dd>
|
||||
|
||||
</dl>
|
||||
@@ -0,0 +1,16 @@
|
||||
<h1 id="html-definition-lists"><a class="header" href="#html-definition-lists">HTML definition lists</a></h1>
|
||||
<p>Test for definition lists manually written in HTML.</p>
|
||||
<dl>
|
||||
|
||||
<dt>Some tag</dt>
|
||||
|
||||
|
||||
<dd>Some defintion</dd>
|
||||
|
||||
|
||||
<dt class="myclass" id="myid"><a class="option-anchor" href="#foo">Another definition</a></dt>
|
||||
|
||||
|
||||
<dd class="def-class">A definition.</dd>
|
||||
|
||||
</dl>
|
||||
@@ -1,3 +1,4 @@
|
||||
# Summary
|
||||
|
||||
- [Definition lists](./definition_lists.md)
|
||||
- [HTML definition lists](./html_definition_lists.md)
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
# HTML definition lists
|
||||
|
||||
Test for definition lists manually written in HTML.
|
||||
|
||||
<dl>
|
||||
<dt>Some tag</dt>
|
||||
<dd>Some defintion</dd>
|
||||
<dt class="myclass" id="myid"><a class="option-anchor" href="#foo">Another definition</a></dt>
|
||||
<dd class="def-class">A definition.</dd>
|
||||
</dl>
|
||||
Reference in New Issue
Block a user