UNPKG

@difftim/excelize

Version:

Excel Workbook Manager - Read and Write xlsx and csv Files.

85 lines (74 loc) 1.84 kB
const BaseXform = require('../../base-xform'); const ARXform = require('./a-r-xform'); class APXform extends BaseXform { constructor() { super(); this.map = { 'a:r': new ARXform(), }; } get tag() { return 'a:p'; } render(xmlStream, model) { xmlStream.openNode(this.tag); this.map['a:r'].render(xmlStream, model); xmlStream.closeNode(); } parseOpen(node) { if (this.parser) { this.parser.parseOpen(node); return true; } switch (node.name) { case this.tag: this.reset(); break; case 'a:r': // console.log('titleparserrrr-a:r', this.map[node.name]); // this.model = { // title: this.model.title ? `${this.model.title}${this.parser.model}` : this.parser.model, // }; this.parser = this.map[node.name]; if (this.parser) { this.parser.parseOpen(node); } break; default: this.parser = this.map[node.name]; if (this.parser) { this.parser.parseOpen(node); } break; } return true; } parseText(text) { if (this.parser) { this.parser.parseText(text); } } parseClose(name) { if (this.parser) { if (!this.parser.parseClose(name)) { this.parser = undefined; } // 可能标题是分段的 多个<a:t>标题</a:t><a:t>--标题</a:t> if (name === 'a:r') { this.title = this.title ? `${this.title}${this.map['a:r'].model.title || ''}` : this.map['a:r'].model.title; } return true; } switch (name) { case this.tag: // this.model = this.map['a:r'].model; this.model = { title: this.title, }; return false; default: return true; } } } module.exports = APXform;