rdfa-streaming-parser 2.0.1 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,11 +15,13 @@ export interface IActiveTag {
15
15
  explicitNewSubject?: boolean;
16
16
  predicates?: RDF.NamedNode[];
17
17
  object?: RDF.NamedNode | RDF.BlankNode | boolean;
18
- text?: string[];
18
+ textWithTags?: string[];
19
+ textWithoutTags?: string[];
19
20
  vocab?: string;
20
21
  language?: string;
21
22
  datatype?: RDF.NamedNode;
22
23
  collectChildTags?: boolean;
24
+ collectChildTagsForCurrentTag?: boolean;
23
25
  collectedPatternTag?: IRdfaPattern;
24
26
  interpretObjectAsTime?: boolean;
25
27
  incompleteTriples?: {
@@ -1 +1 @@
1
- {"version":3,"file":"IActiveTag.js","sourceRoot":"","sources":["IActiveTag.ts"],"names":[],"mappings":"","sourcesContent":["import * as RDF from \"@rdfjs/types\";\nimport {IRdfaPattern} from \"./IRdfaPattern\";\n\n/**\n * Data holder for the RDFa state in XML tags.\n */\nexport interface IActiveTag {\n name: string;\n prefixesAll: {[prefix: string]: string};\n prefixesCustom: {[prefix: string]: string};\n subject?: RDF.NamedNode | RDF.BlankNode | boolean;\n explicitNewSubject?: boolean;\n predicates?: RDF.NamedNode[];\n object?: RDF.NamedNode | RDF.BlankNode | boolean;\n text?: string[];\n vocab?: string;\n language?: string;\n datatype?: RDF.NamedNode;\n collectChildTags?: boolean;\n collectedPatternTag?: IRdfaPattern;\n interpretObjectAsTime?: boolean;\n incompleteTriples?: { predicate: RDF.Quad_Predicate, reverse: boolean, list?: boolean }[];\n inlist: boolean;\n listMapping: {[predicate: string]: (RDF.Term|boolean)[]};\n listMappingLocal: {[predicate: string]: (RDF.Term|boolean)[]};\n skipElement: boolean;\n localBaseIRI?: RDF.NamedNode;\n}\n"]}
1
+ {"version":3,"file":"IActiveTag.js","sourceRoot":"","sources":["IActiveTag.ts"],"names":[],"mappings":"","sourcesContent":["import * as RDF from \"@rdfjs/types\";\nimport {IRdfaPattern} from \"./IRdfaPattern\";\n\n/**\n * Data holder for the RDFa state in XML tags.\n */\nexport interface IActiveTag {\n name: string;\n prefixesAll: {[prefix: string]: string};\n prefixesCustom: {[prefix: string]: string};\n subject?: RDF.NamedNode | RDF.BlankNode | boolean;\n explicitNewSubject?: boolean;\n predicates?: RDF.NamedNode[];\n object?: RDF.NamedNode | RDF.BlankNode | boolean;\n textWithTags?: string[];\n textWithoutTags?: string[];\n vocab?: string;\n language?: string;\n datatype?: RDF.NamedNode;\n collectChildTags?: boolean;\n collectChildTagsForCurrentTag?: boolean;\n collectedPatternTag?: IRdfaPattern;\n interpretObjectAsTime?: boolean;\n incompleteTriples?: { predicate: RDF.Quad_Predicate, reverse: boolean, list?: boolean }[];\n inlist: boolean;\n listMapping: {[predicate: string]: (RDF.Term|boolean)[]};\n listMappingLocal: {[predicate: string]: (RDF.Term|boolean)[]};\n skipElement: boolean;\n localBaseIRI?: RDF.NamedNode;\n}\n"]}
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  import EventEmitter = NodeJS.EventEmitter;
3
2
  import { Parser as HtmlParser } from "htmlparser2";
4
3
  import * as RDF from "@rdfjs/types";
package/lib/RdfaParser.js CHANGED
@@ -72,6 +72,7 @@ class RdfaParser extends readable_stream_1.Transform {
72
72
  // Create a new active tag and inherit language scope and baseIRI from parent
73
73
  const activeTag = {
74
74
  collectChildTags: parentTag.collectChildTags,
75
+ collectChildTagsForCurrentTag: parentTag.collectChildTagsForCurrentTag,
75
76
  incompleteTriples: [],
76
77
  inlist: 'inlist' in attributes,
77
78
  listMapping: [],
@@ -95,7 +96,7 @@ class RdfaParser extends readable_stream_1.Transform {
95
96
  }
96
97
  }
97
98
  const attributesSerialized = Object.keys(attributes).map((key) => `${key}="${attributes[key]}"`).join(' ');
98
- activeTag.text = [`<${name}${attributesSerialized ? ' ' + attributesSerialized : ''}>`];
99
+ activeTag.textWithTags = [`<${name}${attributesSerialized ? ' ' + attributesSerialized : ''}>`];
99
100
  if (this.features.skipHandlingXmlLiteralChildren) {
100
101
  return;
101
102
  }
@@ -397,6 +398,7 @@ class RdfaParser extends readable_stream_1.Transform {
397
398
  && (activeTag.datatype.value === Util_1.Util.RDF + 'XMLLiteral'
398
399
  || (this.features.htmlDatatype && activeTag.datatype.value === Util_1.Util.RDF + 'HTML'))) {
399
400
  activeTag.collectChildTags = true;
401
+ activeTag.collectChildTagsForCurrentTag = true;
400
402
  }
401
403
  }
402
404
  else {
@@ -416,6 +418,12 @@ class RdfaParser extends readable_stream_1.Transform {
416
418
  localObjectResource = typedResource;
417
419
  }
418
420
  }
421
+ // If we're in a parent tag that collects child tags,
422
+ // and we find a tag that does NOT preserve tags,
423
+ // we mark this tag (and children) to not preserve it.
424
+ if (!('datatype' in attributes) || attributes.datatype === '') {
425
+ activeTag.collectChildTagsForCurrentTag = false;
426
+ }
419
427
  if ('content' in attributes) {
420
428
  // Emit triples based on content attribute has preference over text content
421
429
  const object = this.util.createLiteral(attributes.content, activeTag);
@@ -513,10 +521,14 @@ class RdfaParser extends readable_stream_1.Transform {
513
521
  return;
514
522
  }
515
523
  // Save the text inside the active tag
516
- if (!activeTag.text) {
517
- activeTag.text = [];
524
+ if (!activeTag.textWithTags) {
525
+ activeTag.textWithTags = [];
526
+ }
527
+ if (!activeTag.textWithoutTags) {
528
+ activeTag.textWithoutTags = [];
518
529
  }
519
- activeTag.text.push(data);
530
+ activeTag.textWithTags.push(data);
531
+ activeTag.textWithoutTags.push(data);
520
532
  }
521
533
  onTagClose() {
522
534
  // Get the active tag
@@ -546,10 +558,16 @@ class RdfaParser extends readable_stream_1.Transform {
546
558
  // Emit all triples that were determined in the active tag
547
559
  if (activeTag.predicates) {
548
560
  const subject = this.util.getResourceOrBaseIri(activeTag.subject, activeTag);
549
- let textSegments = activeTag.text || [];
550
- if (activeTag.collectChildTags && parentTag.collectChildTags) {
551
- // If we are inside an XMLLiteral child that also has RDFa content, ignore the tag name that was collected.
552
- textSegments = textSegments.slice(1);
561
+ let textSegments;
562
+ if (!activeTag.collectChildTagsForCurrentTag) {
563
+ textSegments = activeTag.textWithoutTags || [];
564
+ }
565
+ else {
566
+ textSegments = activeTag.textWithTags || [];
567
+ if (activeTag.collectChildTags && parentTag.collectChildTags) {
568
+ // If we are inside an XMLLiteral child that also has RDFa content, ignore the tag name that was collected.
569
+ textSegments = textSegments.slice(1);
570
+ }
553
571
  }
554
572
  const object = this.util.createLiteral(textSegments.join(''), activeTag);
555
573
  if (activeTag.inlist) {
@@ -564,7 +582,8 @@ class RdfaParser extends readable_stream_1.Transform {
564
582
  }
565
583
  // Reset text, unless the parent is also collecting text
566
584
  if (!parentTag.predicates) {
567
- activeTag.text = null;
585
+ activeTag.textWithoutTags = null;
586
+ activeTag.textWithTags = null;
568
587
  }
569
588
  }
570
589
  // 14: Handle local list mapping
@@ -594,16 +613,24 @@ class RdfaParser extends readable_stream_1.Transform {
594
613
  // Remove the active tag from the stack
595
614
  this.activeTagStack.pop();
596
615
  // Save the tag contents if needed
597
- if (activeTag.collectChildTags && activeTag.text) {
598
- activeTag.text.push(`</${activeTag.name}>`);
616
+ if (activeTag.collectChildTags && activeTag.textWithTags) {
617
+ activeTag.textWithTags.push(`</${activeTag.name}>`);
599
618
  }
600
619
  // If we still have text contents, try to append it to the parent tag
601
- if (activeTag.text && parentTag) {
602
- if (!parentTag.text) {
603
- parentTag.text = activeTag.text;
620
+ if (activeTag.textWithTags && parentTag) {
621
+ if (!parentTag.textWithTags) {
622
+ parentTag.textWithTags = activeTag.textWithTags;
623
+ }
624
+ else {
625
+ parentTag.textWithTags = parentTag.textWithTags.concat(activeTag.textWithTags);
626
+ }
627
+ }
628
+ if (activeTag.textWithoutTags && parentTag) {
629
+ if (!parentTag.textWithoutTags) {
630
+ parentTag.textWithoutTags = activeTag.textWithoutTags;
604
631
  }
605
632
  else {
606
- parentTag.text = parentTag.text.concat(activeTag.text);
633
+ parentTag.textWithoutTags = parentTag.textWithoutT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EAAE;gBAC7D,IAAI;oBACF,IAAI,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;oBACjC,IAAI,IAAI,CAAC,iBAAiB,EAAE;wBAC1B,IAAI,CAAC,iBAAiB,CAAC,SAAS,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC;qBACpD;iBACF;gBAAC,OAAO,CAAC,EAAE;oBACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;iBACvB;YACH,CAAC;YACD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBACvB,IAAI;oBACF,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;oBAClB,IAAI,IAAI,CAAC,iBAAiB,EAAE;wBAC1B,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;qBACrC;iBACF;gBAAC,OAAO,CAAC,EAAE;oBACV,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;iBACvB;YACH,CAAC;SACF,EACD;YACE,cAAc,EAAE,IAAI;YACpB,oBAAoB,EAAE,IAAI;YAC1B,OAAO;SACR,CAAC,CAAC;IACP,CAAC;CAEF;AA52BD,gCA42BC","sourcesContent":["import {DomHandler} from \"domhandler\";\nimport EventEmitter = NodeJS.EventEmitter;\nimport {Parser as HtmlParser} from \"htmlparser2\";\nimport * as RDF from \"@rdfjs/types\";\nimport {PassThrough, Transform} from \"readable-stream\";\nimport {IActiveTag} from \"./IActiveTag\";\nimport {IHtmlParseListener} from \"./IHtmlParseListener\";\nimport * as INITIAL_CONTEXT_XHTML from \"./initial-context-xhtml.json\";\nimport * as INITIAL_CONTEXT from \"./initial-context.json\";\nimport {IRdfaPattern} from \"./IRdfaPattern\";\nimport {IRdfaFeatures, RDFA_FEATURES, RdfaProfile} from \"./RdfaProfile\";\nimport {Util} from \"./Util\";\n\n/**\n * A stream transformer that parses RDFa (text) streams to an {@link RDF.Stream}.\n */\nexport class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.Stream> {\n\n private readonly options: IRdfaParserOptions;\n private readonly util: Util;\n private readonly defaultGraph?: RDF.Quad_Graph;\n private readonly parser: HtmlParser;\n private readonly features: IRdfaFeatures;\n private readonly htmlParseListener?: IHtmlParseListener;\n private readonly rdfaPatterns: {[patternId: string]: IRdfaPattern};\n private readonly pendingRdfaPatternCopies: {[copyTargetPatternId: string]: IActiveTag[]};\n\n private readonly activeTagStack: IActiveTag[] = [];\n\n constructor(options?: IRdfaParserOptions) {\n super({ readableObjectMode: true });\n options = options || {};\n this.options = options;\n\n this.util = new Util(options.dataFactory, options.baseIRI);\n this.defaultGraph = options.defaultGraph || this.util.dataFactory.defaultGraph();\n const profile = options.contentType ? Util.contentTypeToProfile(options.contentType) : options.profile || '';\n this.features = options.features || RDFA_FEATURES[profile];\n this.htmlParseListener = options.htmlParseListener;\n this.rdfaPatterns = this.features.copyRdfaPatterns ? {} : null;\n this.pendingRdfaPatternCopies = this.features.copyRdfaPatterns ? {} : null;\n\n this.parser = this.initializeParser(profile === 'xml');\n\n this.activeTagStack.push({\n incompleteTriples: [],\n inlist: false,\n language: options.language,\n listMapping: {},\n listMappingLocal: {},\n name: '',\n prefixesAll: {\n ...INITIAL_CONTEXT['@context'],\n ...this.features.xhtmlInitialContext ? INITIAL_CONTEXT_XHTML['@context'] : {},\n },\n prefixesCustom : {},\n skipElement: false,\n vocab: options.vocab,\n });\n }\n\n /**\n * Parses the given text stream into a quad stream.\n * @param {NodeJS.EventEmitter} stream A text stream.\n * @return {RDF.Stream} A quad stream.\n */\n public import(stream: EventEmitter): RDF.Stream {\n const output = new PassThrough({ readableObjectMode: true });\n stream.on('error', (error) => parsed.emit('error', error));\n stream.on('data', (data) => output.push(data));\n stream.on('end', () => output.push(null));\n const parsed = output.pipe(new RdfaParser(this.options));\n return parsed;\n }\n\n public _transform(chunk: any, encoding: string, callback: (error?: Error | null, data?: any) => void): void {\n this.parser.write(chunk.toString());\n callback();\n }\n\n public _flush(callback: (error?: Error | null, data?: any) => void): void {\n this.parser.end();\n callback();\n }\n\n public onTagOpen(name: string, attributes: {[s: string]: string}) {\n // Determine the parent tag (ignore skipped tags)\n let parentTagI: number = this.activeTagStack.length - 1;\n while (parentTagI > 0 && this.activeTagStack[parentTagI].skipElement) {\n parentTagI--;\n }\n let parentTag: IActiveTag = this.activeTagStack[parentTagI];\n // If we skipped a tag, make sure we DO use the lang, prefixes and vocab of the skipped tag\n if (parentTagI !== this.activeTagStack.length - 1) {\n parentTag = {\n ...parentTag,\n language: this.activeTagStack[this.activeTagStack.length - 1].language,\n prefixesAll: this.activeTagStack[this.activeTagStack.length - 1].prefixesAll,\n prefixesCustom: this.activeTagStack[this.activeTagStack.length - 1].prefixesCustom,\n vocab: this.activeTagStack[this.activeTagStack.length - 1].vocab,\n };\n }\n\n // Create a new active tag and inherit language scope and baseIRI from parent\n const activeTag: IActiveTag = {\n collectChildTags: parentTag.collectChildTags,\n incompleteTriples: [],\n inlist: 'inlist' in attributes,\n listMapping: <{[predicate: string]: (RDF.Term|boolean)[]}> <any> [],\n listMappingLocal: parentTag.listMapping,\n localBaseIRI: parentTag.localBaseIRI,\n name,\n prefixesAll: null,\n prefixesCustom: null,\n skipElement: false,\n };\n this.activeTagStack.push(activeTag);\n\n // Save the tag contents if needed\n if (activeTag.collectChildTags) {\n // Add explicitly defined xmlns, xmlns:* and prefixes to attributes, as required by the spec (Step 11, note)\n // Sort prefixes alphabetically for deterministic namespace declaration order\n for (const prefix of Object.keys(parentTag.prefixesCustom).sort()) {\n const suffix = parentTag.prefixesCustom[prefix];\n const attributeKey = prefix === '' ? 'xmlns' : 'xmlns:' + prefix;\n if (!(attributeKey in attributes)) {\n attributes[attributeKey] = suffix;\n }\n }\n\n const attributesSerialized = Object.keys(attributes).map((key) => `${key}=\"${attributes[key]}\"`).join(' ');\n activeTag.text = [`<${name}${attributesSerialized ? ' ' + attributesSerialized : ''}>`];\n if (this.features.skipHandlingXmlLiteralChildren) {\n return;\n }\n }\n\n let allowTermsInRelPredicates: boolean = true;\n let allowTermsInRevPredicates: boolean = true;\n if (this.features.onlyAllowUriRelRevIfProperty) {\n // Ignore illegal rel/rev values when property is present\n if ('property' in attributes && 'rel' in attributes) {\n allowTermsInRelPredicates = false;\n if (attributes.rel.indexOf(':') < 0) {\n delete attributes.rel;\n }\n }\n if ('property' in attributes && 'rev' in attributes) {\n allowTermsInRevPredicates = false;\n if (attributes.rev.indexOf(':') < 0) {\n delete attributes.rev;\n }\n }\n }\n\n if (this.features.copyRdfaPatterns) {\n // Save the tag if needed\n if (parentTag.collectedPatternTag) {\n const patternTag: IRdfaPattern = {\n attributes,\n children: [],\n name,\n referenced: false,\n rootPattern: false,\n text: [],\n };\n parentTag.collectedPatternTag.children.push(patternTag);\n activeTag.collectedPatternTag = patternTag;\n return;\n }\n\n // Store tags with type rdfa:Pattern as patterns\n if (attributes.typeof === 'rdfa:Pattern') {\n activeTag.collectedPatternTag = {\n attributes,\n children: [],\n name,\n parentTag,\n referenced: false,\n rootPattern: true,\n text: [],\n };\n return;\n }\n\n // Instantiate patterns on rdfa:copy\n if (attributes.property === 'rdfa:copy') {\n const copyTargetPatternId: string = attributes.resource || attributes.href || attributes.src;\n if (this.rdfaPatterns[copyTargetPatternId]) {\n this.emitPatternCopy(parentTag, this.rdfaPatterns[copyTargetPatternId], copyTargetPatternId);\n } else {\n if (!this.pendingRdfaPatternCopies[copyTargetPatternId]) {\n this.pendingRdfaPatternCopies[copyTargetPatternId] = [];\n }\n this.pendingRdfaPatternCopies[copyTargetPatternId].push(parentTag);\n }\n return;\n }\n }\n\n // <base> tags override the baseIRI of the whole document\n if (this.features.baseTag && name === 'base' && attributes.href) {\n this.util.baseIRI = this.util.getBaseIRI(attributes.href);\n }\n // xml:base attributes override the baseIRI of the current tag and children\n if (this.features.xmlBase && attributes['xml:base']) {\n activeTag.localBaseIRI = this.util.getBaseIRI(attributes['xml:base']);\n }\n\n // <time> tags set an initial datatype\n if (this.features.timeTag && name === 'time' && !attributes.datatype) {\n activeTag.interpretObjectAsTime = true;\n }\n\n // Processing based on https://www.w3.org/TR/rdfa-core/#s_rdfaindetail\n // 1: initialize values\n let newSubject: RDF.NamedNode | RDF.BlankNode | boolean;\n let currentObjectResource: RDF.NamedNode | RDF.BlankNode | boolean;\n let typedResource: RDF.NamedNode | RDF.BlankNode | boolean;\n\n // 2: handle vocab attribute to set active vocabulary\n // Vocab sets the active vocabulary\n if ('vocab' in attributes) {\n if (attributes.vocab) {\n activeTag.vocab = attributes.vocab;\n this.emitTriple(\n this.util.getBaseIriTerm(activeTag),\n this.util.dataFactory.namedNode(Util.RDFA + 'usesVocabulary'),\n this.util.dataFactory.namedNode(activeTag.vocab),\n );\n } else {\n // If vocab is set to '', then we fallback to the root vocab as defined via the parser constructor\n activeTag.vocab = this.activeTagStack[0].vocab;\n }\n } else {\n activeTag.vocab = parentTag.vocab;\n }\n\n // 3: handle prefixes\n activeTag.prefixesCustom = Util.parsePrefixes(attributes, parentTag.prefixesCustom,\n this.features.xmlnsPrefixMappings);\n activeTag.prefixesAll = Object.keys(activeTag.prefixesCustom).length > 0\n ? { ...parentTag.prefixesAll, ...activeTag.prefixesCustom } : parentTag.prefixesAll;\n\n // Handle role attribute\n if (this.features.roleAttribute && attributes.role) {\n const roleSubject = attributes.id\n ? this.util.createIri('#' + attributes.id, activeTag, false, false, false)\n : this.util.createBlankNode();\n // Temporarily override vocab\n const vocabOld = activeTag.vocab;\n activeTag.vocab = 'http://www.w3.org/1999/xhtml/vocab#';\n for (const role of this.util.createVocabIris(attributes.role, activeTag, true, false)) {\n this.emitTriple(\n roleSubject,\n this.util.dataFactory.namedNode('http://www.w3.org/1999/xhtml/vocab#role'),\n role,\n );\n }\n activeTag.vocab = vocabOld;\n }\n\n // 4: handle language\n // Save language attribute value in active tag\n if ('xml:lang' in attributes || (this.features.langAttribute && 'lang' in attributes)) {\n activeTag.language = attributes['xml:lang'] || attributes.lang;\n } else {\n activeTag.language = parentTag.language;\n }\n\n const isRootTag: boolean = this.activeTagStack.length === 2;\n if (!('rel' in attributes) && !('rev' in attributes)) {\n // 5: Determine the new subject when rel and rev are not present\n if ('property' in attributes && !('content' in attributes) && !('datatype' in attributes)) {\n // 5.1: property is present, but not content and datatype\n // Determine new subject\n if ('about' in attributes) {\n newSubject = this.util.createIri(attributes.about, activeTag, false, true, true);\n activeTag.explicitNewSubject = !!newSubject;\n } else if (isRootTag) {\n newSubject = true;\n } else if (parentTag.object) {\n newSubject = parentTag.object;\n }\n\n // Determine type\n if ('typeof' in attributes) {\n if ('about' in attributes) {\n typedResource = this.util.createIri(attributes.about, activeTag, false, true, true);\n }\n if (!typedResource && isRootTag) {\n typedResource = true;\n }\n if (!typedResource && 'resource' in attributes) {\n typedResource = this.util.createIri(attributes.resource, activeTag, false, true, true);\n }\n if (!typedResource && ('href' in attributes || 'src' in attributes)) {\n typedResource = this.util.createIri(attributes.href || attributes.src, activeTag, false, false, true);\n }\n if (!typedResource && this.isInheritSubjectInHeadBody(name)) {\n typedResource = newSubject;\n }\n if (!typedResource) {\n typedResource = this.util.createBlankNode();\n }\n\n currentObjectResource = typedResource;\n }\n } else {\n // 5.2\n if ('about' in attributes || 'resource' in attributes) {\n newSubject = this.util.createIri(attributes.about || attributes.resource, activeTag, false, true, true);\n activeTag.explicitNewSubject = !!newSubject;\n }\n if (!newSubject && ('href' in attributes || 'src' in attributes)) {\n newSubject = this.util.createIri(attributes.href || attributes.src,\n activeTag, false, false, true);\n activeTag.explicitNewSubject = !!newSubject;\n }\n if (!newSubject) {\n if (isRootTag) {\n newSubject = true;\n } else if (this.isInheritSubjectInHeadBody(name)) {\n newSubject = parentTag.object;\n } else if ('typeof' in attributes) {\n newSubject = this.util.createBlankNode();\n activeTag.explicitNewSubject = true;\n } else if (parentTag.object) {\n newSubject = parentTag.object;\n if (!('property' in attributes)) {\n activeTag.skipElement = true;\n }\n }\n }\n\n // Determine type\n if ('typeof' in attributes) {\n typedResource = newSubject;\n }\n }\n } else { // either rel or rev is present\n // 6: Determine the new subject when rel or rev are present\n\n // Define new subject\n if ('about' in attributes) {\n newSubject = this.util.createIri(attributes.about, activeTag, false, true, true);\n activeTag.explicitNewSubject = !!newSubject;\n if ('typeof' in attributes) {\n typedResource = newSubject;\n }\n } else if (isRootTag) {\n newSubject = true;\n } else if (parentTag.object) {\n newSubject = parentTag.object;\n }\n\n // Define object\n if ('resource' in attributes) {\n currentObjectResource = this.util.createIri(attributes.resource, activeTag, false, true, true);\n }\n if (!currentObjectResource) {\n if ('href' in attributes || 'src' in attributes) {\n currentObjectResource = this.util.createIri(attributes.href || attributes.src, activeTag, false, false, true);\n } else if ('typeof' in attributes && !('about' in attributes) && !this.isInheritSubjectInHeadBody(name)) {\n currentObjectResource = this.util.createBlankNode();\n }\n }\n\n // Set typed resource\n if ('typeof' in attributes && !('about' in attributes)) {\n if (this.isInheritSubjectInHeadBody(name)) {\n typedResource = newSubject;\n } else {\n typedResource = currentObjectResource;\n }\n }\n }\n\n // 7: If a typed resource was defined, emit it as a triple\n if (typedResource) {\n for (const type of this.util.createVocabIris(attributes.typeof, activeTag, true, true)) {\n this.emitTriple(\n this.util.getResourceOrBaseIri(typedResource, activeTag),\n this.util.dataFactory.namedNode(Util.RDF + 'type'),\n type,\n );\n }\n }\n\n // 8: Reset list mapping if we have a new subject\n if (newSubject) {\n activeTag.listMapping = {};\n }\n\n // 9: If an object was defined, emit triples for it\n if (currentObjectResource) {\n // Handle list mapping\n if ('rel' in attributes && 'inlist' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n this.addListMapping(activeTag, newSubject, predicate, currentObjectResource);\n }\n }\n\n // Determine predicates using rel or rev (unless rel and inlist are present)\n if (!('rel' in attributes && 'inlist' in attributes)) {\n if ('rel' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n this.emitTriple(\n this.util.getResourceOrBaseIri(newSubject, activeTag),\n predicate,\n this.util.getResourceOrBaseIri(currentObjectResource, activeTag),\n );\n }\n }\n if ('rev' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates,\n false)) {\n this.emitTriple(\n this.util.getResourceOrBaseIri(currentObjectResource, activeTag),\n predicate,\n this.util.getResourceOrBaseIri(newSubject, activeTag),\n );\n }\n }\n }\n }\n\n // 10: Store incomplete triples if we don't have an object, but we do have predicates\n if (!currentObjectResource) {\n if ('rel' in attributes) {\n if ('inlist' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n this.addListMapping(activeTag, newSubject, predicate, null);\n activeTag.incompleteTriples.push({ predicate, reverse: false, list: true });\n }\n } else {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n activeTag.incompleteTriples.push({ predicate, reverse: false });\n }\n }\n }\n if ('rev' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates,\n false)) {\n activeTag.incompleteTriples.push({ predicate, reverse: true });\n }\n }\n\n // Set a blank node object, so the children can make use of this when completing the triples\n if (activeTag.incompleteTriples.length > 0) {\n currentObjectResource = this.util.createBlankNode();\n }\n }\n\n // 11: Determine current property value\n if ('property' in attributes) {\n // Create predicates\n activeTag.predicates = this.util.createVocabIris(attributes.property, activeTag, true, false);\n\n // Save datatype attribute value in active tag\n let localObjectResource: RDF.Term | boolean;\n if ('datatype' in attributes) {\n activeTag.datatype = <RDF.NamedNode> this.util.createIri(attributes.datatype, activeTag, true, true, false);\n if (activeTag.datatype\n && (activeTag.datatype.value === Util.RDF + 'XMLLiteral'\n || (this.features.htmlDatatype && activeTag.datatype.value === Util.RDF + 'HTML'))) {\n activeTag.collectChildTags = true;\n }\n } else {\n // Try to determine resource\n if (!('rev' in attributes) && !('rel' in attributes) && !('content' in attributes)) {\n if ('resource' in attributes) {\n localObjectResource = this.util.createIri(attributes.resource, activeTag, false, true, true);\n }\n if (!localObjectResource && 'href' in attributes) {\n localObjectResource = this.util.createIri(attributes.href, activeTag, false, false, true);\n }\n if (!localObjectResource && 'src' in attributes) {\n localObjectResource = this.util.createIri(attributes.src, activeTag, false, false, true);\n }\n }\n if ('typeof' in attributes && !('about' in attributes)) {\n localObjectResource = typedResource;\n }\n }\n\n if ('content' in attributes) {\n // Emit triples based on content attribute has preference over text content\n const object = this.util.createLiteral(attributes.content, activeTag);\n if ('inlist' in attributes) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, newSubject, predicate, object);\n }\n } else {\n const subject = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Unset predicate to avoid text contents to produce new triples\n activeTag.predicates = null;\n } else if (this.features.datetimeAttribute && 'datetime' in attributes) {\n activeTag.interpretObjectAsTime = true;\n // Datetime attribute on time tag has preference over text content\n const object = this.util.createLiteral(attributes.datetime, activeTag);\n if ('inlist' in attributes) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, newSubject, predicate, object);\n }\n } else {\n const subject = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Unset predicate to avoid text contents to produce new triples\n activeTag.predicates = null;\n } else if (localObjectResource) {\n // Emit triples for all resource objects\n const object = this.util.getResourceOrBaseIri(localObjectResource, activeTag);\n if ('inlist' in attributes) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, newSubject, predicate, object);\n }\n } else {\n const subject = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Unset predicate to avoid text contents to produce new triples\n activeTag.predicates = null;\n }\n }\n\n // 12: Complete incomplete triples\n let incompleteTriplesCompleted = false;\n if (!activeTag.skipElement && newSubject && parentTag.incompleteTriples.length > 0) {\n incompleteTriplesCompleted = true;\n const subject = this.util.getResourceOrBaseIri(parentTag.subject, activeTag);\n const object = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const incompleteTriple of parentTag.incompleteTriples) {\n if (!incompleteTriple.reverse) {\n if (incompleteTriple.list) {\n // Find the active tag that defined the list by going up the stack\n let firstInListTag = null;\n for (let i = this.activeTagStack.length - 1; i >= 0; i--) {\n if (this.activeTagStack[i].inlist) {\n firstInListTag = this.activeTagStack[i];\n break;\n }\n }\n // firstInListTag is guaranteed to be non-null\n this.addListMapping(firstInListTag, newSubject, incompleteTriple.predicate, object);\n } else {\n this.emitTriple(subject, incompleteTriple.predicate, object);\n }\n } else {\n this.emitTriple(object, incompleteTriple.predicate, subject);\n }\n }\n }\n if (!incompleteTriplesCompleted && parentTag.incompleteTriples.length > 0) {\n activeTag.incompleteTriples = activeTag.incompleteTriples.concat(parentTag.incompleteTriples);\n }\n\n // 13: Save evaluation context into active tag\n activeTag.subject = newSubject || parentTag.subject;\n activeTag.object = currentObjectResource || newSubject;\n }\n\n public onText(data: string) {\n const activeTag: IActiveTag = this.activeTagStack[this.activeTagStack.length - 1];\n\n // Collect text in pattern tag if needed\n if (this.features.copyRdfaPatterns && activeTag.collectedPatternTag) {\n activeTag.collectedPatternTag.text.push(data);\n return;\n }\n\n // Save the text inside the active tag\n if (!activeTag.text) {\n activeTag.text = [];\n }\n activeTag.text.push(data);\n }\n\n public onTagClose() {\n // Get the active tag\n const activeTag: IActiveTag = this.activeTagStack[this.activeTagStack.length - 1];\n const parentTag: IActiveTag = this.activeTagStack[this.activeTagStack.length - 2];\n\n if (!(activeTag.collectChildTags && parentTag.collectChildTags && this.features.skipHandlingXmlLiteralChildren)) {\n\n // If we detect a finalized rdfa:Pattern tag, store it\n if (this.features.copyRdfaPatterns && activeTag.collectedPatternTag\n && activeTag.collectedPatternTag.rootPattern) {\n const patternId = activeTag.collectedPatternTag.attributes.resource;\n\n // Remove resource and typeof attributes to avoid it being seen as a new pattern\n delete activeTag.collectedPatternTag.attributes.resource;\n delete activeTag.collectedPatternTag.attributes.typeof;\n\n // Store the pattern\n this.rdfaPatterns[patternId] = activeTag.collectedPatternTag;\n\n // Apply all pending copies for this pattern\n if (this.pendingRdfaPatternCopies[patternId]) {\n for (const tag of this.pendingRdfaPatternCopies[patternId]) {\n this.emitPatternCopy(tag, activeTag.collectedPatternTag, patternId);\n }\n delete this.pendingRdfaPatternCopies[patternId];\n }\n\n // Remove the active tag from the stack\n this.activeTagStack.pop();\n\n return;\n }\n\n // Emit all triples that were determined in the active tag\n if (activeTag.predicates) {\n const subject = this.util.getResourceOrBaseIri(activeTag.subject, activeTag);\n let textSegments: string[] = activeTag.text || [];\n if (activeTag.collectChildTags && parentTag.collectChildTags) {\n // If we are inside an XMLLiteral child that also has RDFa content, ignore the tag name that was collected.\n textSegments = textSegments.slice(1);\n }\n const object = this.util.createLiteral(textSegments.join(''), activeTag);\n if (activeTag.inlist) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, subject, predicate, object);\n }\n } else {\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Reset text, unless the parent is also collecting text\n if (!parentTag.predicates) {\n activeTag.text = null;\n }\n }\n\n // 14: Handle local list mapping\n if (activeTag.object && Object.keys(activeTag.listMapping).length > 0) {\n const subject = this.util.getResourceOrBaseIri(activeTag.object, activeTag);\n for (const predicateValue in activeTag.listMapping) {\n const predicate = this.util.dataFactory.namedNode(predicateValue);\n const values = activeTag.listMapping[predicateValue];\n\n if (values.length > 0) {\n // Non-empty list, emit linked list of rdf:first and rdf:rest chains\n const bnodes = values.map(() => this.util.createBlankNode());\n for (let i = 0; i < values.length; i++) {\n const object = this.util.getResourceOrBaseIri(values[i], activeTag);\n this.emitTriple(bnodes[i], this.util.dataFactory.namedNode(Util.RDF + 'first'),\n object);\n this.emitTriple(bnodes[i], this.util.dataFactory.namedNode(Util.RDF + 'rest'),\n (i < values.length - 1) ? bnodes[i + 1] : this.util.dataFactory.namedNode(Util.RDF + 'nil'));\n }\n\n // Emit triple for the first linked list chain\n this.emitTriple(subject, predicate, bnodes[0]);\n } else {\n // Empty list, just emit rdf:nil\n this.emitTriple(subject, predicate, this.util.dataFactory.namedNode(Util.RDF + 'nil'));\n }\n }\n }\n\n }\n\n // Remove the active tag from the stack\n this.activeTagStack.pop();\n\n // Save the tag contents if needed\n if (activeTag.collectChildTags && activeTag.text) {\n activeTag.text.push(`</${activeTag.name}>`);\n }\n\n // If we still have text contents, try to append it to the parent tag\n if (activeTag.text && parentTag) {\n if (!parentTag.text) {\n parentTag.text = activeTag.text;\n } else {\n parentTag.text = parentTag.text.concat(activeTag.text);\n }\n }\n }\n\n public onEnd() {\n if (this.features.copyRdfaPatterns) {\n this.features.copyRdfaPatterns = false;\n\n // Emit all unreferenced patterns\n for (const patternId in this.rdfaPatterns) {\n const pattern = this.rdfaPatterns[patternId];\n if (!pattern.referenced) {\n pattern.attributes.typeof = 'rdfa:Pattern';\n pattern.attributes.resource = patternId;\n this.emitPatternCopy(pattern.parentTag, pattern, patternId);\n pattern.referenced = false;\n delete pattern.attributes.typeof;\n delete pattern.attributes.resource;\n }\n }\n\n // Emit all unreferenced copy links\n for (const patternId in this.pendingRdfaPatternCopies) {\n for (const parentTag of this.pendingRdfaPatternCopies[patternId]) {\n this.activeTagStack.push(parentTag);\n this.onTagOpen('link', { property: 'rdfa:copy', href: patternId });\n this.onTagClose();\n this.activeTagStack.pop();\n }\n }\n\n this.features.copyRdfaPatterns = true;\n }\n }\n\n /**\n * If the new subject can be inherited from the parent object\n * if the resource defines no new subject.\n * @param {string} name The current tag name.\n * @returns {boolean} If the subject can be inherited.\n */\n protected isInheritSubjectInHeadBody(name: string) {\n return this.features.inheritSubjectInHeadBody && (name === 'head' || name === 'body');\n }\n\n /**\n * Add a list mapping for the given predicate and object in the active tag.\n * @param {IActiveTag} activeTag The active tag.\n * @param {Term | boolean} subject A subject term, this will only be used to create a separate list\n * if activeTag.explicitNewSubject is true.\n * @param {Term} predicate A predicate term.\n * @param {Term | boolean} currentObjectResource The current object resource.\n */\n protected addListMapping(activeTag: IActiveTag, subject: RDF.Quad_Subject | boolean, predicate: RDF.Quad_Predicate,\n currentObjectResource: RDF.Quad_Object | boolean) {\n if (activeTag.explicitNewSubject) {\n const bNode = this.util.createBlankNode();\n this.emitTriple(this.util.getResourceOrBaseIri(subject, activeTag), predicate, bNode);\n this.emitTriple(bNode, this.util.dataFactory.namedNode(Util.RDF + 'first'),\n this.util.getResourceOrBaseIri(currentObjectResource, activeTag));\n this.emitTriple(bNode, this.util.dataFactory.namedNode(Util.RDF + 'rest'),\n this.util.dataFactory.namedNode(Util.RDF + 'nil'));\n } else {\n let predicateList = activeTag.listMappingLocal[predicate.value];\n if (!predicateList) {\n activeTag.listMappingLocal[predicate.value] = predicateList = [];\n }\n if (currentObjectResource) {\n predicateList.push(currentObjectResource);\n }\n }\n }\n\n /**\n * Emit the given triple to the stream.\n * @param {Term} subject A subject term.\n * @param {Term} predicate A predicate term.\n * @param {Term} object An object term.\n */\n protected emitTriple(subject: RDF.Quad_Subject, predicate: RDF.Quad_Predicate, object: RDF.Quad_Object) {\n // Validate IRIs\n if ((subject.termType === 'NamedNode' && subject.value.indexOf(':') < 0)\n || (predicate.termType === 'NamedNode' && predicate.value.indexOf(':') < 0)\n || (object.termType === 'NamedNode' && object.value.indexOf(':') < 0)) {\n return;\n }\n this.push(this.util.dataFactory.quad(subject, predicate, object, this.defaultGraph));\n }\n\n /**\n * Emit an instantiation of the given pattern with the given parent tag.\n * @param {IActiveTag} parentTag The parent tag to instantiate in.\n * @param {IRdfaPattern} pattern The pattern to instantiate.\n * @param {string} rootPatternId The pattern id.\n */\n protected emitPatternCopy(parentTag: IActiveTag, pattern: IRdfaPattern, rootPatternId: string) {\n this.activeTagStack.push(parentTag);\n pattern.referenced = true;\n\n // Ensure that blank nodes within patterns are instantiated only once.\n // All next pattern copies will reuse the instantiated blank nodes from the first pattern.\n if (!pattern.constructedBlankNodes) {\n pattern.constructedBlankNodes = [];\n this.util.blankNodeFactory = () => {\n const bNode = this.util.dataFactory.blankNode();\n pattern.constructedBlankNodes.push(bNode);\n return bNode;\n };\n } else {\n let blankNodeIndex = 0;\n this.util.blankNodeFactory = () => pattern.constructedBlankNodes[blankNodeIndex++];\n }\n\n // Apply everything within the pattern\n this.emitPatternCopyAbsolute(pattern, true, rootPatternId);\n\n this.util.blankNodeFactory = null;\n this.activeTagStack.pop();\n }\n\n /**\n * Emit an instantiation of the given pattern with the given parent tag.\n *\n * This should probably not be called directly,\n * call {@link emitPatternCopy} instead.\n *\n * @param {IRdfaPattern} pattern The pattern to instantiate.\n * @param {boolean} root If this is the root call for the given pattern.\n * @param {string} rootPatternId The pattern id.\n */\n protected emitPatternCopyAbsolute(pattern: IRdfaPattern, root: boolean, rootPatternId: string) {\n // Stop on detection of cyclic patterns\n if (!root && pattern.attributes.property === 'rdfa:copy' && pattern.attributes.href === rootPatternId) {\n return;\n }\n\n this.onTagOpen(pattern.name, pattern.attributes);\n for (const text of pattern.text) {\n this.onText(text);\n }\n for (const child of pattern.children) {\n this.emitPatternCopyAbsolute(child, false, rootPatternId);\n }\n this.onTagClose();\n }\n\n protected initializeParser(xmlMode: boolean): HtmlParser {\n return new HtmlParser(\n <DomHandler> <any> {\n onclosetag: () => {\n try {\n this.onTagClose();\n if (this.htmlParseListener) {\n this.htmlParseListener.onTagClose();\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n onend: () => {\n try {\n this.onEnd();\n if (this.htmlParseListener) {\n this.htmlParseListener.onEnd();\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n onopentag: (name: string, attributes: {[s: string]: string}) => {\n try {\n this.onTagOpen(name, attributes);\n if (this.htmlParseListener) {\n this.htmlParseListener.onTagOpen(name, attributes);\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n ontext: (data: string) => {\n try {\n this.onText(data);\n if (this.htmlParseListener) {\n this.htmlParseListener.onText(data);\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n },\n {\n decodeEntities: true,\n recognizeSelfClosing: true,\n xmlMode,\n });\n }\n\n}\n\nexport interface IRdfaParserOptions {\n /**\n * A custom RDFJS DataFactory to construct terms and triples.\n */\n dataFactory?: RDF.DataFactory;\n /**\n * An initital default base IRI.\n */\n baseIRI?: string;\n /**\n * A default language for string literals.\n */\n language?: string;\n /**\n * The initial vocabulary.\n */\n vocab?: string;\n /**\n * The default graph for constructing quads.\n */\n defaultGraph?: RDF.Quad_Graph;\n /**\n * A hash of features that should be enabled.\n * Defaults to the features defined by the profile.\n */\n features?: IRdfaFeatures;\n /**\n * The RDFa profile to use.\n * Defaults to a profile with all possible features enabled.\n */\n profile?: RdfaProfile;\n /**\n * The content type of the document that should be parsed.\n * This can be used as an alternative to the 'profile' option.\n */\n contentType?: string;\n /**\n * An optional listener for the internal HTML parse events.\n */\n htmlParseListener?: IHtmlParseListener;\n}\n"]}
1
+ {"version":3,"file":"RdfaParser.js","sourceRoot":"","sources":["RdfaParser.ts"],"names":[],"mappings":";;;AAEA,6CAAiD;AAEjD,qDAAuD;AAGvD,sEAAsE;AACtE,0DAA0D;AAE1D,+CAAwE;AACxE,iCAA4B;AAE5B;;GAEG;AACH,MAAa,UAAW,SAAQ,2BAAS;IAavC,YAAY,OAA4B;QACtC,KAAK,CAAC,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;QAHrB,mBAAc,GAAiB,EAAE,CAAC;QAIjD,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;QACxB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,IAAI,GAAG,IAAI,WAAI,CAAC,OAAO,CAAC,WAAW,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,CAAC,YAAY,GAAG,OAAO,CAAC,YAAY,IAAI,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,YAAY,EAAE,CAAC;QACjF,MAA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,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;YACD,MAAM,EAAE,CAAC,IAAY,EAAE,EAAE;gBACvB,IAAI,CAAC;oBACH,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;oBAClB,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;wBAC3B,IAAI,CAAC,iBAAiB,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;oBACtC,CAAC;gBACH,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;gBACxB,CAAC;YACH,CAAC;SACF,EACD;YACE,cAAc,EAAE,IAAI;YACpB,oBAAoB,EAAE,IAAI;YAC1B,OAAO;SACR,CAAC,CAAC;IACP,CAAC;CAEF;AAt4BD,gCAs4BC","sourcesContent":["import {DomHandler} from \"domhandler\";\nimport EventEmitter = NodeJS.EventEmitter;\nimport {Parser as HtmlParser} from \"htmlparser2\";\nimport * as RDF from \"@rdfjs/types\";\nimport {PassThrough, Transform} from \"readable-stream\";\nimport {IActiveTag} from \"./IActiveTag\";\nimport {IHtmlParseListener} from \"./IHtmlParseListener\";\nimport * as INITIAL_CONTEXT_XHTML from \"./initial-context-xhtml.json\";\nimport * as INITIAL_CONTEXT from \"./initial-context.json\";\nimport {IRdfaPattern} from \"./IRdfaPattern\";\nimport {IRdfaFeatures, RDFA_FEATURES, RdfaProfile} from \"./RdfaProfile\";\nimport {Util} from \"./Util\";\n\n/**\n * A stream transformer that parses RDFa (text) streams to an {@link RDF.Stream}.\n */\nexport class RdfaParser extends Transform implements RDF.Sink<EventEmitter, RDF.Stream> {\n\n private readonly options: IRdfaParserOptions;\n private readonly util: Util;\n private readonly defaultGraph?: RDF.Quad_Graph;\n private readonly parser: HtmlParser;\n private readonly features: IRdfaFeatures;\n private readonly htmlParseListener?: IHtmlParseListener;\n private readonly rdfaPatterns: {[patternId: string]: IRdfaPattern};\n private readonly pendingRdfaPatternCopies: {[copyTargetPatternId: string]: IActiveTag[]};\n\n private readonly activeTagStack: IActiveTag[] = [];\n\n constructor(options?: IRdfaParserOptions) {\n super({ readableObjectMode: true });\n options = options || {};\n this.options = options;\n\n this.util = new Util(options.dataFactory, options.baseIRI);\n this.defaultGraph = options.defaultGraph || this.util.dataFactory.defaultGraph();\n const profile = options.contentType ? Util.contentTypeToProfile(options.contentType) : options.profile || '';\n this.features = options.features || RDFA_FEATURES[profile];\n this.htmlParseListener = options.htmlParseListener;\n this.rdfaPatterns = this.features.copyRdfaPatterns ? {} : null;\n this.pendingRdfaPatternCopies = this.features.copyRdfaPatterns ? {} : null;\n\n this.parser = this.initializeParser(profile === 'xml');\n\n this.activeTagStack.push({\n incompleteTriples: [],\n inlist: false,\n language: options.language,\n listMapping: {},\n listMappingLocal: {},\n name: '',\n prefixesAll: {\n ...INITIAL_CONTEXT['@context'],\n ...this.features.xhtmlInitialContext ? INITIAL_CONTEXT_XHTML['@context'] : {},\n },\n prefixesCustom : {},\n skipElement: false,\n vocab: options.vocab,\n });\n }\n\n /**\n * Parses the given text stream into a quad stream.\n * @param {NodeJS.EventEmitter} stream A text stream.\n * @return {RDF.Stream} A quad stream.\n */\n public import(stream: EventEmitter): RDF.Stream {\n const output = new PassThrough({ readableObjectMode: true });\n stream.on('error', (error) => parsed.emit('error', error));\n stream.on('data', (data) => output.push(data));\n stream.on('end', () => output.push(null));\n const parsed = output.pipe(new RdfaParser(this.options));\n return parsed;\n }\n\n public _transform(chunk: any, encoding: string, callback: (error?: Error | null, data?: any) => void): void {\n this.parser.write(chunk.toString());\n callback();\n }\n\n public _flush(callback: (error?: Error | null, data?: any) => void): void {\n this.parser.end();\n callback();\n }\n\n public onTagOpen(name: string, attributes: {[s: string]: string}) {\n // Determine the parent tag (ignore skipped tags)\n let parentTagI: number = this.activeTagStack.length - 1;\n while (parentTagI > 0 && this.activeTagStack[parentTagI].skipElement) {\n parentTagI--;\n }\n let parentTag: IActiveTag = this.activeTagStack[parentTagI];\n // If we skipped a tag, make sure we DO use the lang, prefixes and vocab of the skipped tag\n if (parentTagI !== this.activeTagStack.length - 1) {\n parentTag = {\n ...parentTag,\n language: this.activeTagStack[this.activeTagStack.length - 1].language,\n prefixesAll: this.activeTagStack[this.activeTagStack.length - 1].prefixesAll,\n prefixesCustom: this.activeTagStack[this.activeTagStack.length - 1].prefixesCustom,\n vocab: this.activeTagStack[this.activeTagStack.length - 1].vocab,\n };\n }\n\n // Create a new active tag and inherit language scope and baseIRI from parent\n const activeTag: IActiveTag = {\n collectChildTags: parentTag.collectChildTags,\n collectChildTagsForCurrentTag: parentTag.collectChildTagsForCurrentTag,\n incompleteTriples: [],\n inlist: 'inlist' in attributes,\n listMapping: <{[predicate: string]: (RDF.Term|boolean)[]}> <any> [],\n listMappingLocal: parentTag.listMapping,\n localBaseIRI: parentTag.localBaseIRI,\n name,\n prefixesAll: null,\n prefixesCustom: null,\n skipElement: false,\n };\n this.activeTagStack.push(activeTag);\n\n // Save the tag contents if needed\n if (activeTag.collectChildTags) {\n // Add explicitly defined xmlns, xmlns:* and prefixes to attributes, as required by the spec (Step 11, note)\n // Sort prefixes alphabetically for deterministic namespace declaration order\n for (const prefix of Object.keys(parentTag.prefixesCustom).sort()) {\n const suffix = parentTag.prefixesCustom[prefix];\n const attributeKey = prefix === '' ? 'xmlns' : 'xmlns:' + prefix;\n if (!(attributeKey in attributes)) {\n attributes[attributeKey] = suffix;\n }\n }\n\n const attributesSerialized = Object.keys(attributes).map((key) => `${key}=\"${attributes[key]}\"`).join(' ');\n activeTag.textWithTags = [`<${name}${attributesSerialized ? ' ' + attributesSerialized : ''}>`];\n if (this.features.skipHandlingXmlLiteralChildren) {\n return;\n }\n }\n\n let allowTermsInRelPredicates: boolean = true;\n let allowTermsInRevPredicates: boolean = true;\n if (this.features.onlyAllowUriRelRevIfProperty) {\n // Ignore illegal rel/rev values when property is present\n if ('property' in attributes && 'rel' in attributes) {\n allowTermsInRelPredicates = false;\n if (attributes.rel.indexOf(':') < 0) {\n delete attributes.rel;\n }\n }\n if ('property' in attributes && 'rev' in attributes) {\n allowTermsInRevPredicates = false;\n if (attributes.rev.indexOf(':') < 0) {\n delete attributes.rev;\n }\n }\n }\n\n if (this.features.copyRdfaPatterns) {\n // Save the tag if needed\n if (parentTag.collectedPatternTag) {\n const patternTag: IRdfaPattern = {\n attributes,\n children: [],\n name,\n referenced: false,\n rootPattern: false,\n text: [],\n };\n parentTag.collectedPatternTag.children.push(patternTag);\n activeTag.collectedPatternTag = patternTag;\n return;\n }\n\n // Store tags with type rdfa:Pattern as patterns\n if (attributes.typeof === 'rdfa:Pattern') {\n activeTag.collectedPatternTag = {\n attributes,\n children: [],\n name,\n parentTag,\n referenced: false,\n rootPattern: true,\n text: [],\n };\n return;\n }\n\n // Instantiate patterns on rdfa:copy\n if (attributes.property === 'rdfa:copy') {\n const copyTargetPatternId: string = attributes.resource || attributes.href || attributes.src;\n if (this.rdfaPatterns[copyTargetPatternId]) {\n this.emitPatternCopy(parentTag, this.rdfaPatterns[copyTargetPatternId], copyTargetPatternId);\n } else {\n if (!this.pendingRdfaPatternCopies[copyTargetPatternId]) {\n this.pendingRdfaPatternCopies[copyTargetPatternId] = [];\n }\n this.pendingRdfaPatternCopies[copyTargetPatternId].push(parentTag);\n }\n return;\n }\n }\n\n // <base> tags override the baseIRI of the whole document\n if (this.features.baseTag && name === 'base' && attributes.href) {\n this.util.baseIRI = this.util.getBaseIRI(attributes.href);\n }\n // xml:base attributes override the baseIRI of the current tag and children\n if (this.features.xmlBase && attributes['xml:base']) {\n activeTag.localBaseIRI = this.util.getBaseIRI(attributes['xml:base']);\n }\n\n // <time> tags set an initial datatype\n if (this.features.timeTag && name === 'time' && !attributes.datatype) {\n activeTag.interpretObjectAsTime = true;\n }\n\n // Processing based on https://www.w3.org/TR/rdfa-core/#s_rdfaindetail\n // 1: initialize values\n let newSubject: RDF.NamedNode | RDF.BlankNode | boolean;\n let currentObjectResource: RDF.NamedNode | RDF.BlankNode | boolean;\n let typedResource: RDF.NamedNode | RDF.BlankNode | boolean;\n\n // 2: handle vocab attribute to set active vocabulary\n // Vocab sets the active vocabulary\n if ('vocab' in attributes) {\n if (attributes.vocab) {\n activeTag.vocab = attributes.vocab;\n this.emitTriple(\n this.util.getBaseIriTerm(activeTag),\n this.util.dataFactory.namedNode(Util.RDFA + 'usesVocabulary'),\n this.util.dataFactory.namedNode(activeTag.vocab),\n );\n } else {\n // If vocab is set to '', then we fallback to the root vocab as defined via the parser constructor\n activeTag.vocab = this.activeTagStack[0].vocab;\n }\n } else {\n activeTag.vocab = parentTag.vocab;\n }\n\n // 3: handle prefixes\n activeTag.prefixesCustom = Util.parsePrefixes(attributes, parentTag.prefixesCustom,\n this.features.xmlnsPrefixMappings);\n activeTag.prefixesAll = Object.keys(activeTag.prefixesCustom).length > 0\n ? { ...parentTag.prefixesAll, ...activeTag.prefixesCustom } : parentTag.prefixesAll;\n\n // Handle role attribute\n if (this.features.roleAttribute && attributes.role) {\n const roleSubject = attributes.id\n ? this.util.createIri('#' + attributes.id, activeTag, false, false, false)\n : this.util.createBlankNode();\n // Temporarily override vocab\n const vocabOld = activeTag.vocab;\n activeTag.vocab = 'http://www.w3.org/1999/xhtml/vocab#';\n for (const role of this.util.createVocabIris(attributes.role, activeTag, true, false)) {\n this.emitTriple(\n roleSubject,\n this.util.dataFactory.namedNode('http://www.w3.org/1999/xhtml/vocab#role'),\n role,\n );\n }\n activeTag.vocab = vocabOld;\n }\n\n // 4: handle language\n // Save language attribute value in active tag\n if ('xml:lang' in attributes || (this.features.langAttribute && 'lang' in attributes)) {\n activeTag.language = attributes['xml:lang'] || attributes.lang;\n } else {\n activeTag.language = parentTag.language;\n }\n\n const isRootTag: boolean = this.activeTagStack.length === 2;\n if (!('rel' in attributes) && !('rev' in attributes)) {\n // 5: Determine the new subject when rel and rev are not present\n if ('property' in attributes && !('content' in attributes) && !('datatype' in attributes)) {\n // 5.1: property is present, but not content and datatype\n // Determine new subject\n if ('about' in attributes) {\n newSubject = this.util.createIri(attributes.about, activeTag, false, true, true);\n activeTag.explicitNewSubject = !!newSubject;\n } else if (isRootTag) {\n newSubject = true;\n } else if (parentTag.object) {\n newSubject = parentTag.object;\n }\n\n // Determine type\n if ('typeof' in attributes) {\n if ('about' in attributes) {\n typedResource = this.util.createIri(attributes.about, activeTag, false, true, true);\n }\n if (!typedResource && isRootTag) {\n typedResource = true;\n }\n if (!typedResource && 'resource' in attributes) {\n typedResource = this.util.createIri(attributes.resource, activeTag, false, true, true);\n }\n if (!typedResource && ('href' in attributes || 'src' in attributes)) {\n typedResource = this.util.createIri(attributes.href || attributes.src, activeTag, false, false, true);\n }\n if (!typedResource && this.isInheritSubjectInHeadBody(name)) {\n typedResource = newSubject;\n }\n if (!typedResource) {\n typedResource = this.util.createBlankNode();\n }\n\n currentObjectResource = typedResource;\n }\n } else {\n // 5.2\n if ('about' in attributes || 'resource' in attributes) {\n newSubject = this.util.createIri(attributes.about || attributes.resource, activeTag, false, true, true);\n activeTag.explicitNewSubject = !!newSubject;\n }\n if (!newSubject && ('href' in attributes || 'src' in attributes)) {\n newSubject = this.util.createIri(attributes.href || attributes.src,\n activeTag, false, false, true);\n activeTag.explicitNewSubject = !!newSubject;\n }\n if (!newSubject) {\n if (isRootTag) {\n newSubject = true;\n } else if (this.isInheritSubjectInHeadBody(name)) {\n newSubject = parentTag.object;\n } else if ('typeof' in attributes) {\n newSubject = this.util.createBlankNode();\n activeTag.explicitNewSubject = true;\n } else if (parentTag.object) {\n newSubject = parentTag.object;\n if (!('property' in attributes)) {\n activeTag.skipElement = true;\n }\n }\n }\n\n // Determine type\n if ('typeof' in attributes) {\n typedResource = newSubject;\n }\n }\n } else { // either rel or rev is present\n // 6: Determine the new subject when rel or rev are present\n\n // Define new subject\n if ('about' in attributes) {\n newSubject = this.util.createIri(attributes.about, activeTag, false, true, true);\n activeTag.explicitNewSubject = !!newSubject;\n if ('typeof' in attributes) {\n typedResource = newSubject;\n }\n } else if (isRootTag) {\n newSubject = true;\n } else if (parentTag.object) {\n newSubject = parentTag.object;\n }\n\n // Define object\n if ('resource' in attributes) {\n currentObjectResource = this.util.createIri(attributes.resource, activeTag, false, true, true);\n }\n if (!currentObjectResource) {\n if ('href' in attributes || 'src' in attributes) {\n currentObjectResource = this.util.createIri(attributes.href || attributes.src, activeTag, false, false, true);\n } else if ('typeof' in attributes && !('about' in attributes) && !this.isInheritSubjectInHeadBody(name)) {\n currentObjectResource = this.util.createBlankNode();\n }\n }\n\n // Set typed resource\n if ('typeof' in attributes && !('about' in attributes)) {\n if (this.isInheritSubjectInHeadBody(name)) {\n typedResource = newSubject;\n } else {\n typedResource = currentObjectResource;\n }\n }\n }\n\n // 7: If a typed resource was defined, emit it as a triple\n if (typedResource) {\n for (const type of this.util.createVocabIris(attributes.typeof, activeTag, true, true)) {\n this.emitTriple(\n this.util.getResourceOrBaseIri(typedResource, activeTag),\n this.util.dataFactory.namedNode(Util.RDF + 'type'),\n type,\n );\n }\n }\n\n // 8: Reset list mapping if we have a new subject\n if (newSubject) {\n activeTag.listMapping = {};\n }\n\n // 9: If an object was defined, emit triples for it\n if (currentObjectResource) {\n // Handle list mapping\n if ('rel' in attributes && 'inlist' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n this.addListMapping(activeTag, newSubject, predicate, currentObjectResource);\n }\n }\n\n // Determine predicates using rel or rev (unless rel and inlist are present)\n if (!('rel' in attributes && 'inlist' in attributes)) {\n if ('rel' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n this.emitTriple(\n this.util.getResourceOrBaseIri(newSubject, activeTag),\n predicate,\n this.util.getResourceOrBaseIri(currentObjectResource, activeTag),\n );\n }\n }\n if ('rev' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates,\n false)) {\n this.emitTriple(\n this.util.getResourceOrBaseIri(currentObjectResource, activeTag),\n predicate,\n this.util.getResourceOrBaseIri(newSubject, activeTag),\n );\n }\n }\n }\n }\n\n // 10: Store incomplete triples if we don't have an object, but we do have predicates\n if (!currentObjectResource) {\n if ('rel' in attributes) {\n if ('inlist' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n this.addListMapping(activeTag, newSubject, predicate, null);\n activeTag.incompleteTriples.push({ predicate, reverse: false, list: true });\n }\n } else {\n for (const predicate of this.util.createVocabIris(attributes.rel, activeTag, allowTermsInRelPredicates,\n false)) {\n activeTag.incompleteTriples.push({ predicate, reverse: false });\n }\n }\n }\n if ('rev' in attributes) {\n for (const predicate of this.util.createVocabIris(attributes.rev, activeTag, allowTermsInRevPredicates,\n false)) {\n activeTag.incompleteTriples.push({ predicate, reverse: true });\n }\n }\n\n // Set a blank node object, so the children can make use of this when completing the triples\n if (activeTag.incompleteTriples.length > 0) {\n currentObjectResource = this.util.createBlankNode();\n }\n }\n\n // 11: Determine current property value\n if ('property' in attributes) {\n // Create predicates\n activeTag.predicates = this.util.createVocabIris(attributes.property, activeTag, true, false);\n\n // Save datatype attribute value in active tag\n let localObjectResource: RDF.Term | boolean;\n if ('datatype' in attributes) {\n activeTag.datatype = <RDF.NamedNode> this.util.createIri(attributes.datatype, activeTag, true, true, false);\n if (activeTag.datatype\n && (activeTag.datatype.value === Util.RDF + 'XMLLiteral'\n || (this.features.htmlDatatype && activeTag.datatype.value === Util.RDF + 'HTML'))) {\n activeTag.collectChildTags = true;\n activeTag.collectChildTagsForCurrentTag = true;\n }\n } else {\n // Try to determine resource\n if (!('rev' in attributes) && !('rel' in attributes) && !('content' in attributes)) {\n if ('resource' in attributes) {\n localObjectResource = this.util.createIri(attributes.resource, activeTag, false, true, true);\n }\n if (!localObjectResource && 'href' in attributes) {\n localObjectResource = this.util.createIri(attributes.href, activeTag, false, false, true);\n }\n if (!localObjectResource && 'src' in attributes) {\n localObjectResource = this.util.createIri(attributes.src, activeTag, false, false, true);\n }\n }\n if ('typeof' in attributes && !('about' in attributes)) {\n localObjectResource = typedResource;\n }\n }\n\n // If we're in a parent tag that collects child tags,\n // and we find a tag that does NOT preserve tags,\n // we mark this tag (and children) to not preserve it.\n if (!('datatype' in attributes) || attributes.datatype === '') {\n activeTag.collectChildTagsForCurrentTag = false;\n }\n\n if ('content' in attributes) {\n // Emit triples based on content attribute has preference over text content\n const object = this.util.createLiteral(attributes.content, activeTag);\n if ('inlist' in attributes) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, newSubject, predicate, object);\n }\n } else {\n const subject = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Unset predicate to avoid text contents to produce new triples\n activeTag.predicates = null;\n } else if (this.features.datetimeAttribute && 'datetime' in attributes) {\n activeTag.interpretObjectAsTime = true;\n // Datetime attribute on time tag has preference over text content\n const object = this.util.createLiteral(attributes.datetime, activeTag);\n if ('inlist' in attributes) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, newSubject, predicate, object);\n }\n } else {\n const subject = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Unset predicate to avoid text contents to produce new triples\n activeTag.predicates = null;\n } else if (localObjectResource) {\n // Emit triples for all resource objects\n const object = this.util.getResourceOrBaseIri(localObjectResource, activeTag);\n if ('inlist' in attributes) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, newSubject, predicate, object);\n }\n } else {\n const subject = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Unset predicate to avoid text contents to produce new triples\n activeTag.predicates = null;\n }\n }\n\n // 12: Complete incomplete triples\n let incompleteTriplesCompleted = false;\n if (!activeTag.skipElement && newSubject && parentTag.incompleteTriples.length > 0) {\n incompleteTriplesCompleted = true;\n const subject = this.util.getResourceOrBaseIri(parentTag.subject, activeTag);\n const object = this.util.getResourceOrBaseIri(newSubject, activeTag);\n for (const incompleteTriple of parentTag.incompleteTriples) {\n if (!incompleteTriple.reverse) {\n if (incompleteTriple.list) {\n // Find the active tag that defined the list by going up the stack\n let firstInListTag = null;\n for (let i = this.activeTagStack.length - 1; i >= 0; i--) {\n if (this.activeTagStack[i].inlist) {\n firstInListTag = this.activeTagStack[i];\n break;\n }\n }\n // firstInListTag is guaranteed to be non-null\n this.addListMapping(firstInListTag, newSubject, incompleteTriple.predicate, object);\n } else {\n this.emitTriple(subject, incompleteTriple.predicate, object);\n }\n } else {\n this.emitTriple(object, incompleteTriple.predicate, subject);\n }\n }\n }\n if (!incompleteTriplesCompleted && parentTag.incompleteTriples.length > 0) {\n activeTag.incompleteTriples = activeTag.incompleteTriples.concat(parentTag.incompleteTriples);\n }\n\n // 13: Save evaluation context into active tag\n activeTag.subject = newSubject || parentTag.subject;\n activeTag.object = currentObjectResource || newSubject;\n }\n\n public onText(data: string) {\n const activeTag: IActiveTag = this.activeTagStack[this.activeTagStack.length - 1];\n\n // Collect text in pattern tag if needed\n if (this.features.copyRdfaPatterns && activeTag.collectedPatternTag) {\n activeTag.collectedPatternTag.text.push(data);\n return;\n }\n\n // Save the text inside the active tag\n if (!activeTag.textWithTags) {\n activeTag.textWithTags = [];\n }\n if (!activeTag.textWithoutTags) {\n activeTag.textWithoutTags = [];\n }\n activeTag.textWithTags.push(data);\n activeTag.textWithoutTags.push(data);\n }\n\n public onTagClose() {\n // Get the active tag\n const activeTag: IActiveTag = this.activeTagStack[this.activeTagStack.length - 1];\n const parentTag: IActiveTag = this.activeTagStack[this.activeTagStack.length - 2];\n\n if (!(activeTag.collectChildTags && parentTag.collectChildTags && this.features.skipHandlingXmlLiteralChildren)) {\n\n // If we detect a finalized rdfa:Pattern tag, store it\n if (this.features.copyRdfaPatterns && activeTag.collectedPatternTag\n && activeTag.collectedPatternTag.rootPattern) {\n const patternId = activeTag.collectedPatternTag.attributes.resource;\n\n // Remove resource and typeof attributes to avoid it being seen as a new pattern\n delete activeTag.collectedPatternTag.attributes.resource;\n delete activeTag.collectedPatternTag.attributes.typeof;\n\n // Store the pattern\n this.rdfaPatterns[patternId] = activeTag.collectedPatternTag;\n\n // Apply all pending copies for this pattern\n if (this.pendingRdfaPatternCopies[patternId]) {\n for (const tag of this.pendingRdfaPatternCopies[patternId]) {\n this.emitPatternCopy(tag, activeTag.collectedPatternTag, patternId);\n }\n delete this.pendingRdfaPatternCopies[patternId];\n }\n\n // Remove the active tag from the stack\n this.activeTagStack.pop();\n\n return;\n }\n\n // Emit all triples that were determined in the active tag\n if (activeTag.predicates) {\n const subject = this.util.getResourceOrBaseIri(activeTag.subject, activeTag);\n let textSegments: string[];\n if (!activeTag.collectChildTagsForCurrentTag) {\n textSegments = activeTag.textWithoutTags || [];\n } else {\n textSegments = activeTag.textWithTags || [];\n if (activeTag.collectChildTags && parentTag.collectChildTags) {\n // If we are inside an XMLLiteral child that also has RDFa content, ignore the tag name that was collected.\n textSegments = textSegments.slice(1);\n }\n }\n const object = this.util.createLiteral(textSegments.join(''), activeTag);\n if (activeTag.inlist) {\n for (const predicate of activeTag.predicates) {\n this.addListMapping(activeTag, subject, predicate, object);\n }\n } else {\n for (const predicate of activeTag.predicates) {\n this.emitTriple(subject, predicate, object);\n }\n }\n\n // Reset text, unless the parent is also collecting text\n if (!parentTag.predicates) {\n activeTag.textWithoutTags = null;\n activeTag.textWithTags = null;\n }\n }\n\n // 14: Handle local list mapping\n if (activeTag.object && Object.keys(activeTag.listMapping).length > 0) {\n const subject = this.util.getResourceOrBaseIri(activeTag.object, activeTag);\n for (const predicateValue in activeTag.listMapping) {\n const predicate = this.util.dataFactory.namedNode(predicateValue);\n const values = activeTag.listMapping[predicateValue];\n\n if (values.length > 0) {\n // Non-empty list, emit linked list of rdf:first and rdf:rest chains\n const bnodes = values.map(() => this.util.createBlankNode());\n for (let i = 0; i < values.length; i++) {\n const object = this.util.getResourceOrBaseIri(values[i], activeTag);\n this.emitTriple(bnodes[i], this.util.dataFactory.namedNode(Util.RDF + 'first'),\n object);\n this.emitTriple(bnodes[i], this.util.dataFactory.namedNode(Util.RDF + 'rest'),\n (i < values.length - 1) ? bnodes[i + 1] : this.util.dataFactory.namedNode(Util.RDF + 'nil'));\n }\n\n // Emit triple for the first linked list chain\n this.emitTriple(subject, predicate, bnodes[0]);\n } else {\n // Empty list, just emit rdf:nil\n this.emitTriple(subject, predicate, this.util.dataFactory.namedNode(Util.RDF + 'nil'));\n }\n }\n }\n\n }\n\n // Remove the active tag from the stack\n this.activeTagStack.pop();\n\n // Save the tag contents if needed\n if (activeTag.collectChildTags && activeTag.textWithTags) {\n activeTag.textWithTags.push(`</${activeTag.name}>`);\n }\n\n // If we still have text contents, try to append it to the parent tag\n if (activeTag.textWithTags && parentTag) {\n if (!parentTag.textWithTags) {\n parentTag.textWithTags = activeTag.textWithTags;\n } else {\n parentTag.textWithTags = parentTag.textWithTags.concat(activeTag.textWithTags);\n }\n }\n if (activeTag.textWithoutTags && parentTag) {\n if (!parentTag.textWithoutTags) {\n parentTag.textWithoutTags = activeTag.textWithoutTags;\n } else {\n parentTag.textWithoutTags = parentTag.textWithoutTags.concat(activeTag.textWithoutTags);\n }\n }\n }\n\n public onEnd() {\n if (this.features.copyRdfaPatterns) {\n this.features.copyRdfaPatterns = false;\n\n // Emit all unreferenced patterns\n for (const patternId in this.rdfaPatterns) {\n const pattern = this.rdfaPatterns[patternId];\n if (!pattern.referenced) {\n pattern.attributes.typeof = 'rdfa:Pattern';\n pattern.attributes.resource = patternId;\n this.emitPatternCopy(pattern.parentTag, pattern, patternId);\n pattern.referenced = false;\n delete pattern.attributes.typeof;\n delete pattern.attributes.resource;\n }\n }\n\n // Emit all unreferenced copy links\n for (const patternId in this.pendingRdfaPatternCopies) {\n for (const parentTag of this.pendingRdfaPatternCopies[patternId]) {\n this.activeTagStack.push(parentTag);\n this.onTagOpen('link', { property: 'rdfa:copy', href: patternId });\n this.onTagClose();\n this.activeTagStack.pop();\n }\n }\n\n this.features.copyRdfaPatterns = true;\n }\n }\n\n /**\n * If the new subject can be inherited from the parent object\n * if the resource defines no new subject.\n * @param {string} name The current tag name.\n * @returns {boolean} If the subject can be inherited.\n */\n protected isInheritSubjectInHeadBody(name: string) {\n return this.features.inheritSubjectInHeadBody && (name === 'head' || name === 'body');\n }\n\n /**\n * Add a list mapping for the given predicate and object in the active tag.\n * @param {IActiveTag} activeTag The active tag.\n * @param {Term | boolean} subject A subject term, this will only be used to create a separate list\n * if activeTag.explicitNewSubject is true.\n * @param {Term} predicate A predicate term.\n * @param {Term | boolean} currentObjectResource The current object resource.\n */\n protected addListMapping(activeTag: IActiveTag, subject: RDF.Quad_Subject | boolean, predicate: RDF.Quad_Predicate,\n currentObjectResource: RDF.Quad_Object | boolean) {\n if (activeTag.explicitNewSubject) {\n const bNode = this.util.createBlankNode();\n this.emitTriple(this.util.getResourceOrBaseIri(subject, activeTag), predicate, bNode);\n this.emitTriple(bNode, this.util.dataFactory.namedNode(Util.RDF + 'first'),\n this.util.getResourceOrBaseIri(currentObjectResource, activeTag));\n this.emitTriple(bNode, this.util.dataFactory.namedNode(Util.RDF + 'rest'),\n this.util.dataFactory.namedNode(Util.RDF + 'nil'));\n } else {\n let predicateList = activeTag.listMappingLocal[predicate.value];\n if (!predicateList) {\n activeTag.listMappingLocal[predicate.value] = predicateList = [];\n }\n if (currentObjectResource) {\n predicateList.push(currentObjectResource);\n }\n }\n }\n\n /**\n * Emit the given triple to the stream.\n * @param {Term} subject A subject term.\n * @param {Term} predicate A predicate term.\n * @param {Term} object An object term.\n */\n protected emitTriple(subject: RDF.Quad_Subject, predicate: RDF.Quad_Predicate, object: RDF.Quad_Object) {\n // Validate IRIs\n if ((subject.termType === 'NamedNode' && subject.value.indexOf(':') < 0)\n || (predicate.termType === 'NamedNode' && predicate.value.indexOf(':') < 0)\n || (object.termType === 'NamedNode' && object.value.indexOf(':') < 0)) {\n return;\n }\n this.push(this.util.dataFactory.quad(subject, predicate, object, this.defaultGraph));\n }\n\n /**\n * Emit an instantiation of the given pattern with the given parent tag.\n * @param {IActiveTag} parentTag The parent tag to instantiate in.\n * @param {IRdfaPattern} pattern The pattern to instantiate.\n * @param {string} rootPatternId The pattern id.\n */\n protected emitPatternCopy(parentTag: IActiveTag, pattern: IRdfaPattern, rootPatternId: string) {\n this.activeTagStack.push(parentTag);\n pattern.referenced = true;\n\n // Ensure that blank nodes within patterns are instantiated only once.\n // All next pattern copies will reuse the instantiated blank nodes from the first pattern.\n if (!pattern.constructedBlankNodes) {\n pattern.constructedBlankNodes = [];\n this.util.blankNodeFactory = () => {\n const bNode = this.util.dataFactory.blankNode();\n pattern.constructedBlankNodes.push(bNode);\n return bNode;\n };\n } else {\n let blankNodeIndex = 0;\n this.util.blankNodeFactory = () => pattern.constructedBlankNodes[blankNodeIndex++];\n }\n\n // Apply everything within the pattern\n this.emitPatternCopyAbsolute(pattern, true, rootPatternId);\n\n this.util.blankNodeFactory = null;\n this.activeTagStack.pop();\n }\n\n /**\n * Emit an instantiation of the given pattern with the given parent tag.\n *\n * This should probably not be called directly,\n * call {@link emitPatternCopy} instead.\n *\n * @param {IRdfaPattern} pattern The pattern to instantiate.\n * @param {boolean} root If this is the root call for the given pattern.\n * @param {string} rootPatternId The pattern id.\n */\n protected emitPatternCopyAbsolute(pattern: IRdfaPattern, root: boolean, rootPatternId: string) {\n // Stop on detection of cyclic patterns\n if (!root && pattern.attributes.property === 'rdfa:copy' && pattern.attributes.href === rootPatternId) {\n return;\n }\n\n this.onTagOpen(pattern.name, pattern.attributes);\n for (const text of pattern.text) {\n this.onText(text);\n }\n for (const child of pattern.children) {\n this.emitPatternCopyAbsolute(child, false, rootPatternId);\n }\n this.onTagClose();\n }\n\n protected initializeParser(xmlMode: boolean): HtmlParser {\n return new HtmlParser(\n <DomHandler> <any> {\n onclosetag: () => {\n try {\n this.onTagClose();\n if (this.htmlParseListener) {\n this.htmlParseListener.onTagClose();\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n onend: () => {\n try {\n this.onEnd();\n if (this.htmlParseListener) {\n this.htmlParseListener.onEnd();\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n onopentag: (name: string, attributes: {[s: string]: string}) => {\n try {\n this.onTagOpen(name, attributes);\n if (this.htmlParseListener) {\n this.htmlParseListener.onTagOpen(name, attributes);\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n ontext: (data: string) => {\n try {\n this.onText(data);\n if (this.htmlParseListener) {\n this.htmlParseListener.onText(data);\n }\n } catch (e) {\n this.emit('error', e);\n }\n },\n },\n {\n decodeEntities: true,\n recognizeSelfClosing: true,\n xmlMode,\n });\n }\n\n}\n\nexport interface IRdfaParserOptions {\n /**\n * A custom RDFJS DataFactory to construct terms and triples.\n */\n dataFactory?: RDF.DataFactory;\n /**\n * An initital default base IRI.\n */\n baseIRI?: string;\n /**\n * A default language for string literals.\n */\n language?: string;\n /**\n * The initial vocabulary.\n */\n vocab?: string;\n /**\n * The default graph for constructing quads.\n */\n defaultGraph?: RDF.Quad_Graph;\n /**\n * A hash of features that should be enabled.\n * Defaults to the features defined by the profile.\n */\n features?: IRdfaFeatures;\n /**\n * The RDFa profile to use.\n * Defaults to a profile with all possible features enabled.\n */\n profile?: RdfaProfile;\n /**\n * The content type of the document that should be parsed.\n * This can be used as an alternative to the 'profile' option.\n */\n contentType?: string;\n /**\n * An optional listener for the internal HTML parse events.\n */\n htmlParseListener?: IHtmlParseListener;\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * A type of RDFa profile
3
3
  */
4
- export declare type RdfaProfile = '' | // All possible RDFa features
4
+ export type RdfaProfile = '' | // All possible RDFa features
5
5
  'core' | // https://www.w3.org/TR/rdfa-core/
6
6
  'html' | // https://www.w3.org/TR/html-rdfa/
7
7
  'xhtml' | // https://www.w3.org/TR/xht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;IACzC,CAAC;;AAlRH,oBAoRC;AAlRwB,QAAG,GAAG,6CAA6C,CAAC;AACpD,QAAG,GAAG,mCAAmC,CAAC;AAC1C,SAAI,GAAG,4BAA4B,CAAC;AAEnC,iBAAY,GAAW,gCAAgC,CAAC;AACxD,iBAAY,GAAsC;IACxE;QACE,KAAK,EAAE,iFAAiF;QACxF,IAAI,EAAE,UAAU;KACjB;IACD;QACE,KAAK,EAAE,oGAAoG;QAC3G,IAAI,EAAE,UAAU;KACjB;IACD,EAAE,KAAK,EAAE,kCAAkC,EAAE,IAAI,EAAE,MAAM,EAAE;IAC3D,EAAE,KAAK,EAAE,uEAAuE,EAAE,IAAI,EAAE,MAAM,EAAE;IAChG,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE;IACpD,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE;CACrC,CAAC;AACsB,cAAS,GAAW,kDAAkD,CAAC","sourcesContent":["import * as RDF from \"@rdfjs/types\";\nimport {resolve} from \"relative-to-absolute-iri\";\nimport {IActiveTag} from \"./IActiveTag\";\nimport {RDFA_CONTENTTYPES, RdfaProfile} from \"./RdfaProfile\";\nimport {DataFactory} from \"rdf-data-factory\";\n\n/**\n * A collection of utility functions.\n */\nexport class Util {\n\n public static readonly RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';\n public static readonly XSD = 'http://www.w3.org/2001/XMLSchema#';\n public static readonly RDFA = 'http://www.w3.org/ns/rdfa#';\n\n private static readonly PREFIX_REGEX: RegExp = /\\s*([^:\\s]*)*:\\s*([^\\s]*)*\\s*/g;\n private static readonly TIME_REGEXES: { regex: RegExp, type: string }[] = [\n {\n regex: /^-?P([0-9]+Y)?([0-9]+M)?([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+(\\.[0-9])?S)?)?$/,\n type: 'duration',\n },\n {\n regex: /^[0-9]+-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]((Z?)|([\\+-][0-9][0-9]:[0-9][0-9]))$/,\n type: 'dateTime',\n },\n { regex: /^[0-9]+-[0-9][0-9]-[0-9][0-9]Z?$/, type: 'date' },\n { regex: /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]((Z?)|([\\+-][0-9][0-9]:[0-9][0-9]))$/, type: 'time' },\n { regex: /^[0-9]+-[0-9][0-9]$/, type: 'gYearMonth' },\n { regex: /^[0-9]+$/, type: 'gYear' },\n ];\n private static readonly IRI_REGEX: RegExp = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^ \"<>{}|\\\\\\[\\]`]*$/;\n\n public readonly dataFactory: RDF.DataFactory;\n public baseIRI: RDF.NamedNode;\n public blankNodeFactory: () => RDF.BlankNode;\n private readonly baseIRIDocument: RDF.NamedNode;\n\n constructor(dataFactory: RDF.DataFactory, baseIRI: string) {\n this.dataFactory = dataFactory || new DataFactory();\n this.baseIRI = this.dataFactory.namedNode(baseIRI || '');\n this.baseIRIDocument = this.baseIRI;\n }\n\n /**\n * Retrieve the prefixes of the current tag's attributes.\n * @param {{[p: string]: string}} attributes A tag's attributes.\n * @param {{[p: string]: string}} parentPrefixes The prefixes from the parent tag.\n * @param {boolean} xmlnsPrefixMappings If prefixes should be extracted from xmlnsPrefixMappings.\n * @return {{[p: string]: string}} The new prefixes.\n */\n public static parsePrefixes(attributes: {[s: string]: string},\n parentPrefixes: {[prefix: string]: string},\n xmlnsPrefixMappings: boolean): {[prefix: string]: string} {\n const additionalPrefixes: {[prefix: string]: string} = {};\n if (xmlnsPrefixMappings) {\n for (const attribute in attributes) {\n if (attribute.startsWith('xmlns')) {\n additionalPrefixes[attribute.substr(6)] = attributes[attribute];\n }\n }\n }\n\n if (attributes.prefix || Object.keys(additionalPrefixes).length > 0) {\n const prefixes: {[prefix: string]: string} = { ...parentPrefixes, ...additionalPrefixes };\n\n if (attributes.prefix) {\n let prefixMatch;\n // tslint:disable-next-line:no-conditional-assignment\n while (prefixMatch = Util.PREFIX_REGEX.exec(attributes.prefix)) {\n prefixes[prefixMatch[1]] = prefixMatch[2];\n }\n }\n\n return prefixes;\n } else {\n return parentPrefixes;\n }\n }\n\n /**\n * Expand the given term value based on the given prefixes.\n * @param {string} term A term value.\n * @param {{[p: string]: string}[]} prefixes The available prefixes.\n * @return {string} An expanded URL, or the term as-is.\n */\n public static expandPrefixedTerm(term: string, activeTag: IActiveTag): string {\n // Check if the term is prefixed\n const colonIndex: number = term.indexOf(':');\n let prefix: string;\n let local: string;\n if (colonIndex >= 0) {\n prefix = term.substr(0, colonIndex);\n local = term.substr(colonIndex + 1);\n }\n\n // Expand default namespace\n if (prefix === '') {\n return 'http://www.w3.org/1999/xhtml/vocab#' + local;\n }\n\n // Try to expand the prefix\n if (prefix) {\n const prefixElement = activeTag.prefixesAll[prefix];\n if (prefixElement) {\n return prefixElement + local;\n }\n }\n\n // Try to expand the term\n if (term) {\n const expandedTerm = activeTag.prefixesAll[term.toLocaleLowerCase()];\n if (expandedTerm) {\n return expandedTerm;\n }\n }\n\n return term;\n }\n\n /**\n * Check if the given IRI is valid.\n * @param {string} iri A potential IRI.\n * @return {boolean} If the given IRI is valid.\n */\n public static isValidIri(iri: string): boolean {\n return Util.IRI_REGEX.test(iri);\n }\n\n /**\n * Determine the RDFa profile from the given content type.\n * Defaults to the default RDFa profile (all features enabled) for unknown content types.\n * @param {string} contentType A content type.\n * @returns {RdfaProfile} An RDFa profile.\n */\n public static contentTypeToProfile(contentType: string): RdfaProfile {\n return RDFA_CONTENTTYPES[contentType] || '';\n }\n\n /**\n * Get the base IRI.\n * @param {string} baseIriValue A base IRI value.\n * @return A base IRI named node.\n */\n public getBaseIRI(baseIriValue: string): RDF.NamedNode {\n let href: string = baseIriValue;\n const fragmentIndex = href.indexOf('#');\n if (fragmentIndex >= 0) {\n href = href.substr(0, fragmentIndex);\n }\n return this.dataFactory.namedNode(resolve(href, this.baseIRI.value));\n }\n\n /**\n * If the term is a boolean, return the baseIRI, otherwise return the term as-is.\n * @param {Term | boolean} term A term or boolean, where the boolean indicates the baseIRI.\n * @param {IActiveTag} activeTag An active tag.\n * @returns {Term} A term.\n */\n public getResourceOrBaseIri(term: RDF.Term | boolean, activeTag: IActiveTag): RDF.NamedNode {\n return term === true ? this.getBaseIriTerm(activeTag) : <RDF.NamedNode> term;\n }\n\n /**\n * Get the active base IRI as an RDF term.\n * @param {IActiveTag} activeTag The active tag.\n * @return {NamedNode} The base IRI term.\n */\n public getBaseIriTerm(activeTag: IActiveTag): RDF.NamedNode {\n return activeTag.localBaseIRI || this.baseIRI;\n }\n\n /**\n * Create vocab terms for the given terms attribute.\n * @param {string} terms An attribute value.\n * @param {IActiveTag} activeTag The current active tag.\n * @param {boolean} allowTerms If terms are allowed (strings without ':')\n * @param {boolean} allowBlankNode If blank nodes are allowed.\n * @return {Term[]} The IRI terms.\n */\n public createVocabIris<B extends boolean>(terms: string, activeTag: IActiveTag, allowTerms: boolean,\n allowBlankNode: B): B extends true\n ? (RDF.BlankNode | RDF.NamedNode)[] : RDF.NamedNode[];\n public createVocabIris(terms: string, activeTag: IActiveTag, allowTerms: boolean,\n allowBlankNode: boolean): (RDF.NamedNode | RDF.BlankNode)[] {\n return terms.split(/\\s+/)\n .filter((term) => term && (allowTerms || term.indexOf(':') >= 0))\n .map((property) => this.createIri(property, activeTag, true, true, allowBlankNode))\n .filter((term) => term != null);\n }\n\n /**\n * Create a new literal node.\n * @param {string} literal The literal value.\n * @param {IActiveTag} activeTag The current active tag.\n * @return {Literal} A new literal node.\n */\n public createLiteral(literal: string, activeTag: IActiveTag): RDF.Literal {\n if (activeTag.interpretObjectAsTime && !activeTag.datatype) {\n for (const entry of Util.TIME_REGEXES) {\n if (literal.match(entry.regex)) {\n activeTag.datatype = this.dataFactory.namedNode(Util.XSD + entry.type);\n break;\n }\n }\n }\n return this.dataFactory.literal(literal, activeTag.datatype || activeTag.language);\n }\n\n /**\n * Create a blank node.\n * @returns {BlankNode} A new blank node.\n */\n public createBlankNode(): RDF.BlankNode {\n if (this.blankNodeFactory) {\n return this.blankNodeFactory();\n }\n return this.dataFactory.blankNode();\n }\n\n /**\n * Create a named node for the given term.\n * This will take care of prefix detection.\n * @param {string} term A term string (CURIE or IRI, aka safe-CURIE in RDFa spec).\n * @param {IActiveTag} activeTag The current active tag.\n * @param {boolean} vocab If creating an IRI in vocab-mode (based on vocab IRI),\n * or in base-mode (based on base IRI).\n * @param {boolean} allowSafeCurie If safe CURIEs are allowed\n * (invalid CURIEs between square brackets will return null)\n * Otherwise, only IRIs are allowed.\n * @param {boolean} allowBlankNode If blank nodes are allowed. Otherwise null will be returned.\n * @return {Term} An RDF term or null.\n */\n public createIri<B extends boolean>(term: string, activeTag: IActiveTag, vocab: boolean, allowSafeCurie: boolean,\n allowBlankNode: B): B extends true\n ? (RDF.NamedNode | RDF.BlankNode) : RDF.NamedNode;\n public createIri<B extends boolean>(term: string, activeTag: IActiveTag, vocab: boolean, allowSafeCurie: boolean,\n allowBlankNode: B): RDF.NamedNode | RDF.BlankNode {\n term = term || '';\n\n if (!allowSafeCurie) {\n if (!vocab) {\n term = resolve(term, this.getBaseIriTerm(activeTag).value);\n }\n if (!Util.isValidIri(term)) {\n return null;\n }\n return this.dataFactory.namedNode(term);\n }\n\n // Handle strict CURIEs\n if (term.length > 0 && term[0] === '[' && term[term.length - 1] === ']') {\n term = term.substr(1, term.length - 2);\n\n // Strict CURIEs MUST have a prefix separator\n if (term.indexOf(':') < 0) {\n return null;\n }\n }\n\n // Handle blank nodes\n if (term.startsWith('_:')) {\n return allowBlankNode ? this.dataFactory.blankNode(term.substr(2) || 'b_identity') : null;\n }\n\n // Handle vocab IRIs\n if (vocab) {\n if (activeTag.vocab && term.indexOf(':') < 0) {\n return this.dataFactory.namedNode(activeTag.vocab + term);\n }\n }\n\n // Handle prefixed IRIs\n let iri: string = Util.expandPrefixedTerm(term, activeTag);\n // Resolve against baseIRI if in base-mode, or if the term was a prefixed relative IRI\n if (!vocab) {\n iri = resolve(iri, this.getBaseIriTerm(activeTag).value);\n } else if (term !== iri) {\n iri = resolve(iri, this.baseIRIDocument.value);\n }\n if (!Util.isValidIri(iri)) {\n return null;\n }\n return this.dataFactory.namedNode(iri);\n }\n\n}\n"]}
1
+ {"version":3,"file":"Util.js","sourceRoot":"","sources":["Util.ts"],"names":[],"mappings":";;;AACA,uEAAiD;AAEjD,+CAA6D;AAC7D,uDAA6C;AAE7C;;GAEG;AACH,MAAa,IAAI;IA4Bf,YAAY,WAA4B,EAAE,OAAe;QACvD,IAAI,CAAC,WAAW,GAAG,WAAW,IAAI,IAAI,8BAAW,EAAE,CAAC;QACpD,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC;QACzD,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,OAAO,CAAC;IACtC,CAAC;IAED;;;;;;OAMG;IACI,MAAM,CAAC,aAAa,CAAC,UAAiC,EACjC,cAA0C,EAC1C,mBAA4B;QACtD,MAAM,kBAAkB,GAA+B,EAAE,CAAC;QAC1D,IAAI,mBAAmB,EAAE,CAAC;YACxB,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE,CAAC;gBACnC,IAAI,SAAS,CAAC,UAAU,CAAC,OAAO,CAAC,EAAE,CAAC;oBAClC,kBAAkB,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC;gBAClE,CAAC;YACH,CAAC;QACH,CAAC;QAED,IAAI,UAAU,CAAC,MAAM,IAAI,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YACpE,MAAM,QAAQ,mCAAoC,cAAc,GAAK,kBAAkB,CAAE,CAAC;YAE1F,IAAI,UAAU,CAAC,MAAM,EAAE,CAAC;gBACtB,IAAI,WAAW,CAAC;gBAChB,qDAAqD;gBACrD,OAAO,WAAW,GAAG,IAAI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I,CAAC,KAAK,EAAE,CAAC;YACX,GAAG,GAAG,IAAA,kCAAO,EAAC,GAAG,EAAE,IAAI,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3D,CAAC;aAAM,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACxB,GAAG,GAAG,IAAA,kCAAO,EAAC,GAAG,EAAE,IAAI,CAAC,eAAe,CAAC,KAAK,CAAC,CAAC;QACjD,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1B,OAAO,IAAI,CAAC;QACd,CAAC;QACD,OAAO,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;IACzC,CAAC;;AAlRH,oBAoRC;AAlRwB,QAAG,GAAG,6CAA6C,CAAC;AACpD,QAAG,GAAG,mCAAmC,CAAC;AAC1C,SAAI,GAAG,4BAA4B,CAAC;AAEnC,iBAAY,GAAW,gCAAgC,CAAC;AACxD,iBAAY,GAAsC;IACxE;QACE,KAAK,EAAE,iFAAiF;QACxF,IAAI,EAAE,UAAU;KACjB;IACD;QACE,KAAK,EAAE,oGAAoG;QAC3G,IAAI,EAAE,UAAU;KACjB;IACD,EAAE,KAAK,EAAE,kCAAkC,EAAE,IAAI,EAAE,MAAM,EAAE;IAC3D,EAAE,KAAK,EAAE,uEAAuE,EAAE,IAAI,EAAE,MAAM,EAAE;IAChG,EAAE,KAAK,EAAE,qBAAqB,EAAE,IAAI,EAAE,YAAY,EAAE;IACpD,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE;CACrC,CAAC;AACsB,cAAS,GAAW,kDAAkD,CAAC","sourcesContent":["import * as RDF from \"@rdfjs/types\";\nimport {resolve} from \"relative-to-absolute-iri\";\nimport {IActiveTag} from \"./IActiveTag\";\nimport {RDFA_CONTENTTYPES, RdfaProfile} from \"./RdfaProfile\";\nimport {DataFactory} from \"rdf-data-factory\";\n\n/**\n * A collection of utility functions.\n */\nexport class Util {\n\n public static readonly RDF = 'http://www.w3.org/1999/02/22-rdf-syntax-ns#';\n public static readonly XSD = 'http://www.w3.org/2001/XMLSchema#';\n public static readonly RDFA = 'http://www.w3.org/ns/rdfa#';\n\n private static readonly PREFIX_REGEX: RegExp = /\\s*([^:\\s]*)*:\\s*([^\\s]*)*\\s*/g;\n private static readonly TIME_REGEXES: { regex: RegExp, type: string }[] = [\n {\n regex: /^-?P([0-9]+Y)?([0-9]+M)?([0-9]+D)?(T([0-9]+H)?([0-9]+M)?([0-9]+(\\.[0-9])?S)?)?$/,\n type: 'duration',\n },\n {\n regex: /^[0-9]+-[0-9][0-9]-[0-9][0-9]T[0-9][0-9]:[0-9][0-9]:[0-9][0-9]((Z?)|([\\+-][0-9][0-9]:[0-9][0-9]))$/,\n type: 'dateTime',\n },\n { regex: /^[0-9]+-[0-9][0-9]-[0-9][0-9]Z?$/, type: 'date' },\n { regex: /^[0-9][0-9]:[0-9][0-9]:[0-9][0-9]((Z?)|([\\+-][0-9][0-9]:[0-9][0-9]))$/, type: 'time' },\n { regex: /^[0-9]+-[0-9][0-9]$/, type: 'gYearMonth' },\n { regex: /^[0-9]+$/, type: 'gYear' },\n ];\n private static readonly IRI_REGEX: RegExp = /^([A-Za-z][A-Za-z0-9+-.]*|_):[^ \"<>{}|\\\\\\[\\]`]*$/;\n\n public readonly dataFactory: RDF.DataFactory;\n public baseIRI: RDF.NamedNode;\n public blankNodeFactory: () => RDF.BlankNode;\n private readonly baseIRIDocument: RDF.NamedNode;\n\n constructor(dataFactory: RDF.DataFactory, baseIRI: string) {\n this.dataFactory = dataFactory || new DataFactory();\n this.baseIRI = this.dataFactory.namedNode(baseIRI || '');\n this.baseIRIDocument = this.baseIRI;\n }\n\n /**\n * Retrieve the prefixes of the current tag's attributes.\n * @param {{[p: string]: string}} attributes A tag's attributes.\n * @param {{[p: string]: string}} parentPrefixes The prefixes from the parent tag.\n * @param {boolean} xmlnsPrefixMappings If prefixes should be extracted from xmlnsPrefixMappings.\n * @return {{[p: string]: string}} The new prefixes.\n */\n public static parsePrefixes(attributes: {[s: string]: string},\n parentPrefixes: {[prefix: string]: string},\n xmlnsPrefixMappings: boolean): {[prefix: string]: string} {\n const additionalPrefixes: {[prefix: string]: string} = {};\n if (xmlnsPrefixMappings) {\n for (const attribute in attributes) {\n if (attribute.startsWith('xmlns')) {\n additionalPrefixes[attribute.substr(6)] = attributes[attribute];\n }\n }\n }\n\n if (attributes.prefix || Object.keys(additionalPrefixes).length > 0) {\n const prefixes: {[prefix: string]: string} = { ...parentPrefixes, ...additionalPrefixes };\n\n if (attributes.prefix) {\n let prefixMatch;\n // tslint:disable-next-line:no-conditional-assignment\n while (prefixMatch = Util.PREFIX_REGEX.exec(attributes.prefix)) {\n prefixes[prefixMatch[1]] = prefixMatch[2];\n }\n }\n\n return prefixes;\n } else {\n return parentPrefixes;\n }\n }\n\n /**\n * Expand the given term value based on the given prefixes.\n * @param {string} term A term value.\n * @param {{[p: string]: string}[]} prefixes The available prefixes.\n * @return {string} An expanded URL, or the term as-is.\n */\n public static expandPrefixedTerm(term: string, activeTag: IActiveTag): string {\n // Check if the term is prefixed\n const colonIndex: number = term.indexOf(':');\n let prefix: string;\n let local: string;\n if (colonIndex >= 0) {\n prefix = term.substr(0, colonIndex);\n local = term.substr(colonIndex + 1);\n }\n\n // Expand default namespace\n if (prefix === '') {\n return 'http://www.w3.org/1999/xhtml/vocab#' + local;\n }\n\n // Try to expand the prefix\n if (prefix) {\n const prefixElement = activeTag.prefixesAll[prefix];\n if (prefixElement) {\n return prefixElement + local;\n }\n }\n\n // Try to expand the term\n if (term) {\n const expandedTerm = activeTag.prefixesAll[term.toLocaleLowerCase()];\n if (expandedTerm) {\n return expandedTerm;\n }\n }\n\n return term;\n }\n\n /**\n * Check if the given IRI is valid.\n * @param {string} iri A potential IRI.\n * @return {boolean} If the given IRI is valid.\n */\n public static isValidIri(iri: string): boolean {\n return Util.IRI_REGEX.test(iri);\n }\n\n /**\n * Determine the RDFa profile from the given content type.\n * Defaults to the default RDFa profile (all features enabled) for unknown content types.\n * @param {string} contentType A content type.\n * @returns {RdfaProfile} An RDFa profile.\n */\n public static contentTypeToProfile(contentType: string): RdfaProfile {\n return RDFA_CONTENTTYPES[contentType] || '';\n }\n\n /**\n * Get the base IRI.\n * @param {string} baseIriValue A base IRI value.\n * @return A base IRI named node.\n */\n public getBaseIRI(baseIriValue: string): RDF.NamedNode {\n let href: string = baseIriValue;\n const fragmentIndex = href.indexOf('#');\n if (fragmentIndex >= 0) {\n href = href.substr(0, fragmentIndex);\n }\n return this.dataFactory.namedNode(resolve(href, this.baseIRI.value));\n }\n\n /**\n * If the term is a boolean, return the baseIRI, otherwise return the term as-is.\n * @param {Term | boolean} term A term or boolean, where the boolean indicates the baseIRI.\n * @param {IActiveTag} activeTag An active tag.\n * @returns {Term} A term.\n */\n public getResourceOrBaseIri(term: RDF.Term | boolean, activeTag: IActiveTag): RDF.NamedNode {\n return term === true ? this.getBaseIriTerm(activeTag) : <RDF.NamedNode> term;\n }\n\n /**\n * Get the active base IRI as an RDF term.\n * @param {IActiveTag} activeTag The active tag.\n * @return {NamedNode} The base IRI term.\n */\n public getBaseIriTerm(activeTag: IActiveTag): RDF.NamedNode {\n return activeTag.localBaseIRI || this.baseIRI;\n }\n\n /**\n * Create vocab terms for the given terms attribute.\n * @param {string} terms An attribute value.\n * @param {IActiveTag} activeTag The current active tag.\n * @param {boolean} allowTerms If terms are allowed (strings without ':')\n * @param {boolean} allowBlankNode If blank nodes are allowed.\n * @return {Term[]} The IRI terms.\n */\n public createVocabIris<B extends boolean>(terms: string, activeTag: IActiveTag, allowTerms: boolean,\n allowBlankNode: B): B extends true\n ? (RDF.BlankNode | RDF.NamedNode)[] : RDF.NamedNode[];\n public createVocabIris(terms: string, activeTag: IActiveTag, allowTerms: boolean,\n allowBlankNode: boolean): (RDF.NamedNode | RDF.BlankNode)[] {\n return terms.split(/\\s+/)\n .filter((term) => term && (allowTerms || term.indexOf(':') >= 0))\n .map((property) => this.createIri(property, activeTag, true, true, allowBlankNode))\n .filter((term) => term != null);\n }\n\n /**\n * Create a new literal node.\n * @param {string} literal The literal value.\n * @param {IActiveTag} activeTag The current active tag.\n * @return {Literal} A new literal node.\n */\n public createLiteral(literal: string, activeTag: IActiveTag): RDF.Literal {\n if (activeTag.interpretObjectAsTime && !activeTag.datatype) {\n for (const entry of Util.TIME_REGEXES) {\n if (literal.match(entry.regex)) {\n activeTag.datatype = this.dataFactory.namedNode(Util.XSD + entry.type);\n break;\n }\n }\n }\n return this.dataFactory.literal(literal, activeTag.datatype || activeTag.language);\n }\n\n /**\n * Create a blank node.\n * @returns {BlankNode} A new blank node.\n */\n public createBlankNode(): RDF.BlankNode {\n if (this.blankNodeFactory) {\n return this.blankNodeFactory();\n }\n return this.dataFactory.blankNode();\n }\n\n /**\n * Create a named node for the given term.\n * This will take care of prefix detection.\n * @param {string} term A term string (CURIE or IRI, aka safe-CURIE in RDFa spec).\n * @param {IActiveTag} activeTag The current active tag.\n * @param {boolean} vocab If creating an IRI in vocab-mode (based on vocab IRI),\n * or in base-mode (based on base IRI).\n * @param {boolean} allowSafeCurie If safe CURIEs are allowed\n * (invalid CURIEs between square brackets will return null)\n * Otherwise, only IRIs are allowed.\n * @param {boolean} allowBlankNode If blank nodes are allowed. Otherwise null will be returned.\n * @return {Term} An RDF term or null.\n */\n public createIri<B extends boolean>(term: string, activeTag: IActiveTag, vocab: boolean, allowSafeCurie: boolean,\n allowBlankNode: B): B extends true\n ? (RDF.NamedNode | RDF.BlankNode) : RDF.NamedNode;\n public createIri<B extends boolean>(term: string, activeTag: IActiveTag, vocab: boolean, allowSafeCurie: boolean,\n allowBlankNode: B): RDF.NamedNode | RDF.BlankNode {\n term = term || '';\n\n if (!allowSafeCurie) {\n if (!vocab) {\n term = resolve(term, this.getBaseIriTerm(activeTag).value);\n }\n if (!Util.isValidIri(term)) {\n return null;\n }\n return this.dataFactory.namedNode(term);\n }\n\n // Handle strict CURIEs\n if (term.length > 0 && term[0] === '[' && term[term.length - 1] === ']') {\n term = term.substr(1, term.length - 2);\n\n // Strict CURIEs MUST have a prefix separator\n if (term.indexOf(':') < 0) {\n return null;\n }\n }\n\n // Handle blank nodes\n if (term.startsWith('_:')) {\n return allowBlankNode ? this.dataFactory.blankNode(term.substr(2) || 'b_identity') : null;\n }\n\n // Handle vocab IRIs\n if (vocab) {\n if (activeTag.vocab && term.indexOf(':') < 0) {\n return this.dataFactory.namedNode(activeTag.vocab + term);\n }\n }\n\n // Handle prefixed IRIs\n let iri: string = Util.expandPrefixedTerm(term, activeTag);\n // Resolve against baseIRI if in base-mode, or if the term was a prefixed relative IRI\n if (!vocab) {\n iri = resolve(iri, this.getBaseIriTerm(activeTag).value);\n } else if (term !== iri) {\n iri = resolve(iri, this.baseIRIDocument.value);\n }\n if (!Util.isValidIri(iri)) {\n return null;\n }\n return this.dataFactory.namedNode(iri);\n }\n\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rdfa-streaming-parser",
3
- "version": "2.0.1",
3
+ "version": "3.0.1",
4
4
  "description": "A fast and lightweight streaming RDFa parser",
5
5
  "keywords": [
6
6
  "rdfa",
@@ -15,6 +15,10 @@
15
15
  "typings": "index",
16
16
  "repository": "git@github.com:rubensworks/rdfa-streaming-parser.js.git",
17
17
  "author": "Ruben Taelman <rubensworks@gmail.com>",
18
+ "funding": {
19
+ "type": "individual",
20
+ "url": "https://github.com/sponsors/rubensworks/"
21
+ },
18
22
  "bugs": {
19
23
  "url": "https://github.com/rubensworks/rdfa-streaming-parser.js/issues"
20
24
  },
@@ -30,9 +34,8 @@
30
34
  "index.js"
31
35
  ],
32
36
  "dependencies": {
33
- "@rdfjs/types": "*",
34
- "htmlparser2": "^8.0.0",
35
- "rdf-data-factory": "^1.1.0",
37
+ "htmlparser2": "^9.0.0",
38
+ "rdf-data-factory": "^2.0.0",
36
39
  "relative-to-absolute-iri": "^1.0.2",
37
40
  "readable-stream": "^4.0.0"
38
41
  },
@@ -44,22 +47,22 @@
44
47
  "devDependencies": {
45
48
  "@types/jest": "^28.0.0",
46
49
  "@types/jest-each": "^24.3.0",
47
- "@types/readable-stream": "^2.3.14",
50
+ "@types/readable-stream": "^4.0.0",
48
51
  "arrayify-stream": "^2.0.0",
49
52
  "coveralls": "^3.0.0",
50
53
  "jest": "^28.0.0",
51
54
  "jest-each": "^28.0.0",
52
- "jest-rdf": "^1.7.0",
55
+ "jest-rdf": "^2.0.0",
53
56
  "manual-git-changelog": "^1.0.1",
54
57
  "pre-commit": "^1.2.2",
55
- "rdf-quad": "^1.5.0",
58
+ "rdf-quad": "^2.0.0",
56
59
  "rdf-test-suite": "^1.13.4",
57
60
  "streamify-string": "^1.0.1",
58
61
  "ts-jest": "^28.0.0",
59
62
  "ts-loader": "^9.3.1",
60
63
  "tslint": "^6.0.0",
61
64
  "tslint-eslint-rules": "^5.3.1",
62
- "typescript": "^4.0.0",
65
+ "typescript": "^5.7.2",
63
66
  "webpack": "^5.73.0",
64
67
  "webpack-cli": "^4.10.0"
65
68
  },
@@ -129,5 +132,6 @@
129
132
  "spec-1-xml-earl": "rdf-test-suite spec/parser.js http://rdfa.info/test-suite/test-cases/rdfa1.0/xml/manifest.ttl -i '{ \"profile\": \"xml\" }' -c .rdf-test-suite-cache/ -o earl -p spec/earl-meta.json > spec/earl-1-rdfastreamingparser-xml.ttl",
130
133
  "spec-clean": "rm -r .rdf-test-suite-cache/"
131
134
  },
132
- "sideEffects": false
135
+ "sideEffects": false,
136
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
133
137
  }