coddingtonbear / obsidian-csv-table

Have a CSV file you want to render some or all of the data from? This plugin allows you to display that data in your obsidian preview.
MIT License
113 stars 5 forks source link

Error evaluating filter expressions #7

Closed kosnik-ng closed 2 years ago

kosnik-ng commented 2 years ago

Hello, My cvs file contains the items below:

"Nom","Localité"
"Zoé","Paris"
"Léa","Lyon"

In the source file, I wrote:

csvtable
columns:
    - Nom
    - Localité
source: contact/export.csv
filter: Localité == "Paris"

If the column name to be filtered contains accents, the following error is encountered:

Error evaluating filter expressions: Lexical error on line 1. Unrecognized text.
Localité == "Paris"
-------^.

I have tried with single and double quotes, but it does not work.

Could not parse CSV table spec: Unexpected scalar at node end at line 6, column 10:

filter: "Localité" == "Paris"
         ^

The accents are not a problem in the values, it matches correctly:

filter:  Nom == "Zoé"
kosnik-ng commented 2 years ago

For the column sorting, If the column name has an accent or a space, the same error occurs :

Error evaluating filter expressions: Lexical error on line 1. Unrecognized text.
Société
----^.

with this code

columns:
    - Nom de famille
    - Prénom
    - Société
    - Emails
    - Téléphones
    - Localité
    - Région
    - URL
    - Notes
source: contact/export-contacts.csv
sortBy:
    - Société

or

columns:
    - Nom de famille
    - Prénom
    - Société
    - Emails
    - Téléphones
    - Localité
    - Région
    - URL
    - Notes
source: contact/export-contacts.csv
sortBy:
    - Nom de famille
coddingtonbear commented 2 years ago

Unfortunately, the library we're using for handling filter expressions and sorting (filtrex) doesn't support non-ascii column names in much the same way that a programming language isn't likely to support them for variable names -- and that's because under the hood, those column names are variable names. There's good news, though: you can easily set a variable name for your columns by using the extended syntax discussed here: https://github.com/coddingtonbear/obsidian-csv-table#user-content-selecting-particular-columns

Unfortunately, this does mean that your CSV file's header line should contain only ascii characters given that those header entries are used like variable names throughout the filtering and sorting system, but you can easily change the displayed header using the instructions above. E.g.

```
columns:
- expression: nom_de_famille
  name: Nom de famille
- expression: prenom
  name: Prenóm
...
```

I know this isn't the answer that you want to hear, and I'm sorry about that! If it helps: this limitation applies even for English headers, it's just a little less likely to pinch in English given that we'll only run into the problem if we have a header having a space in its name.

Good luck!