salve-annos
Version:
A fork with support for documentation of Salve, a Javascript library which implements a validator able to validate an XML document on the basis of a subset of RelaxNG.
62 lines • 2.69 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.XMLLintValidator = void 0;
/**
* A schema validator that spawns xmllint to validate the schema.
*
* @author Louis-Dominique Dubeau
* @license MPL 2.0
* @copyright Mangalam Research Center for Buddhist Languages
*/
const child_process_1 = require("child_process");
const schema_validation_1 = require("../schema-validation");
class XMLLintValidator {
constructor(options) {
this.options = options;
}
validate(schemaURL) {
return __awaiter(this, void 0, void 0, function* () {
let schemaPath = schemaURL.toString();
if (schemaURL.protocol === "file:") {
schemaPath = schemaPath.replace(/^file:\/\//, "");
}
else {
throw new Error("URLs must use the file: protocol");
}
const err = yield new Promise(resolve => {
const child = (0, child_process_1.spawn)("xmllint", ["--relaxng", schemaPath, "/dev/null"], { stdio: ["ignore", "ignore", "pipe"] });
let buffer = "";
child.stderr.on("data", data => {
buffer += data;
});
child.on("close", () => {
resolve(buffer);
});
});
// Search for an actual schema error.
if (err.search(/Relax-NG parser error/) !== -1) {
let msg = "error in schema";
if (!this.options.verbose) {
msg += "; run with --verbose to see what the problem was";
}
else {
process.stderr.write(err);
}
throw new schema_validation_1.SchemaValidationError(msg);
}
return {};
});
}
}
exports.XMLLintValidator = XMLLintValidator;
(0, schema_validation_1.registerValidator)("xmllint", XMLLintValidator);
//# sourceMappingURL=xmllint.js.map