Repository navigation
Add an option that makes a newline in a paragraph a line break - #34
Merged
Merged
Conversation
Models often use a single newline as a line break. CommonMark makes it a space. Add newlinesAsLineBreaks to MarkdownStreamParser.init, MarkdownStreamParser.document(from:) and TranscriptStream.init. The default is false, so the parser follows CommonMark as before. With the option, the block parser puts a line break, not a space, between two lines of a paragraph or a heading. A line that ends in a backslash or two spaces still gives one line break. The text that text(in:) and copyText(in:) give has a newline at the break. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The inline parser trimmed only spaces and tabs around a link destination.
When a line break came after the "(", the destination was empty. This
occurs for [a](\nurl) with the new option, and for a backslash line
break without it. Trim newlines too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the chunk-split test, the frozen-block test and the test that the shown text only grows with the option on and off. Add a text with single-newline paragraphs, hard breaks, lists, quotes, a setext heading, CRLF line ends and lines that could start other blocks. Check that the inline parse of a paragraph of many lines resumes near its end with the option. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With newlinesAsLineBreaks, the inline parser now gets the option too. - A newline right after <br> adds no second line break. A line that ends in <br> gives one break, as a backslash or two spaces do. - A newline in a code span is a space, as in CommonMark. - A built-in tag such as <b> or <br /> can go over two lines. The output with the option off does not change. The streamed text corpus now has these cases, so the chunk-split tests cover them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The TranscriptStream doc now says "a paragraph or a heading", as the MarkdownStreamParser doc does. The README says that <br> at the end of a line gives one break, and that a newline in a code span is a space. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A closing </br> is a tag only when an app adds a custom tag named br. The parser does not look past it, so it must not drop the newline that follows it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Part 4 of a stack of 13 pull requests. The base is #33 (
feature/style-options). #31 (part 1) tells how to merge the stack.On this stacked branch,
swift testpasses (223 tests), and the iOS build and build-for-testing pass.Summary
Models often use a single newline as a line break. CommonMark makes it a space, so an app that shows model output joins lines that the model meant to keep apart. This change adds the option
newlinesAsLineBreaks. The default isfalse, so the parser follows CommonMark as before.newlinesAsLineBreaks: Bool = falsetoMarkdownStreamParser.init,MarkdownStreamParser.document(from:)andTranscriptStream.init. With the option, a newline inside a paragraph or a heading is a line break, also in lists and quotes. A backslash, two spaces or<br>at the end of a line still give one break, not two. A newline in a code span stays a space. Code blocks, tables and display math do not change.[a](, a newline and a URL gave an empty destination. With the option off, this changes one result:[a](, a backslash, a newline and a URL now give a link.LineBreakTests.swift, and add rows with the option to the parser timing test.Tests
swift teston macOS: 193 tests pass.xcodebuild build -scheme TranscriptKit -destination 'generic/platform=iOS' CODE_SIGNING_ALLOWED=NO: passes.Checked on an iPhone 12 mini
A check screen in a local test app ran on main first (3 runs) and showed the problem. Then it ran on this branch (5 passing runs). View A has the option, and view B has the default. Stand-ins: the text comes from code in 3-character chunks every 30 ms, not from a model. The check copies with
selectAllandcopyfrom code. This device does not support screen recording, so the frames come fromlayer.render(in:)at each display refresh.one\ntwo\nthreewith the option is 69 pt (3 lines), the same as with hard breaks. On main it is 21 pt (1 line). A<br>, a backslash or two spaces before a newline give one break each.Not checked
Known limits
🤖 Generated with Claude Code