Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with MKDocs: #26

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
2 changes: 1 addition & 1 deletion openscad_docsgen/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def processFiles(opts):


def main():
target_profiles = ["githubwiki", "stdwiki"]
target_profiles = ["githubwiki", "stdwiki", "mkdocs"]

parser = argparse.ArgumentParser(prog='openscad-docsgen')
parser.add_argument('-D', '--docs-dir', default="docs",
Expand Down
18 changes: 7 additions & 11 deletions openscad_docsgen/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,6 @@ def __init__(self, title, subtitle, body, origin, parent=None):

def get_file_lines(self, controller, target):
sub = self.parse_links(self.subtitle, controller, target)
sub = target.escape_entities(sub)
out = target.block_header(self.title, sub)
out.extend(target.bullet_list(self.body))
return out
Expand All @@ -259,7 +258,6 @@ def __init__(self, title, subtitle, body, origin, parent=None):

def get_file_lines(self, controller, target):
sub = self.parse_links(self.subtitle, controller, target)
sub = target.escape_entities(sub)
out = target.block_header(self.title, sub)
out.extend(target.numbered_list(self.body))
return out
Expand Down Expand Up @@ -464,15 +462,13 @@ def get_tocfile_lines(self, controller, target, n=1, currfile=""):
for child in self.get_children_by_title("Subsection"):
out.extend(child.get_tocfile_lines(controller, target, currfile=currfile))
out.extend(
target.indent_lines(
target.bullet_list(
flatten([
child.get_tocfile_lines(controller, target, currfile=currfile)
for child in self.get_children_by_title(
["Constant","Function","Module","Function&Module"]
)
])
)
target.bullet_list(
flatten([
child.get_tocfile_lines(controller, target, currfile=currfile)
for child in self.get_children_by_title(
["Constant","Function","Module","Function&Module"]
)
])
)
)
return out
Expand Down
28 changes: 10 additions & 18 deletions openscad_docsgen/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ def __init__(self, file, line):

@property
def md_file(self):
if self._md_in_links:
return self.file+".md"
return self.file


Expand All @@ -46,13 +44,6 @@ def __init__(self, opts):
self.items_by_name = {}
self.syntags_data = {}

sfx = self.target.get_suffix()
self.TOCFILE = "TOC" + sfx
self.TOPICFILE = "Topics" + sfx
self.INDEXFILE = "AlphaIndex" + sfx
self.CHEATFILE = "CheatSheet" + sfx
self.SIDEBARFILE = "_Sidebar" + sfx

self._reset_header_defs()

def _reset_header_defs(self):
Expand Down Expand Up @@ -746,9 +737,10 @@ def write_toc_file(self):
if fblock.group != group:
continue
file = fblock.subtitle
fullfilepath = fblock.origin.md_file
anch = target.header_link("{}. {}".format(fnum+1, file))
link = target.get_link(file, anchor=anch, literalize=False)
filelink = target.get_link("docs", file=file, literalize=False)
filelink = target.get_link("docs", file=fullfilepath, literalize=False)
tags = {tag: text for tag, text, origin in fblock.footnotes}
marks = target.mouseover_tags(tags, "#file-footnotes")
out.extend(target.bullet_list_item("{} ({}){}".format(link, filelink, marks)))
Expand All @@ -773,10 +765,10 @@ def write_toc_file(self):
out.append("")

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

out = target.postprocess(out)
outfile = os.path.join(target.docs_dir, self.TOCFILE)
outfile = os.path.join(target.docs_dir, self.target.TOCFILE)
if not self.quiet:
print("Writing {}...".format(outfile))
with open(outfile, "w") as f:
Expand Down Expand Up @@ -836,13 +828,13 @@ def write_topics_file(self):
for name, item in sorted_items:
out.extend(
target.bullet_list_item(
item.get_index_line(self, target, self.TOPICFILE)
item.get_index_line(self, target, self.target.TOPICFILE)
)
)
out.extend(target.bullet_list_end())

out = target.postprocess(out)
outfile = os.path.join(target.docs_dir, self.TOPICFILE)
outfile = os.path.join(target.docs_dir, self.target.TOPICFILE)
if not self.quiet:
print("Writing {}...".format(outfile))
with open(outfile, "w") as f:
Expand Down Expand Up @@ -885,14 +877,14 @@ def write_index_file(self):
]))
for ltr in ltrs_found:
items = [
item.get_index_line(self, target, self.INDEXFILE)
item.get_index_line(self, target, self.target.INDEXFILE)
for name, item in index_by_letter[ltr]
]
out.extend(target.header(ltr, lev=target.SUBSECTION))
out.extend(target.bullet_list(items))

