Matthew 1:19 -- part of Matthew's Christmas story -- provides a wonderful glimpse into the character of Joseph.
The Bible says he was a "righteous man."
As such, Joseph could not take to himself a woman who had sinned. But love and compassion prevented him from pressing the law to its logical extent (death by stoning; Deut. 22:21). The matter would be settled privately without exposure. A "bill of divorcement" in the presence of two or three witnesses would suffice.
Note: "Righteousness" consists in doing the right thing. The idea frequently includes doing the merciful thing. Joseph did just that. He did the merciful -- i.e., milder -- thing. He put Mary away but in the most private manner permitted under Jewish law. And he did this, Matthew says, because he was dikaios/tzadik. In Hebrew thought, tzedakah ("righteousness") referred to (1) a right act, (2) kindness to others, and/or (3) charity. Thus, a righteous person is not someone who is holier than thou. It is a man or a woman who does what it right in a way that is most appropriate to the situation.
Thank God for a man like Joseph!