dart-lang / markdown

A Dart markdown library
https://pub.dev/packages/markdown
BSD 3-Clause "New" or "Revised" License
441 stars 201 forks source link

Support line/column offset in original text #534

Closed jonasfj closed 1 year ago

jonasfj commented 1 year ago

It would be great if Node had a Node.span property that was an instance of SourceSpan from package:source_span.

It would make it easier to provide accurate error messages, if there is something in the parsed output we wish to disallow later.

srawlins commented 1 year ago

Do you mean a SourceSpan that would point to the outputted text?

jonasfj commented 1 year ago

I mean that when we've parsed a markdown string. It'd be nice if the Element and Text, which both implement Node, had a span property with the type SourceSpan.

Where the span property points to substring in the input markdown that gave rise to the markup.


Example

# Hello World!

```dart
void main() => print('hello');
```

Would be parsed to:

(I'm sure I counted something wrong in my example :rofl: )

jonasfj commented 1 year ago

Closing as a duplicate of https://github.com/dart-lang/markdown/issues/369

chenzhiguang commented 1 year ago

@jonasfj Hello Jonas, I have implemented the SourceSpan in this repository: https://github.com/tagnote-app/dart_markdown#syntax-tree. The purpose of this addition was to add SourceSpan support, but there were too many changes which made the PR difficult to review, so I created a separate repository. Perhaps we can consider migrating these features to our main package

srawlins commented 1 year ago

Perhaps we can consider migrating these features to our main package

I would love that.