Skip to content

Commit

Permalink
Fixed synopsis linking.
Browse files Browse the repository at this point in the history
  • Loading branch information
revarbat committed Apr 13, 2023
1 parent 57cbd9a commit 461c980
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
63 changes: 34 additions & 29 deletions openscad_docsgen/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,10 @@ def get_markdown_body(self, controller, target):
out.append(self.parse_links(line, controller, target))
return out

def get_tocfile_lines(self, target, n=1, currfile=""):
def get_tocfile_lines(self, controller, target, n=1, currfile=""):
return []

def get_toc_lines(self, target, n=1, currfile=""):
def get_toc_lines(self, controller, target, n=1, currfile=""):
return []

def get_cheatsheet_lines(self, controller, target):
Expand Down Expand Up @@ -337,7 +337,7 @@ def get_link(self, target, currfile=None, label=""):
literalize=False
)

def get_tocfile_lines(self, target, n=1, currfile=""):
def get_tocfile_lines(self, controller, target, n=1, currfile=""):
sections = [
sect for sect in self.children
if isinstance(sect, SectionBlock)
Expand All @@ -352,19 +352,19 @@ def get_tocfile_lines(self, target, n=1, currfile=""):
out.extend(target.line_with_break(target.italics(note)))
out.extend(target.bullet_list_start())
for n, sect in enumerate(sections):
out.extend(sect.get_tocfile_lines(target, n=n+1, currfile=currfile))
out.extend(sect.get_tocfile_lines(controller, target, n=n+1, currfile=currfile))
out.extend(target.bullet_list_end())
return out

def get_toc_lines(self, target, n=1, currfile=""):
def get_toc_lines(self, controller, target, n=1, currfile=""):
sections = [
sect for sect in self.children
if isinstance(sect, SectionBlock)
]
out = []
out.extend(target.numbered_list_start())
for n, sect in enumerate(sections):
out.extend(sect.get_toc_lines(target, n=n+1, currfile=currfile))
out.extend(sect.get_toc_lines(controller, target, n=n+1, currfile=currfile))
out.extend(target.numbered_list_end())
return out

Expand All @@ -385,7 +385,7 @@ def get_file_lines(self, controller, target):
if not isinstance(child, SectionBlock):
out.extend(child.get_file_lines(controller, target))
out.extend(target.header("Table of Contents", lev=target.SECTION))
out.extend(self.get_toc_lines(target, currfile=self.origin.file))
out.extend(self.get_toc_lines(controller, target, currfile=self.origin.file))
for child in self.children:
if isinstance(child, SectionBlock):
out.extend(child.get_file_lines(controller, target))
Expand Down Expand Up @@ -423,7 +423,7 @@ def get_link(self, target, currfile=None, label=""):
literalize=False
)

def get_tocfile_lines(self, target, n=1, currfile=""):
def get_tocfile_lines(self, controller, target, n=1, currfile=""):
"""
Return the markdown table of contents lines for the children in this
section. This is returned as a series of bullet points.
Expand All @@ -437,13 +437,13 @@ def get_tocfile_lines(self, target, n=1, currfile=""):
if subsects:
out.extend(target.bullet_list_start())
for child in subsects:
out.extend(target.indent_lines(child.get_tocfile_lines(target, currfile=currfile)))
out.extend(target.indent_lines(child.get_tocfile_lines(controller, target, currfile=currfile)))
out.extend(target.bullet_list_end())
out.extend(
target.indent_lines(
target.bullet_list(
flatten([
child.get_tocfile_lines(target, currfile=currfile)
child.get_tocfile_lines(controller, target, currfile=currfile)
for child in self.get_children_by_title(
["Constant","Function","Module","Function&Module"]
)
Expand All @@ -453,12 +453,12 @@ def get_tocfile_lines(self, target, n=1, currfile=""):
)
else:
for child in self.get_children_by_title("Subsection"):
out.extend(child.get_tocfile_lines(target, currfile=currfile))
out.extend(child.get_tocfile_lines(controller, target, currfile=currfile))
out.extend(
target.indent_lines(
target.bullet_list(
flatten([
child.get_tocfile_lines(target, currfile=currfile)
child.get_tocfile_lines(controller, target, currfile=currfile)
for child in self.get_children_by_title(
["Constant","Function","Module","Function&Module"]
)
Expand All @@ -468,7 +468,7 @@ def get_tocfile_lines(self, target, n=1, currfile=""):
)
return out

def get_toc_lines(self, target, n=1, currfile=""):
def get_toc_lines(self, controller, target, n=1, currfile=""):
"""
Return the markdown table of contents lines for the children in this
section. This is returned as a series of bullet points.
Expand All @@ -479,10 +479,10 @@ def get_toc_lines(self, target, n=1, currfile=""):
if subsects:
lines.extend(target.numbered_list_start())
for num, child in enumerate(subsects):
lines.extend(child.get_toc_lines(target, currfile=currfile, n=num+1))
lines.extend(child.get_toc_lines(controller, target, currfile=currfile, n=num+1))
lines.extend(target.numbered_list_end())
for child in self.get_children_by_title(["Constant","Function","Module","Function&Module"]):
lines.extend(child.get_toc_lines(target, currfile=currfile))
lines.extend(child.get_toc_lines(controller, target, currfile=currfile))
out = []
if self.subtitle:
item = self.get_link(target, currfile=currfile)
Expand Down Expand Up @@ -547,7 +547,7 @@ def get_link(self, target, currfile=None, label=""):
literalize=False
)

