From 88a78c7eefcf8f91038e86530f301469dba4bc10 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Mon, 5 Mar 2018 14:58:20 +0100 Subject: [PATCH] Blogger now support embedded youtube video --- src/packages/Blogger/main.coffee | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/src/packages/Blogger/main.coffee b/src/packages/Blogger/main.coffee index cebb44b..9b2ff5d 100644 --- a/src/packages/Blogger/main.coffee +++ b/src/packages/Blogger/main.coffee @@ -311,14 +311,40 @@ class Blogger extends this.OS.GUI.BaseApplication ctimestr: if sel then sel.ctimestr else d.toString() utime: d.timestamp() utimestr: d.toString() - rendered: me.editor.options.previewRender(content).asBase64() + rendered: me.process(me.editor.options.previewRender(content)) publish: if ((@find "blog-publish").get "swon") then 1 else 0 data.id = sel.id if sel - #save the data @blogdb.save data, (r) -> return me.error "Cannot save blog: #{r.error}" if r.error me.loadBlogs() + + process: (text) -> + # find video tag and rendered it + embed = (id) -> + return """ + + """ + re = /\[\[([^:]*):([^\]]*)\]\]/g + replace = [] + while (found = re.exec text) isnt null + replace.push found + return text.asBase64() unless replace.length > 0 + ret = "" + begin = 0 + for it in replace + ret += text.substring begin, it.index + ret += embed(it[2]) + begin = it.index + it[0].length + ret += text.substring begin, text.length + #console.log ret + return ret.asBase64() + clearEditor:() -> @.editor.value "" @.inputtags.value = ""