Skip to main content
Module

x/docxml/mod.ts>default

An experimental Deno tool to transform XML to DOCX with a little XPath- and component based configuration
Go to Latest
class default
import { default } from "https://deno.land/x/docxml@3.1.1/mod.ts";

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

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: OfficeDocument; } & PropsGeneric> | null,
)

Type Parameters

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

Properties

readonly
contentTypes: ContentTypes

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

readonly
document

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

readonly
jsx

The JSX pragma.

readonly
relationships: Relationships

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

Methods

clone(): Promise<Docx<PropsGeneric>>

Clone a new instance of Docx including all existing relationships, media, and XML transformation rules.

forDom(dom: Document, props: PropsGeneric)
forXml(xml: string, props: PropsGeneric)
toArchive(): Archive

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

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

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; }>(location: string): Promise<Docx<PropsGeneric>>

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

fromJsx(roots: OfficeDocumentChild[])

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.