Characterising Continuous functions 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}$.
 A: Much more general results are known: no statement of this form can characterize continuous functions, derivatives, Baire class 1 functions, Borel functions, measurable functions, etc.
THEOREM $\;$ There do not exist families of sets of reals $\rm\: \cal A\:,\:\cal B\;$ such that the following statement is true:   
$\quad\quad$ for every function $\rm\; f : \mathbb R\to \mathbb R\:,\;\;\; f\:$ is continuous $\iff$ for every $\: A\in {\cal A}\:,\;\; {\rm f}\:(A) \in \cal B$
For the elementary proof see this 1997 Monthly paper by Velleman and for more general results on classes of functions characterizable by images of sets see this paper, whose abstract I have appended below:
For non-empty topological spaces $X$ and $Y$ and arbitrary
families $\cal{A}\subseteq\cal{P}(X)$ and $\cal{B}\subseteq\cal{P}(Y)$ we put
$\cal{C}_{\cal{A},\cal{B}}=\{f\in Y^X\colon(\forall A\in\cal{A})(f[A]\in\cal{B})\}$.
In this paper we will examine
which classes of functions $\cal{F}\subseteq Y^X$
can be represented as $\cal{C}_{\cal{A},\cal{B}}$. We will be mainly
interested in the case
when
$\cal{F}=\cal{C}(X,Y)$ is the class of all continuous functions from $X$ into $Y$.
We prove that for non-discrete Tychonoff space $X$ the class
$\cal{F}=\cal{C}(X,\mathbb{R})$
is not equal to $\cal{C}_{\cal{A},\cal{B}}$ for any
$\cal{A}\subseteq \cal{P}(X)$ and $\cal{B}\subseteq\cal{P}(\mathbb{R})$. Thus, $\cal{C}(X,\mathbb{R})$
cannot be characterized by images of sets.
We also show that none of the
following classes of real functions can be represented as
$\cal{C}_{\cal{A},\cal{B}}$:
upper (lower) semicontinuous functions,
derivatives, approximately  continuous functions,
Baire class 1 functions, Borel functions, and measurable functions.
A: No. See Conway's base 13 function. If we call this function $f$,
while $f$ itself is not a counterexample to your question, $g(x)=\sin f(x)$
is. The connected compact subsets of $\mathbb{R}$ are the empty set, the
one-point sets and the closed intervals $[a,b]$ with $a < b$. The Conway
function $f$ takes such closed intervals to $\mathbb{R}$ and so $g$
takes them to $[-1,1]$. The functions $f$ and $g$ are discontinuous everywhere.
ADDED
For functions with domain $\mathbb{R}^n$ the answer is still no. Just
take
$$(x_1,\ldots,x_n)\mapsto g(x_1)$$
where $g$ is the function above.
