Home

# Class goog.editor.plugins.RemoveFormatting

A plugin to handle removing formatting from selected text.

extends goog.editor.Plugin

Instance Method Summary
| `adjustRangeForTables_(?goog.dom.AbstractRange range, ?Node startInTable, ?Node endInTable) ⇒ ?goog.dom.SavedCaretRange` Move the range so that it doesn't include any partially selected tables.
| `convertSelectedHtmlText_(function (string): string convertFunc)` Gets the html inside the current selection, passes it through the given conversion function, and puts it back into the selection.
| `getHtmlText_(?goog.dom.AbstractRange range) ⇒ string` Gets the html inside the selection to send off for further processing. TODO(user): Make this general so that it can be moved into goog.editor.range. The main reason it can't be moved is becuase we need to get the range before we do the execCommand and continue to operate on that same range (reasons are documented above).
| `getValueForNode(?Element node) ⇒ ?string` Handle per node special processing if neccessary. If this function returns null then standard cleanup is applied. Otherwise this node and all children are assumed to be cleaned. NOTE(user): If an alternate RemoveFormatting processor is provided (setRemoveFormattingFunc()), this will no longer work.
| `isSupportedCommand(string command) ⇒ boolean` Whether the string corresponds to a command this plugin handles.
| `pasteHtml_(string html)` Replaces the contents of the selection with html. Does its best to maintain the original selection. Also does its best to result in a valid DOM. TODO(user): See if there's any way to make this work on Ranges, and then move it into goog.editor.range. The Firefox implementation uses execCommand on the document, so must work on the actual selection.
| `putCaretInCave_(?goog.dom.SavedCaretRange caretRange, boolean isStart)` Remove a caret from the dom and hide it in a safe place, so it can be restored later via restoreCaretsFromCave.
| `removeFormattingWorker_(string html) ⇒ string` Does a best-effort attempt at clobbering all formatting that the browser's execCommand couldn't clobber without being totally inefficient. Attempts to convert visual line breaks to BRs. Leaves anchors that contain an href and images. Adapted from Gmail's MessageUtil's htmlToPlainText. http://go/messageutil.js
| `removeFormatting_()` Removes formatting from the current selection. Removes basic formatting (B/I/U) using the browser's execCommand. Then extracts the html from the selection to convert, calls either a client's specified removeFormattingFunc callback or trogedit's general built-in removeFormattingWorker_, and then replaces the current selection with the converted text.

`restoreCaretsFromCave_()`

Restore carets that were hidden away by adding them back into the dom. Note: this does not restore to the original dom location, as that will likely have been modified with remove formatting. The only guarentees here are that start will still be before end, and that they will be in the editable region. This should only be used when you don't actually intend to USE the caret again.

| `setRemoveFormattingFunc(function (string): string removeFormattingFunc)` Sets a function to be used for remove formatting.

Static Method Summary
| `appendNewline_(?Array.<string> sb)` Appends a new line to a string buffer.
| `createRangeDelimitedByRanges_(?goog.dom.AbstractRange startRange, ?goog.dom.AbstractRange endRange) ⇒ ?goog.dom.AbstractRange` Create a new range delimited by the start point of the first range and the end point of the second range.
| `getTableAncestor_(?Node nodeToCheck) ⇒ ?Node` Finds the nearest ancestor of the node that is a table.