Ver Fonte

유튜브 문법

2DU há 9 anos atrás
pai
commit
c898c6d69c
2 ficheiros alterados com 33 adições e 1 exclusões
  1. 29 1
      app.py
  2. 4 0
      templates/index.html

+ 29 - 1
app.py

@@ -36,6 +36,33 @@ def namumark(title, data):
     data = re.sub('__(?P<in>.+?)__(?!_)', '<u>\g<in></u>', data)
     data = re.sub('\^\^(?P<in>.+?)\^\^(?!\^)', '<sup>\g<in></sup>', data)
     data = re.sub(',,(?P<in>.+?),,(?!,)', '<sub>\g<in></sub>', data)
+    
+    while True:
+        p = re.compile("\[youtube\(((?:(?!,|\)\]).)*)(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?(?:,\s)?(?:height=((?:(?!,|\)\]).)*))?(?:,\s)?(?:width=((?:(?!,|\)\]).)*))?\)\]", re.I)
+        m = p.search(data)
+        if(m):
+            result = m.groups()
+            if(result[1]):
+                if(result[2]):
+                    width = result[1]
+                    height = result[2]
+                else:
+                    width = result[1]
+                    height = '315'
+            elif(result[2]):
+                if(result[3]):
+                    height = result[2]
+                    width = result[3]
+                else:
+                    height = result[2]
+                    width = '560'
+            else:
+                width = '560'
+                height = '315'
+            data = p.sub('<iframe width="' + width + '" height="' + height + '" src="https://www.youtube.com/embed/' + result[0] + '" frameborder="0" allowfullscreen></iframe>', data, 1)
+        else:
+            break
+                
 
     while True:
         m = re.search("\[\[(((?!\]\]).)*)\]\]", data)
@@ -44,7 +71,8 @@ def namumark(title, data):
             a = re.search("(((?!\|).)*)\|(.*)", result[0])
             if(a):
                 results = a.groups()
-                b = re.search("^[Hh][Tt][Tt][Pp]([Ss])?:\/\/", results[0])
+                p = re.compile("^http(?:s)?:\/\/", re.I)
+                b = p.search(results[0])
                 if(b):
                     data = re.sub('\[\[(((?!\]\]).)*)\]\]', '<a class="out_link" href="' + results[0] + '">' + results[2] + '</a>', data, 1)
                 else:

+ 4 - 0
templates/index.html

@@ -384,6 +384,10 @@
                 <li>[[내부 링크|보이는 내용]]</li>
                 <li>[[외부 링크]]</li>
                 <li>[[외부 링크|보이는 내용]]</li>
+                <h2>유튜브 문법</h2>
+                <li>[youtube(코드)]</li>
+                <li>[youtube(코드, width=가로, height=세로)]</li>
+                <li>[youtube(코드, height=세로, width=가로)]</li>
 			</div>
 			{% elif tn == 18 %}
 			<h1 class="title">{{title}}</h1>