-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(list): text content of a list item cannot be styled (#120)
BREAKING CHANGE: The `addListItem` method on a `List` no longer accepts a string and it doesn't automagically create a "hidden" paragraph. Instead an empty `ListItem` is being created. On the `ListItem` instance it is now possible to add headings or paragraphs. Fixes: #67
- Loading branch information
Showing
10 changed files
with
146 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { Heading } from './Heading'; | ||
import { ListItem } from './ListItem'; | ||
import { Paragraph } from './Paragraph'; | ||
|
||
describe(ListItem.name, () => { | ||
let listItem: ListItem; | ||
|
||
beforeEach(() => { | ||
listItem = new ListItem(); | ||
}); | ||
|
||
describe('#addHeading', () => { | ||
it('return a heading', () => { | ||
const heading = listItem.addHeading(); | ||
|
||
expect(heading).toBeInstanceOf(Heading); | ||
}); | ||
}); | ||
|
||
describe('#addParagraph', () => { | ||
it('return a paragraph', () => { | ||
const paragraph = listItem.addParagraph(); | ||
|
||
expect(paragraph).toBeInstanceOf(Paragraph); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,58 @@ | ||
import { OdfElement } from '../OdfElement'; | ||
import { Heading } from './Heading'; | ||
import { Paragraph } from './Paragraph'; | ||
|
||
/** | ||
* This class represents an item in a list. | ||
* | ||
* @example | ||
* const list = document.getBody() | ||
* .addList() | ||
* .addItem('First item'); | ||
* const listItem = new ListItem(); | ||
* listItem.addHeading('headline'); | ||
* listItem.addParagraph('paragraph'); | ||
* | ||
* @since 0.2.0 | ||
*/ | ||
export class ListItem extends OdfElement { | ||
private paragraph: Paragraph; | ||
|
||
/** | ||
* Creates a `ListItem` instance that represents an item in a list. | ||
* | ||
* @example | ||
* new ListItem('First item'); | ||
* new ListItem(); | ||
* | ||
* @param {string} [text=''] The text content of the list item; defaults to an empty string if omitted | ||
* @since 0.2.0 | ||
*/ | ||
public constructor (text?: string) { | ||
public constructor () { | ||
super(); | ||
} | ||
|
||
/** | ||
* Adds a heading at the end of the list item. | ||
* If a text is given, this will be set as text content of the heading. | ||
* | ||
* @param {string} [text] The text content of the heading | ||
* @param {number} [level=1] The heading level; defaults to 1 if omitted | ||
* @returns {Heading} The newly added heading | ||
* @since 0.11.0 | ||
*/ | ||
public addHeading (text?: string, level = 1): Heading { | ||
const heading = new Heading(text, level); | ||
this.append(heading); | ||
|
||
return heading; | ||
} | ||
|
||
/** | ||
* Adds a paragraph at the end of the list item. | ||
* If a text is given, this will be set as text content of the paragraph. | ||
* | ||
* @param {string} [text] The text content of the paragraph | ||
* @returns {Paragraph} The newly added paragraph | ||
* @since 0.11.0 | ||
*/ | ||
public addParagraph (text?: string): Paragraph { | ||
const paragraph = new Paragraph(text); | ||
this.append(paragraph); | ||
|
||
this.paragraph = new Paragraph(text); | ||
this.append(this.paragraph); | ||
return paragraph; | ||
} | ||
} |
Oops, something went wrong.