diff --git a/sphinx_markdown_builder/builder.py b/sphinx_markdown_builder/builder.py index fd774d67..c2617d84 100644 --- a/sphinx_markdown_builder/builder.py +++ b/sphinx_markdown_builder/builder.py @@ -13,6 +13,7 @@ from sphinx.locale import __ from sphinx.util import logging from sphinx.util.osutil import ensuredir, os_path +from sphinx.util.fileutil import copy_asset_file from sphinx_markdown_builder.translator import MarkdownTranslator from sphinx_markdown_builder.writer import MarkdownWriter @@ -94,3 +95,18 @@ def write_doc(self, docname: str, doctree: nodes.document): with io_handler(out_filename): with open(out_filename, "w", encoding="utf-8") as file: file.write(self.writer.output) + + def copy_image_files(self) -> None: + if self.images: + for key in self.images.keys(): + copy_asset_file(os.path.join(self.srcdir, key), self.outdir) + + def write( + self, + build_docnames, + updated_docnames, + method: str = 'update', + ) -> None: + super().write(build_docnames, updated_docnames, method) + self.copy_image_files() + diff --git a/sphinx_markdown_builder/translator.py b/sphinx_markdown_builder/translator.py index a05e635d..fb74de8b 100644 --- a/sphinx_markdown_builder/translator.py +++ b/sphinx_markdown_builder/translator.py @@ -86,6 +86,7 @@ document=None, container=None, inline=None, + Inline=None, definition_list=None, definition_list_item=None, glossary=None, @@ -323,6 +324,7 @@ def visit_image(self, node): """Image directive.""" uri = node["uri"] alt = node.attributes.get("alt", "image") + self.builder.images[uri] = uri # We don't need to add EOL before/after the image. # It will be handled by the visit/depart handlers of the paragraph. self.add(f"![{alt}]({uri})") @@ -524,6 +526,12 @@ def _fetch_ref_uri(self, node): @pushing_context def visit_reference(self, node): url = self._fetch_ref_uri(node) + # if the reference object itself has the url + # (such as for an intra-document heading reference) + # use that url instead + ref_id = node.get("refid", None) + if ref_id is not None and url == "": + url = f"#{ref_id}" self._push_context(WrappedContext("[", f"]({url})")) @pushing_context @@ -615,7 +623,14 @@ def visit_desc_signature(self, node): # Insert anchors if enabled by the config if self.config.markdown_anchor_signatures: for anchor in node.get("ids", []): - self._add_anchor(anchor) + # only use v4 cpp anchors + if len(anchor) < 6: + self._add_anchor(anchor) + elif anchor[0:5] == "_CPPv": + if not (anchor[5:6] in ["2","3"]): + self._add_anchor(anchor) + else: + self._add_anchor(anchor) # We don't want methods to be at the same level as classes, # If signature has a non-null class, that's means it is a signature