respect inline title flag when parsing apple dev docs

main
Lee Hanken 2022-05-02 12:04:15 +01:00
parent 0cbf5ad99c
commit a438e92c59
2 changed files with 11 additions and 3 deletions

View File

@ -121,7 +121,7 @@ function read_url(url, res, inline_title, ignore_links) {
} }
function read_apple_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); json_url = apple_dev_parser.dev_doc_url(url);
https.get(json_url,(apple_res) => { https.get(json_url,(apple_res) => {
let body = ""; let body = "";
@ -130,7 +130,7 @@ function read_apple_url(url, res, inline_title, ignore_links) {
}); });
apple_res.on("end", () => { apple_res.on("end", () => {
let json = JSON.parse(body); 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); res.send(markdown);
}); });
}) })

View File

@ -26,9 +26,17 @@ module.exports = {
}, },
parse_dev_doc_json: function (json) { parse_dev_doc_json: function (json, inline_title = true) {
let text = ""; 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') { if (typeof json.references !== 'undefined') {
this.dev_references = json.references; this.dev_references = json.references;
} }