Is it safe to take ranitidine while pregnant or breastfeeding?

Yes. Ranitidine, now an over-the-counter product known as zantac, has been well studied in pregnancy. And for good reason! heartburn is very common in the second and third trimesters, so the good news is that OTC ranitidine is considered safe in pregnancy and breast-feeding.
Probably safe. Ranitidine is pregnancy class B - no demonstrated risk in animal studies, probably safe in 2nd & 3rd trimesters. Also considered "probably safe" in breast feeding. In general, caution is advised, so I would definitely discuss it with your doctor or midwife.