The Temperley--Lieb algebra is a finite dimensional associative algebra that arose in the context of statistical mechanics and occurs naturally as a quotient of the Hecke algebra arising from a Coxeter group of type $A$. It is often realized in terms of a certain diagram algebra, where every diagram can be written as a product of simple diagrams. These factorizations correspond precisely to factorizations of the so-called fully commutative elements of the Coxeter group that index a particular basis. Given a reduced factorization of a fully commutative element, it is straightforward to construct the corresponding diagram. On the other hand, it is generally difficult to reconstruct the factorization given an arbitrary diagram. We present an efficient algorithm for obtaining a reduced factorization for a given diagram.