Skip to content

Commit

Permalink
First refactor of sphinxHtmlToMarkdown.ts (Qiskit#584)
Browse files Browse the repository at this point in the history
Part of Qiskit#223.

First small refactor of the `sphinxHtmlToMarkdown.ts` script. This PR
divides the `sphinxHtmlToMarkdown` function into different helper
functions, reducing its length and allowing the possibility of adding
tests for different parts of the code.

Changes in this PR:

- Renamed the `$page` variable to `$` to reduce the noise introduced by
the number of calls we had and to follow the
[Cheerio](https://cheerio.js.org/docs/basics/loading#load) convention.
- Moved the code to find all the images into a helper function.
- Grouped similar transformations to the HTML (done previous to its
conversion to markdown) into a helper function called `preprocess`.
- Moved the conversion from HTML to markdown process to a different
function to simplify the `sphinxHtmlToMarkdown` function (divide more in
the future).
- Refactored the recursive search of methods, adding early returns and
merging some parts.
- Moved the unified plugin to the `unifiedParser.ts` file in order to
abstract the transformation, which can now be called from other files.
That script can group together all the unified plugins, such as the link
checker, the mergeClassMembers.ts, and this one.

In this PR, the code has been copied almost identically to how it was
before, except for some little adjustments, like in the unified plugin
where we now use an anonymous function and have the two visitors merged.

More changes will be introduced in a follow-up.

---------

Co-authored-by: Eric Arellano <[email protected]>
  • Loading branch information
arnaucasau and Eric-Arellano authored Jan 5, 2024
1 parent 0ec345d commit d00cac5
Show file tree
Hide file tree
Showing 2 changed files with 242 additions and 198 deletions.
18 changes: 10 additions & 8 deletions scripts/lib/sphinx/PythonObjectMeta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,17 @@
// copyright notice, and modified files need to carry a notice indicating
// that they have been altered from the originals.

export type PythonApiType =
| "class"
| "method"
| "property"
| "attribute"
| "module"
| "function"
| "exception";

export type PythonObjectMeta = {
python_api_name?: string;
python_api_type?:
| "class"
| "method"
| "property"
| "attribute"
| "module"
| "function"
| "exception";
python_api_type?: PythonApiType;
hardcoded_frontmatter?: string;
};
Loading

0 comments on commit d00cac5

Please sign in to comment.