Code trình phát video trong bài viết sử dụng Markdown
Trong bài viết, sử dụng:{vid://www.youtube.com/watch?v=s2ICoI8wGkU}
Xử lý:
<div class="menu" style="text-align:justify;font-style:normal;padding:12px" id="content">
{{markdown(content)|raw}}
</div>
<script>
var get_content = document.getElementById("content").innerHTML;
var get_content = get_content.replace(/{vid:\/\/(.*?)}/g, '<div class="video-wrapper" style="text-align:center;"><iframe loading="lazy" src="/video-embed?link=http://$1" height="315" width="560" scrolling="no" allowfullscreen="" frameborder="0"></iframe></div>');
document.getElementById("content").innerHTML = get_content;
</script>
Hoặc
{% macro video(string) %}
{% set pattern = '/{vid:\\/\\/(.*?)}/' %}
{% set replacement = '<div class="video-wrapper" style="text-align: center;"><iframe loading="lazy" src="/video-embed?link=http://$1" height="315" width="560" scrolling="no" allowfullscreen="" frameborder="0"></iframe></div>' %}
{{string|preg_replace(pattern, replacement)|raw}}
{% endmacro %}
{% macro _markdown(string,v) %}
{% set string = markdown(string,v) %}
{% set string = _self.video(string) %}
{{string|raw}}
{% endmacro %}
{% from '_markdown' import '_markdown' %}
<div class="menu" style="text-align:justify;font-style:normal;padding:12px" id="content">
{{_markdown(content)|raw}}
</div>
Trang:
[1]