Skip to content

Commit

Permalink
Merge branch 'main' of github.com:joggrdocs/tempo into feature/expose…
Browse files Browse the repository at this point in the history
…-types-n-arrays
  • Loading branch information
zrosenbauer committed Jul 16, 2023
2 parents a271f14 + cca9bcf commit 0bb1878
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ const result = tempo()
.paragraph('Some things')
.paragraph((txt) =>
txt
.text('A sentence with')
.plainText('A sentence with')
.bold('bolded words')
.plainText('and')
.italic('italicized words')
.append('.')
.plainText('.', { append: true })
.build()
)
.h2((txt) =>
Expand Down Expand Up @@ -103,7 +103,7 @@ const result = tempo()
.bold('bolded words')
.plainText('and')
.italic('italicized words')
.append('.')
.plainText('.', { append: true })
.build()
)
.toJSON();
Expand Down
2 changes: 1 addition & 1 deletion examples/lib/code.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function run() {
txt
.plainText('This includes examples of code blocks and')
.code('inline code')
.append('.')
.plainText('.', { append: true })
)
.h2(txt => txt.plainText('This is a heading with ').code('code'))
.codeBlock(
Expand Down
29 changes: 13 additions & 16 deletions src/lib/Text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ interface BaseTextNode<T> {

export interface PlainTextNode extends BaseTextNode<string> {
type: 'plaintext';
options?: {
append?: boolean;
};
}

export interface AppendTextNode extends BaseTextNode<string> {
Expand Down Expand Up @@ -88,20 +91,12 @@ export type TextNode =
export class Text {
private nodes: TextNode[] = [];

public plainText(value: string) {
public plainText(value: string, options?: { append?: boolean }) {
this.nodes.push({
type: 'plaintext',
data: value,
computed: value
});
return this;
}

public append(value: string) {
this.nodes.push({
type: 'append',
data: value,
computed: value
computed: value,
options
});
return this;
}
Expand Down Expand Up @@ -177,12 +172,14 @@ export class Text {
let output = '';

for (const node of this.nodes) {
if (node.type === 'append') {
output += node.computed;
continue;
} else {
output += ` ${node.computed}`;
if (node.type === 'plaintext') {
if (node.options && node.options.append) {
output += node.computed;
continue;
}
}

output += ` ${node.computed}`;
}

return output.trim();
Expand Down
4 changes: 2 additions & 2 deletions src/lib/__tests__/Text.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ describe('outputs', () => {
const value = 'Hello World';
const txtReal = createText()
.plainText(value)
.append(';')
.plainText(';', { append: true })
.bold(value)
.append('/')
.plainText('/', { append: true })
.italic(value)
.strikeThrough(value)
.link(value, value);
Expand Down

0 comments on commit 0bb1878

Please sign in to comment.