鸿 记5d13.cn

a programer log.

Home other

markdown 语法学习

markdown 语法学习

By 鸿记

Markdown 语法的一些知识点的记录,例如如何写标题,写列表,写 table 等。

h 标题的写法

    #h1
    ##h2
    ######h6

ul 和 li

  • testtest
  • testtest
  • testtest
  • testtest
      * testtest
      * testtest
      * testtest
      * testtest
      * testtest
    
  • testtest
  • testtest
  • testtest
  • testtest
  • testtest
     1. testtest
     2. testtest
     3. testtest
     4. testtest
     5. testtest
    
Markdown 使用 email 形式的區塊引言 果你很熟悉如何在 email 信件中引言i 你就知 道怎麼在 Markdown 文件中建立一個区块引言,那會看起來像是你強迫斷行,然後在每行的 最前面加
格式 用法 示例
h1标签 #标签 #我是h1 ========= ## h2
ul标签 * 标签
  • python代码高亮写法

from django.conf import settings
from django.template import TemplateDoesNotExist
from django.template.loader_tags import ExtendsNode

class OverExtendsNode(ExtendsNode):

<span class="k">def</span> <span class="nf">find_template</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">name</span><span class="p">,</span> <span class="n">dirs</span><span class="p">):</span>
    <span class="s">"""
    Replacement for Django's ``find_template``, that also returns
    the location of the template found.
    """</span>
    <span class="k">for</span> <span class="n">loader_name</span> <span class="ow">in</span> <span class="n">settings</span><span class="o">.</span><span class="n">TEMPLATE_LOADERS</span><span class="p">:</span>
        <span class="n">loader</span> <span class="o">=</span> <span class="n">find_template_loader</span><span class="p">(</span><span class="n">loader_name</span><span class="p">)</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">source</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="n">loader</span><span class="o">.</span><span class="n">load_template_source</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">dirs</span><span class="p">)</span>
        <span class="k">except</span> <span class="n">TemplateDoesNotExist</span><span class="p">:</span>
            <span class="k">pass</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="k">return</span> <span class="n">source</span><span class="p">,</span> <span class="n">path</span>
    <span class="k">raise</span> <span class="n">TemplateDoesNotExist</span><span class="p">(</span><span class="n">name</span><span class="p">)</span>

<span class="k">def</span> <span class="nf">get_parent</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">context</span><span class="p">):</span>
    <span class="s">"""
    Load the parent template using our own ``find_template``, which
    will also give us the path of the template found. We then peek
    at the first node, and if its parent arg is the same as the
    current parent arg, we know circular inheritance is going to
    occur, in which case we try and find the template again, with
    the absolute directory removed from the search list.
    """</span>
    <span class="kn">from</span> <span class="nn">django.template.loaders.app_directories</span> <span class="kn">import</span> <span class="n">app_template_dirs</span>
    <span class="n">dirs</span> <span class="o">=</span> <span class="nb">list</span><span class="p">(</span><span class="n">settings</span><span class="o">.</span><span class="n">TEMPLATE_DIRS</span> <span class="o">+</span> <span class="n">app_template_dirs</span><span class="p">)</span>
    <span class="n">parent</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">parent_name</span><span class="o">.</span><span class="n">resolve</span><span class="p">(</span><span class="n">context</span><span class="p">)</span>
    <span class="n">template</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">find_template</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">dirs</span><span class="p">)</span>
    <span class="k">if</span> <span class="p">(</span><span class="nb">isinstance</span><span class="p">(</span><span class="n">template</span><span class="o">.</span><span class="n">nodelist</span><span class="p">[</span><span class="mi">0</span><span class="p">],</span> <span class="n">ExtendsNode</span><span class="p">)</span> <span class="ow">and</span>
        <span class="n">template</span><span class="o">.</span><span class="n">nodelist</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">parent_name</span><span class="o">.</span><span class="n">resolve</span><span class="p">(</span><span class="n">context</span><span class="p">)</span> <span class="o">==</span> <span class="n">parent</span><span class="p">):</span>
        <span class="c"># Remove the template directory from the available</span>
        <span class="c"># directories to search in, and try again.</span>
        <span class="n">dirs</span><span class="o">.</span><span class="n">remove</span><span class="p">(</span><span class="n">path</span><span class="p">[:</span><span class="o">-</span><span class="nb">len</span><span class="p">(</span><span class="n">parent</span><span class="p">)</span> <span class="o">-</span> <span class="mi">1</span><span class="p">])</span>
        <span class="n">template</span><span class="p">,</span> <span class="n">path</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">find_template</span><span class="p">(</span><span class="n">parent</span><span class="p">,</span> <span class="n">dirs</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">template</span></code></pre></figure>

孙铭鸿logo
by 鸿记

声明:本站文章除注明转载外,均为本站原创或者翻译。
本文采用 署名-非商业性使用-相同方式共享(BY-NC-SA) 协议进行授权。
转载请注明转自: 【鸿记】markdown 语法学习

Fork me on GitHub