From 6be7fee1ad7480b8ce837c073e037c40637a2f30 Mon Sep 17 00:00:00 2001 From: Lee Hanken Date: Mon, 2 May 2022 02:32:36 +0100 Subject: [PATCH] handle lists and references in apple dev docs --- url_to_markdown_apple_dev_docs.js | 75 ++++++++++++++++++++----------- 1 file changed, 50 insertions(+), 25 deletions(-) diff --git a/url_to_markdown_apple_dev_docs.js b/url_to_markdown_apple_dev_docs.js index 245c995..7c45528 100755 --- a/url_to_markdown_apple_dev_docs.js +++ b/url_to_markdown_apple_dev_docs.js @@ -64,30 +64,7 @@ module.exports = { text += "\n\n"; } } else if (section.kind == 'content') { - section.content.forEach((content, i) => { - if (typeof content.type != 'undefined') { - if (content.type == 'paragraph') { - if (typeof content.inlineContent !== 'undefined') { - inline_text = ""; - content.inlineContent.forEach((inline, i) => { - if (typeof inline.type !== 'undefined') { - if (inline.type == "text") { - inline_text += inline.text; - } else if (inline.type == "link") { - inline_text += "["+inline.title+"]("+inline.destination+")"; - } - } - }); - text += inline_text + "\n\n"; - } - } else if (content.type == 'codeListing') { - code_text = "\n```\n"; - code_text += content.code.join("\n"); - code_text += "\n```\n\n"; - text += code_text; - } - } - }); + text += this.process_content_section(section); } } @@ -114,6 +91,54 @@ module.exports = { return text; - } + }, + process_content_section(section) { + text = ""; + section.content.forEach((content, i) => { + + if (typeof content.type != 'undefined') { + if (content.type == 'paragraph') { + if (typeof content.inlineContent !== 'undefined') { + inline_text = ""; + content.inlineContent.forEach((inline, i) => { + if (typeof inline.type !== 'undefined') { + if (inline.type == "text") { + inline_text += inline.text; + } else if (inline.type == "link") { + inline_text += "["+inline.title+"]("+inline.destination+")"; + } else if (inline.type == "reference") { + let ref = inline.identifier.split('/'); + let name = ref[ref.length-1]; + let parts = name.split('-'); + inline_text += parts[parts.length-1]; + } + } + }); + text += inline_text + "\n\n"; + } + } else if (content.type == 'codeListing') { + code_text = "\n```\n"; + code_text += content.code.join("\n"); + code_text += "\n```\n\n"; + text += code_text; + } else if (content.type == 'unorderedList') { + if (typeof content.items !== 'undefined') { + content.items.forEach((list_item, i) => { + text += "* " + this.process_content_section(list_item); + }); + } + } else if (content.type == 'orderedList') { + if (typeof content.items !== 'undefined') { + n=0; + content.items.forEach((list_item, i) => { + n = n + 1; + text += n + " " + this.process_content_section(list_item); + }); + } + } + } + }); + return text; + } }