1. get the selection
  2. for each range in the selection
    1. get the startNode, endNode, startOffset, endOffset of the range
    2. if startNode is an element, let startNode be the startOffset-nth child of startNode
    3. if endNode is an element, let endNode be the (endOffset-1)-nth child of endNode
    4. promote selection to an array of nodes, iterating all nodes in the selection from startNode to endNode in traversal order
      1. if  the iterated node is entirely contained in the selection
        1. if the descendant node is an HTML element equivalent to the style to set, replace it by its contents; continue iterating with first child of the original node
        2. if the node is an element and carries the CSS property to set, delete that CSS style ; if the element carries no CSS style and no other attribute after that, replace it by its contents; continue iterating with first child of the original node
        3. if the node is a significant text node, store it in the array, continue iterating
        4. if the node is an inline element node, store it in the array, continue iterating skipping all children of the node
        5. else continue iterating
      2. else if the node is only partially contained in the selection
        1. if the node is an inline node or a text node, split node deep to selection boundaries; resulting node is now entirely contained in selection, apply steps above.
        2. else continue interating
    5. let startNode be the first node in the array and endNode the last one
    6. let direction be 1
    7. if startNode is not an element and endNode is an element, let direction be -1
    8. for each node in the array browsed in increasing index order if direction is 1 and decreasing order otherwise:
      1. if the ancestors of the node set the requested style, do nothing and continue with next node in array
      2. let refNode be the previousSibling if direction is 1 and the nextSibling otherwise
      3. in HTML mode:
        1. if refNode is the HTML equivalent to the style to set and carries no attribute, append the node to the children of refNode; continue
        2. encapsulate the node into the HTML equivalent element to the style to set
      4. in CSS mode:
        1.  if refNode carries only the CSS style to set and no other attribute, append the node to the children of refNode; continue
        2. encapsulate the node into a span carrying the style to set