mirror of
https://github.com/jzillmann/pdf-to-markdown.git
synced 2025-02-28 15:44:52 +01:00
37 lines
1006 B
JavaScript
37 lines
1006 B
JavaScript
import PageItem from './PageItem.jsx'
|
|
import LineItem from './LineItem.jsx'
|
|
|
|
// A block of LineItem[] within a Page
|
|
export default class LineItemBlock extends PageItem {
|
|
|
|
constructor(options) {
|
|
super(options);
|
|
this.items = [];
|
|
if (options.items) {
|
|
options.items.forEach(item => this.addItem(item));
|
|
}
|
|
}
|
|
|
|
addItem(item:LineItem) {
|
|
if (this.type && item.type && this.type !== item.type) {
|
|
throw `Adding item of type ${item.type} to block of type ${this.type}`
|
|
}
|
|
if (!this.type) {
|
|
this.type = item.type;
|
|
}
|
|
if (item.parsedElements) {
|
|
if (this.parsedElements) {
|
|
this.parsedElements.add(item.parsedElements);
|
|
} else {
|
|
this.parsedElements = item.parsedElements;
|
|
}
|
|
}
|
|
const copiedItem = new LineItem({
|
|
...item
|
|
});
|
|
copiedItem.type = null;
|
|
this.items.push(copiedItem);
|
|
}
|
|
|
|
}
|