question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to recognize escaped characters in AST?

See original GitHub issue

I’m looking for a way to find out whether a given character in an AST String inline node was escaped in the original Markdown.

In particular, I’d like to know this for square brackets. My goal is to enable something like artifact links in SourceForge’s Allura Markdown. You can think of it as an inline marker comparable to a link, but without any use for a custom link text.

With the current CommonMark.NET, I can already scan the text returned as literal strings and check whether there are any [...] like substrings that I would like to process.

However, for this to work properly, I would like to respect explicit escapes by the user. Thus, \[...] should not be considered for custom processing, [...\]...] would recognize the first ] as a part of the string within the processing-worthy square brackets, etc. Is there a (clean) way to retrieve this bit of information already?

It would, of course, be extra-convenient to receive [...] groups as a separate inline tag, but as that is not part of the CommonMark standard, I understand it may not be desirable to integrate this feature so deeply in the CommonMark.NET source code.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fhaagcommented, Aug 24, 2016

Thanks for these explanations. I have successfully integrated the feature into a local copy of CommonMark.NET based upon your last solution. In fact, I have changed a few more lines in order to support a new InlineTag value for that kind of syntax. (I called it Placeholder, because it’s essentially a keyword/string that gets replaced by the host application – if the host application decides it wants to process that particular string rather than insert it as a bracketed literal.)

Looking at this feature again, would it be desirable from your side to add it as an activatable “additional feature”, the way it is currently done with the strikethrough feature? Such a “placeholder” feature could help connect Markdown with application-specific content, as it currently happens with SourceForge’s aforementioned artifact links, tag reference on the Stack Exchange network, the table of contents in Roadkill Wiki (this one uses braces, but it is conceptually the same thing), etc.

If you might consider this worthwhile, I could create a unit test and put my modifications on Github for you guys to have a look.

0reactions
fhaagcommented, Sep 12, 2016

Indeed, all my wishes have been fulfilled 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

AST not parsing strings with escaped backslashes correctly
A decent workaround is s.encode("unicode_escape") as it appears that this is actually a replication of stackoverflow.com/q/18707338/4013571 ...
Read more >
Regular Expression Character Escaping - Blog
When learning how to correctly escape characters in a regular expression, it helps to divide the escaping rules into two different lists of ......
Read more >
Escape character
An escape character is a particular case of metacharacters. Generally, the judgement of whether something is an escape character or not depends on...
Read more >
When to escape characters
When to escape characters. When using SPL2, use the backslash character ( \ ) to ignore characters that have special meaning in a...
Read more >
Character Escapes in .NET Regular Expressions
Character escapes are recognized in regular expression patterns but not in replacement patterns. Character Escapes in .NET. The following table ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found