Skip to main content
Module

x/docxml/mod.ts>default

TypeScript (component) library for building and parsing a DOCX file
Go to Latest
class default
import { default } from "https://deno.land/x/docxml@5.9.0/mod.ts";

Represents the DOCX file as a whole, and collates other responsibilities together. Provides access to DOCX content types (ContentTypesXml), relationships (RelationshipsXml), the document itself (DocumentXml).

An instance of this class can access other classes that represent the various XML files in a DOCX archive, such as ContentTypes.xml, word/document.xml, and _rels/.rels.

Constructors

new
protected
default(
contentTypes?,
relationships?,
rules?: GenericRenderer<RuleResult, { document: DocumentXml; } & PropsGeneric> | null,
)

Type Parameters

optional
PropsGeneric extends { [key: string]: unknown; } = { [key: string]: never; }

Properties

readonly
bookmarks: Bookmarks
readonly
contentTypes: ContentTypesXml

The utility function dealing with the XML for recording content types. Every DOCX file has exactly one of these.

readonly
customProperties: CustomPropertiesXml

The API representing "docProps/custom.xml"

readonly
document: DocumentXml

A short-cut to the relationship that represents visible document content.

readonly
jsx

The JSX pragma.

readonly
relationships: RelationshipsXml

The utility function dealing with the top-level XML file for recording relationships. Other relationships may have their own relationship XMLs.

Methods

private
withXmlRules(renderer: GenericRenderer<RuleResult, { document: DocumentXml; } & PropsGeneric>): this

Add all the XML translatiom rules from another set of translation rules. Useful for cloning.

Clone some reusable configuration to a new instance of Docx:

  • XML rendering rules
  • Settings
  • Default content types
  • Custom styles

Does not clone other things, like:

  • Not content
  • Not content type overrides
  • Not relationships (unless required for settings)
  • Not anything else either
toArchive(): Promise<Archive>

Create a ZIP archive, which is the handler for .docx files as a ZIP archive.

toFile(location: string): Promise<void>

Convenience method to create a DOCX archive from the current document and write it to your disk.

withSettings(settingOverrides: Partial<SettingsI>): this

A convenience method to set a few settings for the document.

withXml(dom: string | Document, props: PropsGeneric): this

Set the document contents to the provided XML, transformed using the rules previously registered through Docx.withXmlRule.

withXmlRule(xPathTest: string, transformer: Parameters<GenericRenderer<RuleResult, { document: DocumentXml; } & PropsGeneric>["add"]>[1]): this

Add an XML translation rule, applied to an element that matches the given XPath test.

If an element matches multiple rules, the rule with the most specific XPath test wins.

Static Properties

readonly
deprecated
jsx

The JSX pragma.

Static Methods

fromArchive<PropsGeneric extends { [key: string]: unknown; } = { [key: string]: never; }>(archive: Archive): Promise<Docx<PropsGeneric>>

Instantiate this class by giving it a .docx file if it is already loaded as a Archive instance.

fromArchive<PropsGeneric extends { [key: string]: unknown; } = { [key: string]: never; }>(data: Uint8Array): Promise<Docx<PropsGeneric>>

Instantiate this class by giving it a .docx file loaded as a byte array.

fromArchive<PropsGeneric extends { [key: string]: unknown; } = { [key: string]: never; }>(location: string): Promise<Docx<PropsGeneric>>

Instantiate this class by pointing at a .docx file location.

fromJsx(roots: DocumentChild[] | Promise<DocumentChild[]>)

Create a new DOCX with contents composed by this library's components. Needs a single JSX component as root, for example <Section> or <Paragragh>.

fromNothing<PropsGeneric extends { [key: string]: unknown; } = { [key: string]: never; }>()

Create an empty DOCX, and populate it with the minimum viable contents to appease MS Word.