diff --git a/CHANGES b/CHANGES index c83d9ab..01b1dfc 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,12 @@ Changes ======= +1.1.0 (*2021-02-??*) +==================== + +- Fix table generation with literal blocks +- Fix image copy when using glob + 1.0.0 (*2021-02-01*) ==================== diff --git a/setup.py b/setup.py index 0b16b71..59e44f6 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ with open("README.rst", "r") as fh: setup( name="sphinx_gemini_builder", - version="1.0.0", + version="1.1.0", url="https://procrastinator.nerv-project.eu/nerv-project/sphinx_gemini_builder", license="EUPL 1.2", author="Kujiu", diff --git a/sphinx_gemini_builder/__init__.py b/sphinx_gemini_builder/__init__.py index 737ed85..701c814 100644 --- a/sphinx_gemini_builder/__init__.py +++ b/sphinx_gemini_builder/__init__.py @@ -5,11 +5,12 @@ Build Gemini blog from Sphinx. """ -__version_info__ = (1, 0, 0) +__version_info__ = (1, 1, 0) __version__ = '.'.join([str(val) for val in __version_info__]) from os import path +from pathlib import Path from typing import Set, Dict, Any from urllib.parse import quote @@ -63,8 +64,12 @@ class GeminiBuilder(TextBuilder): try: ensuredir(destdir) - copyfile(path.join(self.srcdir, src), - path.join(self.outdir, self.imagedir, src)) + srcpaths = Path(self.srcdir).glob(src) + for srcpath in srcpaths: + destpath = path.relpath(srcpath, self.srcdir) + destpath = path.join(self.outdir, self.imagedir, destpath) + copyfile(srcpath, destpath) + except Exception as err: logger.warning(__('cannot copy image file %r: %s'), path.join(self.srcdir, src), err) diff --git a/sphinx_gemini_builder/writer.py b/sphinx_gemini_builder/writer.py index 9e03746..081cca6 100644 --- a/sphinx_gemini_builder/writer.py +++ b/sphinx_gemini_builder/writer.py @@ -59,7 +59,13 @@ class GeminiTranslator(SphinxTranslator): self.body = '' def add_text(self, text: str) -> None: - self.body += text + if self.table: + if len(self.cell_text): + self.cell_text[-1] += text + else: + self.cell_text.append(text) + else: + self.body += text def add_link(self, url: str, label: str = '') -> None: self.body += '=> %s %s' % (url, label) @@ -143,6 +149,7 @@ class GeminiTranslator(SphinxTranslator): pass def visit_attribution(self, node: Element) -> None: + self.end_block() self.add_text('-- ') def depart_attribution(self, node: Element) -> None: @@ -196,6 +203,7 @@ class GeminiTranslator(SphinxTranslator): def depart_desc_parameterlist(self, node: Element) -> None: self.add_text(')') + self.end_block() def visit_desc_parameter(self, node: Element) -> None: if not self.first_param: @@ -206,6 +214,7 @@ class GeminiTranslator(SphinxTranslator): raise nodes.SkipNode def visit_desc_optional(self, node: Element) -> None: + self.end_block() self.add_text('[') def depart_desc_optional(self, node: Element) -> None: @@ -373,26 +382,26 @@ class GeminiTranslator(SphinxTranslator): def depart_table(self, node: Element) -> None: self.enable_pre() - self.add_text(str(self.table)) + text = str(self.table) + self.table = None + self.cell_text = [] + self.add_text(text) self.disable_pre() for line in self.after_table: self.add_text(line) self.end_block() - self.table = None - self.cell_text = [] self.after_table = [] def visit_acks(self, node: Element) -> None: bullet_list = cast(nodes.bullet_list, node[0]) list_items = cast(Iterable[nodes.list_item], bullet_list) - self.new_state(0) self.add_text(', '.join(n.astext() for n in list_items) + '.') raise nodes.SkipNode def visit_image(self, node: Element) -> None: self.end_block() + uri = relative_uri(self.builder.current_docname, node['uri']) if 'alt' in node.attributes: - uri = relative_uri(self.builder.current_docname, node['uri']) self.add_link(uri, __('[image: %s]') % node['alt']) else: self.add_link(uri) @@ -613,7 +622,7 @@ class GeminiTranslator(SphinxTranslator): self.after_table.append( '=> %s %s' % (node['refuri'], node.astext())) - self.cell_text.append(node.astext() or node['refuri']) + self.add_text(node.astext() or node['refuri']) else: self.end_block() self.add_link(node['refuri'], node.astext()) @@ -706,7 +715,7 @@ class GeminiTranslator(SphinxTranslator): def visit_Text(self, node: Text) -> None: text = node.astext() if self.table: - self.cell_text.append(text) + self.add_text(text) raise nodes.SkipNode if isinstance(node.parent, nodes.paragraph):