How do I format code correctly to post in the forums or reddit?

I don’t know what has changed but normally I would select all, copy and paste into code block and format would remain the same. Recently, it goes like this:

cards:  - entities:      - entity: person.jake      - entity: sensor.jake_travel_time    type: entities    show_header_toggle: false  - entities:      - entity: person.emma      - entity: sensor.em_travel_time    type: entities  - entities:      - entity: binary_sensor.rio    type: entitiestype: horizontal-stack

what am I doing wrong?

Reddit is really bad for code blocks - I find that I always need to re-edit (no pun intended) my code-block after posting.

This forum is fine, however. Add 3 ticks before and after (pasting your code in-between). By tick I mean this one ```, not this one ‘’’

However, the problem with your code (above) is that it pasted all onto one line, so you have this:

cards:  - entities:      - entity: person.jake      - entity: sensor.jake_travel_time    type: entities    show_header_toggle: false  - entities:      - entity: person.emma      - entity: sensor.em_travel_time    type: entities  - entities:      - entity: binary_sensor.rio    type: entitiestype: horizontal-stack

You need to edit your post and add the carriage-returns manually to get this:

cards:
  - entities:
      - entity: person.jake
      - entity: sensor.jake_travel_time
    type: entities
    show_header_toggle: false
  - entities:
      - entity: person.emma
      - entity: sensor.em_travel_time
    type: entities
  - entities:
      - entity: binary_sensor.rio
    type: entities
type: horizontal-stack

edit: typos.

1 Like

Thank you! Just wanted to confirm I wasn’t being stupid formatting it manually if there was a knack to it.

It’s strange because it doesn’t always do this but seems like it does it more recently. Either way looks like il be manually editing it then.

Thanks

1 Like