Skip to content

Markdown containing HTML is misdetected as rich text #14

Closed

Description

@trsdn

Problem

ClipboardContentDetector.GetMarkdownScore hard-zeroes the score whenever the text contains anything that looks like an HTML tag:

var trimmed = text.Trim();
if (ContainsHTML(trimmed))
    return 0;

HtmlTagRegex matches common tags including <div>, <p>, <span>, <code>, <br>, <a>, <img>.

Impact

Markdown is allowed to contain raw HTML, and technical Markdown very often mentions tags in inline code or fenced blocks. Any of these score 0 and get classified as RichText:

# Layout notes

Wrap the content in `<div class="card">` before rendering.

```html
<p>hello</p>
```

The app then offers "convert to Markdown" on content that is already Markdown, and Ctrl+Enter does the wrong thing.

Suggested fix

Don't zero the score. Instead:

  • Ignore tags that appear inside fenced blocks or inline code spans when scoring.
  • Treat remaining raw HTML as a negative weight alongside the other signals rather than an absolute veto, so strong Markdown structure (headings, fences, tables) still wins.

Activity

  1. trsdn commented on Aug 19, 2026

    @trsdn
    OwnerAuthor

    Verified repro

    The veto only bites when the clipboard carries both text and HTML — which is exactly what editors (VS Code, browsers, Loop) put there. Same Markdown, with and without an HTML mention:

    Clipboard text HTML also present Detected
    # Title + list + **bold** editor syntax HTML Markdown ✅
    # Layout + list + `<div class="card">` editor syntax HTML RichText ❌
    # Title + list + ```html\n<p>hello</p>\n``` editor syntax HTML RichText ❌

    Adding a single inline-code mention of a tag flips a correctly-detected Markdown document to RichText, so Ctrl+Enter then runs HTML → Markdown on content that is already Markdown.

    Note the tag mentions above are inside an inline code span and a fenced block respectively — both places where raw HTML is unambiguously not markup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions