Skip to content

Commit 59e769c

Browse files
committed
Clean up refactor: remove ternary operators
1 parent 0aec759 commit 59e769c

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

packages/editor/src/api/pandoc_capsule.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,20 +186,27 @@ export function decodeBlockCapsuleText(text: string, tok: PandocToken, filters:
186186
});
187187
return text;
188188
}
189-
const resolveTokenBlockCapsuleText = (token: PandocToken, filters: readonly PandocBlockCapsuleFilter[]) => ({
190-
t: token.t,
191-
c: token.t !== PandocTokenType.Str && typeof token.c === 'string' ?
192-
decodeBlockCapsuleText(token.c, token, filters) :
193-
token.c
194-
});
189+
190+
const decodeContent = (token: PandocToken, filters: readonly PandocBlockCapsuleFilter[]) => {
191+
if (token.t !== PandocTokenType.Str && typeof token.c === 'string') {
192+
return decodeBlockCapsuleText(token.c, token, filters);
193+
} else {
194+
return token.c;
195+
}
196+
};
195197
// block capsules can also end up not as block tokens, but rather as text within another
196198
// token (e.g. within a backtick code block or raw_block). this function takes a set
197199
// of pandoc tokens and recursively converts block capsules that aren't of type
198200
// PandocTokenType.Str (which is what we'd see in a paragraph) into their original form
199201
export const resolvePandocBlockCapsuleText = (
200202
tokens: PandocToken[],
201203
filters: readonly PandocBlockCapsuleFilter[],
202-
) => mapTokensRecursive(tokens, token => resolveTokenBlockCapsuleText(token, filters));
204+
) => mapTokensRecursive(tokens, token => {
205+
return {
206+
t: token.t,
207+
c: decodeContent(token, filters)
208+
};
209+
});
203210

204211
export function blockCapsuleTextHandler(type: string, pattern: RegExp, textFilter?: (text: string) => string) {
205212
return (text: string, tok: PandocToken): string => {

packages/editor/src/pandoc/pandoc_to_prosemirror.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -423,9 +423,11 @@ class ParserState {
423423
}
424424

425425
private maybeMerge(a: ProsemirrorNode, b: ProsemirrorNode): ProsemirrorNode | undefined {
426-
return a?.isText && b?.isText && Mark.sameSet(a.marks, b.marks) ?
427-
this.schema.text((a.text as string) + b.text, a.marks) :
428-
undefined;
426+
if (a?.isText && b?.isText && Mark.sameSet(a.marks, b.marks)) {
427+
return this.schema.text(a.text! + b.text, a.marks);
428+
} else {
429+
return undefined;
430+
}
429431
}
430432
}
431433

0 commit comments

Comments
 (0)