From 801f7525c36913f8ae2e9a317b5357ecc7a1cb18 Mon Sep 17 00:00:00 2001 From: Lee Hanken Date: Mon, 2 May 2022 12:35:23 +0100 Subject: [PATCH] respect links flag in apple dev docs --- index.js | 3 +-- url_to_markdown_apple_dev_docs.js | 22 +++++++++++++--------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/index.js b/index.js index f3dcb56..a8c8af5 100755 --- a/index.js +++ b/index.js @@ -121,7 +121,6 @@ function read_url(url, res, inline_title, ignore_links) { } function read_apple_url(url, res, inline_title, ignore_links) { - //TODO: currently ignores the flag ignore_links json_url = apple_dev_parser.dev_doc_url(url); https.get(json_url,(apple_res) => { let body = ""; @@ -130,7 +129,7 @@ function read_apple_url(url, res, inline_title, ignore_links) { }); apple_res.on("end", () => { let json = JSON.parse(body); - let markdown = apple_dev_parser.parse_dev_doc_json(json, inline_title); + let markdown = apple_dev_parser.parse_dev_doc_json(json, inline_title, ignore_links); res.send(markdown); }); }) diff --git a/url_to_markdown_apple_dev_docs.js b/url_to_markdown_apple_dev_docs.js index eadd729..0467d3a 100755 --- a/url_to_markdown_apple_dev_docs.js +++ b/url_to_markdown_apple_dev_docs.js @@ -26,7 +26,7 @@ module.exports = { }, - parse_dev_doc_json: function (json, inline_title = true) { + parse_dev_doc_json: function (json, inline_title = true, ignore_links = false) { let text = ""; if (inline_title) { @@ -41,14 +41,14 @@ module.exports = { this.dev_references = json.references; } if (typeof json.primaryContentSections !== 'undefined') { - text += this.process_sections(json.primaryContentSections); + text += this.process_sections(json.primaryContentSections, ignore_links); } else if (typeof json.sections !== 'undefined') { - text += this.process_sections(json.sections); + text += this.process_sections(json.sections, ignore_links); } return text; }, - process_sections: function (sections) { + process_sections: function (sections, ignore_links) { let text = ""; sections.forEach((section, i) => { @@ -83,7 +83,7 @@ module.exports = { text += "\n\n"; } } else if (section.kind == 'content') { - text += this.process_content_section(section); + text += this.process_content_section(section, ignore_links); } } @@ -111,7 +111,7 @@ module.exports = { return text; }, - process_content_section(section) { + process_content_section(section, ignore_links) { text = ""; section.content.forEach((content, i) => { @@ -124,7 +124,11 @@ module.exports = { if (inline.type == "text") { inline_text += inline.text; } else if (inline.type == "link") { - inline_text += "["+inline.title+"]("+inline.destination+")"; + if (ignore_links) { + inline_text += inline.title; + } else { + inline_text += "["+inline.title+"]("+inline.destination+")"; + } } else if (inline.type == "reference") { if (typeof inline.identifier !== 'undefined') { if (typeof this.dev_references[inline.identifier] !== 'undefined') { @@ -148,7 +152,7 @@ module.exports = { } else if (content.type == 'unorderedList') { if (typeof content.items !== 'undefined') { content.items.forEach((list_item, i) => { - text += "* " + this.process_content_section(list_item); + text += "* " + this.process_content_section(list_item, ignore_links); }); } } else if (content.type == 'orderedList') { @@ -156,7 +160,7 @@ module.exports = { n=0; content.items.forEach((list_item, i) => { n = n + 1; - text += n + " " + this.process_content_section(list_item); + text += n + " " + this.process_content_section(list_item, ignore_links); }); } } else if (content.type == 'heading') {