Comparing version 0.4.3 to 0.4.4
@@ -1,3 +0,28 @@ | ||
exports.parse = parse; | ||
var myProductName = "opmltojs"; myVersion = "0.4.4"; | ||
/* The MIT License (MIT) | ||
Copyright (c) 2014-2017 Dave Winer | ||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. | ||
*/ | ||
exports.parse = parse; | ||
exports.opmlify = opmlify; //8/6/17 by DW | ||
const xml2js = require ("xml2js"); | ||
@@ -63,1 +88,42 @@ const utils = require ("daveutils"); | ||
} | ||
function opmlify (theOutline, fname) { //returns the opmltext for the outline -- 8/6/17 by DW | ||
var opmltext = "", indentlevel = 0; | ||
function add (s) { | ||
opmltext += utils.filledString ("\t", indentlevel) + s + "\n"; | ||
} | ||
function addSubs (subs) { | ||
if (subs !== undefined) { | ||
for (var i = 0; i < subs.length; i++) { | ||
let sub = subs [i], atts = ""; | ||
for (var x in sub) { | ||
if (x != "subs") { | ||
atts += " " + x + "=\"" + utils.encodeXml (sub [x]) + "\""; | ||
} | ||
} | ||
if (sub.subs === undefined) { | ||
add ("<outline" + atts + " />"); | ||
} | ||
else { | ||
add ("<outline" + atts + " >"); indentlevel++; | ||
addSubs (sub.subs); | ||
add ("</outline>"); indentlevel--; | ||
} | ||
} | ||
} | ||
} | ||
add ("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); | ||
add ("<opml version=\"2.0\">"); indentlevel++; | ||
//do head section | ||
add ("<head>"); indentlevel++; | ||
for (var x in theOutline.opml.head) { | ||
add ("<" + x + ">" + theOutline.opml.head [x] + "</" + x + ">"); | ||
} | ||
add ("</head>"); indentlevel--; | ||
//do body section | ||
add ("<body>"); indentlevel++; | ||
addSubs (theOutline.opml.body.subs); | ||
add ("</body>"); indentlevel--; | ||
add ("</opml>"); indentlevel--; | ||
console.log ("opmlify: opmltext == \n" + opmltext); | ||
return (opmltext); | ||
} |
@@ -6,3 +6,3 @@ { | ||
"license": "MIT", | ||
"version": "0.4.3", | ||
"version": "0.4.4", | ||
"main": "opmltojs.js", | ||
@@ -9,0 +9,0 @@ "repository": { |
@@ -17,1 +17,7 @@ ## opmlToJs package | ||
### Updates | ||
##### v0.4.4 -- 8/4/6 by DW | ||
Added new exported function opmlify. It turns an outline structure returned by opmltojs.parse into the equivalent OPML text. It's the other side of parsing, serializing. | ||
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6409
120
23