From b53e9cb21a765b20b967b0f9f7f9d468535cc8e5 Mon Sep 17 00:00:00 2001 From: odknt <4185305+odknt@users.noreply.github.com> Date: Wed, 6 Feb 2019 16:24:31 +0900 Subject: [PATCH] Finds and replaces TOC in output of asciidoctor with blackfriday compatible TOC --- helpers/content.go | 40 ++++++++++++++++++++++++++++++++++++++-- helpers/content_test.go | 23 +++++++++++++++++++++++ 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/helpers/content.go b/helpers/content.go index f8479cd1b9a..75cb26d9c9c 100644 --- a/helpers/content.go +++ b/helpers/content.go @@ -640,13 +640,49 @@ func getAsciidocContent(ctx *RenderingContext) []byte { } jww.INFO.Println("Rendering", ctx.DocumentName, "with", path, "...") - args := []string{"--no-header-footer", "--safe"} + args := []string{"--no-header-footer", "--safe", "--attribute=toc"} if isAsciidoctor { // asciidoctor-specific arg to show stack traces on errors args = append(args, "--trace") } args = append(args, "-") - return externallyRenderContent(ctx, path, args) + return replaceAsciidocTOC(externallyRenderContent(ctx, path, args)) +} + +// replaceAsciidocTOC replaces html tags for TOC for compatibility with blackfriday rendered TOC. +func replaceAsciidocTOC(content []byte) []byte { + first := []byte(`