Skip to content

Commit 6d19860

Browse files
committed
replace m2r (deprecated, vulnerabilities)
1 parent 9a28c7d commit 6d19860

101 files changed

Lines changed: 1149 additions & 688 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

colrev/package_manager/doc_registry_manager.py

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import json
77
import os
8+
import re
89
import tempfile
910
import typing
1011
from pathlib import Path
@@ -13,7 +14,6 @@
1314
import requests
1415
import toml
1516
from bs4 import BeautifulSoup
16-
from m2r import parse_from_file # pylint: disable=import-error
1717

1818
import colrev.package_manager.colrev_internal_packages
1919
from colrev.constants import EndpointType
@@ -271,18 +271,83 @@ def _get_header_info(self) -> str:
271271

272272
def import_package_docs(self) -> None:
273273
"""Import the package documentation."""
274-
with open(
275-
Filepaths.COLREV_PATH
276-
/ Path(f"docs/source/manual/packages/{self.docs_rst_path}"),
277-
"w",
278-
encoding="utf-8",
279-
) as file:
274+
docs_package_path = Filepaths.COLREV_PATH / Path(
275+
f"docs/source/manual/packages/{self.docs_rst_path}"
276+
)
277+
278+
readme_path = self._copy_readme_for_myst_include()
279+
readme_content = readme_path.read_text(encoding="utf-8")
280+
rst_readme_content = self._convert_markdown_to_rst(readme_content)
281+
282+
with open(docs_package_path, "w", encoding="utf-8") as file:
280283
file.write(self._get_header_info())
281-
output = parse_from_file(self.docs_package_readme_path)
282-
output = output.replace(
283-
".. list-table::", ".. list-table::\n :align: left"
284-
)
285-
file.write(output)
284+
file.write("\n")
285+
file.write(rst_readme_content)
286+
287+
def _convert_markdown_to_rst(self, markdown_content: str) -> str:
288+
"""Convert Markdown content to reStructuredText for generated docs pages."""
289+
heading_chars = {1: "=", 2: "-", 3: "^", 4: '"'}
290+
converted_lines = []
291+
in_fenced_code_block = False
292+
fenced_code_language = ""
293+
294+
for line in markdown_content.splitlines():
295+
fence_match = re.match(r"^```(\w+)?\s*$", line)
296+
if fence_match:
297+
if not in_fenced_code_block:
298+
in_fenced_code_block = True
299+
fenced_code_language = fence_match.group(1) or ""
300+
if fenced_code_language:
301+
converted_lines.append(
302+
f".. code-block:: {fenced_code_language}"
303+
)
304+
else:
305+
converted_lines.append(".. code-block::")
306+
converted_lines.append("")
307+
else:
308+
in_fenced_code_block = False
309+
fenced_code_language = ""
310+
converted_lines.append("")
311+
continue
312+
313+
if in_fenced_code_block:
314+
if line.strip() == "":
315+
converted_lines.append("")
316+
else:
317+
converted_lines.append(f" {line}")
318+
continue
319+
320+
heading_match = re.match(r"^(#{1,6})\s+(.+?)\s*$", line)
321+
if heading_match:
322+
level = len(heading_match.group(1))
323+
title = heading_match.group(2)
324+
underline_char = heading_chars.get(level, '"')
325+
converted_lines.append(title)
326+
converted_lines.append(underline_char * len(title))
327+
converted_lines.append("")
328+
continue
329+
330+
line = re.sub(r"\[([^\]]+)\]\(([^)]+)\)", r"`\1 <\2>`_", line)
331+
line = re.sub(r"^\s*-\s+`([^`]+)\s+<([^>]+)>`_\s*$", r"* `\1 <\2>`_", line)
332+
line = re.sub(r"``([^`]+)```\1`", r"``\1``", line)
333+
converted_lines.append(line)
334+
335+
return "\n".join(converted_lines).rstrip() + "\n"
336+
337+
def _copy_readme_for_myst_include(self) -> Path:
338+
"""Copy the package README to a generated docs folder for MyST inclusion."""
339+
readme_dir = Filepaths.COLREV_PATH / Path(
340+
"docs/source/manual/packages/_package_readmes"
341+
)
342+
readme_dir.mkdir(parents=True, exist_ok=True)
343+
344+
readme_path = readme_dir / f"{self.package_id}.md"
345+
readme_path.write_text(
346+
self.docs_package_readme_path.read_text(encoding="utf-8"),
347+
encoding="utf-8",
348+
)
349+
350+
return readme_path
286351

