def test_markment_finds_1st_level_headers():
    "Markment should find and index 1st level headers"

    MD = MARKDOWN("""
    # Installation

    # Tutorial

    # API Reference

    """)

    mm = Markment(MD)

    mm.index().should.equal([
        {
            "text": "Installation",
            "level": 1,
            "anchor": "#installation"
        },
        {
            "text": "Tutorial",
            "level": 1,
            "anchor": "#tutorial"
        },
        {
            "text": "API Reference",
            "level": 1,
            "anchor": "#api-reference"
        },
    ])
def test_markment_finds_2nd_level_headers():
    "Markment should find and index 2nd level headers"

    MD = MARKDOWN("""
    # Installation

    chuck norris

    ## Through PIP


    ## Compiling manually


    """)

    mm = Markment(MD)

    expect(mm.index()).to.equal([
        {"text": "Installation",
         "anchor": "#installation",
         "level": 1, "child": [
             {"text": "Through PIP", "level": 2, "anchor": "#through-pip"},
             {"text": "Compiling manually", "level": 2, "anchor": "#compiling-manually"},
         ]},
    ])
def test_markment_finds_3rd_level_headers():
    "Markment should find and index 3rd level headers"

    MD = MARKDOWN("""
    # Installation

    chuck norris

    ## Through PIP

    ## Compiling manually

    ### Caveats

    """)

    mm = Markment(MD)

    mm.index().should.equal([
        {"text": "Installation", "level": 1,
         "anchor": "#installation",
         "child": [
             {"text": "Through PIP", "level": 2, "anchor": "#through-pip"},
             {"text": "Compiling manually", "level": 2,
              "anchor": "#compiling-manually",
              "child": [
                  {"text": "Caveats", "level": 3, "anchor": "#caveats"},
              ]},
         ]},
    ])
Exemple #4
0
def test_markment_doesnt_fail_if_has_no_headers():
    "Markment should find and index 3rd level headers"

    MD = MARKDOWN("""
    ```python
    poor code, doesn't have a title
    ```

    """)

    mm = Markment(MD)

    mm.index().should.equal([])
def test_markment_finds_3rd_level_headers():
    "Markment should find and index 3rd level headers"

    MD = MARKDOWN("""
    # Installation

    chuck norris

    ## Through PIP

    ## Compiling manually

    ### Caveats

    """)

    mm = Markment(MD)

    mm.index().should.equal([
        {
            "text":
            "Installation",
            "level":
            1,
            "anchor":
            "#installation",
            "child": [
                {
                    "text": "Through PIP",
                    "level": 2,
                    "anchor": "#through-pip"
                },
                {
                    "text":
                    "Compiling manually",
                    "level":
                    2,
                    "anchor":
                    "#compiling-manually",
                    "child": [
                        {
                            "text": "Caveats",
                            "level": 3,
                            "anchor": "#caveats"
                        },
                    ]
                },
            ]
        },
    ])
def test_markment_doesnt_fail_if_has_no_headers():
    "Markment should find and index 3rd level headers"

    MD = MARKDOWN("""
    ## Installation
    """)

    mm = Markment(MD)

    mm.index().should.equal([
        {
            "text": "Installation",
            "level": 2,
            "anchor": "#installation"
        },
    ])
Exemple #7
0
def test_markment_renders_tables():
    "Markment should be able to render tables"

    MD = MARKDOWN('''
    | button                                     | code                                         |
    | ---------------------------                | :-------------------------------:            |
    | <a class="btn btn-success">Success</a>     | `<a class="btn btn-success">Success</a>`     |
    ''')

    mm = Markment(MD)

    dom = lhtml.fromstring(mm.rendered)

    table = dom.cssselect("table.table")

    table.should_not.be.empty

    table_data = dom.cssselect('tr > td')
    table_data.should.have.length_of(2)

    column1, column2 = table_data

    button = column1.getchildren()
    button.should_not.be.empty
    button[0].text.should.equal('Success')

    code = column2.getchildren()
    code.should_not.be.empty
    code[0].text.should.equal('<a class="btn btn-success">Success</a>')
def test_markment_doesnt_fail_if_has_no_headers():
    "Markment should find and index 3rd level headers"

    MD = MARKDOWN("""
    ## Installation
    """)

    mm = Markment(MD)

    mm.index().should.equal([
        {
            "text": "Installation",
            "level": 2,
            "anchor": "#installation"
        },
    ])
Exemple #9
0
def test_code_block_guesses_lexer():
    "Markment should render code blocks even without a language specified"

    MD = MARKDOWN("""
    # API Reference

    This is good

    ```
    import os
    os.system('ls /')
    ```

    This is not good

    ```python
    import os
    os.system('sudo rm -rf /')
    ```
    """)

    mm = Markment(MD)

    dom = lhtml.fromstring(mm.rendered)

    code_blocks = dom.cssselect("div.highlight pre")

    code_blocks.should.have.length_of(2)

    code1, code2 = code_blocks

    code1.attrib.should.have.key("name").equal("api-reference-example-1")
    code2.attrib.should.have.key("name").equal("api-reference-example-2")
