Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions sphinx_markdown_builder/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()

17 changes: 16 additions & 1 deletion sphinx_markdown_builder/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
document=None,
container=None,
inline=None,
Inline=None,
definition_list=None,
definition_list_item=None,
glossary=None,
Expand Down Expand Up @@ -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})")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down