项目作者: codeinclined

项目描述 :
Shortcode to be used with Wyam's Markdown module to render Bootstrap-compatible tabs and tab panes in your Markdown pages.
高级语言: C#
项目地址: git://github.com/codeinclined/JupiterNebula.Wyam.Shortcodes.TabBlock.git


JupiterNebula.Wyam.Shortcodes.TabBlock

Nuget

TabBlock provides a shortcode for Wyam‘s Markdown module
to render Bootstrap-compatible tabs and tab panes in your Markdown pages.

Output Demonstration

Adding TabBlock to Your Project

The following needs to be added to your config.wyam file:

  1. #n JupiterNebula.Wyam.Shortcodes.TabBlock

That’s it! Wyam will discover the shortcode and automatically use it
when running the Markdown module.

Configuration

Currently, TabBlock just outputs basic, Bootstrap-compatible tabs and
tab panes. Additional customization is planned in the future though, so stay tuned!

Usage

Syntax

TabBlock uses the Wyam shortcode syntax, as defined in
Wyam’s documentation.

The easiest way to define tabs and tab pane content is by creating an unordered
list in Markdown syntax between the opening and closing tag for the TabBlock
shortcode as shown below:

Markdown

  1. <?# TabBlock ?>
  2. - ::Tab Label 1::
  3. All content here will be placed in the tab pane for this tab.
  4. - ::Tab _Label_ 2 with ___formatting___::
  5. Any _valid_ [Markdown](https://daringfireball.net/projects/markdown/syntax) can
  6. be put __here__ as long as each line is indented so as to be included in
  7. the Markdown list item.
  8. - ![Labels Can Be Images](https://jupiternebula.com/favicon.png){style="max-height: 1em;"}
  9. # Tab Pane Header
  10. Lorem ipsum...
  11. <?#/ TabBlock ?>

Rendered HTML (formatted by VSCode)

  1. <div class="tab-block" id="TabBlock__PabWwGf5">
  2. <ul class="nav nav-tabs" role="tablist">
  3. <li class="nav-item"><a class="nav-link active" data-toggle="tab" aria-selected="true"
  4. aria-controls="TabBlock__PabWwGf5-0-pane" href="#TabBlock__PabWwGf5-0-pane"
  5. id="TabBlock__PabWwGf5-0-link"><span>Tab Label 1</span></a></li>
  6. <li class="nav-item"><a class="nav-link" data-toggle="tab" aria-selected="false"
  7. aria-controls="TabBlock__PabWwGf5-1-pane" href="#TabBlock__PabWwGf5-1-pane"
  8. id="TabBlock__PabWwGf5-1-link"><span>Tab <em>Label</em> 2 with
  9. <em><strong>formatting</strong></em></span></a></li>
  10. <li class="nav-item"><a class="nav-link" data-toggle="tab" aria-selected="false"
  11. aria-controls="TabBlock__PabWwGf5-2-pane" href="#TabBlock__PabWwGf5-2-pane"
  12. id="TabBlock__PabWwGf5-2-link"><img src="https://jupiternebula.com/favicon.png" class="img-fluid"
  13. style="max-height: 1em;" alt="Labels Can Be Images"></a></li>
  14. </ul>
  15. <div class="tab-content">
  16. <div class="tab-pane show active" role="tabpanel" aria-labelledby="TabBlock__PabWwGf5-0-link"
  17. id="TabBlock__PabWwGf5-0-pane">
  18. All content here will be placed in the tab pane for this tab.</div>
  19. <div class="tab-pane" role="tabpanel" aria-labelledby="TabBlock__PabWwGf5-1-link"
  20. id="TabBlock__PabWwGf5-1-pane">
  21. Any <em>valid</em><a href="https://daringfireball.net/projects/markdown/syntax">Markdown</a>
  22. can be put <strong>here</strong> as long as each line is indented so as to be included in
  23. the Markdown list item.</div>
  24. <div class="tab-pane" role="tabpanel" aria-labelledby="TabBlock__PabWwGf5-2-link"
  25. id="TabBlock__PabWwGf5-2-pane">
  26. <h1 id="tab-pane-header">Tab Pane Header</h1>
  27. Lorem ipsum...
  28. </div>
  29. </div>
  30. </div>

Each tab above is represented as a Markdown list item. The
labels in this example come at the beginning of each item, wrapped in a
MarkDig custom container.
It is not required to wrap your tab labels, but it is good practice to do so.
This is because TabBlock receives your content after it has already been rendered into HTML and
interprets the first HTML node
it encounters in each list item as the label. The remaining nodes are interpretted as
the tab pane’s content (what is shown to the user when the tab is selected).

As such, wrapping the label’s text (in a <span> in the example above) makes sure the label
doesn’t get mixed up with the tab pane’s content and that it doesn’t get cut off if
you add formatting to your label (such as the second tab above). The third tab’s label
didn’t need to be wrapped because the first node in that case is an <a> element and not just text.

Examples

FizzBuzz in C++, F#, and Rust

Including code snippets in multiple languages is pretty common on software development blogs
and documentation pages. The following example presents implementations of FizzBuzz
from rosettacode.org for multiple languages
as separate tabs.

A demonstration of this in action is found at the top of this document

  1. <?# TabBlock ?>
  2. - C++
  3. ```cpp
  4. #include <iostream>
  5. int main ()
  6. {
  7. for (int i = 1; i <= 100; i++)
  8. {
  9. if ((i % 15) == 0)
  10. std::cout << "FizzBuzz\n";
  11. else if ((i % 3) == 0)
  12. std::cout << "Fizz\n";
  13. else if ((i % 5) == 0)
  14. std::cout << "Buzz\n";
  15. else
  16. std::cout << i << "\n";
  17. }
  18. return 0;
  19. }
  20. ```
  21. - F#
  22. ```fsharp
  23. let fizzbuzz n =
  24. match n%3 = 0, n%5 = 0 with
  25. | true, false -> "fizz"
  26. | false, true -> "buzz"
  27. | true, true -> "fizzbuzz"
  28. | _ -> string n
  29. let printFizzbuzz() =
  30. [1..100] |> List.iter (fizzbuzz >> printfn "%s")
  31. ```
  32. - Rust
  33. ```rust
  34. use std::borrow::Cow; // Allows us to avoid unnecessary allocations
  35. fn main() {
  36. (1..101).map(|n| match (n % 3, n % 5) {
  37. (0, 0) => "FizzBuzz".into(),
  38. (0, _) => "Fizz".into(),
  39. (_, 0) => "Buzz".into(),
  40. _ => Cow::from(n.to_string())
  41. }).for_each(|n| println!("{}", n));
  42. }
  43. ```
  44. <?#/ TabBlock ?>