diff --git a/CHANGELOG.md b/CHANGELOG.md index d548eed8..0b808587 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - **font:** extend font declaration +### Fixed +- **document:** Document title is not recognized by LibreOffice, closes [#68](https://github.com/connium/simple-odf/issues/68) + ## [0.7.0] (2019-02-19) ### Added - **chore:** Add automatically created API documentation, closes [#16](https://github.com/connium/simple-odf/issues/16) diff --git a/README.md b/README.md index aa52a554..daf1c58a 100644 --- a/README.md +++ b/README.md @@ -47,9 +47,10 @@ style1.setKeepTogether(); p1.setStyle(style1); // font usage document.getFontFaceDeclarations().create('Open Sans', 'Open Sans', simpleOdf.FontPitch.Variable); -const p2 = body.addParagraph('It always seems impossible until it\'s done.'); const style2 = new simpleOdf.ParagraphStyle(); -style1.setFontName('Open Sans'); +style2.setFontName('Open Sans'); +const p2 = body.addParagraph('It always seems impossible until it\'s done.'); +p2.setStyle(style2); body.addHeading('Credits', 2); diff --git a/package.json b/package.json index 92659c15..fd6af7cc 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,7 @@ "transform": { "^.+\\.tsx?$": "ts-jest" }, - "testRegex": "src/.*\\.spec\\.(jsx?|tsx?)$", + "testRegex": "(src|test)/.*\\.spec\\.(jsx?|tsx?)$", "moduleFileExtensions": [ "ts", "js" diff --git a/src/xml/TextDocumentWriter.spec.ts b/src/xml/TextDocumentWriter.spec.ts index 8a638a3d..b822be09 100644 --- a/src/xml/TextDocumentWriter.spec.ts +++ b/src/xml/TextDocumentWriter.spec.ts @@ -25,7 +25,7 @@ describe(TextDocumentWriter.name, () => { }); it('add dc namespace', () => { - expect(documentAsString).toMatch(/xmlns:dc="http:\/\/purl.org\/dc\/elements\/1.1"/); + expect(documentAsString).toMatch(/xmlns:dc="http:\/\/purl.org\/dc\/elements\/1.1\/"/); }); it('add draw namespace', () => { diff --git a/src/xml/TextDocumentWriter.ts b/src/xml/TextDocumentWriter.ts index f850a528..ce03372c 100644 --- a/src/xml/TextDocumentWriter.ts +++ b/src/xml/TextDocumentWriter.ts @@ -49,7 +49,7 @@ export class TextDocumentWriter { * @private */ private setXmlNamespaces (root: Element): void { - root.setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1'); + root.setAttribute('xmlns:dc', 'http://purl.org/dc/elements/1.1/'); root.setAttribute('xmlns:draw', 'urn:oasis:names:tc:opendocument:xmlns:drawing:1.0'); root.setAttribute('xmlns:fo', 'urn:oasis:names:tc:opendocument:xmlns:xsl-fo-compatible:1.0'); root.setAttribute('xmlns:meta', 'urn:oasis:names:tc:opendocument:xmlns:meta:1.0'); diff --git a/test/integration.spec.ts b/test/integration.spec.ts index b2dbbbde..096f878e 100644 --- a/test/integration.spec.ts +++ b/test/integration.spec.ts @@ -33,17 +33,21 @@ xdescribe('integration', () => { it('metadata', () => { document.getMeta() + .setInitialCreator('Marge Simpson') .setCreator('Homer Simpson') .setLanguage('en-US') .setTitle('simple-odf') .setSubject('ODF document creation') - .setDescription('ODF text document created with Node.js powered by simple-odf'); + .setDescription('ODF text document created with Node.js powered by simple-odf') + .addKeyword('Simpson').addKeyword('Springfield'); }); it('image', () => { + const style = new ParagraphStyle(); + style.setHorizontalAlignment(HorizontalAlignment.Center); + const paragraph = body.addParagraph(); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setHorizontalAlignment(HorizontalAlignment.Center); + paragraph.setStyle(style); const image = paragraph.addImage(join(__dirname, 'data', 'ODF.png')); image.getStyle().setAnchorType(AnchorType.AsChar); @@ -60,75 +64,97 @@ xdescribe('integration', () => { describe('paragraph formatting', () => { it('page break', () => { + const style = new ParagraphStyle(); + style.setPageBreakBefore(); + const heading = body.addHeading('Paragraph Formatting', 2); - heading.setStyle(new ParagraphStyle()); - heading.getStyle().setPageBreakBefore(); + heading.setStyle(style); }); it('keep together', () => { + const style = new ParagraphStyle(); + style.setKeepTogether(); + const heading = body.addParagraph('Paragraph Formatting'); - heading.setStyle(new ParagraphStyle()); - heading.getStyle().setKeepTogether(); + heading.setStyle(style); }); it('align text', () => { + const style = new ParagraphStyle(); + style.setHorizontalAlignment(HorizontalAlignment.Center); + const paragraph = body.addParagraph('Some centered text'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setHorizontalAlignment(HorizontalAlignment.Center); + paragraph.setStyle(style); }); it('tab stops', () => { + const style = new ParagraphStyle(); + style.addTabStop(new TabStop(40)); + style.addTabStop(new TabStop(120, TabStopType.Right)); + const paragraph = body.addParagraph('first\tsecond\tthird'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().addTabStop(new TabStop(40)); - paragraph.getStyle().addTabStop(new TabStop(120, TabStopType.Right)); + paragraph.setStyle(style); }); }); describe('text formatting', () => { beforeAll(() => { + const style = new ParagraphStyle(); + style.setPageBreakBefore(); + const heading = body.addHeading('Text Formatting', 2); - heading.setStyle(new ParagraphStyle()); - heading.getStyle().setPageBreakBefore(); + heading.setStyle(style); }); it('color', () => { + const style = new ParagraphStyle(); + style.setColor(Color.fromRgb(62, 180, 137)); + const paragraph = body.addParagraph('Some mint-colored text'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setColor(Color.fromRgb(62, 180, 137)); + paragraph.setStyle(style); }); it('font name', () => { document.getFontFaceDeclarations().create('Open Sans', 'Open Sans', FontPitch.Variable); + const style = new ParagraphStyle(); + style.setFontName('Open Sans'); + const paragraph = body.addParagraph('Open Sans'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setFontName('Open Sans'); + paragraph.setStyle(style); }); it('font size', () => { + const style = new ParagraphStyle(); + style.setFontSize(8); + const paragraph = body.addParagraph('Some small text'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setFontSize(8); + paragraph.setStyle(style); }); it('text transformation', () => { + const style = new ParagraphStyle(); + style.setTextTransformation(TextTransformation.Uppercase); + const paragraph = body.addParagraph('Some uppercase text'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setTextTransformation(TextTransformation.Uppercase); + paragraph.setStyle(style); }); it('typeface', () => { + const style = new ParagraphStyle(); + style.setTypeface(Typeface.Bold); + const paragraph = body.addParagraph('Some bold text'); - paragraph.setStyle(new ParagraphStyle()); - paragraph.getStyle().setTypeface(Typeface.Bold); + paragraph.setStyle(style); }); }); it('hyperlink', () => { + const style = new ParagraphStyle(); + style.setPageBreakBefore(); + const heading = body.addHeading('Hyperlink', 2); - heading.setStyle(new ParagraphStyle()); - heading.getStyle().setPageBreakBefore(); + heading.setStyle(style); const paragraph = body.addParagraph('This is just an '); paragraph.addHyperlink('example', 'http://example.org'); @@ -136,9 +162,11 @@ xdescribe('integration', () => { }); it('list', () => { + const style = new ParagraphStyle(); + style.setPageBreakBefore(); + const heading = body.addHeading('List', 2); - heading.setStyle(new ParagraphStyle()); - heading.getStyle().setPageBreakBefore(); + heading.setStyle(style); const list = body.addList(); list.addItem('first item');