File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -77,7 +77,7 @@ codelinks = "sphinx_codelinks.cmd:app"
7777"docs" = " sphinx-build -nW --keep-going -b html -T -c docs docs/source docs/_build/html"
7878"docs:clean" = { chain = [" docs:rm" , " docs" ] }
7979# needextend demo
80- "analyse" = " codelinks analyse tests/data/analyse/default_config .toml"
80+ "analyse" = " codelinks analyse tests/data/configs/minimum_config .toml"
8181"analyse:rm" = " rm -rf output/marked_content.json"
8282"bridge" = " codelinks bridge output/marked_content.json --outdir tests/data/needextend_demo"
8383"bridge:rm" = " rm -rf tests/data/needextend_demo/needextend.rst"
Original file line number Diff line number Diff line change @@ -216,6 +216,49 @@ def discover(
216216 typer .echo (file_path )
217217
218218
219+ @app .command (no_args_is_help = True )
220+ def bridge (
221+ jsonpath : Annotated [
222+ Path ,
223+ typer .Argument (
224+ ...,
225+ help = "Path of the JSON file which contains the extracted markers" ,
226+ show_default = False ,
227+ dir_okay = False ,
228+ file_okay = True ,
229+ exists = True ,
230+ resolve_path = True ,
231+ ),
232+ ],
233+ outdir : Annotated [
234+ Path ,
235+ typer .Option (
236+ "--outdir" ,
237+ "-o" ,
238+ help = "The output directory for needextend.rst" ,
239+ show_default = True ,
240+ dir_okay = True ,
241+ file_okay = False ,
242+ exists = True ,
243+ ),
244+ ] = Path .cwd (), # noqa: B008 # to show default value in this CLI
245+ remote_url_field : Annotated [
246+ str ,
247+ typer .Option (
248+ "--remote-url-field" ,
249+ "-r" ,
250+ help = "The field name for the remote url" ,
251+ show_default = True ,
252+ ),
253+ ] = "remote_url" , # to show default value in this CLI
254+ verbose : OptVerbose = False ,
255+ quiet : OptQuiet = False ,
256+ ) -> None :
257+ """Generate needextend.rst from the extracted obj in JSON."""
258+ logger .configure (verbose , quiet )
259+ convert_marked_content (jsonpath , outdir , remote_url_field )
260+
261+
219262def load_config_from_toml (toml_file : Path ) -> CodeLinksConfigType :
220263 try :
221264 with toml_file .open ("rb" ) as f :
Original file line number Diff line number Diff line change @@ -168,10 +168,15 @@ def convert_marked_content(
168168) -> None :
169169 """Convert marked objects extracted by anaylse CLI to needextend in RST"""
170170 with jsonpath .open ("r" ) as f :
171- marked_objs = json .load (f )
171+ marked_content = json .load (f )
172172
173173 warnings = []
174174
175+ # flatten objects
176+ marked_objs : list [MarkedObjType ] = [
177+ obj for objs in marked_content .values () for obj in objs
178+ ]
179+
175180 need_id_refs = [
176181 obj
177182 for obj in marked_objs
You can’t perform that action at this time.
0 commit comments