Skip to content

Commit

Permalink
fix(document): document title is not recognized by LibreOffice (#69)
Browse files Browse the repository at this point in the history
Added trailing `/` to `xmlns:dc` declaration and reenabled integration test.

Fixes: #68
  • Loading branch information
connium authored Feb 26, 2019
1 parent d50bbae commit 63f3079
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 33 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"transform": {
"^.+\\.tsx?$": "ts-jest"
},
"testRegex": "src/.*\\.spec\\.(jsx?|tsx?)$",
"testRegex": "(src|test)/.*\\.spec\\.(jsx?|tsx?)$",
"moduleFileExtensions": [
"ts",
"js"
Expand Down
2 changes: 1 addition & 1 deletion src/xml/TextDocumentWriter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
2 changes: 1 addition & 1 deletion src/xml/TextDocumentWriter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
84 changes: 56 additions & 28 deletions test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -60,85 +64,109 @@ 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');
paragraph.addText('.');
});

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');
Expand Down

0 comments on commit 63f3079

Please sign in to comment.