github / github/paste-markdown

Links with nested HTML or \n confuse the markdown converter

Đang mở
#53 1 bình luận 1 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
234
Fork
47
Merge trung bình
1 ngày 12 giờ
Pull request đã merge (30 ngày)
5

Mô tả

A couple cases that generate the wrong markup.

### 1. nested html elements in link
```html
foo bar foo bar
```
gets converted to

```markdown
[foo](http://example.com/) bar foo [bar](http://example.com/)
```

when I would expect

```markdown
[foo](http://example.com/) [bar](http://example.com/) foo bar
```

What happens: the walker enters the `a` and then enters the `span` again, finding the same text twice. But the proper label text was already consumed, so it consumes until it finds another match. In some cases (like above) it even linkifies the wrong text.

### 2. line breaks in link
```html
foo
bar

```
(notice the line break) gets converted to

```markdown
foo bar
```

when I would expect

```markdown
[foo bar](https://example.com/)
```

What happens: the node textContent is `'foo\nbar'` which doesn't match any text in the plaintext.

### 2b. `
` in link
Another similar (but possibly harder to fix) case is

```html
foo
bar

```

which like 2 doesn't create a link:

```markdown
foo
bar
```

---

In general, since the code can't rely on the browser to properly deal with HTML content, some of these corner cases will probably keep popping up. But this happened in the real world (try copying and pasting the first news entry in the deprecated section [here](https://docs.python.org/dev/whatsnew/3.10.html#deprecated)) and it seemed to be significant enough to report.

I will follow up with a PR that suggests potential fixes for 1 and 2 (but not 2b), but this is not my field so it might be far from good.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Hướng nghiên cứu

The issue names no files or tests. Start by reproducing the three HTML-link cases from the report in the markdown converter, then inspect the anchor-text matching and node textContent handling described there. Done means nested elements and line breaks in links produce the expected Markdown links, with regression coverage for the reported examples.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
tooling
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.