out = target.postprocess(out)
outfile = os.path.join(target.docs_dir, self.INDEXFILE)
outfile = os.path.join(target.docs_dir, self.target.INDEXFILE)
if not self.quiet:
print("Writing {}...".format(outfile))
with open(outfile, "w") as f:
Expand All @@ -913,7 +905,7 @@ def write_cheatsheet_file(self):
out.extend(file_block.get_cheatsheet_lines(self, self.opts.target))

out = target.postprocess(out)
outfile = os.path.join(target.docs_dir, self.CHEATFILE)
outfile = os.path.join(target.docs_dir, self.target.CHEATFILE)
if not self.quiet:
print("Writing {}...".format(outfile))
with open(outfile, "w") as f:
Expand Down Expand Up @@ -981,7 +973,7 @@ def write_sidebar_file(self):
out.extend(self.opts.sidebar_footer)

out = target.postprocess(out)
outfile = os.path.join(target.docs_dir, self.SIDEBARFILE)
outfile = os.path.join(target.docs_dir, self.target.SIDEBARFILE)
if not self.quiet:
print("Writing {}...".format(outfile))
with open(outfile, "w") as f:
Expand Down
2 changes: 2 additions & 0 deletions openscad_docsgen/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

from .target_githubwiki import Target_GitHubWiki
from .target_wiki import Target_Wiki
from .target_mkdocs import Target_MKDocs


default_target = "githubwiki"
target_classes = {
"githubwiki": Target_GitHubWiki,
"wiki": Target_Wiki,
"mkdocs": Target_MKDocs,
}


Expand Down
39 changes: 39 additions & 0 deletions openscad_docsgen/target_mkdocs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
from __future__ import print_function

import re

from .target_wiki import Target_Wiki


class Target_MKDocs(Target_Wiki):

@property
def TOCFILE(self):
return "index" + self.get_suffix()

@property
def TOPICFILE(self):
return "topics" + self.get_suffix()

@property
def INDEXFILE(self):
return "alphaindex" + self.get_suffix()

@property
def CHEATFILE(self):
return "cheatsheet" + self.get_suffix()

@property
def SIDEBARFILE(self):
return "_sidebar" + self.get_suffix()

def get_link(self, label, anchor="", file="", literalize=True):
if literalize:
label = "`{0}`".format(label)
else:
label = self.escape_entities(label)
if file:
file += '.md'
if anchor:
anchor = "#" + anchor
return "[{0}]({1}{2})".format(label, file, anchor)
20 changes: 20 additions & 0 deletions openscad_docsgen/target_wiki.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,26 @@ def __init__(self, project_name=None, docs_dir="docs"):
def get_suffix(self):
return ".md"

@property
def TOCFILE(self):
return "TOC" + self.get_suffix()

@property
def TOPICFILE(self):
return "Topics" + self.get_suffix()

@property
def INDEXFILE(self):
return "AlphaIndex" + self.get_suffix()

@property
def CHEATFILE(self):
return "CheatSheet" + self.get_suffix()

@property
def SIDEBARFILE(self):
return "_Sidebar" + self.get_suffix()

def postprocess(self, lines):
return lines

Expand Down