def generate_markdown() -> None: logging.getLogger('table_schema_to_markdown').setLevel(logging.WARNING) logging.info("Conversion des schémas en fichier texte Markdown") for schema_path in get_all_schema_path(): markdown_path = schema_path.replace(SCHEMAS_DIR, MARKDOWN_DIR).replace( '.json', '.md') os.makedirs(os.path.dirname(markdown_path), exist_ok=True) with open(markdown_path, 'w', encoding='utf8') as out: table_schema_to_markdown.convert_source(schema_path, out)
def test_convert_source(self): files = ["repertoire"] for test in files: source_filepath, expected_filepath = map( filepath, [test + ".json", "expected_" + test + ".md"]) buff = io.StringIO() convert_source(source_filepath, buff) got = buff.getvalue().split("\n") buff.close() with open(expected_filepath, encoding="utf-8") as f: expected = f.read().split("\n") self.assertEqual(expected, got)
def extract(self): with open(self.filepath("documentation.md"), "w") as out: convert_source(self.filepath(self.SCHEMA_FILENAME), out) files = { self.SCHEMA_FILENAME: self.filepath_or_none(self.SCHEMA_FILENAME), "README.md": self.filepath_or_none("README.md"), "SEE_ALSO.md": self.filepath_or_none("SEE_ALSO.md"), "CONTEXT.md": self.filepath_or_none("CONTEXT.md"), "documentation.md": self.filepath("documentation.md"), } if self.is_latest_version(): files[self.CHANGELOG_FILENAME] = self.filepath_or_none( self.CHANGELOG_FILENAME) self.move_files(files)
def extract(self): links = [] documentationfiles = {} assetfiles = {} assetnewnames = {} if(os.path.isdir(self.filepath("documentation/"))): if(os.path.isdir(self.filepath("documentation/assets/"))): for filename in os.listdir(self.filepath("documentation/assets/")): assetnewnames = {**assetnewnames, **{filename: str(uuid.uuid1())}} assetfiles = {**assetfiles, **{filename: self.filepath("documentation/assets/"+filename)}} for filename in os.listdir(self.filepath("documentation/")): if filename.endswith(".md"): links.append(os.path.splitext(filename)[0].lower()) documentationfiles = {**documentationfiles, **{filename: self.filepath("documentation/")+filename}} with open(self.filepath("documentation.md"), "w") as out: convert_source(self.filepath(self.SCHEMA_FILENAME), out, 'page',links) files = { self.SCHEMA_FILENAME: self.filepath_or_none(self.SCHEMA_FILENAME), "README.md": self.filepath_or_none("README.md"), "SEE_ALSO.md": self.filepath_or_none("SEE_ALSO.md"), "CONTEXT.md": self.filepath_or_none("CONTEXT.md"), "documentation.md": self.filepath("documentation.md"), } files = {**files, **documentationfiles} if self.is_latest_version(): files[self.CHANGELOG_FILENAME] = self.filepath_or_none( self.CHANGELOG_FILENAME ) self.move_files(files,assetnewnames) self.move_assets(assetfiles,assetnewnames)
from table_schema_to_markdown import convert_source # Generate a Markdown documentation from a JSON file table_schema = '../schema.json' with open('../documentation/schema-table.md', 'w') as out: convert_source(table_schema, out) # Generate Markdown documentation in a string import io with io.StringIO() as buff: convert_source(table_schema, buff) documentation = buff.getvalue()
from table_schema_to_markdown import convert_source # Generate a Markdown documentation from a JSON file table_schema = '../schema.json' with open('../documentation/schema-page.md', 'w') as out: convert_source(table_schema, out, style='page') # Generate Markdown documentation in a string import io with io.StringIO() as buff: convert_source(table_schema, buff, style='page') documentation = buff.getvalue()