Skip to content

Subscript extension (~) breaks table cell boundary parsing when combined with bold (**) #932

Closed

Description

@forest6511

Summary

When the subscript extension is enabled (via UseAdvancedExtensions() or UseEmphasisExtras()), an unclosed tilde (~) inside a bold-wrapped table cell (e.g., **~$1.50**) causes the table parser to produce phantom TableCell nodes, inflating the column count.

Reproduction

var pipeline = new MarkdownPipelineBuilder()
    .UseAdvancedExtensions()
    .Build();

var md = @"| Component | Per query | Per 1,000 queries |
|-----------|-----------|-------------------|
| Embedding | ~$0.00001 | ~$0.01 |
| LLM       | ~$0.0015  | ~$1.50 |
| **Total** | **~$0.0015** | **~$1.50** |";

var doc = Markdown.Parse(md, pipeline);
var table = doc.Descendants<Table>().First();

foreach (var child in table)
{
    if (child is TableRow row)
        Console.WriteLine($"Row IsHeader={row.IsHeader}, Cells={row.Count}");
}

Expected output

Row IsHeader=True, Cells=3
Row IsHeader=False, Cells=3
Row IsHeader=False, Cells=3
Row IsHeader=False, Cells=3

Actual output

Row IsHeader=True, Cells=4
Row IsHeader=False, Cells=4
Row IsHeader=False, Cells=4
Row IsHeader=False, Cells=4

Every row gets a phantom 4th cell. The cell content is also garbled — text from adjacent cells bleeds across boundaries.

Isolation tests

Input pattern in cell Subscript ext Columns Result
**$1.50** (bold only) enabled 3 Correct
~$1.50 (tilde only) enabled 3 Correct
**~$1.50** (bold + tilde) enabled 4 Broken
**~$1.50** (bold + tilde) disabled 3 Correct

The bug only manifests when both bold (**) and an unclosed subscript delimiter (~) appear together in a table cell.

Real-world impact

~$1.50 (meaning "approximately $1.50") is a common notation in tables, especially cost/pricing summaries with bold total rows:

| **Total** | **~$0.0015** | **~$1.50** |

Environment

  • Markdig: 0.45.0
  • .NET: 8.0
  • OS: macOS (Darwin 25.3.0)

Current workaround

Use UseEmphasisExtras(EmphasisExtraOptions.Strikethrough) instead of the default EmphasisExtraOptions.Default to disable the subscript extension while keeping strikethrough support.

Activity

  1. Kryptos-FR commented on Apr 18, 2026

    @Kryptos-FR
    Contributor

    Alternative workaround: escape the ~ characters when inside the bold section:

    | Component | Per query | Per 1,000 queries |
    |-----------|-----------|-------------------|
    | Embedding | ~$0.00001 | ~$0.01 |
    | LLM       | ~$0.0015  | ~$1.50 |
    | **Total** | **\~$0.0015** | **\~$1.50** |

    Shown to work in babelmark.

  2. xoofx commented on Jun 13, 2026

    @xoofx
    Owner

    Fixed via 0f98267

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions