PrismJS / prism

Lightweight, robust, elegant syntax highlighting.
https://prismjs.com
MIT License
12.29k stars 1.29k forks source link

[Feature Request] Support for EXCEL Formula Arguments Syntax on `xlsx` #3479

Open FelipeRearden opened 2 years ago

FelipeRearden commented 2 years ago

Hello friends !!!!

My FR is about a little feature to be added when using the syntax xlsx or xls .

In many cases we need to present the argument of an EXCEL formula instead of the cell.

=FORMULA(argument_1,argument_2)

=VLOOKUP(lookup_value,table_array,col_index_num, [range_lookup])

We only get syntax highlight when inserting cells

=FORMULA(A1,A2)

=VLOOKUP(A1,A2,A3,A4)

Why I am asking this ?

The Note-taking App Obsidian uses PrismJS to highlight code syntax .

I am creating a documentation about my EXCEL formula knowledge and I want to describe the formula arguments as a code block.

Suggestion of Implementation

I was talking about this idea with ganesshkumar on this Issue here

ganesshkumar suggests these approach:

Little more context, a rendered syntax like the below

image

We can see that the arguments are not wrapped inside span elements and are not annotated with classes - token, argument or text. If they can wrap the arguments in span with some css classes then we can use some custom css in obsidian to show the alternating arguments in different colors as you are expecting.

This the original comment with all the details.

I was not able to insert images in this issue (I don’t know why) but I tried the best to show my FR.


Thanks for reading this. Let me know if something is not clear.

Have a great day!

RunDevelopment commented 2 years ago

In many cases we need to present the argument of an EXCEL formula instead of the cell.

=FORMULA(argument_1,argument_2)

=VLOOKUP(lookup_value,table_array,col_index_num, [range_lookup])

We only get syntax highlight when inserting cells

=FORMULA(A1,A2)

=VLOOKUP(A1,A2,A3,A4)

Please clarify what you mean. Functions take arguments, so any arbitrary expression (variables, cells, functions calls, etc.) can be an argument. Why exactly do you want highlighted?

FelipeRearden commented 2 years ago

Hello @RunDevelopment !!!!

Thank you very much for your reply :)

Please clarify what you mean.

Sorry for my bad explanation. Let me be more clear about my FR.

Functions take arguments, so any arbitrary expression (variables, cells, functions calls, etc.) can be an argument.

1️⃣ EXCEL Fundamentals

AN EXCEL formula is designed is with elements

For example the EXCEL formula VLOOKUP has these structure:

Formula_Name -> VLOOKUP

Arguments

2️⃣ EXCEL Formula Syntax

The EXCEL formula syntax is this :

=formula_name(argument_1, argument_2, argument_3)

💡 each argument is separated by comma

For Example with the VLOOUP formula.

=VLOOKUP(lookup_value,table_array,col_index_num, [range_lookup])

Why exactly do you want highlighted?

MY FR is to highlight the arguments

1ADE0950-4E5F-4056-8EB2-D2B718D66B15

When I use the codeblock above, this what we get:

118AE7EC-7FD1-4949-8CF1-6011AC35BE25

This is my FR 🙏 :

5EC2E1C5-1C6A-4386-88D5-31A7AF33E75D


Let me know if something is not clear know !

Thanks for reading this!

Have a great day

FelipeRearden commented 2 years ago

Hello @RunDevelopment

Sorry to bother you :)

Just to know if my FR is now clear (from my previous comment)

Thanks.

RunDevelopment commented 2 years ago

Sorry for the delay!

Yes, it's clear now. Unfortunately, this won't be too easy to implement. The problem is that to wrap an argument, we need to match arbitrary expressions, which isn't possible with regexes (context-free grammar vs regex). So we'll have to use a few tricks to make this happen.

FelipeRearden commented 2 years ago

Sorry for the delay!

No problem 😀 !!!! Sorry again for bothering you :)

Yes, it's clear now.

I'm glad to know that is clear :)

Unfortunately, this won't be too easy to implement. The problem is that to wrap an argument, we need to match arbitrary expressions, which isn't possible with regexes (context-free grammar vs regex). So we'll have to use a few tricks to make this happen.

I appreciate you feedback ! My hope is that would be something easy to implement :)

I am going to start to create my EXCEL documentation in Obsidian maybe in the future we get the highlights for the EXCEL arguments.

Thanks and have a great day!!!!!!