Skip to content

Commit 02d6257

Browse files
committed
Search: remove non-generic parser code
Closes #10272. We can't remove the code that generates the fjson files, since they are being used by the embed API (v2), that API is mentioned as deprecated, we should do the actual deprecation by contacting projects using it.
1 parent 40bfe63 commit 02d6257

20 files changed

+60
-378
lines changed

readthedocs/embed/tests/data/mkdocs/latest/index.json

-6
This file was deleted.

readthedocs/embed/tests/test_api.py

+3-33
Original file line numberDiff line numberDiff line change
@@ -281,14 +281,8 @@ def test_embed_sphinx(self, storage_mock, section, client):
281281
assert response.data == expected
282282
assert response['Cache-tag'] == 'project,project:latest'
283283

284-
@mock.patch('readthedocs.embed.views.build_media_storage')
285-
def test_embed_mkdocs(self, storage_mock, client):
286-
json_file = data_path / 'mkdocs/latest/index.json'
287-
storage_mock.exists.return_value = True
288-
storage_mock.open.side_effect = self._mock_open(
289-
json_file.open().read()
290-
)
291-
284+
def test_embed_mkdocs(self, client):
285+
"""API v2 doesn't support mkdocs."""
292286
self.version.documentation_type = MKDOCS
293287
self.version.save()
294288

@@ -303,31 +297,7 @@ def test_embed_mkdocs(self, storage_mock, client):
303297
}
304298
)
305299

306-
expected = {
307-
'content': mock.ANY, # too long to compare here
308-
'headers': [
309-
{'Overview': 'overview'},
310-
{'Installation': 'installation'},
311-
{'Getting Started': 'getting-started'},
312-
{'Adding pages': 'adding-pages'},
313-
{'Theming our documentation': 'theming-our-documentation'},
314-
{'Changing the Favicon Icon': 'changing-the-favicon-icon'},
315-
{'Building the site': 'building-the-site'},
316-
{'Other Commands and Options': 'other-commands-and-options'},
317-
{'Deploying': 'deploying'},
318-
{'Getting help': 'getting-help'},
319-
],
320-
'url': 'http://project.readthedocs.io/en/latest/index.html',
321-
'meta': {
322-
'project': 'project',
323-
'version': 'latest',
324-
'doc': 'index',
325-
'section': 'Installation',
326-
},
327-
}
328-
329-
assert response.status_code == status.HTTP_200_OK
330-
assert response.data == expected
300+
assert response.status_code == status.HTTP_404_NOT_FOUND
331301

332302
def test_no_access(self, client, settings):
333303
settings.RTD_DEFAULT_FEATURES = {}

readthedocs/embed/views.py

+2-56
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def do_embed(*, project, version, doc=None, path=None, section=None, url=None):
145145

146146
content = None
147147
headers = None
148+
# Embed API v2 supports Sphinx only.
148149
if version.is_sphinx_type:
149150
file_content = _get_doc_content(
150151
project=project,
@@ -160,18 +161,7 @@ def do_embed(*, project, version, doc=None, path=None, section=None, url=None):
160161
url=url,
161162
)
162163
else:
163-
# TODO: this should read from the html file itself,
164-
# we don't have fjson files for mkdocs.
165-
file_content = _get_doc_content(
166-
project=project,
167-
version=version,
168-
doc=doc,
169-
)
170-
content, headers, section = parse_mkdocs(
171-
content=file_content,
172-
section=section,
173-
url=url,
174-
)
164+
return None
175165

176166
if content is None:
177167
return None
@@ -310,47 +300,3 @@ def dump(obj):
310300

311301
ret = [dump(clean_references(obj, url)) for obj in query_result]
312302
return ret, headers, section
313-
314-
315-
def parse_mkdocs(content, section, url): # pylint: disable=unused-argument
316-
"""Get the embed content for the section."""
317-
ret = []
318-
headers = []
319-
320-
if not content or not content.get('content'):
321-
return (None, None, section)
322-
323-
body = content['content']
324-
for element in PQ(body)('h2'):
325-
headers.append(recurse_while_none(element))
326-
327-
if not section and headers:
328-
# If no section is sent, return the content of the first one
329-
section = list(headers[0].keys())[0].lower()
330-
331-
if section:
332-
body_obj = PQ(body)
333-
escaped_section = escape_selector(section)
334-
section_list = body_obj(
335-
':header:contains("{title}")'.format(title=str(escaped_section)))
336-
for num in range(len(section_list)):
337-
header2 = section_list.eq(num)
338-
# h2_title = h2.text().strip()
339-
# section_id = h2.attr('id')
340-
h2_content = ""
341-
next_p = header2.next()
342-
while next_p:
343-
if next_p[0].tag == 'h2':
344-
break
345-
h2_html = next_p.outerHtml()
346-
if h2_html:
347-
h2_content += "\n%s\n" % h2_html
348-
next_p = next_p.next()
349-
if h2_content:
350-
ret.append(h2_content)
351-
# ret.append({
352-
# 'id': section_id,
353-
# 'title': h2_title,
354-
# 'content': h2_content,
355-
# })
356-
return (ret, headers, section)

0 commit comments

Comments
 (0)