Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(renderer): support manpage doctype #531

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 0 additions & 77 deletions libasciidoc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,83 +231,6 @@ a paragraph with _italic content_`
},
}))
})

It("should include adoc file without leveloffset from relative file", func() {
source := "include::../test/includes/grandchild-include.adoc[]"
expectedContent := `<div class="sect1">
<h2 id="_grandchild_title">grandchild title</h2>
<div class="sectionbody">
<div class="paragraph">
<p>first line of grandchild</p>
</div>
<div class="paragraph">
<p>last line of grandchild</p>
</div>
</div>
</div>`
Expect(RenderHTML(source, configuration.WithFilename("tmp/foo.adoc"))).To(Equal(expectedContent))
})

It("document with custom icon attributes", func() {
// given
attrs := map[string]string{
"icons": "font",
"source-highlighter": "pygments",
}
source := `[source]
----
foo
----

NOTE: a note`
expected := `<div class="listingblock">
<div class="content">
<pre class="pygments highlight"><code>foo</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<i class="fa icon-note" title="Note"></i>
</td>
<td class="content">
a note
</td>
</tr>
</table>
</div>`
Expect(RenderHTML(source, configuration.WithAttributes(attrs))).To(Equal(expected))
})

It("document without custom icon attributes", func() {
// given
attrs := map[string]string{}
source := `[source]
----
foo
----

NOTE: a note`
expected := `<div class="listingblock">
<div class="content">
<pre class="highlight"><code>foo</code></pre>
</div>
</div>
<div class="admonitionblock note">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">
a note
</td>
</tr>
</table>
</div>`
Expect(RenderHTML(source, configuration.WithAttributes(attrs))).To(Equal(expected))
})
})

Context("complete Document ", func() {
Expand Down
11 changes: 7 additions & 4 deletions pkg/parser/document_processing_include_toc_placeholder.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func doInsertTableOfContentsPlaceHolder(doc types.Document, location string) typ
toc := types.TableOfContentsPlaceHolder{}
switch location {
case "", "auto":
// insert TableOfContentsPlaceHolder at first position (in section0 if it exists)
// insert TableOfContentsPlaceHolder at first position (in section '0' if it exists)
if header, ok := doc.Header(); ok {
header.Elements = append([]interface{}{toc}, header.Elements...)
doc.Elements[0] = header
Expand All @@ -35,11 +35,11 @@ func doInsertTableOfContentsPlaceHolder(doc types.Document, location string) typ
// insert TableOfContentsPlaceHolder just after preamble
if header, ok := doc.Header(); ok {
if preambleIndex, ok := lookupPreamble(header.Elements); ok {
header.Elements = insert(header.Elements, toc, preambleIndex)
header.Elements = insertAt(header.Elements, toc, preambleIndex)
doc.Elements[0] = header
}
} else if preambleIndex, ok := lookupPreamble(doc.Elements); ok {
doc.Elements = insert(doc.Elements, toc, preambleIndex)
doc.Elements = insertAt(doc.Elements, toc, preambleIndex)
}
// case "macro":
default:
Expand All @@ -48,6 +48,7 @@ func doInsertTableOfContentsPlaceHolder(doc types.Document, location string) typ
return doc
}

// returns the index of the preamble if it was found in the given elements
func lookupPreamble(elements []interface{}) (int, bool) {
for i, e := range elements {
if _, ok := e.(types.Preamble); ok {
Expand All @@ -56,7 +57,9 @@ func lookupPreamble(elements []interface{}) (int, bool) {
}
return -1, false
}
func insert(elements []interface{}, element interface{}, index int) []interface{} {

// inserts the given element at the given index
func insertAt(elements []interface{}, element interface{}, index int) []interface{} {
remainingElements := make([]interface{}, len(elements)-(index+1))
copy(remainingElements, elements[index+1:])
result := append(elements[0:index+1], element)
Expand Down
Loading