timdown / rangy

A cross-browser JavaScript range and selection library.
MIT License
2.23k stars 367 forks source link

Cannot set dynamic values to ClassApplier properties #469

Open Azuf opened 3 years ago

Azuf commented 3 years ago

I tried to assign a variable and a function returning a string to the elementProperties and it doesn't work. When setting attempting to use a function it sets the function definition in string format o_O and setting a variable does nothing when its clearly got a value

highlighter.addClassApplier(
      rangy.createClassApplier('note', {
        ignoreWhiteSpace: true,
        elementTagName: 'a',
        elementProperties: {
          href: '#',
          title: noteText,
        },
      })
    );
Azuf commented 3 years ago

https://github.com/timdown/rangy/blob/1e55169d2e4d1d9458c2a87119addf47a8265276/src/modules/rangy-classapplier.js#L557

issue with this line. forces whatever is passed to turn into a string. Wouldn't it be better to just check if the value or whatever is passed is a string instead of doing this