`
diff --git a/packages/core/cpp/enrmrkd/enrmrkd.c b/packages/core/cpp/enrmrkd/enrmrkd.c
index 686d3e5cf..2e81b534c 100644
--- a/packages/core/cpp/enrmrkd/enrmrkd.c
+++ b/packages/core/cpp/enrmrkd/enrmrkd.c
@@ -4784,6 +4784,8 @@ md_process_inlines(MD_CTX* ctx, const MD_LINE* lines, ENRMRKD_SIZE n_lines)
case '\\': /* Backslash escape. */
if(ISNEWLINE(mark->beg+1))
enforce_hardbreak = 1;
+ else if((ctx->parser.flags & ENRMRKD_FLAG_ESCAPEDTEXT) && text_type == ENRMRKD_TEXT_NORMAL)
+ ENRMRKD_TEXT(ENRMRKD_TEXT_ESCAPED, STR(mark->beg+1), 1);
else
ENRMRKD_TEXT(text_type, STR(mark->beg+1), 1);
break;
diff --git a/packages/core/cpp/enrmrkd/enrmrkd.h b/packages/core/cpp/enrmrkd/enrmrkd.h
index 3e219e0f2..46cded762 100644
--- a/packages/core/cpp/enrmrkd/enrmrkd.h
+++ b/packages/core/cpp/enrmrkd/enrmrkd.h
@@ -244,7 +244,12 @@ typedef enum ENRMRKD_TEXTTYPE {
/* Text is inside an equation. This is processed the same way as inlined code
* spans (`code`). */
- ENRMRKD_TEXT_LATEXMATH
+ ENRMRKD_TEXT_LATEXMATH,
+
+ /* Character escaped by a backslash (e.g. "\\*"), without the backslash.
+ * Sent only with ENRMRKD_FLAG_ESCAPEDTEXT, and only where the escaped character
+ * would otherwise be ENRMRKD_TEXT_NORMAL. */
+ ENRMRKD_TEXT_ESCAPED
} ENRMRKD_TEXTTYPE;
@@ -406,6 +411,7 @@ typedef struct ENRMRKD_BLOCK_BLANK_DETAIL {
#define ENRMRKD_FLAG_HIGHLIGHT 0x200000 /* Enable ==highlight== spans. */
#define ENRMRKD_FLAG_PRESERVEBLANKLINES 0x400000 /* Report blank line runs as ENRMRKD_BLOCK_BLANK. */
#define ENRMRKD_FLAG_INSERT 0x800000 /* Enable insert extension. */
+#define ENRMRKD_FLAG_ESCAPEDTEXT 0x2000000 /* Report backslash-escaped characters as ENRMRKD_TEXT_ESCAPED. */
#define ENRMRKD_FLAG_PERMISSIVEAUTOLINKS (ENRMRKD_FLAG_PERMISSIVEEMAILAUTOLINKS | ENRMRKD_FLAG_PERMISSIVEURLAUTOLINKS | ENRMRKD_FLAG_PERMISSIVEWWWAUTOLINKS)
#define ENRMRKD_FLAG_NOHTML (ENRMRKD_FLAG_NOHTMLBLOCKS | ENRMRKD_FLAG_NOHTMLSPANS)
diff --git a/packages/core/cpp/parser/MD4CParser.cpp b/packages/core/cpp/parser/MD4CParser.cpp
index 2a648a206..2b685af3f 100644
--- a/packages/core/cpp/parser/MD4CParser.cpp
+++ b/packages/core/cpp/parser/MD4CParser.cpp
@@ -1,11 +1,13 @@
#include "MD4CParser.hpp"
#include "enrmrkd.h"
+#include
#include
#include
extern "C" {
#include "enrmrkd-entity.h"
}
#include
+#include
#include
namespace Markdown {
@@ -71,6 +73,48 @@ void appendCharacterReference(std::string &output, const char *text, size_t size
appendCodepoint(output, codepoint);
}
+bool isPathWhitespace(const std::string &text, size_t at) {
+ const auto c = static_cast(text[at]);
+ if (c < 128)
+ return c == ' ' || (c >= '\t' && c <= '\r');
+ if (c != 0xC2 && c != 0xE1 && c != 0xE2 && c != 0xE3 && c != 0xEF)
+ return false;
+ // Match JavaScript's \s, including non-ASCII spaces in decoded prose.
+ static const std::string_view spaces[] = {"\u00a0", "\u1680", "\u2000", "\u2001", "\u2002", "\u2003", "\u2004",
+ "\u2005", "\u2006", "\u2007", "\u2008", "\u2009", "\u200a", "\u2028",
+ "\u2029", "\u202f", "\u205f", "\u3000", "\ufeff"};
+ for (const auto space : spaces)
+ if (text.compare(at, space.size(), space) == 0)
+ return true;
+ return false;
+}
+
+bool isDriveLetter(unsigned char c) {
+ return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
+}
+
+bool isWordCharacter(unsigned char c) {
+ return isDriveLetter(c) || (c >= '0' && c <= '9') || c == '_';
+}
+
+// A drive path can run through formatting, as in `C:/Users/**me**\.config`.
+bool carriesWindowsPath(NodeType type) {
+ switch (type) {
+ case NodeType::Strong:
+ case NodeType::Emphasis:
+ case NodeType::Underline:
+ case NodeType::Strikethrough:
+ case NodeType::Spoiler:
+ case NodeType::Superscript:
+ case NodeType::Subscript:
+ case NodeType::Highlight:
+ case NodeType::Link:
+ return true;
+ default:
+ return false;
+ }
+}
+
struct HtmlTag {
std::string name;
std::unordered_map attributes;
@@ -84,6 +128,11 @@ class MD4CParser::Impl {
std::shared_ptr root;
std::vector> nodeStack;
std::string currentText;
+ bool trackWindowsPaths = false;
+ size_t pathScanned = 0;
+ bool inWindowsPath = false;
+ // The last three bytes scanned, newest first; 0 before any.
+ unsigned char pathTail[3] = {0, 0, 0};
const char *inputText = nullptr;
bool inHtmlBlock = false;
std::string htmlBlockContent;
@@ -108,12 +157,16 @@ class MD4CParser::Impl {
nodeStack.reserve(std::min(estimatedDepth, static_cast(128)));
nodeStack.push_back(root);
currentText.clear();
+ resetWindowsPath();
currentText.reserve(256);
inHtmlBlock = false;
htmlBlockContent.clear();
}
void flushText() {
+ if (trackWindowsPaths)
+ scanWindowsPath();
+ pathScanned = 0;
if (!currentText.empty() && !nodeStack.empty()) {
auto textNode = std::make_shared(NodeType::Text);
textNode->content = std::move(currentText);
@@ -122,8 +175,40 @@ class MD4CParser::Impl {
}
}
+ void resetWindowsPath() {
+ pathScanned = 0;
+ inWindowsPath = false;
+ pathTail[0] = pathTail[1] = pathTail[2] = 0;
+ }
+
+ // Inspects only text appended since the last scan, so many escapes cannot rescan a paragraph.
+ void scanWindowsPath() {
+ for (; pathScanned < currentText.size(); ++pathScanned) {
+ const auto c = static_cast(currentText[pathScanned]);
+ if (isPathWhitespace(currentText, pathScanned)) {
+ inWindowsPath = false;
+ } else if (!inWindowsPath && (c == '/' || c == '\\') && endsInDrive()) {
+ inWindowsPath = true;
+ }
+ pathTail[2] = pathTail[1];
+ pathTail[1] = pathTail[0];
+ pathTail[0] = c;
+ }
+ }
+
+ bool endsInDrive() const {
+ return pathTail[0] == ':' && isDriveLetter(pathTail[1]) && !isWordCharacter(pathTail[2]);
+ }
+
+ bool endsInWindowsPath() {
+ scanWindowsPath();
+ return inWindowsPath || endsInDrive();
+ }
+
void pushNode(std::shared_ptr node) {
flushText();
+ if (!node || !carriesWindowsPath(node->type))
+ resetWindowsPath();
if (node && !nodeStack.empty()) {
nodeStack.back()->addChild(node);
nodeStack.push_back(std::move(node));
@@ -132,6 +217,8 @@ class MD4CParser::Impl {
void popNode() {
flushText();
+ if (nodeStack.empty() || !carriesWindowsPath(nodeStack.back()->type))
+ resetWindowsPath();
if (nodeStack.size() > 1) {
nodeStack.pop_back();
}
@@ -139,6 +226,7 @@ class MD4CParser::Impl {
void addInlineNode(std::shared_ptr node) {
flushText();
+ resetWindowsPath();
if (node && !nodeStack.empty()) {
nodeStack.back()->addChild(node);
}
@@ -513,6 +601,15 @@ class MD4CParser::Impl {
return 0;
}
+ if (type == ENRMRKD_TEXT_ESCAPED) {
+ const bool inImage = std::any_of(impl->nodeStack.begin(), impl->nodeStack.end(),
+ [](const auto &node) { return node->type == NodeType::Image; });
+ if (!inImage && impl->endsInWindowsPath())
+ impl->currentText += '\\';
+ impl->currentText.append(text, size);
+ return 0;
+ }
+
// Handle text content (normal text, code text, LaTeX math, etc.)
if (type == ENRMRKD_TEXT_NORMAL || type == ENRMRKD_TEXT_CODE || type == ENRMRKD_TEXT_LATEXMATH) {
impl->currentText.append(text, size);
@@ -903,6 +1000,7 @@ std::shared_ptr MD4CParser::parse(const std::string &markdown,
impl_->reset(estimatedDepth);
impl_->inputText = markdown.c_str();
+ impl_->trackWindowsPaths = md4cFlags.preserveWindowsPaths;
unsigned flags = ENRMRKD_FLAG_NOHTMLSPANS | ENRMRKD_FLAG_SPOILERS;
if (isGFM) {
@@ -935,6 +1033,9 @@ std::shared_ptr MD4CParser::parse(const std::string &markdown,
if (md4cFlags.admonitions) {
flags |= ENRMRKD_FLAG_ADMONITIONS;
}
+ if (md4cFlags.preserveWindowsPaths) {
+ flags |= ENRMRKD_FLAG_ESCAPEDTEXT;
+ }
// Configure MD4C parser with callbacks
ENRMRKD_PARSER parser = {
diff --git a/packages/core/cpp/parser/MD4CParser.hpp b/packages/core/cpp/parser/MD4CParser.hpp
index 75d333852..8254d6867 100644
--- a/packages/core/cpp/parser/MD4CParser.hpp
+++ b/packages/core/cpp/parser/MD4CParser.hpp
@@ -16,12 +16,15 @@ struct Md4cFlags {
bool hardSoftBreaks = false;
bool preserveBlankLines = false;
bool admonitions = true;
+ // Keeps the backslash in prose such as `C:\Users\me\.config`, where CommonMark reads `\.` as an escape.
+ bool preserveWindowsPaths = false;
bool operator==(const Md4cFlags &other) const {
return underline == other.underline && latexMath == other.latexMath && superscript == other.superscript &&
subscript == other.subscript && highlight == other.highlight &&
permissiveAutolinks == other.permissiveAutolinks && hardSoftBreaks == other.hardSoftBreaks &&
- preserveBlankLines == other.preserveBlankLines && admonitions == other.admonitions;
+ preserveBlankLines == other.preserveBlankLines && admonitions == other.admonitions &&
+ preserveWindowsPaths == other.preserveWindowsPaths;
}
};
diff --git a/packages/core/cpp/tests/ast_dump.cpp b/packages/core/cpp/tests/ast_dump.cpp
index d3a04fd42..b85524119 100644
--- a/packages/core/cpp/tests/ast_dump.cpp
+++ b/packages/core/cpp/tests/ast_dump.cpp
@@ -37,6 +37,7 @@ Markdown::Md4cFlags allEnabled() {
flags.hardSoftBreaks = true;
flags.preserveBlankLines = true;
flags.admonitions = true;
+ flags.preserveWindowsPaths = true;
return flags;
}
diff --git a/packages/core/cpp/tests/fixtures/windows-paths.md b/packages/core/cpp/tests/fixtures/windows-paths.md
new file mode 100644
index 000000000..b02abb1ec
--- /dev/null
+++ b/packages/core/cpp/tests/fixtures/windows-paths.md
@@ -0,0 +1,18 @@
+Saved to C:\Users\me\.t3\_build\shot.png and C:/work\.config and C:\folder\(draft.
+
+A drive alone keeps it too: D:\.hidden
+
+A space ends the path: C:\tmp \*not emphasis\*
+
+Not a drive after a word: abC:\x\.y
+
+Code stays literal: `C:\a\.b`
+
+Link text [C:\x\.y](/p\.q "t\.u") and image 
+
+Formatting inside a path: C:/Users/**name**\.config and C:\a\_*b*\.c
+
+Code ends a path: `C:\a`\.b
+
+A line break ends it too: C:\tmp
+\*not emphasis\*
diff --git a/packages/core/cpp/tests/golden/ast.txt b/packages/core/cpp/tests/golden/ast.txt
index 1d50b6161..7ade55090 100644
--- a/packages/core/cpp/tests/golden/ast.txt
+++ b/packages/core/cpp/tests/golden/ast.txt
@@ -48,3 +48,13 @@
{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Intro paragraph before the video."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Video","attributes":{"url":"https://example.com/clip.mp4"}},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Paragraph between."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"UnorderedList","children":[{"type":"ListItem","children":[{"type":"Video","attributes":{"url":"https://example.com/in-list.mp4"}},{"type":"BlankLine","attributes":{"count":"1"}}]}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Inline html span inside a paragraph."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Video","attributes":{"url":"https://example.com/multiline.mp4"}}]}
=== html-blocks.md [extensions-on-commonmark] ===
{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Intro paragraph before the video."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Video","attributes":{"url":"https://example.com/clip.mp4"}},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Paragraph between."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"UnorderedList","children":[{"type":"ListItem","children":[{"type":"Video","attributes":{"url":"https://example.com/in-list.mp4"}},{"type":"BlankLine","attributes":{"count":"1"}}]}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Inline html span inside a paragraph."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Video","attributes":{"url":"https://example.com/multiline.mp4"}}]}
+=== windows-paths.md [defaults-gfm] ===
+{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Saved to C:\\Users\\me.t3_build\\shot.png and C:/work.config and C:\\folder(draft."}]},{"type":"Paragraph","children":[{"type":"Text","content":"A drive alone keeps it too: D:.hidden"}]},{"type":"Paragraph","children":[{"type":"Text","content":"A space ends the path: C:\\tmp *not emphasis*"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Not a drive after a word: abC:\\x.y"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Code stays literal: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a\\.b"}]}]},{"type":"Paragraph","children":[{"type":"Text","content":"Link text "},{"type":"Link","attributes":{"title":"t.u","url":"/p.q"},"children":[{"type":"Text","content":"C:\\x.y"}]},{"type":"Text","content":" and image "},{"type":"Image","attributes":{"url":"i.png"},"children":[{"type":"Text","content":"C:\\a.b"}]}]},{"type":"Paragraph","children":[{"type":"Text","content":"Formatting inside a path: C:/Users/"},{"type":"Strong","children":[{"type":"Text","content":"name"}]},{"type":"Text","content":".config and C:\\a_"},{"type":"Emphasis","children":[{"type":"Text","content":"b"}]},{"type":"Text","content":".c"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Code ends a path: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a"}]},{"type":"Text","content":".b"}]},{"type":"Paragraph","children":[{"type":"Text","content":"A line break ends it too: C:\\tmp"},{"type":"SoftBreak"},{"type":"Text","content":"*not emphasis*"}]}]}
+=== windows-paths.md [defaults-commonmark] ===
+{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Saved to C:\\Users\\me.t3_build\\shot.png and C:/work.config and C:\\folder(draft."}]},{"type":"Paragraph","children":[{"type":"Text","content":"A drive alone keeps it too: D:.hidden"}]},{"type":"Paragraph","children":[{"type":"Text","content":"A space ends the path: C:\\tmp *not emphasis*"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Not a drive after a word: abC:\\x.y"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Code stays literal: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a\\.b"}]}]},{"type":"Paragraph","children":[{"type":"Text","content":"Link text "},{"type":"Link","attributes":{"title":"t.u","url":"/p.q"},"children":[{"type":"Text","content":"C:\\x.y"}]},{"type":"Text","content":" and image "},{"type":"Image","attributes":{"url":"i.png"},"children":[{"type":"Text","content":"C:\\a.b"}]}]},{"type":"Paragraph","children":[{"type":"Text","content":"Formatting inside a path: C:/Users/"},{"type":"Strong","children":[{"type":"Text","content":"name"}]},{"type":"Text","content":".config and C:\\a_"},{"type":"Emphasis","children":[{"type":"Text","content":"b"}]},{"type":"Text","content":".c"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Code ends a path: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a"}]},{"type":"Text","content":".b"}]},{"type":"Paragraph","children":[{"type":"Text","content":"A line break ends it too: C:\\tmp"},{"type":"SoftBreak"},{"type":"Text","content":"*not emphasis*"}]}]}
+=== windows-paths.md [extensions-off-gfm] ===
+{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Saved to C:\\Users\\me.t3_build\\shot.png and C:/work.config and C:\\folder(draft."}]},{"type":"Paragraph","children":[{"type":"Text","content":"A drive alone keeps it too: D:.hidden"}]},{"type":"Paragraph","children":[{"type":"Text","content":"A space ends the path: C:\\tmp *not emphasis*"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Not a drive after a word: abC:\\x.y"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Code stays literal: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a\\.b"}]}]},{"type":"Paragraph","children":[{"type":"Text","content":"Link text "},{"type":"Link","attributes":{"title":"t.u","url":"/p.q"},"children":[{"type":"Text","content":"C:\\x.y"}]},{"type":"Text","content":" and image "},{"type":"Image","attributes":{"url":"i.png"},"children":[{"type":"Text","content":"C:\\a.b"}]}]},{"type":"Paragraph","children":[{"type":"Text","content":"Formatting inside a path: C:/Users/"},{"type":"Strong","children":[{"type":"Text","content":"name"}]},{"type":"Text","content":".config and C:\\a_"},{"type":"Emphasis","children":[{"type":"Text","content":"b"}]},{"type":"Text","content":".c"}]},{"type":"Paragraph","children":[{"type":"Text","content":"Code ends a path: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a"}]},{"type":"Text","content":".b"}]},{"type":"Paragraph","children":[{"type":"Text","content":"A line break ends it too: C:\\tmp"},{"type":"SoftBreak"},{"type":"Text","content":"*not emphasis*"}]}]}
+=== windows-paths.md [extensions-on-gfm] ===
+{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Saved to C:\\Users\\me\\.t3\\_build\\shot.png and C:/work\\.config and C:\\folder\\(draft."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"A drive alone keeps it too: D:\\.hidden"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"A space ends the path: C:\\tmp *not emphasis*"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Not a drive after a word: abC:\\x.y"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Code stays literal: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a\\.b"}]}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Link text "},{"type":"Link","attributes":{"title":"t.u","url":"/p.q"},"children":[{"type":"Text","content":"C:\\x\\.y"}]},{"type":"Text","content":" and image "},{"type":"Image","attributes":{"url":"i.png"},"children":[{"type":"Text","content":"C:\\a.b"}]}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Formatting inside a path: C:/Users/"},{"type":"Strong","children":[{"type":"Text","content":"name"}]},{"type":"Text","content":"\\.config and C:\\a\\_"},{"type":"Emphasis","children":[{"type":"Text","content":"b"}]},{"type":"Text","content":"\\.c"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Code ends a path: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a"}]},{"type":"Text","content":".b"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"A line break ends it too: C:\\tmp"},{"type":"LineBreak"},{"type":"Text","content":"*not emphasis*"}]}]}
+=== windows-paths.md [extensions-on-commonmark] ===
+{"type":"Document","children":[{"type":"Paragraph","children":[{"type":"Text","content":"Saved to C:\\Users\\me\\.t3\\_build\\shot.png and C:/work\\.config and C:\\folder\\(draft."}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"A drive alone keeps it too: D:\\.hidden"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"A space ends the path: C:\\tmp *not emphasis*"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Not a drive after a word: abC:\\x.y"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Code stays literal: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a\\.b"}]}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Link text "},{"type":"Link","attributes":{"title":"t.u","url":"/p.q"},"children":[{"type":"Text","content":"C:\\x\\.y"}]},{"type":"Text","content":" and image "},{"type":"Image","attributes":{"url":"i.png"},"children":[{"type":"Text","content":"C:\\a.b"}]}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Formatting inside a path: C:/Users/"},{"type":"Strong","children":[{"type":"Text","content":"name"}]},{"type":"Text","content":"\\.config and C:\\a\\_"},{"type":"Emphasis","children":[{"type":"Text","content":"b"}]},{"type":"Text","content":"\\.c"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"Code ends a path: "},{"type":"Code","children":[{"type":"Text","content":"C:\\a"}]},{"type":"Text","content":".b"}]},{"type":"BlankLine","attributes":{"count":"1"}},{"type":"Paragraph","children":[{"type":"Text","content":"A line break ends it too: C:\\tmp"},{"type":"LineBreak"},{"type":"Text","content":"*not emphasis*"}]}]}
diff --git a/packages/core/cpp/wasm/md4c_wasm.cpp b/packages/core/cpp/wasm/md4c_wasm.cpp
index 27da3df0d..fcbf959dc 100644
--- a/packages/core/cpp/wasm/md4c_wasm.cpp
+++ b/packages/core/cpp/wasm/md4c_wasm.cpp
@@ -22,11 +22,12 @@ extern "C" {
* @param preserveBlankLines 1 → report runs of blank lines as BlankLine nodes; 0 → collapse them.
* @param admonitions 1 → enable GitHub-style admonitions/alerts; 0 → disable.
* @param permissiveAutolinks 1 → autolink bare URLs/e-mails; 0 → explicit links only.
+ * @param preserveWindowsPaths 1 → keep backslashes separating a Windows drive path; 0 → CommonMark escapes.
* @return Null-terminated UTF-8 JSON string, valid until the next call.
*/
const char *parseMarkdown(const char *markdown, int underline, int latexMath, int superscript, int subscript,
int highlight, int hardSoftBreaks, int preserveBlankLines, int admonitions,
- int permissiveAutolinks) {
+ int permissiveAutolinks, int preserveWindowsPaths) {
if (!markdown) {
g_resultBuffer = "{\"type\":\"Document\"}";
return g_resultBuffer.c_str();
@@ -42,6 +43,7 @@ const char *parseMarkdown(const char *markdown, int underline, int latexMath, in
flags.preserveBlankLines = (preserveBlankLines != 0);
flags.admonitions = (admonitions != 0);
flags.permissiveAutolinks = (permissiveAutolinks != 0);
+ flags.preserveWindowsPaths = (preserveWindowsPaths != 0);
Markdown::MD4CParser parser;
auto root = parser.parse(std::string(markdown), flags);
diff --git a/packages/enriched-markdown-android/parser/src/main/cpp/jni/ParserJni.cpp b/packages/enriched-markdown-android/parser/src/main/cpp/jni/ParserJni.cpp
index 95ffae195..2a244cf9e 100644
--- a/packages/enriched-markdown-android/parser/src/main/cpp/jni/ParserJni.cpp
+++ b/packages/enriched-markdown-android/parser/src/main/cpp/jni/ParserJni.cpp
@@ -75,6 +75,7 @@ Md4cFlags JMd4cFlags::toCppFlags() const {
static const auto permissiveAutolinksField = javaClassStatic()->getField("permissiveAutolinks");
static const auto hardSoftBreaksField = javaClassStatic()->getField("hardSoftBreaks");
static const auto preserveBlankLinesField = javaClassStatic()->getField("preserveBlankLines");
+ static const auto preserveWindowsPathsField = javaClassStatic()->getField("preserveWindowsPaths");
static const auto admonitionsField = javaClassStatic()->getField("admonitions");
Md4cFlags flags;
@@ -86,6 +87,7 @@ Md4cFlags JMd4cFlags::toCppFlags() const {
flags.permissiveAutolinks = getFieldValue(permissiveAutolinksField) == JNI_TRUE;
flags.hardSoftBreaks = getFieldValue(hardSoftBreaksField) == JNI_TRUE;
flags.preserveBlankLines = getFieldValue(preserveBlankLinesField) == JNI_TRUE;
+ flags.preserveWindowsPaths = getFieldValue(preserveWindowsPathsField) == JNI_TRUE;
flags.admonitions = getFieldValue(admonitionsField) == JNI_TRUE;
return flags;
}
diff --git a/packages/enriched-markdown-android/parser/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt b/packages/enriched-markdown-android/parser/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt
index 22eb43177..99fd2cf9b 100644
--- a/packages/enriched-markdown-android/parser/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt
+++ b/packages/enriched-markdown-android/parser/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt
@@ -11,6 +11,7 @@ data class Md4cFlags(
val permissiveAutolinks: Boolean = true,
val hardSoftBreaks: Boolean = false,
val preserveBlankLines: Boolean = false,
+ val preserveWindowsPaths: Boolean = false,
val admonitions: Boolean = false,
) {
companion object {
diff --git a/packages/enriched-markdown-android/ui/src/main/java/com/swmansion/enriched/markdown/MarkdownOptions.kt b/packages/enriched-markdown-android/ui/src/main/java/com/swmansion/enriched/markdown/MarkdownOptions.kt
index 93ec4a08e..254c2f7d7 100644
--- a/packages/enriched-markdown-android/ui/src/main/java/com/swmansion/enriched/markdown/MarkdownOptions.kt
+++ b/packages/enriched-markdown-android/ui/src/main/java/com/swmansion/enriched/markdown/MarkdownOptions.kt
@@ -21,6 +21,8 @@ data class MarkdownOptions(
val hardSoftBreaks: Boolean = false,
/** Each blank line renders as an empty line instead of collapsing into one paragraph break. */
val preserveBlankLines: Boolean = false,
+ /** Backslashes separating a Windows drive path (`C:\\Users\\me\\.config`) stay instead of acting as escapes. */
+ val preserveWindowsPaths: Boolean = false,
/** `> [!NOTE]` and the other GitHub alert blockquotes render as admonitions. */
val admonitions: Boolean = false,
) {
@@ -35,6 +37,7 @@ data class MarkdownOptions(
permissiveAutolinks = permissiveAutolinks,
hardSoftBreaks = hardSoftBreaks,
preserveBlankLines = preserveBlankLines,
+ preserveWindowsPaths = preserveWindowsPaths,
admonitions = admonitions,
)
diff --git a/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParserBridge.swift b/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParserBridge.swift
index d19ea98f0..fb74095fa 100644
--- a/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParserBridge.swift
+++ b/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParserBridge.swift
@@ -18,6 +18,7 @@ enum MarkdownParserBridge {
options.hardSoftBreaks ? 1 : 0,
options.permissiveAutolinks ? 1 : 0,
options.preserveBlankLines ? 1 : 0,
+ options.preserveWindowsPaths ? 1 : 0,
options.admonitions ? 1 : 0
) else {
return MarkdownASTNode(type: .document)
diff --git a/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParsingOptions.swift b/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParsingOptions.swift
index 53f735303..5120e8af2 100644
--- a/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParsingOptions.swift
+++ b/packages/enriched-markdown-ios/Sources/EnrichedMarkdown/Parser/MarkdownParsingOptions.swift
@@ -6,6 +6,9 @@ public struct MarkdownParsingOptions: Sendable, Equatable {
public var hardSoftBreaks: Bool
public var permissiveAutolinks: Bool
public var preserveBlankLines: Bool
+ /// Keeps backslashes that separate a Windows drive path (`C:\\Users\\me\\.config`)
+ /// instead of treating them as escapes. Off by default; CommonMark drops them.
+ public var preserveWindowsPaths: Bool
public var admonitions: Bool
/// Set only via `MarkdownRenderPlugin.adjustParsingOptions` (the
@@ -20,6 +23,7 @@ public struct MarkdownParsingOptions: Sendable, Equatable {
hardSoftBreaks: Bool = false,
permissiveAutolinks: Bool = true,
preserveBlankLines: Bool = false,
+ preserveWindowsPaths: Bool = false,
admonitions: Bool = false
) {
self.underline = underline
@@ -29,6 +33,7 @@ public struct MarkdownParsingOptions: Sendable, Equatable {
self.hardSoftBreaks = hardSoftBreaks
self.permissiveAutolinks = permissiveAutolinks
self.preserveBlankLines = preserveBlankLines
+ self.preserveWindowsPaths = preserveWindowsPaths
self.admonitions = admonitions
}
diff --git a/packages/enriched-markdown-ios/cpp/SwiftParserCAPI.h b/packages/enriched-markdown-ios/cpp/SwiftParserCAPI.h
index ab374031a..47ae82b80 100644
--- a/packages/enriched-markdown-ios/cpp/SwiftParserCAPI.h
+++ b/packages/enriched-markdown-ios/cpp/SwiftParserCAPI.h
@@ -10,7 +10,7 @@ typedef struct EMCParseResult EMCParseResult;
EMCParseResult *em_parse_markdown(const char *markdown, int underline, int latexMath, int superscript, int subscript,
int highlight, int hardSoftBreaks, int permissiveAutolinks, int preserveBlankLines,
- int admonitions);
+ int preserveWindowsPaths, int admonitions);
void em_parse_result_release(EMCParseResult *result);
diff --git a/packages/enriched-markdown-ios/cpp/SwiftParserShim.cpp b/packages/enriched-markdown-ios/cpp/SwiftParserShim.cpp
index 1ea0bcd62..ea8e674d8 100644
--- a/packages/enriched-markdown-ios/cpp/SwiftParserShim.cpp
+++ b/packages/enriched-markdown-ios/cpp/SwiftParserShim.cpp
@@ -37,7 +37,7 @@ extern "C" {
EMCParseResult *em_parse_markdown(const char *markdown, int underline, int latexMath, int superscript, int subscript,
int highlight, int hardSoftBreaks, int permissiveAutolinks, int preserveBlankLines,
- int admonitions) {
+ int preserveWindowsPaths, int admonitions) {
auto *result = new (std::nothrow) EMCParseResult();
if (!result) {
return nullptr;
@@ -52,6 +52,7 @@ EMCParseResult *em_parse_markdown(const char *markdown, int underline, int latex
flags.hardSoftBreaks = hardSoftBreaks != 0;
flags.permissiveAutolinks = permissiveAutolinks != 0;
flags.preserveBlankLines = preserveBlankLines != 0;
+ flags.preserveWindowsPaths = preserveWindowsPaths != 0;
flags.admonitions = admonitions != 0;
Markdown::MD4CParser parser;
diff --git a/packages/react-native-enriched-markdown/__tests__/md4c-flags.test.tsx b/packages/react-native-enriched-markdown/__tests__/md4c-flags.test.tsx
index bedf70f2a..b201ee06c 100644
--- a/packages/react-native-enriched-markdown/__tests__/md4c-flags.test.tsx
+++ b/packages/react-native-enriched-markdown/__tests__/md4c-flags.test.tsx
@@ -50,6 +50,26 @@ it('forwards md4cFlags.preserveBlankLines to native when enabled', () => {
expect(nativeView.props.md4cFlags.preserveBlankLines).toBe(true);
});
+it('defaults md4cFlags.preserveWindowsPaths to false on the native prop', () => {
+ const nativeView = renderNative(
+
+ );
+
+ expect(nativeView.props.md4cFlags.preserveWindowsPaths).toBe(false);
+});
+
+it('forwards md4cFlags.preserveWindowsPaths to native when enabled', () => {
+ const nativeView = renderNative(
+
+ );
+
+ expect(nativeView.props.md4cFlags.preserveWindowsPaths).toBe(true);
+});
+
it('disables GFM extensions for the commonmark flavor', () => {
const nativeView = renderNative(
GetBooleanField(flags, preserveBlankLinesField) == JNI_TRUE;
}
+ jfieldID preserveWindowsPathsField = env->GetFieldID(flagsClass, "preserveWindowsPaths", "Z");
+ if (preserveWindowsPathsField) {
+ md4cFlags.preserveWindowsPaths = env->GetBooleanField(flags, preserveWindowsPathsField) == JNI_TRUE;
+ }
jfieldID admonitionsField = env->GetFieldID(flagsClass, "admonitions", "Z");
if (admonitionsField) {
md4cFlags.admonitions = env->GetBooleanField(flags, admonitionsField) == JNI_TRUE;
diff --git a/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt b/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt
index 31ef1ebc7..fa757dcb8 100644
--- a/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt
+++ b/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/MeasurementStore.kt
@@ -415,6 +415,7 @@ object MeasurementStore {
highlight = props.getMapOrNull("md4cFlags").getBooleanOrDefault("highlight", false),
hardSoftBreaks = props.getMapOrNull("md4cFlags").getBooleanOrDefault("hardSoftBreaks", false),
preserveBlankLines = props.getMapOrNull("md4cFlags").getBooleanOrDefault("preserveBlankLines", false),
+ preserveWindowsPaths = props.getMapOrNull("md4cFlags").getBooleanOrDefault("preserveWindowsPaths", false),
admonitions = props.getMapOrNull("md4cFlags").getBooleanOrDefault("admonitions", true),
)
val isGFM = props.getBooleanOrDefault("isGFM", false)
@@ -550,6 +551,7 @@ object MeasurementStore {
highlight = props.getMapOrNull("md4cFlags").getBooleanOrDefault("highlight", false),
hardSoftBreaks = props.getMapOrNull("md4cFlags").getBooleanOrDefault("hardSoftBreaks", false),
preserveBlankLines = props.getMapOrNull("md4cFlags").getBooleanOrDefault("preserveBlankLines", false),
+ preserveWindowsPaths = props.getMapOrNull("md4cFlags").getBooleanOrDefault("preserveWindowsPaths", false),
admonitions = props.getMapOrNull("md4cFlags").getBooleanOrDefault("admonitions", true),
)
val isGFM = props.getBooleanOrDefault("isGFM", true)
diff --git a/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt b/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt
index 52ed9a521..ae7dc7d9c 100644
--- a/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt
+++ b/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/parser/Parser.kt
@@ -13,6 +13,7 @@ data class Md4cFlags(
val permissiveAutolinks: Boolean = true,
val hardSoftBreaks: Boolean = false,
val preserveBlankLines: Boolean = false,
+ val preserveWindowsPaths: Boolean = false,
val admonitions: Boolean = true,
) {
companion object {
diff --git a/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt b/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt
index 6614fe306..9eaf020a4 100644
--- a/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt
+++ b/packages/react-native-enriched-markdown/android/src/main/java/com/swmansion/enriched/markdown/utils/common/MarkdownViewManagerUtils.kt
@@ -140,6 +140,7 @@ fun parseMd4cFlags(flags: ReadableMap?): Md4cFlags =
highlight = flags?.getBoolean("highlight") ?: false,
hardSoftBreaks = flags?.getBoolean("hardSoftBreaks") ?: false,
preserveBlankLines = flags?.getBoolean("preserveBlankLines") ?: false,
+ preserveWindowsPaths = flags?.getBoolean("preserveWindowsPaths") ?: false,
admonitions = flags?.getBoolean("admonitions") ?: true,
)
diff --git a/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.cpp b/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.cpp
index 3db283787..376513083 100644
--- a/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.cpp
+++ b/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.cpp
@@ -22,6 +22,7 @@ Markdown::Md4cFlags toCoreFlags(const EnrichedMarkdownParserMd4cFlags &flags) {
core.highlight = flags.highlight;
core.hardSoftBreaks = flags.hardSoftBreaks;
core.preserveBlankLines = flags.preserveBlankLines;
+ core.preserveWindowsPaths = flags.preserveWindowsPaths;
core.admonitions = flags.admonitions;
return core;
}
diff --git a/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.h b/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.h
index fdb881102..ce5daafcb 100644
--- a/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.h
+++ b/packages/react-native-enriched-markdown/common/EnrichedMarkdownParser.h
@@ -34,7 +34,7 @@ struct Bridging
: NativeEnrichedMarkdownParserNativeLinkOccurrenceBridging {};
using EnrichedMarkdownParserMd4cFlags =
- NativeEnrichedMarkdownParserNativeMd4cFlags;
+ NativeEnrichedMarkdownParserNativeMd4cFlags;
template <>
struct Bridging
: NativeEnrichedMarkdownParserNativeMd4cFlagsBridging {};
diff --git a/packages/react-native-enriched-markdown/ios/EnrichedMarkdown.mm b/packages/react-native-enriched-markdown/ios/EnrichedMarkdown.mm
index 3f35e621f..f69549c2c 100644
--- a/packages/react-native-enriched-markdown/ios/EnrichedMarkdown.mm
+++ b/packages/react-native-enriched-markdown/ios/EnrichedMarkdown.mm
@@ -196,6 +196,7 @@ + (ENRMMd4cFlags *)flagsFromProps:(const EnrichedMarkdownMd4cFlagsStruct &)props
flags.highlight = props.highlight;
flags.hardSoftBreaks = props.hardSoftBreaks;
flags.preserveBlankLines = props.preserveBlankLines;
+ flags.preserveWindowsPaths = props.preserveWindowsPaths;
flags.admonitions = props.admonitions;
return flags;
}
@@ -1500,6 +1501,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
newViewProps.md4cFlags.highlight != oldViewProps.md4cFlags.highlight ||
newViewProps.md4cFlags.hardSoftBreaks != oldViewProps.md4cFlags.hardSoftBreaks ||
newViewProps.md4cFlags.preserveBlankLines != oldViewProps.md4cFlags.preserveBlankLines ||
+ newViewProps.md4cFlags.preserveWindowsPaths != oldViewProps.md4cFlags.preserveWindowsPaths ||
newViewProps.md4cFlags.admonitions != oldViewProps.md4cFlags.admonitions) {
_md4cFlags = [EnrichedMarkdown flagsFromProps:newViewProps.md4cFlags];
_dirtyFlags |= ENRMDirtyForceHeight | ENRMDirtyRender;
diff --git a/packages/react-native-enriched-markdown/ios/EnrichedMarkdownText.mm b/packages/react-native-enriched-markdown/ios/EnrichedMarkdownText.mm
index f41930f4d..f916b1974 100644
--- a/packages/react-native-enriched-markdown/ios/EnrichedMarkdownText.mm
+++ b/packages/react-native-enriched-markdown/ios/EnrichedMarkdownText.mm
@@ -160,6 +160,7 @@ + (ENRMMd4cFlags *)flagsFromProps:(const EnrichedMarkdownTextMd4cFlagsStruct &)p
flags.highlight = props.highlight;
flags.hardSoftBreaks = props.hardSoftBreaks;
flags.preserveBlankLines = props.preserveBlankLines;
+ flags.preserveWindowsPaths = props.preserveWindowsPaths;
flags.admonitions = props.admonitions;
return flags;
}
@@ -719,6 +720,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
newViewProps.md4cFlags.highlight != oldViewProps.md4cFlags.highlight ||
newViewProps.md4cFlags.hardSoftBreaks != oldViewProps.md4cFlags.hardSoftBreaks ||
newViewProps.md4cFlags.preserveBlankLines != oldViewProps.md4cFlags.preserveBlankLines ||
+ newViewProps.md4cFlags.preserveWindowsPaths != oldViewProps.md4cFlags.preserveWindowsPaths ||
newViewProps.md4cFlags.admonitions != oldViewProps.md4cFlags.admonitions) {
_md4cFlags = [EnrichedMarkdownText flagsFromProps:newViewProps.md4cFlags];
_forceHeightUpdateOnNextRender = YES;
diff --git a/packages/react-native-enriched-markdown/ios/internals/ENRMViewFreeMeasurement.h b/packages/react-native-enriched-markdown/ios/internals/ENRMViewFreeMeasurement.h
index 65281b101..2626b098c 100644
--- a/packages/react-native-enriched-markdown/ios/internals/ENRMViewFreeMeasurement.h
+++ b/packages/react-native-enriched-markdown/ios/internals/ENRMViewFreeMeasurement.h
@@ -99,6 +99,7 @@ template static inline ENRMMd4cFlags *ENRMMd4cFlagsFromPro
flags.highlight = props.highlight;
flags.hardSoftBreaks = props.hardSoftBreaks;
flags.preserveBlankLines = props.preserveBlankLines;
+ flags.preserveWindowsPaths = props.preserveWindowsPaths;
flags.admonitions = props.admonitions;
return flags;
}
diff --git a/packages/react-native-enriched-markdown/ios/internals/MeasurementCache.h b/packages/react-native-enriched-markdown/ios/internals/MeasurementCache.h
index 017e4ea3a..2a9deb1e4 100644
--- a/packages/react-native-enriched-markdown/ios/internals/MeasurementCache.h
+++ b/packages/react-native-enriched-markdown/ios/internals/MeasurementCache.h
@@ -43,6 +43,7 @@ struct MeasurementCacheKey {
bool md4cFlagsLatexMath;
bool md4cFlagsHardSoftBreaks;
bool md4cFlagsPreserveBlankLines;
+ bool md4cFlagsPreserveWindowsPaths;
bool md4cFlagsAdmonitions;
size_t styleFingerprint;
size_t linkPillContentFingerprint;
@@ -63,18 +64,18 @@ struct MeasurementCacheKey {
{
return std::tie(markdown, maxWidth, allowTrailingMargin, allowFontScaling, maxFontSizeMultiplier,
md4cFlagsUnderline, md4cFlagsSuperscript, md4cFlagsSubscript, md4cFlagsHighlight,
- md4cFlagsLatexMath, md4cFlagsHardSoftBreaks, md4cFlagsPreserveBlankLines, md4cFlagsAdmonitions,
- styleFingerprint, linkPillContentFingerprint, imageSourcesFingerprint, wrappedCodeBlocksFingerprint,
- fontScale, flavor, lineBreakStrategyIOS, writingDirection, numberOfLines, ellipsizeMode,
- linkRegexKey, inlineCodeLinkRegexKey) ==
+ md4cFlagsLatexMath, md4cFlagsHardSoftBreaks, md4cFlagsPreserveBlankLines,
+ md4cFlagsPreserveWindowsPaths, md4cFlagsAdmonitions, styleFingerprint, linkPillContentFingerprint,
+ imageSourcesFingerprint, wrappedCodeBlocksFingerprint, fontScale, flavor, lineBreakStrategyIOS,
+ writingDirection, numberOfLines, ellipsizeMode, linkRegexKey, inlineCodeLinkRegexKey) ==
std::tie(other.markdown, other.maxWidth, other.allowTrailingMargin, other.allowFontScaling,
other.maxFontSizeMultiplier, other.md4cFlagsUnderline, other.md4cFlagsSuperscript,
other.md4cFlagsSubscript, other.md4cFlagsHighlight, other.md4cFlagsLatexMath,
- other.md4cFlagsHardSoftBreaks, other.md4cFlagsPreserveBlankLines, other.md4cFlagsAdmonitions,
- other.styleFingerprint, other.linkPillContentFingerprint, other.imageSourcesFingerprint,
- other.wrappedCodeBlocksFingerprint, other.fontScale, other.flavor, other.lineBreakStrategyIOS,
- other.writingDirection, other.numberOfLines, other.ellipsizeMode, other.linkRegexKey,
- other.inlineCodeLinkRegexKey);
+ other.md4cFlagsHardSoftBreaks, other.md4cFlagsPreserveBlankLines,
+ other.md4cFlagsPreserveWindowsPaths, other.md4cFlagsAdmonitions, other.styleFingerprint,
+ other.linkPillContentFingerprint, other.imageSourcesFingerprint, other.wrappedCodeBlocksFingerprint,
+ other.fontScale, other.flavor, other.lineBreakStrategyIOS, other.writingDirection,
+ other.numberOfLines, other.ellipsizeMode, other.linkRegexKey, other.inlineCodeLinkRegexKey);
}
};
@@ -94,6 +95,7 @@ struct MeasurementCacheKeyHash {
HashUtils::hash_one(h, key.md4cFlagsLatexMath);
HashUtils::hash_one(h, key.md4cFlagsHardSoftBreaks);
HashUtils::hash_one(h, key.md4cFlagsPreserveBlankLines);
+ HashUtils::hash_one(h, key.md4cFlagsPreserveWindowsPaths);
HashUtils::hash_one(h, key.md4cFlagsAdmonitions);
HashUtils::hash_one(h, key.styleFingerprint);
HashUtils::hash_one(h, key.linkPillContentFingerprint);
@@ -249,6 +251,7 @@ inline MeasurementCacheKey buildMeasurementCacheKey(const PropsType &props, CGFl
.md4cFlagsLatexMath = props.md4cFlags.latexMath,
.md4cFlagsHardSoftBreaks = props.md4cFlags.hardSoftBreaks,
.md4cFlagsPreserveBlankLines = props.md4cFlags.preserveBlankLines,
+ .md4cFlagsPreserveWindowsPaths = props.md4cFlags.preserveWindowsPaths,
.md4cFlagsAdmonitions = props.md4cFlags.admonitions,
.styleFingerprint = computeStyleFingerprint(props.markdownStyle),
.linkPillContentFingerprint = computeLinkPillContentFingerprint(props.linkPillContent),
diff --git a/packages/react-native-enriched-markdown/ios/internals/ShadowMeasurementUtils.h b/packages/react-native-enriched-markdown/ios/internals/ShadowMeasurementUtils.h
index 6a30af0ee..b12de87db 100644
--- a/packages/react-native-enriched-markdown/ios/internals/ShadowMeasurementUtils.h
+++ b/packages/react-native-enriched-markdown/ios/internals/ShadowMeasurementUtils.h
@@ -70,6 +70,7 @@ static inline bool ENRMPropsNeedExactStreamingMeasurement(const PropsT &oldProps
oldProps.md4cFlags.highlight != newProps.md4cFlags.highlight ||
oldProps.md4cFlags.hardSoftBreaks != newProps.md4cFlags.hardSoftBreaks ||
oldProps.md4cFlags.preserveBlankLines != newProps.md4cFlags.preserveBlankLines ||
+ oldProps.md4cFlags.preserveWindowsPaths != newProps.md4cFlags.preserveWindowsPaths ||
oldProps.isGFM != newProps.isGFM || oldProps.md4cFlags.admonitions != newProps.md4cFlags.admonitions ||
computeStyleFingerprint(oldProps.markdownStyle) != computeStyleFingerprint(newProps.markdownStyle);
}
diff --git a/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.h b/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.h
index 699988ee8..c36895f60 100644
--- a/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.h
+++ b/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.h
@@ -10,6 +10,7 @@
@property (nonatomic, assign) BOOL highlight;
@property (nonatomic, assign) BOOL hardSoftBreaks;
@property (nonatomic, assign) BOOL preserveBlankLines;
+@property (nonatomic, assign) BOOL preserveWindowsPaths;
@property (nonatomic, assign) BOOL admonitions;
+ (instancetype)defaultFlags;
diff --git a/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.mm b/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.mm
index 6651baec9..7f8ae2cb2 100644
--- a/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.mm
+++ b/packages/react-native-enriched-markdown/ios/parser/ENRMMarkdownParser.mm
@@ -21,6 +21,7 @@ - (instancetype)init
_highlight = NO;
_hardSoftBreaks = NO;
_preserveBlankLines = NO;
+ _preserveWindowsPaths = NO;
_admonitions = YES;
}
return self;
@@ -41,6 +42,7 @@ - (id)copyWithZone:(NSZone *)zone
copy.highlight = self.highlight;
copy.hardSoftBreaks = self.hardSoftBreaks;
copy.preserveBlankLines = self.preserveBlankLines;
+ copy.preserveWindowsPaths = self.preserveWindowsPaths;
copy.admonitions = self.admonitions;
return copy;
}
diff --git a/packages/react-native-enriched-markdown/ios/parser/MarkdownParserBridge.mm b/packages/react-native-enriched-markdown/ios/parser/MarkdownParserBridge.mm
index 77a786b73..bb2393c66 100644
--- a/packages/react-native-enriched-markdown/ios/parser/MarkdownParserBridge.mm
+++ b/packages/react-native-enriched-markdown/ios/parser/MarkdownParserBridge.mm
@@ -207,6 +207,7 @@
cppFlags.highlight = flags.highlight;
cppFlags.hardSoftBreaks = flags.hardSoftBreaks;
cppFlags.preserveBlankLines = flags.preserveBlankLines;
+ cppFlags.preserveWindowsPaths = flags.preserveWindowsPaths;
cppFlags.admonitions = flags.admonitions;
return cppFlags;
}
diff --git a/packages/react-native-enriched-markdown/src/EnrichedMarkdownNativeComponent.ts b/packages/react-native-enriched-markdown/src/EnrichedMarkdownNativeComponent.ts
index af6574c59..309c3f2a8 100644
--- a/packages/react-native-enriched-markdown/src/EnrichedMarkdownNativeComponent.ts
+++ b/packages/react-native-enriched-markdown/src/EnrichedMarkdownNativeComponent.ts
@@ -427,6 +427,7 @@ export interface Md4cFlagsInternal {
* @default false
*/
preserveBlankLines: boolean;
+ preserveWindowsPaths: boolean;
/**
* Enable GitHub-style admonitions/alerts extension.
* Forced off for `flavor="commonmark"`.
diff --git a/packages/react-native-enriched-markdown/src/EnrichedMarkdownTextNativeComponent.ts b/packages/react-native-enriched-markdown/src/EnrichedMarkdownTextNativeComponent.ts
index ba0dc96e4..c0697b192 100644
--- a/packages/react-native-enriched-markdown/src/EnrichedMarkdownTextNativeComponent.ts
+++ b/packages/react-native-enriched-markdown/src/EnrichedMarkdownTextNativeComponent.ts
@@ -422,6 +422,7 @@ export interface Md4cFlagsInternal {
* @default false
*/
preserveBlankLines: boolean;
+ preserveWindowsPaths: boolean;
/**
* Enable GitHub-style admonitions/alerts extension.
* Forced off for `flavor="commonmark"`.
diff --git a/packages/react-native-enriched-markdown/src/NativeEnrichedMarkdownParser.ts b/packages/react-native-enriched-markdown/src/NativeEnrichedMarkdownParser.ts
index 68a92012e..546b091ea 100644
--- a/packages/react-native-enriched-markdown/src/NativeEnrichedMarkdownParser.ts
+++ b/packages/react-native-enriched-markdown/src/NativeEnrichedMarkdownParser.ts
@@ -9,6 +9,7 @@ export interface NativeMd4cFlags {
highlight: boolean;
hardSoftBreaks: boolean;
preserveBlankLines: boolean;
+ preserveWindowsPaths: boolean;
admonitions: boolean;
}
diff --git a/packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx b/packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx
index f4356481b..0386cb11e 100644
--- a/packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx
+++ b/packages/react-native-enriched-markdown/src/native/EnrichedMarkdownText.tsx
@@ -160,6 +160,7 @@ const defaultMd4cFlags: Md4cFlags = {
highlight: false,
hardSoftBreaks: false,
preserveBlankLines: false,
+ preserveWindowsPaths: false,
admonitions: true,
};
@@ -237,6 +238,7 @@ export const EnrichedMarkdownText = ({
const highlight = md4cFlags.highlight ?? false;
const hardSoftBreaks = md4cFlags.hardSoftBreaks ?? false;
const preserveBlankLines = md4cFlags.preserveBlankLines ?? false;
+ const preserveWindowsPaths = md4cFlags.preserveWindowsPaths ?? false;
// Admonitions are a GitHub-flavor feature; force them off in commonmark so
// `> [!NOTE]` renders as a plain blockquote.
const admonitions =
@@ -250,6 +252,7 @@ export const EnrichedMarkdownText = ({
highlight,
hardSoftBreaks,
preserveBlankLines,
+ preserveWindowsPaths,
admonitions,
}),
[
@@ -260,6 +263,7 @@ export const EnrichedMarkdownText = ({
highlight,
hardSoftBreaks,
preserveBlankLines,
+ preserveWindowsPaths,
admonitions,
]
);
diff --git a/packages/react-native-enriched-markdown/src/types/MarkdownStyle.ts b/packages/react-native-enriched-markdown/src/types/MarkdownStyle.ts
index ee1a80613..c7660e088 100644
--- a/packages/react-native-enriched-markdown/src/types/MarkdownStyle.ts
+++ b/packages/react-native-enriched-markdown/src/types/MarkdownStyle.ts
@@ -475,6 +475,12 @@ export interface Md4cFlags {
* @default false
*/
preserveBlankLines?: boolean;
+ /**
+ * Keep backslashes that separate a Windows drive path (`C:\Users\me\.config`)
+ * instead of treating them as escapes. Off by default; CommonMark drops them.
+ * @default false
+ */
+ preserveWindowsPaths?: boolean;
/**
* Enable GitHub-style admonitions/alerts (`> [!NOTE]`, `> [!TIP]`,
* `> [!IMPORTANT]`, `> [!WARNING]`, `> [!CAUTION]`).
diff --git a/packages/react-native-enriched-markdown/src/web/EnrichedMarkdownText.tsx b/packages/react-native-enriched-markdown/src/web/EnrichedMarkdownText.tsx
index fadc7a56e..0339778f9 100644
--- a/packages/react-native-enriched-markdown/src/web/EnrichedMarkdownText.tsx
+++ b/packages/react-native-enriched-markdown/src/web/EnrichedMarkdownText.tsx
@@ -75,6 +75,7 @@ export const EnrichedMarkdownText = ({
highlight = false,
hardSoftBreaks = false,
preserveBlankLines = false,
+ preserveWindowsPaths = false,
admonitions = true,
} = md4cFlags;
@@ -98,6 +99,7 @@ export const EnrichedMarkdownText = ({
highlight,
hardSoftBreaks,
preserveBlankLines,
+ preserveWindowsPaths,
admonitions,
}),
katexPromise,
@@ -143,6 +145,7 @@ export const EnrichedMarkdownText = ({
highlight,
hardSoftBreaks,
preserveBlankLines,
+ preserveWindowsPaths,
admonitions,
textLinkKey,
inlineCodeLinkKey,
diff --git a/packages/react-native-enriched-markdown/src/web/parseMarkdown.ts b/packages/react-native-enriched-markdown/src/web/parseMarkdown.ts
index cd101f734..34d9da1ba 100644
--- a/packages/react-native-enriched-markdown/src/web/parseMarkdown.ts
+++ b/packages/react-native-enriched-markdown/src/web/parseMarkdown.ts
@@ -11,7 +11,8 @@ type ParseFn = (
hardSoftBreaks: number,
preserveBlankLines: number,
admonitions: number,
- permissiveAutolinks: number
+ permissiveAutolinks: number,
+ preserveWindowsPaths: number
) => string;
/**
@@ -99,6 +100,7 @@ export async function parseMarkdown(
highlight = false,
hardSoftBreaks = false,
preserveBlankLines = false,
+ preserveWindowsPaths = false,
admonitions = true,
permissiveAutolinks = true,
}: WebMd4cFlags = {}
@@ -116,7 +118,8 @@ export async function parseMarkdown(
hardSoftBreaks ? 1 : 0,
preserveBlankLines ? 1 : 0,
admonitions ? 1 : 0,
- permissiveAutolinks ? 1 : 0
+ permissiveAutolinks ? 1 : 0,
+ preserveWindowsPaths ? 1 : 0
)
);
diff --git a/packages/react-native-enriched-markdown/src/web/wasm/md4c.js b/packages/react-native-enriched-markdown/src/web/wasm/md4c.js
index 4ac1f8a98..8797d9c84 100644
Binary files a/packages/react-native-enriched-markdown/src/web/wasm/md4c.js and b/packages/react-native-enriched-markdown/src/web/wasm/md4c.js differ
diff --git a/scripts/test-web-bundle.mjs b/scripts/test-web-bundle.mjs
index 2f2acc3e8..4d903a3dd 100755
--- a/scripts/test-web-bundle.mjs
+++ b/scripts/test-web-bundle.mjs
@@ -25,16 +25,16 @@ const BUNDLE = join(
const FIXTURES = join(REPO_ROOT, 'packages/core/cpp/tests/fixtures');
const GOLDEN = join(REPO_ROOT, 'packages/core/cpp/tests/golden/ast.txt');
-// parseMarkdown() in md4c_wasm.cpp exposes nine of the parser's flags; isGFM
+// parseMarkdown() in md4c_wasm.cpp exposes ten of the parser's flags; isGFM
// keeps its default (true). That reaches the golden dump's three -gfm
// variants - the two -commonmark ones turn isGFM off, so they cannot be
// reproduced through this entry point.
const VARIANTS = {
// underline, latexMath, superscript, subscript, highlight, hardSoftBreaks,
- // preserveBlankLines, admonitions, permissiveAutolinks
- 'defaults-gfm': [0, 1, 0, 0, 0, 0, 0, 1, 1],
- 'extensions-off-gfm': [0, 0, 0, 0, 0, 0, 0, 0, 0],
- 'extensions-on-gfm': [1, 1, 1, 1, 1, 1, 1, 1, 1],
+ // preserveBlankLines, admonitions, permissiveAutolinks, preserveWindowsPaths
+ 'defaults-gfm': [0, 1, 0, 0, 0, 0, 0, 1, 1, 0],
+ 'extensions-off-gfm': [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
+ 'extensions-on-gfm': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
};
function readGolden() {
@@ -91,7 +91,7 @@ const module = await import(pathToFileURL(BUNDLE).href);
const instance = await module.default();
const parse = instance.cwrap('parseMarkdown', 'string', [
'string',
- ...Array(9).fill('number'),
+ ...Array(10).fill('number'),
]);
console.log('==> Comparing its AST against the golden dump');