wed
Version:
Wed is a schema-aware editor for XML documents.
88 lines • 3.38 kB
JavaScript
define(["require", "exports", "wed", "./doc-pattern", "./metadata-versioned-reader"], function (require, exports, wed_1, doc_pattern_1, metadata_versioned_reader_1) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Execution context for the [[DocPattern]] objects we evaluate with
* [[MetadataV2]].
*/
class MetadataContext {
/**
* @param name The value to return when we interpolate the symbol "name".
*/
constructor(name) {
this.name = name;
}
resolveName(name) {
if (name === "name") {
return this.name;
}
throw new Error(`cannot resolve: ${name}`);
}
}
// tslint:disable-next-line:completed-docs
class MetadataV2 extends metadata_versioned_reader_1.MetadataBase {
constructor(metadata) {
super("2", metadata);
if (metadata.namespaces === undefined) {
throw new Error("namespaces are not optional in version 2");
}
// The parent class already does this check but we need it to get TS to know
// what specific type metadata.inline is.
if (metadata.version !== "2") {
throw new Error("need version 2");
}
this.inline = metadata.inline;
if (this.inline !== undefined && this.inline.method !== "name") {
throw new Error("only the 'name' method is supported for inlines");
}
this.dochtml = metadata.dochtml;
if (this.dochtml !== undefined) {
if (this.dochtml.method !== "simple-pattern") {
throw new Error("only the 'simple-pattern' method is supported for dochtml");
}
this.docPattern = doc_pattern_1.compile(this.dochtml.pattern);
}
}
isInline(node) {
if (this.inline === undefined) {
return false;
}
// We need to normalize the name to fit the names we have below.
const originalName = wed_1.util.getOriginalName(node);
const parts = originalName.split(":");
if (parts.length === 1) {
parts[1] = parts[0];
parts[0] = "tei";
}
const name = parts.join(":");
const result = this.inline.rules[name];
if (result === undefined) {
return false;
}
return result;
}
documentationLinkFor(name) {
const docPattern = this.docPattern;
if (docPattern === undefined) {
return undefined;
}
const unresolved = this.unresolveName(name);
if (unresolved === undefined) {
return undefined;
}
return docPattern.execute(new MetadataContext(unresolved));
}
}
/**
* A reader that reads version 2 of the metadata format.
*/
class MetadataReaderV2 extends metadata_versioned_reader_1.MetadataReaderBase {
constructor() {
super(MetadataV2);
}
}
MetadataReaderV2.version = "2";
exports.MetadataReaderV2 = MetadataReaderV2;
});
// LocalWords: MPL inlines tei
//# sourceMappingURL=metadata-reader-v2.js.map