Implement Minecraft's Rails Background Information
Inspired by this answer on Arqade SE
Minecraft has rails which allow you to move minecarts around on them for transporting players, entities, and items. There are many types of rails, but today we're only interested in regular rails, which are also the only type that can curve.
When you place down a normal rail that has two adjacent rails, it will connect them. If they are not on opposite sides of the rail, the rail will curve to a 90 degree angle. However, if there are more than two adjacent rails, it can't connect all of them. In that case, it will always favor going south-east (this is called the south-east or Z-X rule) (for this challenge, north is up, east is right, south is down, west is left). If there is a T-junction, the rail will always connect to the &quot;vertical&quot; branch of the T, and then it will prioritize south over north if the main branch is east-west, and east over west if the main branch is north-south. If there is a four-way junction, the rail will connect south and east.
I/O
For this challenge, you will need eight distinct characters: empty space, vertical rail, horizontal rail, up-left curved rail, up-right curved rail, down-left curved rail, down-right curved rail, and placeholder. You may select any characters; I choose to use box-drawing characters in my examples. You may count these eight characters as one byte in your code (this is just to allow people to use box-drawing characters instead of just like &quot; |-WXYZ#&quot; or something not as nice-looking).
You will be given input in a convenient format for a layout of existing rails. This will be a grid, so you may take it as a matrix of characters, a list of strings, newline-separated strings, etc. Anything reasonable. To simplify a bit, your input will only contain straight rails, placeholders, and blanks.
Your output should be a grid of the same size, but in each placeholder you are to place a rail according to the rules given. To make this challenge a bit simpler, every placeholder will always have at least two adjacent rails that are already facing the appropriate direction, so you should not change any cells except the placeholders. Note that it is possible for the rails to be on opposite sides of the placeholder, in which case you may need to place down a straight rail.
Detailed Example
This contains every possible configuration:
.═.═.═.
║ ═ ║ ║
.║  ║ ║
║   ║ ║
.═══.═.
║   ║ ║
.═══.═.

The output for this would be:
╔═══╔═╗
║ ═ ║ ║
║║  ║ ║
║   ║ ║
╔═══╔═╗
║   ║ ║
╚═══╚═╝

Note that it's valid to have rails facing the wrong direction next to placeholders. You are guaranteed that at least two adjacent rails are facing the right way though. Technically, in Minecraft, this might cause the side rails to turn to face the new rail and then curve, but in this specific challenge, we'll just assume that existing straight rails will not turn, and you just need to connect up exactly two of the adjacent, correctly-oriented rails in accordance to the S-E rule.
   .══.══.             ╔═════╗
   ║     ║             ║     ║
.══.══.  .          ╔══╔══╗  ║
║  ║  ║  ║    -&gt;    ║  ║  ║  ║
.══.══.  .          ╚══╔══╝  ║
   ║     ║             ║     ║
   .══.══.             ╚═════╝

You're running out of space on your minecart to write your code, so your code must be as short as possible! This is code-golf, so the shortest answer in bytes wins (remember that you may count your eight I/O characters as one byte).
Python 3, 394 378 370 328 bytes

def p(s,i,R,C,H='═',V='║'):
 v=i%C and s[i-1]==H
 v|=(i//C and s[i-C]==V)&lt;&lt;3
 v|=(i%C-C+1and s[i+1]==H)&lt;&lt;2
 return' ═║╗══╔╔║╝║╗╚╚╔╔'[v|(i//C-R+1and s[i+C]==V)&lt;&lt;1]
def f(s,i=0):
 t=s.split('\n');R,C,s=len(t),len(t[0]),''.join(t)
 for c in s:print([c,p(s,i,R,C)][c=='.'],end='\n'[:-~i%C==0]);i+=1

Try it online!
A very naive method. Receives as input a string and iterates over its characters. If a character is a point (a placeholder), replace it with the character returned by p.
The function p builds a &quot;4-bits integer&quot; v, where:

if its 1st bit is set, the placeholder has a valid connection with the west;
if its 2nd bit is set, the placeholder has a valid connection with the south;
if its 3rd bit is set, the placeholder has a valid connection with the east; and
if its 4th bit is set, the placeholder has a valid connection with the north.

A invalid connection occurs with a direction when

the rail is on a border of that direction (the first placeholder in the example given by the OP has an invalid connection with the north and the west since it's in the border, so its 4-bit integer is 1010).


the rail of that direction is misaligned with the placeholder (the fifth placeholder in the example given by the OP has an invalid connection with the east since the east rail is misaligned, so its 4-bit integer is 1011).

After this 4-bit integer is built, it returns the corresponding box-drawing character using this integer as index of a string.