Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

TSDocEmitter 0.17.0 drops the line break before a code span or {@link}, joining words

Open Beginner friendly
#493 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
85/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
typescript
Domain
documentation

Research direction

Start at TrimSpacesTransform.pushAccumulatedText() and run the supplied TSDocEmitter reproduction for code spans, links, and plain text. Done means a soft break before an inline non-text node is preserved without changing the intended handling of breaks between plain words or after inline nodes.

Written by the indexing model from the issue text.

Description

Summary

Since 0.17.0 ("Update emitter to not replace line breaks"), TSDocEmitter drops a soft break that sits immediately before an inline non-text node (code span, {@link}, HTML element), and emits no space in its place. The two words end up joined.

API Extractor 7.59.2 (which moved to @microsoft/tsdoc ~0.17.0) writes this output into the docComment field of .api.json models, so every downstream consumer of the model (documenters, generated indexes) receives the damaged text.

Repro

const t = require("@microsoft/tsdoc");
const cases = {
  code: "/**\n * policy is\n * `\"fail\"`.\n */",
  link: "/**\n * see the\n * {@link Foo} thing.\n */",
  plain: "/**\n * policy is\n * fail now.\n */",
  codeMid: "/**\n * a `x`\n * then b.\n */",
};
for (const [k, src] of Object.entries(cases)) {
  const sb = new t.StringBuilder();
  new t.TSDocEmitter().renderComment(sb, new t.TSDocParser().parseString(src).docComment);
  console.log(k, JSON.stringify(sb.toString()));
}
Case 0.16.0 0.17.0
break before code span policy is `"fail"`. policy is`"fail"`.
break before {@link} see the {@link Foo} thing. see the{@link Foo} thing.
break between plain words policy is fail now. policy is\n * fail now. (preserved, as intended)
break after code span a `x` then b. a `x`\n * then b. (preserved, as intended)

Cause

TrimSpacesTransform.pushAccumulatedText() splits the accumulated text on \n and only emits a DocSoftBreak ahead of a non-empty line. When the accumulated text ends in a soft break ("policy is\n"), the split yields a trailing empty line; it is skipped, and with it the soft break. The default branch then pushes the inline node straight after the text. Before 0.17.0 the soft break was rendered as a space, which masked this.

Suggested fix

In pushAccumulatedText(), when the final line is empty and i !== 0 (the text ended in a line break), still push a DocSoftBreak so the following inline node starts on a new line.

Environment

  • @microsoft/tsdoc 0.17.0 (0.16.0 is correct)
  • @microsoft/api-extractor 7.59.2 / @microsoft/api-extractor-model 7.33.13
  • Node 26
Dominant language
TypeScript
Stars
5k
Forks
162
Avg merge
17h 4m
Merged PRs (30d)
7

Getting set up

We have not checked this project's setup files yet. Start from its README, and see our first-contribution guide for the general steps.

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from microsoft/tsdoc

All issues in microsoft/tsdoc

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.