forked from docs/doc-exports
Adding new rule for colon and asterisk combination
Reviewed-by: gtema <artem.goncharov@gmail.com> Co-authored-by: Hasko, Vladimir <vladimir.hasko@t-systems.com> Co-committed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
This commit is contained in:
parent
c24a3e0de3
commit
f173c9af19
@ -423,7 +423,7 @@ class OTCDocConvertor:
|
||||
]
|
||||
self.rawize_me(soup, rawize_strings)
|
||||
|
||||
# Pandoc seem to be not escaping properly asterists which are
|
||||
# Pandoc seem to be not escaping properly asterisks which are
|
||||
# immediately following non word chars
|
||||
# (https://docutils.sourceforge.io/docs/ref/rst/restructuredtext.html#toc-entry-44)
|
||||
# NOTE(gtema):
|
||||
@ -431,12 +431,26 @@ class OTCDocConvertor:
|
||||
# escapings above
|
||||
# 2. we are not escaping asterisks at the end of the paragraphs (pandoc
|
||||
# deals correctly with that)
|
||||
re_escape = re.compile(r"([-:/'\"<\([{])(\*+)(.)")
|
||||
re_escape = re.compile(r"([-/'\"<\([{])(\*+)(.)")
|
||||
for p in soup.body.find_all(string=re_escape):
|
||||
if p.string and p.parent.name == "p":
|
||||
p.string.replace_with(
|
||||
re.sub(re_escape, r"\1``\2``\3", p.string))
|
||||
|
||||
# Special case for multiple asterisks and colons like ecs:*:*
|
||||
re_escape = re.compile(r"([:])(\*+)")
|
||||
re_escape_new = re.compile(r"([:])(\*)[^$]")
|
||||
for p in soup.body.find_all(string=re_escape):
|
||||
if p.string and (p.parent.name == "p" or p.parent.name == "li"):
|
||||
string = p.string
|
||||
while re.search(re_escape, string):
|
||||
if re.search(re_escape_new, string):
|
||||
string = re.sub(
|
||||
re_escape, r"\1``\2``", string, count=1)
|
||||
else:
|
||||
break
|
||||
p.string.replace_with(string)
|
||||
|
||||
# Drop parent link at the bottom of the page
|
||||
for parent in soup.body.find_all("p", class_="familylinks"):
|
||||
parent.decompose()
|
||||
|
@ -65,7 +65,7 @@ class TestConvertor(TestCase):
|
||||
Turbo instance, including the permissions for verifying VPCs, subnets,
|
||||
and security groups, creating virtual IP addresses and ports, and
|
||||
creating security group rules. You must add the following
|
||||
action:<ul><li>"vpc:*:*"</li></ul></li></ul></td>
|
||||
action:<ul><li>"vpc:``*``:``*``"</li></ul></li></ul></td>
|
||||
"""
|
||||
soup = bs4.BeautifulSoup(test_data, 'lxml')
|
||||
res = self.convertor.streamline_html(soup, "dummy")
|
||||
@ -76,7 +76,7 @@ class TestConvertor(TestCase):
|
||||
<ul><li>"dss:*:get",</li><li>"dss:*:list",</li><li>"dss:*:count"</li></ul>
|
||||
"""
|
||||
expected = """
|
||||
<ul><li>"dss:*:get",</li><li>"dss:*:list",</li><li>"dss:*:count"</li></ul>
|
||||
<ul><li>"dss:``*``:get",</li><li>"dss:``*``:list",</li><li>"dss:``*``:count"</li></ul>
|
||||
"""
|
||||
soup = bs4.BeautifulSoup(test_data, 'lxml')
|
||||
res = self.convertor.streamline_html(soup, "dummy")
|
||||
@ -87,7 +87,7 @@ class TestConvertor(TestCase):
|
||||
<ul><li>"vpc:*:*"</li></ul>
|
||||
"""
|
||||
expected = """
|
||||
<ul><li>"vpc:*:*"</li></ul>
|
||||
<ul><li>"vpc:``*``:``*``"</li></ul>
|
||||
"""
|
||||
soup = bs4.BeautifulSoup(test_data, 'lxml')
|
||||
res = self.convertor.streamline_html(soup, "dummy")
|
||||
@ -163,3 +163,31 @@ class TestConvertor(TestCase):
|
||||
str(res.find('td')),
|
||||
expected.strip(),
|
||||
)
|
||||
|
||||
def test_streamline_html_escape_12(self):
|
||||
test_data= """
|
||||
<p id="dli_03_0101__en-us_topic_0000001174688342_p1256384461610">DLI:*:*:database:databases.dbname</p>
|
||||
""" # noqa
|
||||
expected = """
|
||||
<p id="dli_03_0101__en-us_topic_0000001174688342_p1256384461610">DLI:``*``:``*``:database:databases.dbname</p>
|
||||
""" # noqa
|
||||
soup = bs4.BeautifulSoup(test_data, 'lxml')
|
||||
res = self.convertor.streamline_html(soup, "dummy")
|
||||
self.assertEqual(
|
||||
str(res.find('p')),
|
||||
expected.strip(),
|
||||
)
|
||||
|
||||
def test_streamline_html_escape_13(self):
|
||||
test_data= """
|
||||
<p id="dli_03_0101__en-us_topic_0000001174688342_p4564244131615">DLI:*:*:queue:queues.*</p>
|
||||
""" # noqa
|
||||
expected = """
|
||||
<p id="dli_03_0101__en-us_topic_0000001174688342_p4564244131615">DLI:``*``:``*``:queue:queues.*</p>
|
||||
""" # noqa
|
||||
soup = bs4.BeautifulSoup(test_data, 'lxml')
|
||||
res = self.convertor.streamline_html(soup, "dummy")
|
||||
self.assertEqual(
|
||||
str(res.find('p')),
|
||||
expected.strip(),
|
||||
)
|
||||
|
@ -1,4 +1,5 @@
|
||||
bs4
|
||||
lxml
|
||||
Jinja2
|
||||
requests
|
||||
bs4>=0.0.1
|
||||
beautifulsoup4>=4.0 # MIT
|
||||
lxml>=4.9 # BSD-3-Clause
|
||||
Jinja2>=3.1 # BSD-3-Clause
|
||||
requests>=2.28 # Apache-2.0
|
||||
|
@ -1 +1,2 @@
|
||||
flake8
|
||||
flake8>=6.0 # MIT
|
||||
stestr>=4.0 # Apache-2.0
|
||||
|
4
tox.ini
4
tox.ini
@ -1,6 +1,6 @@
|
||||
[tox]
|
||||
minversion = 3.6
|
||||
envlist = pep8
|
||||
envlist = py3,pep8
|
||||
skipsdist = True
|
||||
ignore_basepython_conflict = True
|
||||
|
||||
@ -15,6 +15,8 @@ setenv =
|
||||
deps =
|
||||
-r{toxinidir}/requirements.txt
|
||||
-r{toxinidir}/test-requirements.txt
|
||||
commands = stestr run {posargs}
|
||||
stestr slowest
|
||||
|
||||
[testenv:pep8]
|
||||
commands =
|
||||
|
Loading…
x
Reference in New Issue
Block a user