[PATCH] D75687: [clangd] Only minimally escape text when rendering to markdown.

Sam McCall via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 17 05:43:30 PDT 2020


sammccall marked an inline comment as done.
sammccall added a comment.

Filed https://github.com/google/llvm-premerge-checks/issues/147 for the spurious unit test failure.



================
Comment at: clang-tools-extra/clangd/FormattedString.cpp:150
+    // Not a delimiter if surrounded by space.
+    return !SpaceSurrounds();
+  case '-': // Setex heading, horizontal ruler, or bullet.
----------------
kadircet wrote:
> kadircet wrote:
> > `_` seems to behave different than `*` :(
> > 
> > it seems to rather depend on the spaces around the text being emphasized, i.e
> > 
> > ```
> > foo _ bar _ foo -> no emphasis
> > foo _ bar_ foo -> no emphasis
> > foo _bar_ foo -> emphasis on bar
> > foo_bar_ foo -> no emphasis
> > ```
> > 
> > so this should rather be `Before.endswith(" ") && isAlpha(After)` for the beginning of emphasis and the opposite for the ending.
> > Not sure if there's an easy way to decide on it in isolation.
> regarding this one, i suppose we'll just be escaping in some unnecessary cases(like the 2nd and the 4th), but still better than the current state so nvm.
Oops, I forgot to reply to this one. Good catch that `*` and `_` are different.
The rules are indeed really complicated (particularly for _ next to punctuation) and we don't know whether we are at the start or end.

However my reading of the spec says alnum_alnum never needs to be escaped, and that's incredibly common, so I've added that special case. (Same is true for alnum___alnum, but I don't think that's common enough to bother with).


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D75687/new/

https://reviews.llvm.org/D75687





More information about the cfe-commits mailing list