dart-lang / markdown

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

Unable to fully parse HTML tags #566

Closed shanliangdeYWJ closed 10 months ago

shanliangdeYWJ commented 10 months ago

flutter v3.0 markdown: ^7.0.1

My return value for HTML is as follows: deep nesting cannot fully parse into a tree structure to return

image

Here is the case I used,

import 'package:markdown/markdown.dart';

void main() {
  print(markdownToHtml('''
Hello *Markdown*

<span class="green">
Markdown
</span>

<h2>aaaa</h2>

| foo | bar |
| --- | --- |
| baz | bim |

    ''', extensionSet: ExtensionSet.gitHubWeb));
}

I tried debugging the source code and felt that the problem was with this function, but I don't know how to handle it. It seems that he only handled the external p tag and didn't handle the internal tag.

markdown-7.0.1/lib/src/document.dart

  void _parseInlineContent(List<Node> nodes) {
    for (var i = 0; i < nodes.length; i++) {
      final node = nodes[i];
      if (node is UnparsedContent) {
        final inlineNodes = parseInline(node.textContent);
        nodes.removeAt(i);
        nodes.insertAll(i, inlineNodes);
        i += inlineNodes.length - 1;
      } else if (node is Element && node.children != null) {
        _parseInlineContent(node.children!);
      }
    }
  }

But it may not be here either, because tags like table are all passed in with nested structures. What I mean is a table syntax similar to markup, rather than a table with HTML tags. Therefore, there might be a place where deep nesting is ignored when dealing with HTML tags.

srawlins commented 10 months ago

The markdown package does not parse HTML, and there is no intention or design for it to parse HTML. Can you explain your need for it to parse HTML? Can you use the html package to parse the HTML?

shanliangdeYWJ commented 10 months ago

The markdown package does not parse HTML, and there is no intention or design for it to parse HTML. Can you explain your need for it to parse HTML? Can you use the html package to parse the HTML?

So that I can parse it out, I can replace it with a Flutter widget based on the tag, because my markdown is written on another software and can parse HTML. The project I wrote with jsbridge is quite slow, so I want to try using Flutter instead.

srawlins commented 10 months ago

That all sounds good. But markdown is not an HTML-parsing package. I would try the html package, or maybe there are others.