robindijkhof / overleaf-textarea

This plugin displays your tex source in a textarea so plugins like grammarly can check it.
GNU General Public License v3.0
513 stars 31 forks source link

latex comment filter #38

Closed MartinoMensio closed 3 years ago

MartinoMensio commented 3 years ago

This filter excludes comments (starting with %).

This matches:

And does not match:

How it works: The regex /(?<!\\)%.*/g has:

This filter has been tested by using the user filters in the extension. Please let me know if it has some issues

robindijkhof commented 3 years ago

Hi, I'm not entirely sure what problem this PR solves. AFAIK comments are already filtered and escaped % are still displayed.

image

MartinoMensio commented 3 years ago

Hi, Sorry, you are right. It is already filtered by your first filter /w*(?<!\\)%.*\n?/g.

I didn't see it working because I have some errors in my console for my file:

2021-02-24T16:12:02.256Z Pattern incorrect. Text length reduced by :/w*(?<!\\)%.*\n?/g,

This is probably caused by the last line of my tex file that is currently a comment. So when you check on the number of lines (newText.split("\n").length === text.split("\n").length) there is something not working.

The minimal file to reproduce the issue is the following:

a
%b

Without a new line at the end.

So the fix I propose is now the following:

I hope this helps

robindijkhof commented 3 years ago

Thanks!