We know that if $f : \mathbb{R} \to \mathbb{R}$ is a continuous function, then $f$ carries connected sets to connected sets and compact sets to compact sets. That is if $A \subset \mathbb{R}$ is connected then $f(A)$ is connected, and if $A$ is compact then $f(A)$ is compact.
Question: Suppose $f: \mathbb{R} \to \mathbb{R}$ is a function such that for every connected, compact subsets $A \subset \mathbb{R}$, $f(A)$ is connected, compact, then is $f$ continuous? If yes, i would like to see a proof.
Update: Does this result remain true if $f: \mathbb{R}^{2} \to \mathbb{R}$, or from any $f: \mathbb{R}^{m} \to \mathbb{R}^{n}$.