[PR #920] Support escaped quotes in generic attribute values #1308

Open
opened 2026-01-29 14:52:56 +00:00 by claunia · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/xoofx/markdig/pull/920
Author: @jnraine
Created: 1/15/2026
Status: 🔄 Open

Base: masterHead: support-escaped-quotes-in-attributes


📝 Commits (1)

  • e73a9b0 Support escaped quotes in generic attribute values

📊 Changes

3 files changed (+207 additions, -26 deletions)

View changed files

📝 src/Markdig.Tests/Specs/GenericAttributesSpecs.generated.cs (+105 -0)
📝 src/Markdig.Tests/Specs/GenericAttributesSpecs.md (+53 -0)
📝 src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs (+49 -26)

📄 Description

Hi! I've been using Markdig and it's been great. Wanted to contribute back with this small feature.

This is my first PR here so happy to make any revisions or tweaks as necessary. And also, if this isn't something wanted by the maintainers, feel free to close.

Summary

  • Add backslash escape handling for quoted attribute values following kramdown's approach
  • This allows including quote characters within attribute values using backslash escapes (e.g. data-value="hello \"world\"")
  • It also works with single-quotes

Motivation

This was discovered when using markdown to generate Word documents from the Markdig AST. Word field codes use quoted strings:

[January 15, 2026](){field="DATE @ \"MMMM d, yyyy\""}

This can work if the outer quotes are changed to single-quotes but escape sequences are useful for our context (and we preprocess the markdown so it works with Markdig today).

Implementation

Follows the same hasEscape pattern used in LinkHelper.TryParseTitle, using IsAsciiPunctuation() for escaping.

This matches kramdown's behavior for inline attribute lists:

"If you need to use the value delimiter (a single or a double quote) inside the value, you need to escape it with a backslash."

See: https://kramdown.gettalong.org/syntax.html

Test plan

  • Added 6 test cases covering escaped double/single quotes, escaped backslashes, and complex escape sequences

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/xoofx/markdig/pull/920 **Author:** [@jnraine](https://github.com/jnraine) **Created:** 1/15/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `support-escaped-quotes-in-attributes` --- ### 📝 Commits (1) - [`e73a9b0`](https://github.com/xoofx/markdig/commit/e73a9b0f4bc5319efab14eeba0bd11855009eb59) Support escaped quotes in generic attribute values ### 📊 Changes **3 files changed** (+207 additions, -26 deletions) <details> <summary>View changed files</summary> 📝 `src/Markdig.Tests/Specs/GenericAttributesSpecs.generated.cs` (+105 -0) 📝 `src/Markdig.Tests/Specs/GenericAttributesSpecs.md` (+53 -0) 📝 `src/Markdig/Extensions/GenericAttributes/GenericAttributesParser.cs` (+49 -26) </details> ### 📄 Description Hi! I've been using Markdig and it's been great. Wanted to contribute back with this small feature. This is my first PR here so happy to make any revisions or tweaks as necessary. And also, if this isn't something wanted by the maintainers, feel free to close. ## Summary - Add backslash escape handling for quoted attribute values following kramdown's approach - This allows including quote characters within attribute values using backslash escapes (e.g. `data-value="hello \"world\""`) - It also works with single-quotes ## Motivation This was discovered when using markdown to generate Word documents from the Markdig AST. Word field codes use quoted strings: ```markdown [January 15, 2026](){field="DATE @ \"MMMM d, yyyy\""} ``` This can work if the outer quotes are changed to single-quotes but escape sequences are useful for our context (and we preprocess the markdown so it works with Markdig today). ## Implementation Follows the same `hasEscape` pattern used in `LinkHelper.TryParseTitle`, using `IsAsciiPunctuation()` for escaping. This matches kramdown's behavior for inline attribute lists: > "If you need to use the value delimiter (a single or a double quote) inside the value, you need to escape it with a backslash." See: https://kramdown.gettalong.org/syntax.html ## Test plan - [x] Added 6 test cases covering escaped double/single quotes, escaped backslashes, and complex escape sequences --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
claunia added the pull-request label 2026-01-29 14:52:56 +00:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/markdig#1308