287352
def get_endpoint_item(self, endpoint_type: EndpointType) -> dict:
288353
"""Get the endpoint item for the package.

docs/source/conf.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
"sphinx_collapse",
5151
"sphinx_design",
5252
"sphinx_copybutton",
53+
"myst_parser",
5354
]
5455

5556

@@ -64,6 +65,7 @@
6465

6566
# Add any paths that contain templates here, relative to this directory.
6667
templates_path = ["_templates"]
68+
exclude_patterns = ["manual/packages/_package_readmes/**"]
6769

6870
# -- Options for HTML output -------------------------------------------------
6971

docs/source/manual/packages/colrev-sync.rst

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,16 @@ colrev-sync
4646
Summary
4747
-------
4848

49+
4950
The colrev-sync package imports references from CoLRev projects (through local_index) into non-CoLRev paper projects that use Markdown and BibTeX.
5051
If BibTeX citations keys are used in the paper project, the following command retrieves the corresponding bibliographical details and adds them to the BibTeX file:
5152

5253
.. code-block::
5354
5455
colrev-sync
5556
56-
CoLRev sync can also be used through pre-commit hooks, when the following is included in the ``.pre-commit-config.yaml``\ :
57+
58+
CoLRev sync can also be used through pre-commit hooks, when the following is included in the `.pre-commit-config.yaml`:
5759

5860
.. code-block::
5961

docs/source/manual/packages/colrev.abi_inform_proquest.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,15 @@ colrev.abi_inform_proquest
5151
Summary
5252
-------
5353

54+
5455
search
5556
------
5657

58+
5759
DB search
5860
^^^^^^^^^
5961

62+
6063
`ABI/INFORM ProQuest <https://about.proquest.com/en/products-services/abi_inform_complete/>`_
6164

6265
Links

docs/source/manual/packages/colrev.acm_digital_library.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,16 +51,20 @@ colrev.acm_digital_library
5151
Summary
5252
-------
5353

54+
5455
search
5556
------
5657

58+
5759
DB search
5860
^^^^^^^^^
5961

60-
.. code-block::
62+
63+
.. code-block:: bash
6164
6265
colrev search --add colrev.acm_digital_library
6366
67+
6468
Links
6569
-----
6670

docs/source/manual/packages/colrev.add_journal_ranking.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,11 @@ colrev.add_journal_ranking
5151
Summary
5252
-------
5353

54+
5455
prep
5556
----
5657

58+
5759
**Prerequisite** Initial ranking data is extracted from ranking.csv into SQLite Database sqlite_index.db with 'colrev env -i'.
5860

5961
**Description**
@@ -62,19 +64,21 @@ The add_journal_ranking package allows the user to add a ranking to the records
6264

6365
Example:
6466

65-
.. code-block::
67+
.. code-block:: text
6668
6769
journal_ranking = {Senior Scholars' List of Premier Journals}, or
6870
journal_ranking = {not included in a ranking},
6971
72+
7073
Should the journal be in the Beall's Predatory Journal list, then the record will be marked as "Predatory Journal: Do not include!" and be predestined to be excluded in the scope_prescreen process.
7174

7275
Example:
7376

74-
.. code-block::
77+
.. code-block:: text
7578
7679
journal_ranking = {Predatory Journal: Do not include!},
7780
81+
7882
The journal ranking will also be used in the colrev prescreen method and allows the user to decide if the record should be marked as 'rev_prescreen_excluded' or 'rev_prescreen_included'.
7983

8084
For further information see `scope_prescreen <https://colrev-environment.github.io/colrev/manual/packages/colrev.scope_prescreen.html>`_.

docs/source/manual/packages/colrev.ais_library.rst

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,37 +51,44 @@ colrev.ais_library
5151
Summary
5252
-------
5353

54+
5455
search
5556
------
5657

57-
**Limitation**\ : The AIS eLibrary currently limits search results an 3.000 records (for DB and API searches).
58+
59+
**Limitation**: The AIS eLibrary currently limits search results an 3.000 records (for DB and API searches).
5860

5961
DB search
6062
^^^^^^^^^
6163

64+
6265
Run a search on `aisel.aisnet.org <https://aisel.aisnet.org/>`_.
6366

64-
Download the search results (advanced search, format:Bibliography Export, click Search) and store them in the ``data/search/`` directory.
67+
Download the search results (advanced search, format:Bibliography Export, click Search) and store them in the `data/search/` directory.
6568

66-
.. code-block::
69+
.. code-block:: bash
6770
6871
colrev search --add colrev.ais_library
6972
73+
7074
API search
7175
^^^^^^^^^^
7276

77+
7378
Copy the search link and add an API search (replacing the link):
7479

75-
.. code-block::
80+
.. code-block:: bash
7681
7782
colrev search --add colrev.ais_library -p "https://aisel.aisnet.org/do/search/?q=microsourcing&start=0&context=509156&facet="
7883
84+
7985
Note: Complex queries can be entered in the basic search field. Example:
8086

81-
.. code-block::
87+
.. code-block:: text
8288
8389
title:microsourcing AND ( digital OR online)
8490
91+
8592
Format of the search-history file (DB search):
8693

8794
.. code-block:: json
@@ -94,6 +101,7 @@ Format of the search-history file (DB search):
94101
"version": "0.1.0"
95102
}
96103
104+
97105
Format of the search-history file (API search):
98106

99107
.. code-block:: json
@@ -109,7 +117,9 @@ Format of the search-history file (API search):
109117
"version": "0.1.0"
110118
}
111119
120+
112121
Links
113122
-----
114123

124+
115125
`AIS eLibrary <https://aisel.aisnet.org/>`_

docs/source/manual/packages/colrev.arxiv.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,18 +51,22 @@ colrev.arxiv
5151
Summary
5252
-------
5353

54+
5455
Add the search source
5556
---------------------
5657

58+
5759
API
5860
^^^
5961

62+
6063
ℹ️ Restriction: API searches do not support complex queries (yet)
6164

62-
.. code-block::
65+
.. code-block:: bash
6366
6467
colrev search --add colrev.arxiv -p "https://arxiv.org/search/?query=fitbit&searchtype=all&abstracts=show&order=-announced_date_first&size=50"
6568
69+
6670
Format of the search-history file:
6771

6872
.. code-block:: json
@@ -78,6 +82,7 @@ Format of the search-history file:
7882
"version": "0.1.0"
7983
}
8084
85+
8186
Links
8287
-----
8388

docs/source/manual/packages/colrev.bibliography_export.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@ colrev.bibliography_export
5151
Summary
5252
-------
5353

54+
5455
data
5556
----
5657

58+
5759
This endpoint exports the records in different bibliographical formats, which can be useful when the team works with a particular reference manager.
5860

5961
To add an endpoint, run any of the following:
6062

61-
.. code-block::
63+
.. code-block:: bash
6264
6365
colrev data -a colrev.bibliography_export -p zotero
6466
colrev data -a colrev.bibliography_export -p jabref
@@ -69,6 +71,4 @@ To add an endpoint, run any of the following:
6971
colrev data -a colrev.bibliography_export -p EXCEL
7072
7173
72-
.. raw:: html
73-
74-
<!-- ## Links -->
74+
<!-- ## Links -->

docs/source/manual/packages/colrev.blank.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,5 @@ colrev.blank
5151
Summary
5252
-------
5353

54+
5455
The *blank* ReviewType does not include any settings. It is primarily used for simulations.

0 commit comments

Comments
 (0)