From a438e92c59a98f3da9c984d80757f5be418700a3 Mon Sep 17 00:00:00 2001 From: Lee Hanken Date: Mon, 2 May 2022 12:04:15 +0100 Subject: [PATCH] respect inline title flag when parsing apple dev docs --- index.js | 4 ++-- url_to_markdown_apple_dev_docs.js | 10 +++++++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index a55027a..f3dcb56 100755 --- a/index.js +++ b/index.js @@ -121,7 +121,7 @@ function read_url(url, res, inline_title, ignore_links) { } function read_apple_url(url, res, inline_title, ignore_links) { - //TODO: currently ignores the flags inline_title and 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 +130,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); + let markdown = apple_dev_parser.parse_dev_doc_json(json, inline_title); res.send(markdown); }); }) diff --git a/url_to_markdown_apple_dev_docs.js b/url_to_markdown_apple_dev_docs.js index 6b5e651..4ee767a 100755 --- a/url_to_markdown_apple_dev_docs.js +++ b/url_to_markdown_apple_dev_docs.js @@ -26,9 +26,17 @@ module.exports = { }, - parse_dev_doc_json: function (json) { + parse_dev_doc_json: function (json, inline_title = true) { let text = ""; + if (inline_title) { + if (typeof json.metadata !== 'undefined') { + if (typeof json.metadata.title !== 'undefined') { + text += "# "+json.metadata.title + "\n\n"; + } + } + } + if (typeof json.references !== 'undefined') { this.dev_references = json.references; }