• Markdown小册


    概述

    Markdown是一门轻量级标记语言,用简洁的语法代替了手动排版,让我们更专注于写作。简而言之,我们通过一些符号告诉计算机「应当怎样排列一段文字」。

    许多软件对Markdown的支持存在不一致的情况,我们将参考广泛使用的GitHub Flavored Markdown,对常用的语法作出简单的介绍,并附上示例与一些参考链接。

    • 注意:当不希望文本中的符号成为语法的一部分时,使用转义字符;在表达特定的语法时,插入必要的空格分离文本与符号。

    块级元素

    块级元素占据其水平方向的所有空间,只能够纵向排列。一篇文章由数个纵向排列的块构成。

    段落

    输入一行或连续的多行文字即可建立一个段落。段内换行时,应当在上一行的末尾留下两个空格,以确保正确换行;否则,标准允许一个解析器将单次换行解析为一个空格。

    • 提示:示例代码包含三个段落,第二个段落由两行组成,其第一行末尾存在两个空格。
    Once is the inspirational tale of two kindred spirits who find each other on the bustling streets of Dublin.
    
    One is a street musician who lacks the confidence to perform his own songs.  
    The other is a young mother trying to find her way in a strange new town.
    
    As their lives intertwine, they discover each others talents and push one another to realize what each had only dreamt about before. Once is their inspiring story.
    

    Once is the inspirational tale of two kindred spirits who find each other on the bustling streets of Dublin.

    One is a street musician who lacks the confidence to perform his own songs.
    The other is a young mother trying to find her way in a strange new town.

    As their lives intertwine, they discover each others talents and push one another to realize what each had only dreamt about before. Once is their inspiring story.

    标题

    在行首放置一到六个#建立标题。标题仅占用一行,无需多余空行分隔下文的块。

    # Once
    ## Glen Hansard
    ## Marketa Irglova
    ###### Once is their inspiring story
    

    Once

    Glen Hansard

    Marketa Irglova

    Once is their inspiring story

    引用块

    在行首放置一个>以建立引用块。引用块是容器,若引用的内容超过一行,>应当被放置到每一行之前。

    • 注意:若引用块后的内容能够与其末尾的内容组成一个块,这部分内容也会被包括到引用块中,参考示例
    A thirty-something busker (Guy) performs with his guitar on Grafton Street, a Dublin shopping district and chases a man who steals his money.  
    
    > Lured by his music,  
    a young Czech flower seller (Girl) talks to him about his songs. 
    

    A thirty-something busker (Guy) performs with his guitar on Grafton Street, a Dublin shopping district and chases a man who steals his money.

    Lured by his music,
    a young Czech flower seller (Girl) talks to him about his songs.

    列表

    一个列表由至少一个列表项组成,连续且使用相同符号的列表项将被包括到同一个列表中。列表项是容器,通过额外的缩进将一个列表项扩展至多行,参考示例

    • 注意:若列表项后的内容能够与其末尾的内容组成一个块,这部分内容也会被包括到表项中,参考示例

    无序列表

    通过一个*+-建立一个列表项。

    + Delighted to learn that he repairs hoovers, Girl insists that Guy fix her broken hoover.
    + The next day Girl returns with her broken hoover and tells Guy that she is also a musician.
      
      At a music store where Girl regularly plays piano, Guy teaches her one of his songs ("Falling Slowly"); they sing and play together.
    
    • Delighted to learn that he repairs hoovers, Girl insists that Guy fix her broken hoover.

    • The next day Girl returns with her broken hoover and tells Guy that she is also a musician.

      At a music store where Girl regularly plays piano, Guy teaches her one of his songs ("Falling Slowly"); they sing and play together.

    有序列表

    在序号之后接上一个.)即可建立一个列表项。

    1. Guy invites her to his father's shop, and on the bus home musically answers Girl's question about what his songs are about: 
    2. a long-time girlfriend who cheated on him,  
    then left ("Broken Hearted Hoover Fixer Sucker Guy").
    
    1. Guy invites her to his father's shop, and on the bus home musically answers Girl's question about what his songs are about:
    2. a long-time girlfriend who cheated on him,
      then left ("Broken Hearted Hoover Fixer Sucker Guy").

    代码块

    通过一对```~~~建立代码块。在首行的末尾可添加别名(Alias)以启用对应的语法高亮方案。若高亮功能由highlight.js提供,在这里能够找到可用的别名。若高亮功能由prism.js提供,在这里能够找到可用的别名。

    ``` rust
    impl Life for Love<Guy, Girl> {
        fn life() -> ! {
            panic!();
        }
    }
    fn main() {
        Love::<Guy, Girl>::life();
    }
    ```
    
    impl Life for Love<Guy, Girl> {
        fn life() -> ! {
            panic!();
        }
    }
    fn main() {
        Love::<Guy, Girl>::life();
    }
    

    数学公式

    • 注意:数学公式不是GFM的一部分。

    通过一对$$建立公式块,它接受Tex/LaTeX代码。若这个功能由MathJax提供,在这里能够找到可用的命令。

    $$
    \frac{0}{0},\frac{\infty}{\infty}\Leftarrow\begin{cases}
    	0\times\infty\Leftarrow\begin{cases}
    		1^\infty\\
    		\infty^0\\
    		0^0
    	\end{cases}\\
    	\infty-\infty
    \end{cases}
    $$
    

    \[\frac{0}{0},\frac{\infty}{\infty}\Leftarrow\begin{cases} 0\times\infty\Leftarrow\begin{cases} 1^\infty\\ \infty^0\\ 0^0 \end{cases}\\ \infty-\infty \end{cases} \]

    表格

    表格的一行由数个|分隔的小格组成,可包含文字与内联元素。特别的,第二行表示分隔行,包含数个-以及可选的前后缀:,用于指定所在列的对齐方式。

    | cats  | always |            meow |
    | :---- | :----: | --------------: |
    | life  | always |       works out |
    | music | always | evokes memories |
    
    cats always meow
    life always works out
    music always evokes memories

    脚注

    脚注由注解与引用两部分组成;注解部分会被渲染至页面的底部,引用部分会被渲染为一个链接,可多次使用;它们由一个标签相关联。

    "Falling Slowly"[^falling-slowly] won the 2007 Academy Award for Best Original Song. 
    
    [^falling-slowly]: "Falling Slowly", available at [NeteaseMusic](https://music.163.com/#/song?id=4340758). 
    

    "Falling Slowly"[1] won the 2007 Academy Award for Best Original Song.

    分隔线

    输入 ***--- 即可生成一条水平分隔线。

    At the shop, Guy introduces Girl to his father and takes her to his room, but when he asks her to stay the night, Girl feels insulted and leaves. 
    
    ---
    
    The next day, they reconcile and spend the week writing, rehearsing and recording songs. 
    

    At the shop, Guy introduces Girl to his father and takes her to his room, but when he asks her to stay the night, Girl feels insulted and leaves.


    The next day, they reconcile and spend the week writing, rehearsing and recording songs.

    行内元素

    行内元素依照文字的顺序排列,拥有确定的高度与宽度。

    链接

    • 注意:多数网站会为标题生成一个锚(Anchor),链接可以借此在页面内跳转;但锚的生成不是GFM的一部分。

    一个链接包含三个要素:文字、地址、标题,后两者是可选的。通常,光标悬停至链接上方时,标题以工具提示的方式呈现。若同一个链接被多次用到,应当使用引用链接

    Girl rehearses lyrics for one of Guy's songs ("[If You Want Me](<http://music.163.com/song?id=4340760> "Music From The Motion Picture Once")"), singing to herself while walking down the street; at a party, people perform impromptu (including "Gold"). 
    

    Girl rehearses lyrics for one of Guy's songs ("If You Want Me"), singing to herself while walking down the street; at a party, people perform impromptu (including "Gold").

    链接地址

    规范的,一个Autolink由一对<>包括的URI构成;但标准也允许一个解析器自动识别没有被<>包括的URI。

    The place where the dream originated: <http://primary-yuiko.com/>. 
    

    The place where the dream originated: http://primary-yuiko.com/.

    引用链接

    通过一个标签将链接的地址与标题同文字联系起来,实现链接的复用。当文字与标签相同时,可以省略文字部分的标签。

    Guy works on "[Lies]", a song about his [ex-girlfriend][Lies], who moved to London. Girl encourages him to win her back. Invited to the woman's home, Guy discovers that Girl has a toddler and lives with her mother. 
    
    [Lies]: <http://music.163.com/song?id=4340768> "Music From The Motion Picture Once"
    

    Guy works on "Lies", a song about his ex-girlfriend, who moved to London. Girl encourages him to win her back. Invited to the woman's home, Guy discovers that Girl has a toddler and lives with her mother.

    图片

    类似于链接,图片也包含文字、地址、标题三部分。文字部分在图像加载失败或语音朗读时被使用。通常,光标悬停至图片上方时,标题以工具提示的方式呈现。

    ![FIGURE: Guy talks with Girl after getting their album](<https://img2020.cnblogs.com/blog/2084381/202105/2084381-20210524003408549-694219766.png> "The Motion Picture Once")
    

    FIGURE: Guy talks with Girl after getting their album

    强调

    一对*_包括的文字将被强调,词组中的_不会受到影响。

    Guy decides to move to London, but he wants to record a demo of his songs to take with him and asks Girl to record it with him. They secure a bank loan and reserve time at a recording studio. Guy learns Girl has a husband in the _Czech Republic_.
    

    Guy decides to move to London, but he wants to record a demo of his songs to take with him and asks Girl to record it with him. They secure a bank loan and reserve time at a recording studio. Guy learns Girl has a husband in the Czech Republic.

    加粗

    一对**__包括的文字将被加粗,词组中的__不会受到影响。

    When he asks if she still loves her husband, Girl answers in Czech, "**Miluji tebe**" ("I love you"), but coyly declines to translate. After recruiting a band from other buskers, they go into the studio to record. 
    

    When he asks if she still loves her husband, Girl answers in Czech, "Miluji tebe" ("I love you"), but coyly declines to translate. After recruiting a band from other buskers, they go into the studio to record.

    行内代码

    一对```包括的文字将被渲染为代码。

    They impress Eamon, the jaded studio engineer, with their first song ("When Your Mind's Made Up"). On a break in the early morning, Girl finds a piano in an empty studio and plays Guy one of her own compositions ("`The Hill`"). 
    

    They impress Eamon, the jaded studio engineer, with their first song ("When Your Mind's Made Up"). On a break in the early morning, Girl finds a piano in an empty studio and plays Guy one of her own compositions ("The Hill").

    删除线

    通过一对~~为被其包括的文字添加删除线。

    After the ~~all-night~~ session wraps up, they walk home. Before they part ways, Girl reveals that she spoke to her husband and he is coming to live with her in Dublin.
    

    After the all-night session wraps up, they walk home. Before they part ways, Girl reveals that she spoke to her husband and he is coming to live with her in Dublin.

    Emoji

    一对:包括的简码将被解释为絵文字。在这里能够找到可用的简码。

    :man: persuades :woman: to spend his last night in Dublin with him, but :woman: stands him up and :man: cannot find her to say goodbye before his :airplane:. :man: plays the demo for his father, who gives him :dollar: to help him get settled in London.
    

    persuades to spend his last night in Dublin with him, but stands him up and cannot find her to say goodbye before his ✈️. plays the demo for his father, who gives him to help him get settled in London.

    行内数学公式

    • 注意:数学公式不是GFM的一部分。

    一对$包括的内容将被渲染为公式,它接受 Tex/LaTeX 指令。若这个功能由MathJax提供,在这里能够找到可用的指令。

    What if there is a $\LaTeX$ formula about music?
    

    What if there is a \(\LaTeX\) formula about music?

    转义字符

    通过\对紧随其后的一个标点符号进行转义,被转义的字符将不再被Markdown解释。若跟随的字符不可被转义,则\自身将被渲染。

    Before leaving for the airport\, Guy buys Girl a piano and makes arrangements for its delivery\, then calls his ex\-girlfriend\, who is happy about his imminent arrival\. \
    Girl reunites with her husband in Dublin and plays the piano in their home\. 
    

    Before leaving for the airport, Guy buys Girl a piano and makes arrangements for its delivery, then calls his ex-girlfriend, who is happy about his imminent arrival.
    Girl reunites with her husband in Dublin and plays the piano in their home.

    HTML

    GFM支持在源文件中直接包含HTML代码,其中的字符不再被Markdown解释。

    <object type="image/svg+xml" data="https://blog-static.cnblogs.com/files/yuiko/claw.svg" style="background-color:#feb6b9;padding:16px;64px;height:64px;"></object>
    


    1. "Falling Slowly", available at NeteaseMusic. ↩︎

  • 相关阅读:
    scrapy框架
    selenium解析
    xpath解析
    解析语法
    request-html-render
    牛逼的requests-html
    Beautifulsoup
    请求和响应
    reuqests请求
    Django文件上传下载与富文本编辑框
  • 原文地址:https://www.cnblogs.com/yuiko/p/markdown.html
Copyright © 2020-2023  润新知