在Fossil wiki页面中包含th1代码

时间:2017-02-16 17:08:41

标签: fossil

我希望能够在Fossil wiki页面中包含th1代码。具体来说,我希望特定页面根据用户显示不同的信息。在页眉或页脚中很容易做到这一点,但我还没有找到任何方法将th1代码直接插入到wiki文档中。

编辑:

我发现的一个hack是在头文件中生成Javascript以使用th1生成变量,如下所示:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Home</title>
<link href="jquery-ui.css" rel="stylesheet" type="text/css" />
 <script type="text/javascript" src="jquery-ui.js"></script>
<style type="text/css">

    html {
      height: 100%;
    }

    body {
      height: 100%;
    }

    table {
      width: 100%;
      height: 90%;
    }

    table td {
      text-align: center;
      border: 1px solid black;
    }

    #views-container {
      height: 10%;
    }

</style>


<script type="text/javascript">

/**
 * Created by yako on 1/25/16.
 */
var tds = document.getElementsByTagName('td');
var inputs = document.getElementsByTagName('input');
var rows = document.getElementsByTagName('tr');

console.log(inputs);
console.log(tds);
var changeView = function() {

  for (var i = 0; i < inputs.length; i++) {
    if (!inputs[i].checked) {
      if (tds[i].style.display !== 'none') tds[i].style.display = 'none';
    } else {
      if (tds[i].style.display === 'none') tds[i].style.display = '';
    }
  }

  if (!inputs[0].checked && !inputs[1].checked) rows[0].style.display = 'none';
  else rows[0].style.display = '';

  if (!inputs[2].checked) rows[1].style.display = 'none';
  else rows[1].style.display = '';

};

changeView();



$(window).on("load resize", function() {

  var windowWidth = $(window).width();
  var windowHeight = $(window).height();
  var v1Width = $("#v1").width()


  $("#v1").resizable({
    minWidth: 50,
    maxWidth: windowWidth - 80,
    maxHeight: windowHeight * (.83),
    handles: "e, s"
  }).on("resize", function() {

    if (v1Width == $("#v1").width()) {
      $("#v2").height(0)
    }
    v1Width = $("#v1").width()
  });

  $("#v2").resizable({
    maxHeight: windowHeight * (.83),
    handles: "s"
  }).on("resize", function() {
    $("#v1").height(0)
  });

});
</script>

</head>

<body>




 <table>
    <tr>
      <td id="v1">View 1</td>

      <td id="v2">View 2</td>
    </tr>

    <tr>
      <td colspan="2">View 3</td>
    </tr>
  </table>
  <div id="views-container">
    <input type="checkbox" checked="checked" onclick="changeView()">
    <label>View 1</label>
    <input type="checkbox" checked="checked" onclick="changeView()">
    <label>View 2</label>
    <input type="checkbox" checked="checked" onclick="changeView()">
    <label>View 3</label>
  </div>


</body>
</html>

然后我可以直接在Markdown文件中插入Javascript调用,如下所示:

<th1>
html "<script>var foo = \"$login\";</script>"
</th1>

由于这是一个hack,并且需要在每个页面的标题中生成这些变量,我宁愿直接在wiki页面中使用th1。

1 个答案:

答案 0 :(得分:1)

出于安全原因,我认为这是不可能的:如果为wiki启用了TH1,那么拥有wiki权限的任何人都可以执行代码......即使在wiki中使用HTML也必须明确启用

使用Javascript的解决方法(或黑客)工作正常;为了防止Javascript被包含在每个页面中,您可以使用TH1语句enable_output后跟0来禁止输出到页面。在页面名称上添加if条件之后,您就可以了。在你的Javascript之后忘记用enable_output 1重新启用输出!

编辑:这是我用来在/artifact页面上包含语法突出显示的示例。您将使用脚本元素替换link标记。另请注意,我使用 ne (不等于)忽略每个页面工件页面的语法高亮显示。

<th1>
  if { "$current_page" ne "artifact" } {
    enable_output 0
  }
</th1>
    <link rel="stylesheet" href="$highlighterpath/styles/shCoreDefault.css" type="text/css" media="screen" />
<th1>
  enable_output 1
</th1>