Skip to content

Instantly share code, notes, and snippets.

@andysylvester
Created June 6, 2022 01:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andysylvester/cbe239f6ab2fdd453a7251524349d78e to your computer and use it in GitHub Desktop.
Save andysylvester/cbe239f6ab2fdd453a7251524349d78e to your computer and use it in GitHub Desktop.
Demo of opmlPackage includes feature, also writes the outline to a file
//5/11/22; 4:59:24 PM by DW
//Read an OPML file that has includes.
//Pass it through opml.expandIncludes.
//Display the resulting outline, with the includes expanded.
const fs = require ("fs");
const opml = require ("opml");
fs.readFile ("includesALS.opml", function (err, opmltext) {
if (err) {
console.log (err.message);
}
else {
opml.parse (opmltext, function (err, theOutline) { //convert OPML text into a JavaScript structure
opml.expandIncludes (theOutline, function (theNewOutline) {
console.log (JSON.stringify (theNewOutline, undefined, 4));
console.log (opml.stringify (theNewOutline));
data = opml.stringify (theNewOutline);
fs.writeFile("newoutline.opml", data, (err) => {
if (err)
console.log(err);
else {
console.log("File written successfully\n");
console.log("The written has the following contents:");
console.log(fs.readFileSync("newoutline.opml", "utf8"));
}
});
});
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment