Add more content type files

This commit is contained in:
Dolan Miu
2018-02-03 20:56:20 +00:00
parent cfd3505414
commit 69707a7207
5 changed files with 55 additions and 3 deletions

View File

@ -46,6 +46,7 @@ export class Compiler {
const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer)); const xmlFooter = xml(this.formatter.format(this.file.Footer.Footer));
const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships)); const xmlHeaderRelationships = xml(this.formatter.format(this.file.Header.Relationships));
const xmlFooterRelationships = xml(this.formatter.format(this.file.Footer.Relationships)); const xmlFooterRelationships = xml(this.formatter.format(this.file.Footer.Relationships));
const xmlContentTypes = xml(this.formatter.format(this.file.ContentTypes));
this.archive.append(xmlDocument, { this.archive.append(xmlDocument, {
name: "word/document.xml", name: "word/document.xml",
@ -83,6 +84,10 @@ export class Compiler {
name: "word/_rels/footer1.xml.rels", name: "word/_rels/footer1.xml.rels",
}); });
this.archive.append(xmlContentTypes, {
name: "[Content_Types].xml",
});
for (const data of this.file.Media.array) { for (const data of this.file.Media.array) {
this.archive.append(data.stream, { this.archive.append(data.stream, {
name: `word/media/${data.fileName}`, name: `word/media/${data.fileName}`,

View File

@ -1,5 +1,6 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { ContentTypeAttributes } from "./content-types-attributes"; import { ContentTypeAttributes } from "./content-types-attributes";
import { Default } from "./default/default";
export class ContentTypes extends XmlComponent { export class ContentTypes extends XmlComponent {
constructor() { constructor() {
@ -10,5 +11,22 @@ export class ContentTypes extends XmlComponent {
xmlns: "http://schemas.openxmlformats.org/package/2006/content-types", 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"));
} }
} }

View 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",
};
}

View File

@ -1,9 +1,16 @@
import { XmlComponent } from "file/xml-components"; import { XmlComponent } from "file/xml-components";
import { DefaultAttributes } from "./default-attributes";
export class Default extends XmlComponent { export class Default extends XmlComponent {
constructor() { constructor(contentType: string, extension?: string, partName?: string) {
super("Types"); super("Default");
this.root.push(); this.root.push(
new DefaultAttributes({
contentType: contentType,
extension: extension,
partName: partName,
}),
);
} }
} }

View File

@ -1,3 +1,4 @@
import { ContentTypes } from "./content-types/content-types";
import { Document } from "./document"; import { Document } from "./document";
import { SectionPropertiesOptions } from "./document/body/section-properties/section-properties"; import { SectionPropertiesOptions } from "./document/body/section-properties/section-properties";
import { FooterWrapper } from "./footer-wrapper"; import { FooterWrapper } from "./footer-wrapper";
@ -20,6 +21,7 @@ export class File {
private readonly relationships: Relationships; private readonly relationships: Relationships;
private readonly headerWrapper: HeaderWrapper; private readonly headerWrapper: HeaderWrapper;
private readonly footerWrapper: FooterWrapper; private readonly footerWrapper: FooterWrapper;
private readonly contentTypes: ContentTypes;
constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) { constructor(options?: IPropertiesOptions, sectionPropertiesOptions?: SectionPropertiesOptions) {
this.document = new Document(sectionPropertiesOptions); this.document = new Document(sectionPropertiesOptions);
@ -40,6 +42,7 @@ export class File {
this.media = new Media(); this.media = new Media();
this.headerWrapper = new HeaderWrapper(this.media); this.headerWrapper = new HeaderWrapper(this.media);
this.footerWrapper = new FooterWrapper(this.media); this.footerWrapper = new FooterWrapper(this.media);
this.contentTypes = new ContentTypes();
} }
public addParagraph(paragraph: Paragraph): void { public addParagraph(paragraph: Paragraph): void {
@ -99,4 +102,8 @@ export class File {
public get Footer(): FooterWrapper { public get Footer(): FooterWrapper {
return this.footerWrapper; return this.footerWrapper;
} }
public get ContentTypes(): ContentTypes {
return this.contentTypes;
}
} }