Add more content type files
This commit is contained in:
@ -46,6 +46,7 @@ export class Compiler {
|
||||
const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer));
|
||||
const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships));
|
||||
const xmlFooterRelationships = xml(this.formatter.format(this.file.Footer.Relationships));
|
||||
const xmlContentTypes = xml(this.formatter.format(this.file.ContentTypes));
|
||||
|
||||
this.archive.append(xmlDocument, {
|
||||
name: "word/document.xml",
|
||||
@ -83,6 +84,10 @@ export class Compiler {
|
||||
name: "word/_rels/footer1.xml.rels",
|
||||
});
|
||||
|
||||
this.archive.append(xmlContentTypes, {
|
||||
name: "[Content_Types].xml",
|
||||
});
|
||||
|
||||
for (const data of this.file.Media.array) {
|
||||
this.archive.append(data.stream, {
|
||||
name: `word/media/${data.fileName}`,
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { ContentTypeAttributes } from "./content-types-attributes";
|
||||
import { Default } from "./default/default";
|
||||
|
||||
export class ContentTypes extends XmlComponent {
|
||||
constructor() {
|
||||
@ -10,5 +11,22 @@ export class ContentTypes extends XmlComponent {
|
||||
xmlns: "http://schemas.openxmlformats.org/package/2006/content-types",
|
||||
}),
|
||||
);
|
||||
|
||||
this.root.push(new Default("image/png", "png"));
|
||||
this.root.push(new Default("image/jpeg", "jpeg"));
|
||||
this.root.push(new Default("image/jpeg", "jpg"));
|
||||
this.root.push(new Default("image/bmp", "bmp"));
|
||||
this.root.push(new Default("image/gif", "gif"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-package.relationships+xml", "rels"));
|
||||
this.root.push(new Default("application/xml", "xml"));
|
||||
|
||||
this.root.push(new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.document.main+xml", undefined, "/word/document.xml"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.header+xml", undefined, "/word/header1.xml"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.footer+xml", undefined, "/word/footer1.xml"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.styles+xml", undefined, "/word/styles.xml"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-package.core-properties+xml", undefined, "/docProps/core.xml"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-officedocument.extended-properties+xml", undefined, "/docProps/app.xml"));
|
||||
this.root.push(new Default("application/vnd.openxmlformats-officedocument.wordprocessingml.numbering+xml", undefined, "/word/numbering.xml"));
|
||||
|
||||
}
|
||||
}
|
||||
|
15
src/file/content-types/default/default-attributes.ts
Normal file
15
src/file/content-types/default/default-attributes.ts
Normal file
@ -0,0 +1,15 @@
|
||||
import { XmlAttributeComponent } from "file/xml-components";
|
||||
|
||||
export interface IDefaultAttributes {
|
||||
contentType: string;
|
||||
extension?: string;
|
||||
partName?: string;
|
||||
}
|
||||
|
||||
export class DefaultAttributes extends XmlAttributeComponent<IDefaultAttributes> {
|
||||
protected xmlKeys = {
|
||||
contentType: "ContentType",
|
||||
extension: "Extension",
|
||||
partName: "PartName",
|
||||
};
|
||||
}
|
@ -1,9 +1,16 @@
|
||||
import { XmlComponent } from "file/xml-components";
|
||||
import { DefaultAttributes } from "./default-attributes";
|
||||
|
||||
export class Default extends XmlComponent {
|
||||
constructor() {
|
||||
super("Types");
|
||||
constructor(contentType: string, extension?: string, partName?: string) {
|
||||
super("Default");
|
||||
|
||||
this.root.push();
|
||||
this.root.push(
|
||||
new DefaultAttributes({
|
||||
contentType: contentType,
|
||||
extension: extension,
|
||||
partName: partName,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
import { ContentTypes } from "./content-types/content-types";
|
||||
import { Document } from "./document";
|
||||
import { SectionPropertiesOptions } from "./document/body/section-properties/section-properties";
|
||||
import { FooterWrapper } from "./footer-wrapper";
|
||||
@ -20,6 +21,7 @@ export class File {
|
||||
private readonly relationships: Relationships;
|
||||
private readonly headerWrapper: HeaderWrapper;
|
||||
private readonly footerWrapper: FooterWrapper;
|
||||
private readonly contentTypes: ContentTypes;
|
||||
|
||||
constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) {
|
||||
this.document = new Document(sectionPropertiesOptions);
|
||||
@ -40,6 +42,7 @@ export class File {
|
||||
this.media = new Media();
|
||||
this.headerWrapper = new HeaderWrapper(this.media);
|
||||
this.footerWrapper = new FooterWrapper(this.media);
|
||||
this.contentTypes = new ContentTypes();
|
||||
}
|
||||
|
||||
public addParagraph(paragraph: Paragraph): void {
|
||||
@ -99,4 +102,8 @@ export class File {
|
||||
public get Footer(): FooterWrapper {
|
||||
return this.footerWrapper;
|
||||
}
|
||||
|
||||
public get ContentTypes(): ContentTypes {
|
||||
return this.contentTypes;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user