TITLE: Is any function taking compact sets to compact sets, and connected sets to connected sets, necessarily continuous?
QUESTION [17 upvotes]: It is well-known that continuous image of any compact set is compact, and that continuous image of any connected set is connected.
How far is the converse of the above statements true?
More precisely: Let $X$ be a topological space. Suppose there is a map $f$ from $X$ into itself which takes compact sets to compact sets and connected sets to connected sets. Do these conditions imply that $f$ is continuous?
If not in general, at least when $X$ is a metric space? or, when $f$ is a bijection? or both? or under any other additional conditions?
My apologies if my question in boringly elementary.
Thanks in advance!

REPLY [22 votes]: There are highly non-trivial positive results. 
Let us call a function $f$ from a space $X$ into a space $Y$ preserving if the image of every compact subspace of $X$ is compact in $Y$ and the image of every connected subspace of $X$ is connected in $Y$. 
McMillan  [On continuity conditions for functions, Pacific J. Math. 32 (1970) 479-494] proved the following result:
Theorem: If $X$ is Hausdorff, locally connected and Fréchet, and $Y$ is Hausdorff (e.g. if $X=Y=\mathbb R$), then any preserving function $f:X\to Y$ is continuous.
For further  results see Gerlits, Juhasz, Soukup, Szentmiklossy: Characterizing continuity by preserving compactness and connectedness, Top. Appl, 138 (2004), 21-44
Our main result is the following:
Theorem:  If $X$ is any product of connected linearly ordered spaces (e.g., if $X = \mathbb R^\kappa$ ) and $f:X \to Y$ is a preserving function into a regular space $Y$, then $f$ is continuous.