javalent / dice-roller

Inline dice rolling for Obsidian.md
265 stars 27 forks source link

JavaScript section roller returns object not string #283

Closed chmac closed 6 months ago

chmac commented 7 months ago

Check for existing bug reports before submitting.

Expected Behavior

I would expect that calling roller.roll() on a section roller should return a string, but it returns an object.

Current behaviour

const diceRollerPlugin = app.plugins.getPlugin('obsidian-dice-roller')
const manifestoRoller = await diceRollerPlugin.getRoller('[[Quotes]]')
const section = await manifestoRoller.roll()
console.log(JSON.stringify(section))

This outputs a JSON object like so:

{
  "type": "paragraph",
  "position": {
    "start": {
      "line": 9,
      "col": 0,
      "offset": 66
    },
    "end": {
      "line": 10,
      "col": 10,
      "offset": 88
    }
  },
  "id": "dice-j5v2"
}

Reproduction

Reproduction posted above.

Which Operating Systems are you using?

Obsidian Version Check

1.4.16

Plugin Version

10.4.0

Confirmation

Possible solution

No response

valentine195 commented 6 months ago

This is expected behavior, but you can use SectionRoller#transformResultsToString to get a string result.

chmac commented 6 months ago

@valentine195 Aha, thanks for sharing the way to resolve a string, I couldn't figure that out. 👍🏼