Let $F$ be a closed subset of $\mathbb R$ and let $f:F\to \mathbb R$ be a continuous function. I want to show that there exists a continuous extension of $f$ on $\mathbb R$. For that I proceed as follows:
Since $\mathbb R\setminus F$ is open there exists countable collection $\{(a_n,b_n):n\in \mathbb N\}$ of pairwise disjoint open intervals such that $\mathbb R\setminus F=\bigcup\limits_{n=1}^{\infty} (a_n,b_n)$.
We define $g:\mathbb R\to \mathbb R$ by $g(x)=f(x)$ if $x\in F$. If $x\notin F$, there must exist unique $(a,b)$ in the above collection such that $x\in (a,b)$ and we define $g(x)=\frac{b-x}{b-a}f(a)+\frac{x-a}{b-a}f(b)$ if $a,b\in \mathbb R$. If $a,b$ are infinite, then we adjust accordingly. I could show that if $x_0\in \mathbb R\setminus F$, then $g$ is continuous at $x_0$. Problem starts if $x_0\in F$. If $x\in F^{0}$, then also I can show. But if $x\in \partial F$, then I could not do anything. Please help!
Hint: The solution is probably going to use this inequality: If $0\le t\le 1$ then $$\begin{align}|f(x)-(tf(a)+(1-t)f(b))|&=|t(f(x)-f(a))+(1-t)(f(x)-f(b))| \\&\le|t(f(x)-f(a))|+|(1-t)(f(x)-f(b))| \\&=t|f(x)-f(a)|+(1-t)|f(x)-f(b)| \\&\le\max(|f(x)-f(a)|,|f(x)-f(b)|).\end{align}$$