aboutsummaryrefslogtreecommitdiff
path: root/_ext
diff options
context:
space:
mode:
Diffstat (limited to '_ext')
-rw-r--r--_ext/gemtext_builder.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/_ext/gemtext_builder.py b/_ext/gemtext_builder.py
index 9c31788..1e21d29 100644
--- a/_ext/gemtext_builder.py
+++ b/_ext/gemtext_builder.py
@@ -27,7 +27,8 @@ class GemtextTranslator(SphinxTranslator):
self.current_line = ''
self.body = []
self.literal = False
-
+ self.pending_links = []
+
def _finish_line(self):
if self.current_line != '':
self.body.append(self.current_line)
@@ -38,6 +39,7 @@ class GemtextTranslator(SphinxTranslator):
self.current_line = ''
self.body = []
self.literal = False
+ self.pending_links = []
def depart_document(self, node: nodes.document):
self._finish_line()
@@ -72,6 +74,9 @@ class GemtextTranslator(SphinxTranslator):
def depart_paragraph(self, node: nodes.paragraph):
self._finish_line()
+ self.body += self.pending_links
+ self.pending_links = []
+ self.body.append('')
def visit_reference(self, node: nodes.reference):
pass
@@ -81,7 +86,7 @@ class GemtextTranslator(SphinxTranslator):
self._finish_line()
self.body.append('=> {} {}'.format(node.attributes['refuri'], node.astext()))
else:
- self.current_line = '=> {} {}'.format(node.attributes['refuri'], self.current_line)
+ self.pending_links.append('=> {} {}'.format(node.attributes['refuri'], node.astext()))
def visit_image(self, node: nodes.image):
if self.current_line == '':
@@ -112,13 +117,17 @@ class GemtextTranslator(SphinxTranslator):
pass
def depart_bullet_list(self, node: nodes.bullet_list):
- pass
+ if self.body[-1] != '':
+ self.body.append('')
def visit_list_item(self, node: nodes.list_item):
self.current_line += '* '
def depart_list_item(self, node: nodes.list_item):
- pass
+ if self.body[-1] == '':
+ self.body = self.body[:-1]
+ if self.body[-1].startswith('=>') and self.body[-1].endswith(self.body[-2].replace('* ', '')):
+ self.body = self.body[:-2] + [self.body[-1]]
def visit_compound(self, node: nodes.compound):
pass
@@ -144,7 +153,8 @@ class GemtextTranslator(SphinxTranslator):
depart_literal = visit_literal
def visit_literal_block(self, nodes: nodes.literal_block):
- self.body.append('')
+ if self.body[-1] != '':
+ self.body.append('')
self.body.append('```')
self.literal = True
@@ -165,7 +175,7 @@ class GemtextBuilder(Builder):
return self.env.found_docs # can't be fucked to implement this right
def get_target_uri(self, docname: str, typ: str = None):
- return docname
+ return docname + '.gmi'
def prepare_writing(self, docnames: Set[str]):
self.writer = GemtextWriter(self)