diff --git a/RichEditorView/Assets/editor/rich_editor.js b/RichEditorView/Assets/editor/rich_editor.js index 6fc55d4e..a526414f 100644 --- a/RichEditorView/Assets/editor/rich_editor.js +++ b/RichEditorView/Assets/editor/rich_editor.js @@ -130,6 +130,10 @@ RE.updatePlaceholder = function() { }; RE.removeFormat = function() { + // https://stackoverflow.com/a/52137754/4514671 + // https://stackoverflow.com/questions/14028773/javascript-execcommandremoveformat-doesnt-strip-h2-tag + // formatting to 'p' because removeFormat cannot deal with headers (h1, h2, ...) + document.execCommand('formatBlock', false, 'p'); document.execCommand('removeFormat', false, null); }; @@ -137,6 +141,13 @@ RE.setFontSize = function(size) { RE.editor.style.fontSize = size; }; +RE.setFontFamily = function(font) { + RE.restorerange(); + document.execCommand("styleWithCSS", null, true); + document.execCommand('fontName', false, font); + document.execCommand("styleWithCSS", null, false); +}; + RE.setBackgroundColor = function(color) { RE.editor.style.backgroundColor = color; }; diff --git a/RichEditorView/Assets/editor/style.css b/RichEditorView/Assets/editor/style.css index f7484847..92f1d679 100644 --- a/RichEditorView/Assets/editor/style.css +++ b/RichEditorView/Assets/editor/style.css @@ -23,6 +23,7 @@ html { body { min-height: 100%; overflow: auto; + padding: 10px; } body, h1, p { diff --git a/RichEditorView/Classes/RichEditorView.swift b/RichEditorView/Classes/RichEditorView.swift index 527b81c7..8c1a6932 100644 --- a/RichEditorView/Classes/RichEditorView.swift +++ b/RichEditorView/Classes/RichEditorView.swift @@ -233,6 +233,10 @@ import UIKit runJS("RE.setFontSize('\(size)px');") } + public func setFontFamily(_ font: String) { + runJS("RE.setFontFamily('\(font)');") + } + public func setEditorBackgroundColor(_ color: UIColor) { runJS("RE.setBackgroundColor('\(color.hex)');") }