UNPKG

@makakwastaken/ts-edifact

Version:
61 lines 2.33 kB
/** * @author Roman Vottner * @copyright 2021 Roman Vottner * @license Apache-2.0 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { DomHandler } from 'htmlparser2'; /** * Customization of the `DomHandler` class to allow for extending the behavior * performed on processing text and "open tags by the dom handler. * * This implementation is necessary due to a version update of htmlparser2 * and/or domhandler which now manages elements passed to the `opentag` method * by putting such on an `openTag` stack and removing these on processing * `onclosetag` calls. By replacing the function calls as previously done * DomHandler isn't able to manage this tag stack properly and thus invalid * operations are attempted on `undefined` references. * * This implementation overrides `ontext` and `onopentag` methods of DomHandler * and defines two replacement functions (`onText` and`onOpenTag`), which need * to be implemented by the user class. These replacement functions are invoked * after the parent methods got called. */ export class UNECEDomHandler extends DomHandler { /** * Do not use this method. Please use {@link onText} instead. * * This method just ensures that the parent method is executed before an * overriden version of {@link onText} * * @internal */ ontext(data) { super.ontext(data); this.onText(data); } /** * Do not use this method. Please use {@link onOpenTag} instead. * * This method just ensures that the parent method is executed before an * overriden version of {@link onOpenTag} * * @internal */ onopentag(name, attribs) { super.onopentag(name, attribs); this.onOpenTag(name, attribs); } } //# sourceMappingURL=uneceDomHandler.js.map