The Heart of Midlothian by Sir Walter Scott is an historical novel. What this means, on the most basic level, is that it blends historical fact with a fictional imagination. While there are many real events in the novel, there are also imaginary characters mixed in. Moreover, the historical records contains only limited details. The thoughts and conversations of the characters are all imagined by Scott as they were not written down.
The central historical events of the novel are the Porteous Riots of 1736. Captain John Porteous, a real person, used excessive violence in ending riots in Edinburgh, killing civilian protesters. The story of his lynching in Scott's novel follows the real and gruesome historical events. The character of Jeanie Deans, and her walk to London to petition the Queen is loosely based on a real woman, Helen Walker. Effie and other members of the Deans family are purely imaginary, as are the lovers of the two girls. The religious and nationalistic issues both follow the historical record, and remained conflicts even in Scott's own period.