Closed jonasfj closed 1 year ago
Do you mean a SourceSpan
that would point to the outputted text?
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:
Element
with
tag = 'h1'
span = SourceSpan(SourceLocation(0), SourceLocation(14), '# Hello World!')
children
as
Text
withspan = SourceSpan(SourceLocation(2), SourceLocation(14), 'Hello World!')
textContent = "Hello World!"
Element
with
tag = 'pre'
span = SourceSpan(SourceLocation(16), SourceLocation(58), '```dart\nvoid main() => print('hello');\n```')
children
as
Element
withtag = 'code'
attributes = {'class': 'language-dart'}
span = SourceSpan(SourceLocation(16), SourceLocation(58), '```dart\nvoid main() => print('hello');\n```')
children
as
Text
withspan = SourceSpan(SourceLocation(24), SourceLocation(54), 'void main() => print('hello');')
textContent = "Hello World!"
(I'm sure I counted something wrong in my example :rofl: )
Closing as a duplicate of https://github.com/dart-lang/markdown/issues/369
@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
Perhaps we can consider migrating these features to our main package
I would love that.
It would be great if
Node
had aNode.span
property that was an instance ofSourceSpan
frompackage: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.