mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Improved collapsing of adjacent whitespace and removal of empty elements in search plugin
This commit is contained in:
parent
7484b19e9a
commit
68257348b8
@ -444,7 +444,20 @@ class Parser(HTMLParser):
|
|||||||
if self.section.el in self.context:
|
if self.section.el in self.context:
|
||||||
data = self.section.title
|
data = self.section.title
|
||||||
|
|
||||||
|
# Search for corresponding opening tag
|
||||||
|
index = data.index(f"<{tag}>")
|
||||||
|
for i in range(index + 1, len(data)):
|
||||||
|
if not data[i].isspace():
|
||||||
|
index = len(data)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Remove element if empty (or only whitespace)
|
||||||
|
if len(data) > index:
|
||||||
|
while len(data) > index:
|
||||||
|
data.pop()
|
||||||
|
|
||||||
# Append to section title or text
|
# Append to section title or text
|
||||||
|
else:
|
||||||
data.append(f"</{tag}>")
|
data.append(f"</{tag}>")
|
||||||
|
|
||||||
# Called for the text contents of each tag
|
# Called for the text contents of each tag
|
||||||
@ -477,6 +490,11 @@ class Parser(HTMLParser):
|
|||||||
escape(data, quote = False)
|
escape(data, quote = False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Collapse adjacent whitespace
|
||||||
|
elif data.isspace():
|
||||||
|
if not self.section.text or not self.section.text[-1].isspace():
|
||||||
|
self.section.text.append(data)
|
||||||
|
|
||||||
# Handle everything else
|
# Handle everything else
|
||||||
else:
|
else:
|
||||||
self.section.text.append(
|
self.section.text.append(
|
||||||
|
@ -444,7 +444,20 @@ class Parser(HTMLParser):
|
|||||||
if self.section.el in self.context:
|
if self.section.el in self.context:
|
||||||
data = self.section.title
|
data = self.section.title
|
||||||
|
|
||||||
|
# Search for corresponding opening tag
|
||||||
|
index = data.index(f"<{tag}>")
|
||||||
|
for i in range(index + 1, len(data)):
|
||||||
|
if not data[i].isspace():
|
||||||
|
index = len(data)
|
||||||
|
break
|
||||||
|
|
||||||
|
# Remove element if empty (or only whitespace)
|
||||||
|
if len(data) > index:
|
||||||
|
while len(data) > index:
|
||||||
|
data.pop()
|
||||||
|
|
||||||
# Append to section title or text
|
# Append to section title or text
|
||||||
|
else:
|
||||||
data.append(f"</{tag}>")
|
data.append(f"</{tag}>")
|
||||||
|
|
||||||
# Called for the text contents of each tag
|
# Called for the text contents of each tag
|
||||||
@ -477,6 +490,11 @@ class Parser(HTMLParser):
|
|||||||
escape(data, quote = False)
|
escape(data, quote = False)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Collapse adjacent whitespace
|
||||||
|
elif data.isspace():
|
||||||
|
if not self.section.text or not self.section.text[-1].isspace():
|
||||||
|
self.section.text.append(data)
|
||||||
|
|
||||||
# Handle everything else
|
# Handle everything else
|
||||||
else:
|
else:
|
||||||
self.section.text.append(
|
self.section.text.append(
|
||||||
|
Loading…
Reference in New Issue
Block a user