# looking for a system for writing branching dialog

I'm creating an HTML5 RPG and need to write NPC dialog. In my beta, I wrote the dialog in spreadsheets and assigned lines to NPC by ID. Branching required writing a complicated flag system. It was impossible for anyone to read through it and understand what was going on.

I'm looking for a better alternative to writing branching story dialog. The dialog will require some degree of in-text markdown support (so I can be sure which text to highlight with CSS). In the spreadsheet, that looked like

"Hello, my name is [name: John]. Welcome to [location: Aragon]. Please fetch the [keyword: sword]"

Would would appear as:

"Hello, my name is John. Welcome to Aragon. Please fetch the sword"

These would be higlighted/handled differently in code.