Gutenberg add extra attributes to custom format

I was able to add the attribute by passing it in attributes through the registerFormatType settings:

attributes: {
   'custom-attr': 'custom-attr'
},

then in edit():

toggleFormat( value, {
    attributes: {
      'custom-attr': 'Hello world'
    },
} )

I don’t know how exactly it all works together because I could not find detailed explanations in the current documentation.

Another great feature would be the ability to add extra HTML markup in custom formats but I could not find any examples. For example:

<div custom-attr="Hello world"><div class="an-extra-div"></div>Lorem ipsum dolor...</div>

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)