pytorch-lightning

Форк
0
78 строк · 2.7 Кб
1
/* Copied from the official Python docs: https://docs.python.org/3/_static/copybutton.js */
2
$(document).ready(function () {
3
  /* Add a [>>>] button on the top-right corner of code samples to hide
4
   * the >>> and ... prompts and the output and thus make the code
5
   * copyable. */
6
  var div = $(
7
    ".highlight-python .highlight," +
8
      ".highlight-python3 .highlight," +
9
      ".highlight-pycon .highlight," +
10
      ".highlight-default .highlight",
11
  );
12
  var pre = div.find("pre");
13

14
  // get the styles from the current theme
15
  pre.parent().parent().css("position", "relative");
16
  var hide_text = "Hide the prompts and output";
17
  var show_text = "Show the prompts and output";
18
  var border_width = pre.css("border-top-width");
19
  var border_style = pre.css("border-top-style");
20
  var border_color = pre.css("border-top-color");
21
  var button_styles = {
22
    cursor: "pointer",
23
    position: "absolute",
24
    top: "0",
25
    right: "0",
26
    "border-color": border_color,
27
    "border-style": border_style,
28
    "border-width": border_width,
29
    color: border_color,
30
    "text-size": "75%",
31
    "font-family": "monospace",
32
    "padding-left": "0.2em",
33
    "padding-right": "0.2em",
34
    "border-radius": "0 3px 0 0",
35
  };
36

37
  // create and add the button to all the code blocks that contain >>>
38
  div.each(function (index) {
39
    var jthis = $(this);
40
    if (jthis.find(".gp").length > 0) {
41
      var button = $('<span class="copybutton">&gt;&gt;&gt;</span>');
42
      button.css(button_styles);
43
      button.attr("title", hide_text);
44
      button.data("hidden", "false");
45
      jthis.prepend(button);
46
    }
47
    // tracebacks (.gt) contain bare text elements that need to be
48
    // wrapped in a span to work with .nextUntil() (see later)
49
    jthis
50
      .find("pre:has(.gt)")
51
      .contents()
52
      .filter(function () {
53
        return this.nodeType == 3 && this.data.trim().length > 0;
54
      })
55
      .wrap("<span>");
56
  });
57

58
  // define the behavior of the button when it's clicked
59
  $(".copybutton").click(function (e) {
60
    e.preventDefault();
61
    var button = $(this);
62
    if (button.data("hidden") === "false") {
63
      // hide the code output
64
      button.parent().find(".go, .gp, .gt").hide();
65
      button.next("pre").find(".gt").nextUntil(".gp, .go").css("visibility", "hidden");
66
      button.css("text-decoration", "line-through");
67
      button.attr("title", show_text);
68
      button.data("hidden", "true");
69
    } else {
70
      // show the code output
71
      button.parent().find(".go, .gp, .gt").show();
72
      button.next("pre").find(".gt").nextUntil(".gp, .go").css("visibility", "visible");
73
      button.css("text-decoration", "none");
74
      button.attr("title", hide_text);
75
      button.data("hidden", "false");
76
    }
77
  });
78
});
79

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.