def get_tocfile_lines(self, target, n=1, currfile=""):
def get_tocfile_lines(self, controller, target, n=1, currfile=""):
"""
Return the markdown table of contents lines for the children in this
subsection. This is returned as a series of bullet points.
Expand All @@ -562,23 +562,23 @@ def get_tocfile_lines(self, target, n=1, currfile=""):
target.indent_lines(
target.bullet_list(
flatten([
child.get_tocfile_lines(target, currfile=currfile)
child.get_tocfile_lines(controller, target, currfile=currfile)
for child in items
])
)
)
)
return out

def get_toc_lines(self, target, n=1, currfile=""):
def get_toc_lines(self, controller, target, n=1, currfile=""):
"""
Return the markdown table of contents lines for the children in this
subsection. This is returned as a series of bullet points.
`indent` sets the level of indentation for the bullet points
"""
lines = []
for child in self.get_children_by_title(["Constant","Function","Module","Function&Module"]):
lines.extend(child.get_toc_lines(target, currfile=currfile))
lines.extend(child.get_toc_lines(controller, target, currfile=currfile))
out = []
if self.subtitle:
item = self.get_link(target, currfile=currfile)
Expand Down Expand Up @@ -693,24 +693,29 @@ def get_data(self):
d["children"] = list(filter(lambda x: x["name"] not in skip_titles and not x["name"].startswith("Example"), d["children"]))
return d

def get_tocfile_lines(self, target, n=1, currfile=""):
def get_synopsis(self, controller, target):
sub = self.parse_links(self.synopsis, controller, target)
out = "{}{}{}".format(
" – " if self.synopsis or self.syntags else "",
target.escape_entities(sub),
target.mouseover_tags(self.syntags),
)
return out

def get_tocfile_lines(self, controller, target, n=1, currfile=""):
out = [
"{}{}{}{}".format(
"{}{}".format(
self.get_link(target, currfile=currfile),
" – " if self.synopsis or self.syntags else "",
target.escape_entities(self.synopsis),
target.mouseover_tags(self.syntags),
self.get_synopsis(controller, target),
)
]
return out

def get_toc_lines(self, target, n=1, currfile=""):
def get_toc_lines(self, controller, target, n=1, currfile=""):
out = target.bullet_list_item(
"{}{}{}{}".format(
"{}{}".format(
self.get_link(target, currfile=currfile),
" – " if self.synopsis or self.syntags else "",
target.escape_entities(self.synopsis),
target.mouseover_tags(self.syntags),
self.get_synopsis(controller, target),
)
)
return out
Expand Down
14 changes: 5 additions & 9 deletions openscad_docsgen/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ def write_toc_file(self):
out.append("")

for fnum, fblock in enumerate(prifiles):
out.extend(fblock.get_tocfile_lines(self.opts.target, n=fnum+1, currfile=self.TOCFILE))
out.extend(fblock.get_tocfile_lines(self, self.opts.target, n=fnum+1, currfile=self.TOCFILE))

out = target.postprocess(out)
outfile = os.path.join(target.docs_dir, self.TOCFILE)
Expand Down Expand Up @@ -811,11 +811,9 @@ def write_topics_file(self):
for name, item in sorted_items:
out.extend(
target.bullet_list_item(
"{}{}{}{}".format(
"{}{}".format(
item.get_link(target, label=name, currfile=self.TOPICFILE),
" – " if item.synopsis or item.syntags else "",
target.escape_entities(item.synopsis),
target.mouseover_tags(item.syntags),
item.get_synopsis(self, target),
)
)
)
Expand Down Expand Up @@ -865,11 +863,9 @@ def write_index_file(self):
]))
for ltr in ltrs_found:
items = [
"{}{}{}{}".format(
"{}{}".format(
item.get_link(target, label=name, currfile=self.INDEXFILE),
" – " if item.synopsis or item.syntags else "",
target.escape_entities(item.synopsis),
target.mouseover_tags(item.syntags),
item.get_synopsis(self, target),
)
for name, item in index_by_letter[ltr]
]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from setuptools import setup

VERSION = "2.0.36"
VERSION = "2.0.37"


with open('README.rst') as f:
Expand Down

0 comments on commit 461c980

Please sign in to comment.