mkdocsmkdocs-material

Material for MkDocs - formatting to two panels


I use Material for MkDocs. Is it possible (perhaps with some plugin or Markdown extension) to render two blocks so they show as two panels next to each other? Each panel would occupy half of its container width.

This feature would be useful for rendering examples - left panel could contain source code and right panel its output. GitHub Flavored Markdown Specification uses it frequently.

The closest features I could find are for instance:


Solution

  • Finally solved using tabbed extension with custom css style which formats two tabs to desired layout.

    What needs to be in project:

    h6.twopanels {
        display: none;
    }
    
    h6.twopanels + .tabbed-set {
        --md-indicator-x: 0px !important;
        --md-indicator-y: 0px !important;
        --md-indicator-width: 0px !important;
        --gap-between-two-panels: 1rem;
    }
    
    h6.twopanels + .tabbed-set .tabbed-content {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--gap-between-two-panels);
    }
    
    h6.twopanels + .tabbed-set .tabbed-block {
        display: block;
        overflow-x: scroll;
    }
    
    h6.twopanels + .tabbed-set .tabbed-labels {
        box-shadow: unset;
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: var(--gap-between-two-panels);
    }
    
    h6.twopanels + .tabbed-set .tabbed-labels label {
        box-shadow: 0 -.2rem var(--md-default-fg-color--lightest) inset;
        width: 100%;
    }
    
    h6.twopanels + .tabbed-set .tabbed-labels label a {
        color: var(--md-default-fg-color);
    }
    
    h6.twopanels + .tabbed-set input[type="radio"] {
        display: none;
    }
    

    Usage:

    ###### Example {: .twopanels}
    
    === "Source"
    
        ```markdown
            Normal, **bold**, *italic*, _underlined_, `monospaced` text.
        ```
    
    === "Result"
    
        Normal, **bold**, *italic*, _underlined_, `monospaced` text.
    
    

    Note: