Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.

Conversation

chenzhiguang
Copy link
Contributor

The Line is used to maintain the tabRemaining for now.

This is a use case of Line, it can also explain the meaning of the tabRemaining:
https://spec.commonmark.org/0.30/#example-6

Normally the > that begins a block quote may be followed optionally by a space, which is not considered part of the content. In the following case > is followed by a tab, which is treated as if it were expanded into three spaces. Since one of these spaces is considered part of the delimiter, foo is considered to be indented six spaces inside the block quote context, so we get an indented code block starting with two spaces.

In this example the tabRemaining is the two spaces from blockquote which will be used in the nested indented code block.

@coveralls
Copy link

coveralls commented Nov 16, 2022

Pull Request Test Coverage Report for Build 3482854805

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 79 of 86 (91.86%) changed or added relevant lines in 18 files are covered.
  • 2 unchanged lines in 2 files lost coverage.
  • Overall coverage decreased (-0.3%) to 94.713%

Changes Missing Coverage Covered Lines Changed/Added Lines %
lib/src/block_parser.dart 4 5 80.0%
lib/src/document.dart 2 4 50.0%
lib/src/block_syntaxes/block_syntax.dart 1 5 20.0%
Files with Coverage Reduction New Missed Lines %
lib/src/block_syntaxes/fenced_code_block_syntax.dart 1 98.08%
lib/src/util.dart 1 98.18%
Totals Coverage Status
Change from base Build 3475609872: -0.3%
Covered Lines: 1236
Relevant Lines: 1305

💛 - Coveralls

@chenzhiguang
Copy link
Contributor Author

chenzhiguang commented Nov 16, 2022

Can we review this sooner? I need it to create PRs to fix the tab related issues.

@kevmoo
Copy link
Contributor

kevmoo commented Nov 16, 2022

We'll need to get this working w/ flutter_markdown – which is tricky because the API has changed!

@chenzhiguang
Copy link
Contributor Author

Yes, I think we can use the same way as we did before to fix it.

@chenzhiguang chenzhiguang force-pushed the introduce-a-Line-class branch 2 times, most recently from f28dfd8 to 6d0c977 Compare November 16, 2022 20:05
@chenzhiguang
Copy link
Contributor Author

Now it looks better.

@kevmoo
Copy link
Contributor

kevmoo commented Nov 16, 2022

Help me understand the point of Line? The API is now a bit more complex. What do we get by having a Line construct instead of just using String? (Might be good to have in the change log, too)

@chenzhiguang
Copy link
Contributor Author

I found It seems the tab issues could be fixed without using this Line type. I will do more research tomorrow.

The idea came from https://github.com/tagnote-app/dart_markdown/blob/master/lib/src/line.dart, but the Line there maintains much more information.

@kevmoo
Copy link
Contributor

kevmoo commented Nov 16, 2022

Also: mind running benchmarks?

@chenzhiguang
Copy link
Contributor Author

No difference, I have tried. Let me do it again

@kevmoo
Copy link
Contributor

kevmoo commented Nov 16, 2022

just because we're allocating a bit more...

@chenzhiguang
Copy link
Contributor Author

Benchmark before

Screenshot 2022-11-16 at 21 59 12

Benchmark after

Screenshot 2022-11-16 at 21 58 29

@chenzhiguang
Copy link
Contributor Author

We might need this Line in the future.

@chenzhiguang
Copy link
Contributor Author

chenzhiguang commented Nov 17, 2022

@kevmoo
We might still need Line to maintain the tabRemaining, we can not just simply convert the tabRemaining to spaces and prepend them to a string, then passes it to the nested structure.

For example: (See: https://spec.commonmark.org/0.30/#example-5)

- foo

→→bar

There are 2 space sized tabRemaining from the list block, if we just prepend two spaces to →bar like this ..→bar,
the output of the indented code block will be: (See: https://spec.commonmark.org/0.30/#example-2)

<pre><code>foo
</code></pre>

More information about tabs behaves: see https://spec.commonmark.org/0.30/#tabs

Tabs in lines are not expanded to spaces. However, in contexts where spaces help to define block structure, tabs behave as if they were replaced by spaces with a tab stop of 4 characters.

Thus, for example, a tab can be used instead of four spaces in an indented code block. (Note, however, that internal tabs are passed through as literal tabs, not expanded to spaces.)

@chenzhiguang
Copy link
Contributor Author

I have added some more comment for the tabRemaining property of Line.

Sorry for this back and forth, it has been a few months since I created this Line type, I should have written a detailed comment.

@chenzhiguang
Copy link
Contributor Author

Should we continue? I am blocked by this PR.

@kevmoo
Copy link
Contributor

kevmoo commented Nov 17, 2022

@srawlins should really chime in here

@chenzhiguang
Copy link
Contributor Author

What do we say?

@chenzhiguang
Copy link
Contributor Author

@srawlins Hi Sam, I need your decision in order to plan the next steps.
cc @kevmoo

@srawlins
Copy link
Collaborator

I will try to get to this today.

@chenzhiguang chenzhiguang force-pushed the introduce-a-Line-class branch from 6bfbb75 to 3c87feb Compare November 24, 2022 19:02
@chenzhiguang
Copy link
Contributor Author

@srawlins Hi Sam, please don’t forget this one.

// A line containing no characters, or a line containing only spaces
// (`U+0020`) or tabs (`U+0009`), is called a blank line.
// https://spec.commonmark.org/0.30/#blank-line
bool get isBlankLine => emptyPattern.hasMatch(content);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'd be interesting to consider how many Lines are queried for whether they are blank. I suspect it is a high number, but it'd be good to really look. And how many Lines are queried multiple times whether they are blank. If most isBlankLine is called on most Lines, and called multiple times on some Lines, it might be a win to store this bool as a final field.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. The ListSyntax does call isBlankLine on most lines and also calls multiple times on some lines

this.tabRemaining,
});

Map<String, dynamic> toMap() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is only called in tests, I don't think it is worth it to implement here.

@chenzhiguang chenzhiguang force-pushed the introduce-a-Line-class branch from 43653d3 to fc4e498 Compare November 29, 2022 18:53
Copy link
Collaborator

@srawlins srawlins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super cool, great feature, sorry for the delay.

@srawlins srawlins merged commit c3d1136 into dart-archive:master Nov 29, 2022
@chenzhiguang
Copy link
Contributor Author

No worries! Thanks!

@chenzhiguang chenzhiguang deleted the introduce-a-Line-class branch November 29, 2022 19:09
mosuem pushed a commit to dart-lang/tools that referenced this pull request Dec 9, 2024
* introduce a Line class

* Update CHANGELOG

* maintain backwards compatibility

* Update CHANGELOG

* Improve CHANGELOG.md

* Improve CHANGELOG.md

* Add more comment for tabRemaining

* Remove toMap from Line

* set `isBlankLine` of `Line` as final

* remove extension name LineX
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants