code: function applyCaretFormat() {
            var rng, caretContainer, textNode, offset, bookmark, container, text;
  
            rng = selection.getRng(true);
            offset = rng.startOffset;
            container = rng.startContainer;
            text = container.nodeValue;
  
            caretContainer = getParentCaretContainer(selection.getStart());
            if (caretContainer) {
              textNode = findFirstTextNode(caretContainer);
            }
  
            // Expand to word if caret is in the middle of a text node and the char before/after is a alpha numeric character
            var wordcharRegex = /[^\s\u00a0\u00ad\u200b\ufeff]/;
            if (text && offset > 0 && offset < text.length &&
              wordcharRegex.test(text.charAt(offset)) && wordcharRegex.test(text.charAt(offset - 1))) {
              // Get bookmark of caret position
              bookmark = selection.getBookmark();
  
              // Collapse bookmark range (WebKit)
              rng.collapse(true);
  
              // Expand the range to the closest word and split it at those points
              rng = expandRng(rng, get(name));
              rng = rangeUtils.split(rng);
  
              // Apply the format to the range
              apply(name, vars, rng);
  
              // Move selection back to caret position
              selection.moveToBookmark(bookmark);
            } else {
              if (!caretContainer || textNode.nodeValue !== INVISIBLE_CHAR) {
                caretContainer = createCaretContainer(true);
                textNode = caretContainer.firstChild;
  
                rng.insertNode(caretContainer);
                offset = 1;
  
                apply(name, vars, caretContainer);
              } else {
                apply(name, vars, caretContainer);
              }
  
              // Move selection to text node
              selection.setCursorLocation(textNode, offset);
            }
          }
docs: Applies formatting to the caret position