Exemple #10
0
def test_anchors_in_2nd_level_headers():
    "Markment should put anchors in 2nd level headers"

    MD = MARKDOWN("""
    # API Reference

    ## Rendering content
    """)

    mm = Markment(MD)

    dom = lhtml.fromstring(mm.rendered)

    headers = dom.cssselect("h2")

    headers.should.have.length_of(1)

    h2 = headers[0]
    h2.attrib.should.have.key("name").being.equal("rendering-content")
    h2.attrib.should.have.key("id").being.equal("rendering-content")

    links = h2.getchildren()
    links.should.have.length_of(1)

    a = links[0]
    a.text.should.equal("Rendering content")
    a.attrib.should.have.key("href").equal("#rendering-content")
Exemple #11
0
def test_anchors_in_1st_level_headers():
    "Markment should put anchors in 1st level headers"

    MD = MARKDOWN("""
    # API Reference

    some content
    """)

    mm = Markment(MD)

    dom = lhtml.fromstring(mm.rendered)

    headers = dom.cssselect("h1")

    headers.should.have.length_of(1)

    h1 = headers[0]
    h1.attrib.should.have.key("name").being.equal("api-reference")
    h1.attrib.should.have.key("id").being.equal("api-reference")

    links = h1.getchildren()
    links.should.have.length_of(1)

    a = links[0]
    a.text.should.equal("API Reference")
    a.attrib.should.have.key("href").equal("#api-reference")
def test_markment_finds_1st_level_headers():
    "Markment should find and index 1st level headers"

    MD = MARKDOWN("""
    # Installation

    # Tutorial

    # API Reference

    """)

    mm = Markment(MD)

    mm.index().should.equal([
        {"text": "Installation", "level": 1, "anchor": "#installation"},
        {"text": "Tutorial", "level": 1, "anchor": "#tutorial"},
        {"text": "API Reference", "level": 1, "anchor": "#api-reference"},
    ])
Exemple #13
0
def test_markment_finds_2nd_level_headers():
    "Markment should find and index 2nd level headers"

    MD = MARKDOWN("""
    # Installation

    chuck norris

    ## Through PIP


    ## Compiling manually


    """)

    mm = Markment(MD)

    expect(mm.index()).to.equal([
        {
            "text":
            "Installation",
            "anchor":
            "#installation",
            "level":
            1,
            "child": [
                {
                    "text": "Through PIP",
                    "level": 2,
                    "anchor": "#through-pip"
                },
                {
                    "text": "Compiling manually",
                    "level": 2,
                    "anchor": "#compiling-manually"
                },
            ]
        },
    ])
Exemple #14
0
def test_markment_contains_the_raw_markdown():
    "Markment should contain the original markment"

    MD = MARKDOWN("""
    # Installation
    Such a cool lib

    # API Reference
    """)

    mm = Markment(MD)

    mm.raw.should.equal(MD)
Exemple #15
0
def test_link_absolute():
    "Markment should render links with absolute path"

    MD = MARKDOWN("""
    [LOGO](http://octomarks.io/file.md)
    """)

    mm = Markment(MD, url_prefix='http://falcao.it')

    dom = lhtml.fromstring(mm.rendered)

    links = dom.cssselect("a")

    links.should.have.length_of(1)

    a = links[0]

    a.attrib.should.have.key("href").equal("http://octomarks.io/file.md")
    a.text.should.equal('LOGO')
Exemple #16
0
def test_markment_header_accepts_unicode_characters():
    "Markment supports unicode (at least in the headers :)"

    MD = MARKDOWN('''
    # Curdling

    ## Curdle /ˈkərdl/

    ''')

    mm = Markment(MD)

    dom = lhtml.fromstring(mm.rendered)

    headers = dom.cssselect("h2 a")

    headers.should_not.be.empty

    h2 = headers[0]
    h2.text.should.equal('Curdle /ˈkərdl/')
Exemple #17
0
def test_image_absolute():
    "Markment should render images with absolute path"

    MD = MARKDOWN("""
    # Awesome project

    ![LOGO](http://octomarks.io/logo.png)
    """)

    mm = Markment(MD, url_prefix='http://falcao.it')

    dom = lhtml.fromstring(mm.rendered)

    images = dom.cssselect("img")

    images.should.have.length_of(1)

    img = images[0]

    img.attrib.should.have.key("src").equal("http://octomarks.io/logo.png")
    img.attrib.should.have.key("alt").equal("LOGO")
Exemple #18
0
def test_image_relative_with_callback():
    "Markment should render images with relative path"

    MD = MARKDOWN("""
    # Awesome project

    ![LOGO](logo.png)

    [Documentation](docs.md)
    """)

    def process_url(path):
        if path.lower().endswith("md"):
            return "http://markdown.com/{0}".format(path)
        else:
            return "http://images.com/{0}".format(path)

    mm = Markment(MD, url_prefix=process_url)

    dom = lhtml.fromstring(mm.rendered)

    images = dom.cssselect("img")

    images.should.have.length_of(1)

    img = images[0]

    img.attrib.should.have.key("src").equal("http://images.com/logo.png")
    img.attrib.should.have.key("alt").equal("LOGO")

    links = dom.cssselect("a")

    links.should.have.length_of(2)

    a = links[-1]

    a.attrib.should.have.key("href").equal("http://markdown.com/docs.md")