Skip to content

Commit 1eed935

Browse files
committed
markup parse and tests
1 parent 381a1bc commit 1eed935

File tree

7 files changed

+223
-264
lines changed

7 files changed

+223
-264
lines changed

src/textual/content.py

+20
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ def styled(
271271
return new_content
272272

273273
def __eq__(self, other: object) -> bool:
274+
"""Compares text only, so that markup doesn't effect sorting."""
274275
if isinstance(other, str):
275276
return self.plain == other
276277
elif isinstance(other, Content):
@@ -284,6 +285,25 @@ def __lt__(self, other: object) -> bool:
284285
return self.plain < other.plain
285286
return NotImplemented
286287

288+
def is_same(self, content: Content) -> bool:
289+
"""Compare to another Content object.
290+
291+
Two Content objects are the same if their text and spans match.
292+
Note that if you use the `==` operator to compare Content instances, it will only consider the plain text.
293+
294+
295+
Args:
296+
content: Content instance.
297+
298+
Returns:
299+
`True` if this is identical to `content`, otherwise False
300+
"""
301+
if self is content:
302+
return True
303+
if self.plain != content.plain:
304+
return False
305+
return self.spans == content.spans
306+
287307
def get_optimal_width(
288308
self,
289309
rules: RulesMap,

src/textual/css/tokenizer.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ def get_token(self, expect: Expect) -> Token:
283283
match = expect.match(line, col_no)
284284

285285
if match is None:
286-
error_line = line[col_no:].rstrip()
286+
error_line = line[col_no:]
287287
error_message = (
288288
f"{expect.description} (found {error_line.split(';')[0]!r})."
289289
)

0 commit comments

Comments
 (0)