Facile synthesis of metal/metal oxide nanoparticles inside a nanoporous carbon matrix (M/MO@C) through the morphology-preserved transformation of metal-organic framework.