Skip to content

Basic formatting elements

Code
docs/staging/basic.py
from mkreports import Report, md


def use_basic(report: Report) -> None:
    p = report.page("usage/basic.md", truncate=True)

    p.H1("Basic formatting elements")

    p.CollapsedCodeFile(__file__)

    with p.H2("Headings", anchor=(heading_anchor := p.md.Anchor())):
        p.Code(
            """
            md.H1("Header type 1")
            md.H2("Header type 2")
            md.H3("Header type 3")
            md.H4("Header type 4")
            md.H5("Header type 5")
            md.H6("Header type 6")
            md.H7("Header type 7")
            """,
            title="Available headings",
        )

    with p.H2("Lists") as p2:
        numbered_list = (
            md.List(marker="1")
            .append("First item")
            .append("Second item")
            .append("Third item")
        )
        unordered_list = md.List(("apples", "pears", "strawberry"), marker="*")

        numbered_list = numbered_list.append(
            md.Raw("Some fruit:") + unordered_list
        ).append(
            md.Raw("A code block:")
            + md.Code(
                """
                print("Hello world")                    
                """,
                title="Hello world",
                language="python",
            ),
        )

        p2.add(numbered_list)

    with p.H2("Links") as p2:
        p2.Raw(
            """
            A number of different types of links are possible. Those within
            a page to an anchor or to another page (with or without anchor)
            """
        )
        p2.P(
            "A link back to the "
            + p.md.ReportLink(anchor=heading_anchor, text="first heading")
        )
        p2.P(
            "A link to another page "
            + p.md.ReportLink(
                "Images", to_page_path=report.page("usage/images.md").path
            )
        )
        p2.P("Or just to any page " + p.md.Link("Google", url="https://google.com"))
        p2.P("Or of course also just straight markdown [Google](https://google.com)")

Headings

Available headings
md.H1("Header type 1")
md.H2("Header type 2")
md.H3("Header type 3")
md.H4("Header type 4")
md.H5("Header type 5")
md.H6("Header type 6")
md.H7("Header type 7")
docs/staging/basic.py
12
13
14
15
16
17
18
19
20
21
22
23
p.Code(
    """
    md.H1("Header type 1")
    md.H2("Header type 2")
    md.H3("Header type 3")
    md.H4("Header type 4")
    md.H5("Header type 5")
    md.H6("Header type 6")
    md.H7("Header type 7")
    """,
    title="Available headings",
)

Lists

  1. First item
  2. Second item
  3. Third item
  4. Some fruit:

    • apples
    • pears
    • strawberry
  5. A code block:

    Hello world
    print("Hello world")                    
    
docs/staging/basic.py
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
numbered_list = (
    md.List(marker="1")
    .append("First item")
    .append("Second item")
    .append("Third item")
)
unordered_list = md.List(("apples", "pears", "strawberry"), marker="*")

numbered_list = numbered_list.append(
    md.Raw("Some fruit:") + unordered_list
).append(
    md.Raw("A code block:")
    + md.Code(
        """
        print("Hello world")                    
        """,
        title="Hello world",
        language="python",
    ),
)

p2.add(numbered_list)

A number of different types of links are possible. Those within a page to an anchor or to another page (with or without anchor)

A link back to the first heading

A link to another page Images

Or just to any page Google

Or of course also just straight markdown Google

docs/staging/basic.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
p2.Raw(
    """
    A number of different types of links are possible. Those within
    a page to an anchor or to another page (with or without anchor)
    """
)
p2.P(
    "A link back to the "
    + p.md.ReportLink(anchor=heading_anchor, text="first heading")
)
p2.P(
    "A link to another page "
    + p.md.ReportLink(
        "Images", to_page_path=report.page("usage/images.md").path
    )
)
p2.P("Or just to any page " + p.md.Link("Google", url="https://google.com"))
p2.P("Or of course also just straight markdown [Google](https://google.com)")