我想在TinyMCE编辑器中将所有{baseurl}
个关键字替换为正确的网址。我怎么能这样做?
例如,如果用户将在编辑器<img src="{baseurl}/image.jpg" />
中添加HTML,我想在TinyMCE编辑器中看到此图像 - 因此这将替换为<img src="http://mydomain.com
/image.jpg" />
有什么想法吗?
答案 0 :(得分:48)
以下是替换编辑器内容的代码。但是你需要在正确的时间做这个动作。
var editor = tinymce.get('my_editor_id'); // use your own editor id here - equals the id of your textarea
var content = editor.getContent();
content = content.replace(/{\$baseurl}/g, 'http://mydomain.com');
editor.setContent(content);
答案 1 :(得分:1)
通过这个解决方案,我能够即时修改内容,而无需整体替换内容:
tinymce.init({
setup: (editor)=>{
editor.on('init', ()=>{
$(editor.contentDocument).find('a').prop('title', 'my new title');
});
}
});
也许它有助于某人:)
答案 2 :(得分:0)
我使用了非常简单的代码,可以很好地与我合作
import time
import keyboard #pip install keyboard - could use pynput listener instead.
from threading import Thread
hshtag = int(0)
done = False
fire = False
def StopStart():
while not done:
# global fire - You're setting StopStart up for a param that needs passed, that also is named another variable
# So it will just over write it (Also, no arg is passed for StopStart(fire))
if keyboard.is_pressed('#'):
hshtag = hshtag + 1
if hshtag % 2 == 0 : fire = False
else : fire = true
return fire
def NormalFire():
while not done:
#global fire - Don't need to global it, you would've had to global done if that was the case
if fire: # don't need == true, just need if fire (if true)
print("x")
t1 = Thread(target=StopStart)
t2 = Thread(target=NormalFire)
t1.start()
t2.start()