Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何将tocify与ascidoctor一起用于动态toc?_Javascript_Jquery_Tableofcontents_Asciidoctor_Jquery Tocify Js - Fatal编程技术网

Javascript 如何将tocify与ascidoctor一起用于动态toc?

Javascript 如何将tocify与ascidoctor一起用于动态toc?,javascript,jquery,tableofcontents,asciidoctor,jquery-tocify-js,Javascript,Jquery,Tableofcontents,Asciidoctor,Jquery Tocify Js,默认情况下,创建静态toc。这是非常酷的,但是对于长文档,如果toc可以更紧凑一些,并且能够突出显示读者当前在文档中的位置,那就太好了 在这一点上,他进来了。Tocify是一个很好的Javascript解决方案,正好可以解决这个问题 现在的问题是:如何将tocify与ascidoctor一起使用 Asciidoctor与此相关。在您的asciidoc文件中启用,例如通过将以下选项传递给Asciidoctor: -a toc=left -a docinfo=shared 在ASCIIDC文件旁边

默认情况下,创建静态toc。这是非常酷的,但是对于长文档,如果toc可以更紧凑一些,并且能够突出显示读者当前在文档中的位置,那就太好了

在这一点上,他进来了。Tocify是一个很好的Javascript解决方案,正好可以解决这个问题

现在的问题是:如何将tocify与ascidoctor一起使用

Asciidoctor与此相关。

在您的asciidoc文件中启用,例如通过将以下选项传递给Asciidoctor:

-a toc=left -a docinfo=shared
在ASCIIDC文件旁边添加一个
docinfo.html
文件,其中包含以下内容:

<!-- Generate a nice TOC -->
<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="https://code.jquery.com/ui/1.11.4/jquery-ui.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tocify/1.9.0/javascripts/jquery.tocify.min.js"></script>
<!-- We do not need the tocify CSS because the asciidoc CSS already provides most of what we neeed -->

<style>
.tocify-header {
    font-style: italic;
}

.tocify-subheader {
    font-style: normal;
    font-size: 90%;
}

.tocify ul {
    margin: 0;
 }

.tocify-focus {
    color: #7a2518; 
    background-color: rgba(0, 0, 0, 0.1);
}

.tocify-focus > a {
    color: #7a2518; 
}
</style>

<script type="text/javascript">
    $(function () {
        // Add a new container for the tocify toc into the existing toc so we can re-use its
        // styling
        $("#toc").append("<div id='generated-toc'></div>");
        $("#generated-toc").tocify({
            extendPage: true,
            context: "#content",
            highlightOnScroll: true,
            hideEffect: "slideUp",
            // Use the IDs that asciidoc already provides so that TOC links and intra-document
            // links are the same. Anything else might confuse users when they create bookmarks.
            hashGenerator: function(text, element) {
                return $(element).attr("id");
            },
            // Smooth scrolling doesn't work properly if we use the asciidoc IDs
            smoothScroll: false,
            // Set to 'none' to use the tocify classes
            theme: "none",
            // Handle book (may contain h1) and article (only h2 deeper)
            selectors: $( "#content" ).has( "h1" ).size() > 0 ? "h1,h2,h3,h4,h5" : "h2,h3,h4,h5",
            ignoreSelector: ".discrete"
        });

        // Switch between static asciidoc toc and dynamic tocify toc based on browser size
        // This is set to match the media selectors in the asciidoc CSS
        // Without this, we keep the dynamic toc even if it is moved from the side to preamble
        // position which will cause odd scrolling behavior
        var handleTocOnResize = function() {
            if ($(document).width() < 768) {
                $("#generated-toc").hide();
                $(".sectlevel0").show();
                $(".sectlevel1").show();
            }
            else {
                $("#generated-toc").show();
                $(".sectlevel0").hide();
                $(".sectlevel1").hide();
            }
        }

        $(window).resize(handleTocOnResize);
        handleTocOnResize();
    });
</script>

.tocify标题{
字体:斜体;
}
.tocify副标题{
字体风格:普通;
字体大小:90%;
}
.tocify ul{
保证金:0;
}
.TocifFocus{
颜色:#7a2518;
背景色:rgba(0,0,0,0.1);
}
.tocify focus>a{
颜色:#7a2518;
}
$(函数(){
//将tociftoc的新容器添加到现有toc中,这样我们就可以重用其
//造型
$(“#toc”)。追加(“”);
$(“#生成的toc”).tocify({
扩展页:是的,
上下文:“#内容”,
没错,
hideEffect:“slideUp”,
//使用Ascidoc已经提供的ID,以便TOC链接和内部文档
//链接是一样的。当用户创建书签时,其他任何东西都可能会让他们感到困惑。
hashGenerator:函数(文本、元素){
返回$(元素).attr(“id”);
},
//如果使用ascidoc ID,平滑滚动无法正常工作
smoothScroll:false,
//设置为“无”以使用tocify类
主题:“无”,
//手册(可能包含h1)和物品(仅h2)
选择器:$(“#内容”).has(“h1”).size()>0?“h1、h2、h3、h4、h5”:“h2、h3、h4、h5”,
忽略选择器:“.离散”
});
//根据浏览器大小在静态AsciDoc toc和动态tocify toc之间切换
//此选项设置为与asciidoc CSS中的媒体选择器匹配
//没有这一点,即使动态toc从一侧移动到另一侧,我们也会保持动态toc
//将导致奇怪滚动行为的位置
var handleTocOnResize=函数(){
if($(文档).width()<768){
$(“#生成的toc”).hide();
$(“.sectlevel0”).show();
$(“.sectlevel1”).show();
}
否则{
$(“#生成的toc”).show();
$(“.sectlevel0”).hide();
$(“.sectlevel1”).hide();
}
}
$(窗口)。调整大小(HandletoResize);
handleTocOnResize();
});