farling42 / obsidian-import-json

Plug-in for Obsidian.md which will create Notes from JSON files
MIT License
91 stars 5 forks source link

Support wildcards in table helper #5

Closed ckennedy666 closed 2 years ago

ckennedy666 commented 2 years ago

It would be useful if we could use wildcards such as "?" and "*" in the {{table ...}} helper. I could also see the need for a new helper to be defined.

Proposed behavior:

Given data of ["F1", "G3"]

template: {{table item "F?" "[[Stellar Class#F|F]]?" "G?" "[[Stellar Class#G|G]]?"}}

Produces: [[Stellar Class#F|F]]1 [[Stellar Class#G|G]]3

Thanks.

farling42 commented 2 years ago

Implemented in 0.10.0

Full javascript regular expression patterns (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions)

Since "?" matches a single character, your example would need to be coded as:

{{table item "F(?)" "[[Stellar Class#F|F]]$1" "G(?)" "[[Stellar Class#G|G]]$1"}}

where "(?)" is creating a numbered group containing a single character, and "$1" in the resulting string gets replaced by that first numbered group.

For a traveller UPP, you could use:

{{table upp "(\d)(\d)(\d)(\d)(\d)(\d)" "Str $1 Dex $2 End $3 Int $4 Edu $5 Soc $6"}}

which is a bit weird since there aren't multiple entries to extract, but it gets everything into a single string :-)