From 6736f84d54211c20947365e928ae95825bdb10bf Mon Sep 17 00:00:00 2001 From: Nikita Khromov Date: Fri, 2 Aug 2024 21:26:44 +0700 Subject: [PATCH] Fixed jsdoc md generation --- scripts/sdkjs_common/jsdoc/generate_docs_json.py | 15 +++++++++++---- scripts/sdkjs_common/jsdoc/generate_docs_md.py | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/scripts/sdkjs_common/jsdoc/generate_docs_json.py b/scripts/sdkjs_common/jsdoc/generate_docs_json.py index 653653a..b4710bb 100644 --- a/scripts/sdkjs_common/jsdoc/generate_docs_json.py +++ b/scripts/sdkjs_common/jsdoc/generate_docs_json.py @@ -19,7 +19,7 @@ editors_maps = { "forms": "CFE" } -def generate(output_dir): +def generate(output_dir, md=False): missing_examples_file = f'{output_dir}/missing_examples.txt' if not os.path.exists(output_dir): @@ -51,9 +51,12 @@ def generate(output_dir): if 'see' in doclet: if doclet['see'] is not None: if editor_name == 'forms': - file_path = '../../../../' + doclet['see'][0].replace('{Editor}', 'Word') + doclet['see'][0] = doclet['see'][0].replace('{Editor}', 'Word') else: - file_path = '../../../../' + doclet['see'][0].replace('{Editor}', editor_name.title()) + doclet['see'][0] = doclet['see'][0].replace('{Editor}', editor_name.title()) + + file_path = '../../../../' + doclet['see'][0] + if os.path.exists(file_path): with open(file_path, 'r', encoding='utf-8') as see_file: example_content = see_file.read() @@ -68,7 +71,11 @@ def generate(output_dir): code_content = example_content # Format content for doclet['example'] - doclet['example'] = remove_js_comments(comment) + "```js\n" + remove_builder_lines(code_content) + "\n```" + doclet['example'] = remove_js_comments(comment) + "```js\n" + code_content + "\n```" + + if md == False: + doclet['description'] = doclet['description'] + f'\n\n## Try it\n\n ```js document-builder={{"documentType": "{editor_name.title()}"}}\n{code_content}\n```' + else: # Record missing examples in missing_examples.txt with open(missing_examples_file, 'a', encoding='utf-8') as missing_file: diff --git a/scripts/sdkjs_common/jsdoc/generate_docs_md.py b/scripts/sdkjs_common/jsdoc/generate_docs_md.py index f734572..ea4dc39 100644 --- a/scripts/sdkjs_common/jsdoc/generate_docs_md.py +++ b/scripts/sdkjs_common/jsdoc/generate_docs_md.py @@ -241,7 +241,7 @@ def process_doclets(data, output_dir): def generate(output_dir): print('Generating Markdown documentation...') - generate_docs_json.generate(output_dir + 'tmp_json') + generate_docs_json.generate(output_dir + 'tmp_json', md=True) for editor_name in editors: input_file = os.path.join(output_dir + 'tmp_json', editor_name + ".json") os.makedirs(output_dir + f'/{editor_name.title()}', exist_ok=True)