Mercurial Hosting > freedit
changeset 23:cdcd1b70c15e
tinymce work
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 18 Jul 2022 23:50:48 -0600 |
parents | d87a8f9f43d7 |
children | fccbe5554fcc |
files | src/lib/Bbcode.luan src/test/tiny.html |
diffstat | 2 files changed, 36 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
diff -r d87a8f9f43d7 -r cdcd1b70c15e src/lib/Bbcode.luan --- a/src/lib/Bbcode.luan Sun Jul 17 21:47:55 2022 -0600 +++ b/src/lib/Bbcode.luan Mon Jul 18 23:50:48 2022 -0600 @@ -16,6 +16,7 @@ local String = require "luan:String.luan" local gsub = String.gsub or error() local matches = String.matches or error() +local match = String.match or error() local User = require "site:/lib/User.luan" local Shared = require "site:/lib/Shared.luan" local list_to_set = Shared.list_to_set or error() @@ -79,7 +80,7 @@ end function html.size(bbcode,options) - %><span style="font-size:<%=bbcode.param%>%"><% to_html(bbcode.contents,options) %></span><% + %><span style="font-size:<%=bbcode.param%>"><% to_html(bbcode.contents,options) %></span><% end function html.quote(bbcode,options) @@ -100,21 +101,31 @@ options.strip_newline = true end +local youtube_ptn1 = [[https://youtu.be/([a-zA-Z0-9_-]+)(?:\?t=([0-9]+))?]] +local youtube_ptn2 = [[https://www.youtube.com/watch\?v=([a-zA-Z0-9_-]+)(?:&t=([0-9]+)s)?]] +local bitchute_ptn = [[https://www.bitchute.com/video/([a-zA-Z0-9]+)/]] + function html.video(bbcode,options) - local url = html_encode(bbcode.contents) - local site = bbcode.site - if site == "youtube" then - %><iframe width="420" height="315" src="https://www.youtube.com/embed/<%=bbcode.id%><% - local start = bbcode.start + local url = bbcode.contents + local id, start = match(url,youtube_ptn1) + if id == nil then + id, start = match(url,youtube_ptn2) + end + if id ~= nil then + %><iframe width="560" height="315" src="https://www.youtube.com/embed/<%=id%><% if start ~= nil then %>?start=<%=start%><% end %>" frameborder="0" allowfullscreen></iframe><% - elseif site == "bitchute" then - %><iframe width="420" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/<%=bbcode.id%>/"></iframe><% - else - %><a href="<%=url%>"><%=url%></a><% + return end + id = match(url,bitchute_ptn) + if id ~= nil then + %><iframe width="560" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/<%=id%>/"></iframe><% + return + end + url = html_encode(url) + %><a href="<%=url%>"><%=url%></a><% end local function list_to_html(bbcode,options)
diff -r d87a8f9f43d7 -r cdcd1b70c15e src/test/tiny.html --- a/src/test/tiny.html Sun Jul 17 21:47:55 2022 -0600 +++ b/src/test/tiny.html Mon Jul 18 23:50:48 2022 -0600 @@ -17,21 +17,29 @@ url2 = url; let result; if( result = url.match(youtubePtn1) || url.match(youtubePtn2) ) { - html = '<iframe data-url="'+url+'" width="560" height="315" src="https://www.youtube.com/embed/' + result[1]; + html = '<iframe data-video="'+url+'" width="560" height="315" src="https://www.youtube.com/embed/' + result[1]; if( result[2] ) html += '?start=' + result[2] html += '" frameborder="0" allowfullscreen></iframe>'; } else if( result = url.match(bitchutePtn) ) { - html = '<iframe data-url="'+url+'" width="560" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/' + result[1] + '/"></iframe>'; + html = '<iframe data-video="'+url+'" width="560" height="315" scrolling="no" frameborder="0" style="border: none;" src="https://www.bitchute.com/embed/' + result[1] + '/"></iframe>'; } else { - html = '<a href="'+url+'">'+url+'</a>'; + html = '<a data-video="'+url+'" href="'+url+'">'+url+'</a>'; } resolve({ html: html }); } + function tinymceSetup(editor) { + editor.ui.registry.addButton('styleCode', { + text: 'code', + onAction: () => alert('Button clicked!') + }); + } + tinymce.init({ selector: 'textarea', - plugins: ['link', 'image', 'media'], + setup: tinymceSetup, + plugins: ['link', 'image', 'media', 'lists'], link_target_list: false, link_title: false, image_description: false, @@ -44,8 +52,8 @@ media_url_resolver: media_url_resolver, text_patterns: false, content_style: 'img {max-width: 500px;}', - newline_behavior: 'linebreak', - //toolbar: 'image', + //newline_behavior: 'linebreak', + toolbar: 'link image media | styleCode bold | numlist bullist', extended_valid_elements: 'b,i', formats: { bold: { inline: 'b' }, @@ -60,9 +68,8 @@ </script> </head> <body> - <p>top</p> + <p><a href="https://www.tiny.cloud/">TinyMCE</a></p> <textarea></textarea> <p><button onclick="log()">log</button></p> - <p>bottom</p> </body> </html>