A sex attacker who tried to rape a woman who was walking her dogs in Fife has been jailed indefinitely.

Alexander McIlravie knocked the woman to the ground during the "harrowing" attack in Burntisland Links on November 2015.

He was forced to flee after her dogs started biting him and the 31-year-old woman fought him off.

The 26-year-old was jailed for four years and given an order for lifelong restriction at the High Court in Livingston.

The order means he will not be automatically released at the end of his four-year sentence but will be held until a parole board decides it is safe to free him.

McIlravie was found guilty of assaulting the woman with intent to rape at Burntisland Links on November 11, 2015.

The court was told McIlravie ran at her and pinned her to the ground before repeatedly saying he would rape her.

She struggled with him and let go of her dog leads but the animals stayed at her side and started barking at McIlravie.

Sentencing him at the High Court in Livingston on Thursday, judge Lord Uist said: "The dogs remained on the spot, harassed you and continued to bark. Eventually you got up and ran away.

"Your victim believes that it was the presence and involvement of her dogs that made you break off your attack and leave."

McIlravie was later found with injuries consistent with dog bites.

The judge continued: "This was a terrifying experience for her and it has had a devastating effect upon her daily life."

Lord Uist said McIlravie had psychopathic personality disorder and a "history of sexually violent behaviour involving physical coercion".

Issueing an order for lifelong restriction, Lord Uist said: "There is overwhelming evidence that you are a highly dangerous and violent man who presents a grave risk to the safety of the public.

"I am satisfied that the risk criteria are met in your case, there is a likelihood that, if at liberty, you will seriously endanger the lives, or physical or psychological well-being, of members of the public at large."

Police said McIlravie's victim had showed courage during the "harrowing" attack and the two-year period before he as jailed.

Detective inspector Paul Dick, of Kirkcaldy CID, said: "I would like to pay tribute to the victim in this case who has been courageous not only during the harrowing incident but throughout the last two years and was unfortunately required to give evidence in court.

"I would also like to thank the other witnesses who assisted us in this inquiry and also the detectives and other police officers for their hard work and dedication during this investigation.

"In all cases of serious sexual crime Police Scotland will conduct a detailed and thorough investigation, working closely with the Crown Office and Procurator Fiscal Service and other partner agencies to ensure that perpetrators such as McIlravie are brought to justice and victims are supported."