-
The text + hello, world + is not passed through.
+
The text + hello, world + is not passed through.
`
Expect(RenderHTML(source)).To(MatchHTML(expected))
diff --git a/pkg/renderer/sgml/html5/special_character.go b/pkg/renderer/sgml/html5/special_character.go
new file mode 100644
index 00000000..a0885cdd
--- /dev/null
+++ b/pkg/renderer/sgml/html5/special_character.go
@@ -0,0 +1,5 @@
+package html5
+
+const (
+ specialCharacterTmpl = `{{ if eq .Content ">" }}>{{ else if eq .Content "<" }}<{{ else if eq .Content "&" }}&{{ else if eq .Content "+" }}+{{ end }}`
+)
diff --git a/pkg/renderer/sgml/html5/templates.go b/pkg/renderer/sgml/html5/templates.go
index fd58e289..af98a110 100644
--- a/pkg/renderer/sgml/html5/templates.go
+++ b/pkg/renderer/sgml/html5/templates.go
@@ -63,6 +63,7 @@ var templates = sgml.Templates{
SectionHeader: sectionHeaderTmpl,
SidebarBlock: sidebarBlockTmpl,
SourceBlock: sourceBlockTmpl,
+ SpecialCharacter: specialCharacterTmpl,
StringElement: stringTmpl,
SubscriptText: subscriptTextTmpl,
SuperscriptText: superscriptTextTmpl,
diff --git a/pkg/renderer/sgml/icon.go b/pkg/renderer/sgml/icon.go
index fc893466..2b30caac 100644
--- a/pkg/renderer/sgml/icon.go
+++ b/pkg/renderer/sgml/icon.go
@@ -2,11 +2,12 @@ package sgml
import (
fmt "fmt"
+ "path"
+ "strings"
+
"github.com/bytesparadise/libasciidoc/pkg/renderer"
"github.com/bytesparadise/libasciidoc/pkg/types"
"github.com/pkg/errors"
- "path"
- "strings"
)
func (r *sgmlRenderer) renderInlineIcon(ctx *renderer.Context, icon types.Icon) (string, error) {
@@ -24,8 +25,8 @@ func (r *sgmlRenderer) renderInlineIcon(ctx *renderer.Context, icon types.Icon)
Role string
Link string
Window string
- ID sanitized
- Icon sanitized
+ ID string
+ Icon string
}{
Class: icon.Class,
Icon: iconStr,
@@ -41,7 +42,7 @@ func (r *sgmlRenderer) renderInlineIcon(ctx *renderer.Context, icon types.Icon)
return result.String(), nil
}
-func (r *sgmlRenderer) renderIcon(ctx *renderer.Context, icon types.Icon, admonition bool) (sanitized, error) {
+func (r *sgmlRenderer) renderIcon(ctx *renderer.Context, icon types.Icon, admonition bool) (string, error) {
icons := ctx.Attributes.GetAsStringWithDefault("icons", "text")
var template *textTemplate
font := false
@@ -105,7 +106,7 @@ func (r *sgmlRenderer) renderIcon(ctx *renderer.Context, icon types.Icon, admoni
Path: renderIconPath(ctx, icon.Class),
Admonition: admonition,
})
- return sanitized(s.String()), err
+ return string(s.String()), err
}
func renderIconPath(ctx *renderer.Context, name string) string {
diff --git a/pkg/renderer/sgml/image.go b/pkg/renderer/sgml/image.go
index 0682c36d..70da3d7e 100644
--- a/pkg/renderer/sgml/image.go
+++ b/pkg/renderer/sgml/image.go
@@ -36,11 +36,11 @@ func (r *sgmlRenderer) renderImageBlock(ctx *renderer.Context, img types.ImageBl
caption.WriteString(c)
}
err := r.blockImage.Execute(result, struct {
- ID sanitized
- Title sanitized
+ ID string
+ Title string
ImageNumber int
Caption string
- Roles sanitized
+ Roles string
Href string
Alt string
Width string
@@ -69,8 +69,8 @@ func (r *sgmlRenderer) renderImageBlock(ctx *renderer.Context, img types.ImageBl
func (r *sgmlRenderer) renderInlineImage(img types.InlineImage) (string, error) {
result := &strings.Builder{}
err := r.inlineImage.Execute(result, struct {
- Roles sanitized
- Title sanitized
+ Roles string
+ Title string
Href string
Alt string
Width string
diff --git a/pkg/renderer/sgml/labeled_list.go b/pkg/renderer/sgml/labeled_list.go
index 0821e8a4..2468cdab 100644
--- a/pkg/renderer/sgml/labeled_list.go
+++ b/pkg/renderer/sgml/labeled_list.go
@@ -27,17 +27,17 @@ func (r *sgmlRenderer) renderLabeledList(ctx *renderer.Context, l types.LabeledL
// here we must preserve the HTML tags
err = tmpl.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
- Roles sanitized
- Content sanitized
+ ID string
+ Title string
+ Roles string
+ Content string
Items []types.LabeledListItem
}{
Context: ctx,
ID: r.renderElementID(l.Attributes),
Title: r.renderElementTitle(l.Attributes),
Roles: r.renderElementRoles(l.Attributes),
- Content: sanitized(content.String()),
+ Content: string(content.String()),
Items: l.Items,
})
if err != nil {
@@ -73,14 +73,14 @@ func (r *sgmlRenderer) renderLabeledListItem(ctx *renderer.Context, tmpl *textTe
}
err = tmpl.Execute(w, struct {
Context *renderer.Context
- Term sanitized
- Content sanitized
+ Term string
+ Content string
Continuation bool
}{
Context: ctx,
- Term: sanitized(term),
+ Term: string(term),
Continuation: continuation,
- Content: sanitized(content),
+ Content: string(content),
})
return content == "", err
}
diff --git a/pkg/renderer/sgml/literal_blocks.go b/pkg/renderer/sgml/literal_blocks.go
index eb685549..620f6e29 100644
--- a/pkg/renderer/sgml/literal_blocks.go
+++ b/pkg/renderer/sgml/literal_blocks.go
@@ -42,9 +42,9 @@ func (r *sgmlRenderer) renderLiteralBlock(ctx *renderer.Context, b types.Literal
result := &strings.Builder{}
err := r.literalBlock.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
- Roles sanitized
+ ID string
+ Title string
+ Roles string
Content string
Lines []string
}{
diff --git a/pkg/renderer/sgml/ordered_list.go b/pkg/renderer/sgml/ordered_list.go
index f6357e07..280a0fc1 100644
--- a/pkg/renderer/sgml/ordered_list.go
+++ b/pkg/renderer/sgml/ordered_list.go
@@ -21,13 +21,13 @@ func (r *sgmlRenderer) renderOrderedList(ctx *renderer.Context, l types.OrderedL
err := r.orderedList.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
- Roles sanitized
+ ID string
+ Title string
+ Roles string
Style string
- ListStyle sanitized
+ ListStyle string
Start string
- Content sanitized
+ Content string
Reversed bool
Items []types.OrderedListItem
}{
@@ -37,7 +37,7 @@ func (r *sgmlRenderer) renderOrderedList(ctx *renderer.Context, l types.OrderedL
Style: getNumberingStyle(l),
ListStyle: r.numberingType(getNumberingStyle(l)),
Start: l.Attributes.GetAsStringWithDefault(types.AttrStart, ""),
- Content: sanitized(content.String()),
+ Content: string(content.String()),
Reversed: l.Attributes.HasOption("reversed"),
Items: l.Items,
})
@@ -55,7 +55,7 @@ func getNumberingStyle(l types.OrderedList) string {
}
// this numbering style is only really relevant to HTML
-func (r *sgmlRenderer) numberingType(style string) sanitized {
+func (r *sgmlRenderer) numberingType(style string) string {
switch style {
case types.LowerAlpha:
return `a`
@@ -78,9 +78,9 @@ func (r *sgmlRenderer) renderOrderedListItem(ctx *renderer.Context, w io.Writer,
}
return r.orderedListItem.Execute(w, struct {
Context *renderer.Context
- Content sanitized
+ Content string
}{
Context: ctx,
- Content: sanitized(content),
+ Content: string(content),
})
}
diff --git a/pkg/renderer/sgml/paragraph.go b/pkg/renderer/sgml/paragraph.go
index 8a1d0afe..0fafc570 100644
--- a/pkg/renderer/sgml/paragraph.go
+++ b/pkg/renderer/sgml/paragraph.go
@@ -33,16 +33,16 @@ func (r *sgmlRenderer) renderParagraph(ctx *renderer.Context, p types.Paragraph)
log.Debug("rendering a standalone paragraph")
err = r.paragraph.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Roles sanitized
- Title sanitized
+ ID string
+ Roles string
+ Title string
Lines []interface{}
- Content sanitized
+ Content string
}{
Context: ctx,
ID: r.renderElementID(p.Attributes),
Title: r.renderElementTitle(p.Attributes),
- Content: sanitized(content),
+ Content: string(content),
Roles: r.renderElementRoles(p.Attributes),
Lines: p.Lines,
})
@@ -71,21 +71,21 @@ func (r *sgmlRenderer) renderAdmonitionParagraph(ctx *renderer.Context, p types.
}
err = r.admonitionParagraph.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
- Roles sanitized
- Icon sanitized
- Kind sanitized
- Content sanitized
+ ID string
+ Title string
+ Roles string
+ Icon string
+ Kind string
+ Content string
Lines []interface{}
}{
Context: ctx,
ID: r.renderElementID(p.Attributes),
Title: r.renderElementTitle(p.Attributes),
- Kind: sanitized(k),
+ Kind: string(k),
Roles: r.renderElementRoles(p.Attributes),
Icon: icon,
- Content: sanitized(content),
+ Content: string(content),
Lines: p.Lines,
})
@@ -110,17 +110,17 @@ func (r *sgmlRenderer) renderVerseParagraph(ctx *renderer.Context, p types.Parag
}
err = r.verseParagraph.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
+ ID string
+ Title string
Attribution Attribution
- Content sanitized
+ Content string
Lines []interface{}
}{
Context: ctx,
ID: r.renderElementID(p.Attributes),
Title: r.renderElementTitle(p.Attributes),
Attribution: newParagraphAttribution(p),
- Content: sanitized(content),
+ Content: string(content),
Lines: p.Lines,
})
@@ -137,17 +137,17 @@ func (r *sgmlRenderer) renderQuoteParagraph(ctx *renderer.Context, p types.Parag
}
err = r.quoteParagraph.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
+ ID string
+ Title string
Attribution Attribution
- Content sanitized
+ Content string
Lines []interface{}
}{
Context: ctx,
ID: r.renderElementID(p.Attributes),
Title: r.renderElementTitle(p.Attributes),
Attribution: newParagraphAttribution(p),
- Content: sanitized(content),
+ Content: string(content),
Lines: p.Lines,
})
@@ -165,11 +165,11 @@ func (r *sgmlRenderer) renderManpageNameParagraph(ctx *renderer.Context, p types
err = r.manpageNameParagraph.Execute(result, struct {
Context *renderer.Context
- Content sanitized
+ Content string
Lines []interface{}
}{
Context: ctx,
- Content: sanitized(content),
+ Content: string(content),
Lines: p.Lines,
})
return result.String(), err
@@ -185,17 +185,17 @@ func (r *sgmlRenderer) renderDelimitedBlockParagraph(ctx *renderer.Context, p ty
}
err = r.delimitedBlockParagraph.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
+ ID string
+ Title string
CheckStyle string
- Content sanitized
+ Content string
Lines []interface{}
}{
Context: ctx,
ID: r.renderElementID(p.Attributes),
Title: r.renderElementTitle(p.Attributes),
CheckStyle: renderCheckStyle(p.Attributes[types.AttrCheckStyle]),
- Content: sanitized(content),
+ Content: string(content),
Lines: p.Lines,
})
return result.String(), err
@@ -212,9 +212,9 @@ func renderCheckStyle(style interface{}) string {
}
}
-func (r *sgmlRenderer) renderElementTitle(attrs types.Attributes) sanitized {
+func (r *sgmlRenderer) renderElementTitle(attrs types.Attributes) string {
if title, found := attrs.GetAsString(types.AttrTitle); found {
- return sanitized(EscapeString(strings.TrimSpace(title)))
+ return string(EscapeString(strings.TrimSpace(title)))
}
return ""
}
diff --git a/pkg/renderer/sgml/quoted_text.go b/pkg/renderer/sgml/quoted_text.go
index 48ca8fed..32038d1e 100644
--- a/pkg/renderer/sgml/quoted_text.go
+++ b/pkg/renderer/sgml/quoted_text.go
@@ -1,10 +1,11 @@
package sgml
import (
+ "strings"
+
"github.com/bytesparadise/libasciidoc/pkg/renderer"
"github.com/bytesparadise/libasciidoc/pkg/types"
"github.com/pkg/errors"
- "strings"
)
// TODO: The bold, italic, and monospace items should be refactored to support semantic tags instead.
@@ -41,15 +42,15 @@ func (r *sgmlRenderer) renderQuotedText(ctx *renderer.Context, t types.QuotedTex
result := &strings.Builder{}
err := tmpl.Execute(result, struct {
- ID sanitized
- Roles sanitized
+ ID string
+ Roles string
Attributes types.Attributes
- Content sanitized
+ Content string
}{
Attributes: t.Attributes,
ID: r.renderElementID(t.Attributes),
Roles: r.renderElementRoles(t.Attributes),
- Content: sanitized(elementsBuffer.String()),
+ Content: string(elementsBuffer.String()),
}) //nolint: gosec
if err != nil {
return "", errors.Wrap(err, "unable to render monospaced quote")
diff --git a/pkg/renderer/sgml/renderer.go b/pkg/renderer/sgml/renderer.go
index cddcbc12..cc99e5b1 100644
--- a/pkg/renderer/sgml/renderer.go
+++ b/pkg/renderer/sgml/renderer.go
@@ -1,7 +1,6 @@
package sgml
import (
- htmltemplate "html/template"
"io"
"strings"
texttemplate "text/template"
@@ -112,13 +111,13 @@ func (r *sgmlRenderer) Render(ctx *renderer.Context, doc types.Document, output
err = r.article.Execute(output, struct {
Generator string
Doctype string
- Title sanitized
+ Title string
Authors string
Header string
Role string
- ID sanitized
- Roles sanitized
- Content sanitized
+ ID string
+ Roles string
+ Content string
RevNumber string
LastUpdated string
CSS string
@@ -132,7 +131,7 @@ func (r *sgmlRenderer) Render(ctx *renderer.Context, doc types.Document, output
Header: renderedHeader,
Roles: r.renderDocumentRoles(doc),
ID: r.renderDocumentID(doc),
- Content: sanitized(renderedContent), //nolint: gosec
+ Content: string(renderedContent), //nolint: gosec
RevNumber: doc.Attributes.GetAsStringWithDefault("revnumber", ""),
LastUpdated: ctx.Config.LastUpdated.Format(configuration.LastUpdatedFormat),
CSS: ctx.Config.CSS,
@@ -223,14 +222,14 @@ func (r *sgmlRenderer) splitAndRenderForManpage(ctx *renderer.Context, doc types
return "", result.String(), nil
}
-func (r *sgmlRenderer) renderDocumentRoles(doc types.Document) sanitized {
+func (r *sgmlRenderer) renderDocumentRoles(doc types.Document) string {
if header, found := doc.Header(); found {
return r.renderElementRoles(header.Attributes)
}
return ""
}
-func (r *sgmlRenderer) renderDocumentID(doc types.Document) sanitized {
+func (r *sgmlRenderer) renderDocumentID(doc types.Document) string {
if header, found := doc.Header(); found {
if header.Attributes.Has(types.AttrCustomID) {
// We only want to emit a document body ID, if one was explicitly set
@@ -252,14 +251,14 @@ func (r *sgmlRenderer) renderAuthors(doc types.Document) string {
return strings.Join(authorStrs, "; ")
}
-func (r *sgmlRenderer) renderDocumentTitle(ctx *renderer.Context, doc types.Document) (sanitized, error) {
+func (r *sgmlRenderer) renderDocumentTitle(ctx *renderer.Context, doc types.Document) (string, error) {
if header, found := doc.Header(); found {
// TODO: This feels wrong. The title should not need markup.
title, err := r.renderPlainText(ctx, header.Title)
if err != nil {
return "", errors.Wrap(err, "unable to render document title")
}
- return sanitized(title), nil
+ return string(title), nil
}
return "", nil
}
@@ -277,7 +276,7 @@ func (r *sgmlRenderer) renderArticleHeader(ctx *renderer.Context, header types.S
output := &strings.Builder{}
err = r.articleHeader.Execute(output, struct {
Header string
- Details *htmltemplate.HTML // TODO: convert to sanitized (no need to be a pointer)
+ Details *string // TODO: convert to string (no need to be a pointer)
}{
Header: renderedHeader,
Details: documentDetails,
@@ -310,12 +309,12 @@ func (r *sgmlRenderer) renderManpageHeader(ctx *renderer.Context, header types.S
err = r.manpageHeader.Execute(output, struct {
Header string
Name string
- Content sanitized
+ Content string
IncludeH1 bool
}{
Header: renderedHeader,
Name: renderedName,
- Content: sanitized(renderedContent), //nolint: gosec
+ Content: string(renderedContent), //nolint: gosec
IncludeH1: len(renderedHeader) > 0,
})
if err != nil {
diff --git a/pkg/renderer/sgml/section.go b/pkg/renderer/sgml/section.go
index 4d82f8e5..453b9f87 100644
--- a/pkg/renderer/sgml/section.go
+++ b/pkg/renderer/sgml/section.go
@@ -22,11 +22,11 @@ func (r *sgmlRenderer) renderPreamble(ctx *renderer.Context, p types.Preamble) (
err = r.preamble.Execute(result, struct {
Context *renderer.Context
Wrapper bool
- Content sanitized
+ Content string
}{
Context: ctx,
Wrapper: ctx.HasHeader,
- Content: sanitized(content),
+ Content: string(content),
})
if err != nil {
return "", errors.Wrap(err, "error while rendering preamble")
@@ -50,11 +50,11 @@ func (r *sgmlRenderer) renderSection(ctx *renderer.Context, s types.Section) (st
result := &strings.Builder{}
err = r.sectionContent.Execute(result, struct {
Context *renderer.Context
- Header sanitized
- Content sanitized
+ Header string
+ Content string
Elements []interface{}
- ID sanitized
- Roles sanitized
+ ID string
+ Roles string
Level int
}{
Context: ctx,
@@ -63,7 +63,7 @@ func (r *sgmlRenderer) renderSection(ctx *renderer.Context, s types.Section) (st
Elements: s.Elements,
ID: r.renderElementID(s.Attributes),
Roles: r.renderElementRoles(s.Attributes),
- Content: sanitized(content),
+ Content: string(content),
})
if err != nil {
return "", errors.Wrap(err, "error while rendering section")
@@ -72,7 +72,7 @@ func (r *sgmlRenderer) renderSection(ctx *renderer.Context, s types.Section) (st
return result.String(), nil
}
-func (r *sgmlRenderer) renderSectionTitle(ctx *renderer.Context, s types.Section) (sanitized, error) {
+func (r *sgmlRenderer) renderSectionTitle(ctx *renderer.Context, s types.Section) (string, error) {
result := &strings.Builder{}
renderedContent, err := r.renderInlineElements(ctx, s.Title)
if err != nil {
@@ -82,8 +82,8 @@ func (r *sgmlRenderer) renderSectionTitle(ctx *renderer.Context, s types.Section
err = r.sectionHeader.Execute(result, struct {
Level int
LevelPlusOne int
- ID sanitized
- Roles sanitized
+ ID string
+ Roles string
Content string
}{
Level: s.Level,
@@ -96,5 +96,5 @@ func (r *sgmlRenderer) renderSectionTitle(ctx *renderer.Context, s types.Section
return "", errors.Wrapf(err, "error while rendering sectionTitle")
}
// log.Debugf("rendered sectionTitle: %s", result.Bytes())
- return sanitized(result.String()), nil
+ return string(result.String()), nil
}
diff --git a/pkg/renderer/sgml/sgml_renderer.go b/pkg/renderer/sgml/sgml_renderer.go
index 980748be..cbd4cd04 100644
--- a/pkg/renderer/sgml/sgml_renderer.go
+++ b/pkg/renderer/sgml/sgml_renderer.go
@@ -63,6 +63,7 @@ type sgmlRenderer struct {
sectionHeader *textTemplate
sidebarBlock *textTemplate
sourceBlock *textTemplate
+ specialCharacter *textTemplate
stringElement *textTemplate
subscriptText *textTemplate
superscriptText *textTemplate
@@ -142,6 +143,7 @@ func (r *sgmlRenderer) prepareTemplates() error {
r.stringElement, err = r.newTemplate("string-element", tmpls.StringElement, err)
r.sidebarBlock, err = r.newTemplate("sidebar-block", tmpls.SidebarBlock, err)
r.sourceBlock, err = r.newTemplate("source-block", tmpls.SourceBlock, err)
+ r.specialCharacter, err = r.newTemplate("special-character", tmpls.SpecialCharacter, err)
r.subscriptText, err = r.newTemplate("subscript", tmpls.SubscriptText, err)
r.superscriptText, err = r.newTemplate("superscript", tmpls.SuperscriptText, err)
r.table, err = r.newTemplate("table", tmpls.Table, err)
diff --git a/pkg/renderer/sgml/special_character.go b/pkg/renderer/sgml/special_character.go
new file mode 100644
index 00000000..91d1fcbc
--- /dev/null
+++ b/pkg/renderer/sgml/special_character.go
@@ -0,0 +1,22 @@
+package sgml
+
+import (
+ "strings"
+
+ "github.com/bytesparadise/libasciidoc/pkg/types"
+ "github.com/pkg/errors"
+ log "github.com/sirupsen/logrus"
+)
+
+func (r *sgmlRenderer) renderSpecialCharacter(s types.SpecialCharacter) (string, error) {
+ log.Debugf("rendering special character...")
+ result := &strings.Builder{}
+ if err := r.specialCharacter.Execute(result, struct {
+ Content string
+ }{
+ Content: s.Content,
+ }); err != nil {
+ return "", errors.Wrap(err, "error while rendering special character")
+ }
+ return result.String(), nil
+}
diff --git a/pkg/renderer/sgml/table.go b/pkg/renderer/sgml/table.go
index 6857f4f3..4b79d4bc 100644
--- a/pkg/renderer/sgml/table.go
+++ b/pkg/renderer/sgml/table.go
@@ -74,7 +74,7 @@ func (r *sgmlRenderer) renderTable(ctx *renderer.Context, t types.Table) (string
err = r.table.Execute(result, struct {
Context *renderer.Context
- Title sanitized
+ Title string
Columns []types.TableColumn
TableNumber int
Caption string
@@ -84,7 +84,7 @@ func (r *sgmlRenderer) renderTable(ctx *renderer.Context, t types.Table) (string
Float string
Stripes string
Width int
- Roles sanitized
+ Roles string
Header string
Body string
}{
diff --git a/pkg/renderer/sgml/table_of_contents.go b/pkg/renderer/sgml/table_of_contents.go
index e654d4e5..8a22d622 100644
--- a/pkg/renderer/sgml/table_of_contents.go
+++ b/pkg/renderer/sgml/table_of_contents.go
@@ -72,14 +72,14 @@ func (r *sgmlRenderer) renderTableOfContentsEntry(ctx *renderer.Context, entry t
err = r.tocEntry.Execute(resultBuf, struct {
Context *renderer.Context
Level int
- ID sanitized
+ ID string
Title string
Content string
Children []types.ToCSection
}{
Context: ctx,
Level: entry.Level,
- ID: sanitized(entry.ID),
+ ID: string(entry.ID),
Title: entry.Title,
Content: content,
Children: entry.Children,
diff --git a/pkg/renderer/sgml/templates.go b/pkg/renderer/sgml/templates.go
index 38a7ae2d..b28c3088 100644
--- a/pkg/renderer/sgml/templates.go
+++ b/pkg/renderer/sgml/templates.go
@@ -56,6 +56,7 @@ type Templates struct {
SectionHeader string
SidebarBlock string
SourceBlock string
+ SpecialCharacter string
StringElement string
SubscriptText string
SuperscriptText string
diff --git a/pkg/renderer/sgml/unordered_list.go b/pkg/renderer/sgml/unordered_list.go
index 7a055108..611b6dc6 100644
--- a/pkg/renderer/sgml/unordered_list.go
+++ b/pkg/renderer/sgml/unordered_list.go
@@ -28,20 +28,20 @@ func (r *sgmlRenderer) renderUnorderedList(ctx *renderer.Context, l types.Unorde
// here we must preserve the HTML tags
err := r.unorderedList.Execute(result, struct {
Context *renderer.Context
- ID sanitized
- Title sanitized
- Roles sanitized
- Style sanitized
+ ID string
+ Title string
+ Roles string
+ Style string
Checklist bool
Items []types.UnorderedListItem
- Content sanitized
+ Content string
}{
Context: ctx,
ID: r.renderElementID(l.Attributes),
Title: r.renderElementTitle(l.Attributes),
Checklist: checkList,
Items: l.Items,
- Content: sanitized(content.String()),
+ Content: string(content.String()),
Roles: r.renderElementRoles(l.Attributes),
Style: r.renderElementStyle(l.Attributes),
})
@@ -58,9 +58,9 @@ func (r *sgmlRenderer) renderUnorderedListItem(ctx *renderer.Context, w io.Write
}
return r.unorderedListItem.Execute(w, struct {
Context *renderer.Context
- Content sanitized
+ Content string
}{
Context: ctx,
- Content: sanitized(content),
+ Content: string(content),
})
}
diff --git a/pkg/renderer/sgml/xhtml5/article_adoc_test.go b/pkg/renderer/sgml/xhtml5/article_adoc_test.go
index 04c187fa..cc159fd2 100644
--- a/pkg/renderer/sgml/xhtml5/article_adoc_test.go
+++ b/pkg/renderer/sgml/xhtml5/article_adoc_test.go
@@ -3,9 +3,10 @@ package xhtml5_test
import (
"bufio"
"bytes"
- "github.com/bytesparadise/libasciidoc/pkg/renderer/sgml/xhtml5"
"os"
+ "github.com/bytesparadise/libasciidoc/pkg/renderer/sgml/xhtml5"
+
"github.com/bytesparadise/libasciidoc/pkg/configuration"
"github.com/bytesparadise/libasciidoc/pkg/parser"
"github.com/bytesparadise/libasciidoc/pkg/renderer"
diff --git a/pkg/renderer/sgml/xhtml5/passthrough_test.go b/pkg/renderer/sgml/xhtml5/passthrough_test.go
index 8d3ae64a..c974091c 100644
--- a/pkg/renderer/sgml/xhtml5/passthrough_test.go
+++ b/pkg/renderer/sgml/xhtml5/passthrough_test.go
@@ -54,7 +54,7 @@ var _ = Describe("passthroughs", func() {
It("an empty standalone singleplus passthrough", func() {
source := `++`
expected := `
-
The text + hello, world + is not passed through.
+
The text + hello, world + is not passed through.
`
Expect(RenderXHTML(source)).To(MatchHTML(expected))
diff --git a/pkg/types/predefined_attributes.go b/pkg/types/predefined_attributes.go
index 27d040bb..4bce7f3e 100644
--- a/pkg/types/predefined_attributes.go
+++ b/pkg/types/predefined_attributes.go
@@ -18,12 +18,12 @@ func init() {
"ldquo": "\u201c",
"rdquo": "\u201d",
"deg": "\u00b0",
- "plus": "+", // leave this to prevent passthrough decode?
+ "plus": "+", // leave this to prevent passthrough decode?
"brvbar": "\u00a6",
"vbar": "|", // TODO: maybe convert this because of tables?
- "amp": "&",
- "lt": "<",
- "gt": ">",
+ "amp": "&",
+ "lt": "<",
+ "gt": ">",
"startsb": "[",
"endsb": "]",
"caret": "^",
diff --git a/pkg/types/predefined_attributes_test.go b/pkg/types/predefined_attributes_test.go
index b883be2e..cff11fe6 100644
--- a/pkg/types/predefined_attributes_test.go
+++ b/pkg/types/predefined_attributes_test.go
@@ -23,12 +23,12 @@ var _ = DescribeTable("predefined attributes",
Entry("ldquo", "ldquo", "\u201c"),
Entry("rdquo", "rdquo", "\u201d"),
Entry("deg", "deg", "\u00b0"),
- Entry("plus", "plus", "+"),
+ Entry("plus", "plus", "+"),
Entry("brvbar", "brvbar", "\u00a6"),
Entry("vbar", "vbar", "|"),
- Entry("amp", "amp", "&"),
- Entry("lt", "lt", "<"),
- Entry("gt", "gt", ">"),
+ Entry("amp", "amp", "&"),
+ Entry("lt", "lt", "<"),
+ Entry("gt", "gt", ">"),
Entry("startsb", "startsb", "["),
Entry("endsb", "endsb", "]"),
Entry("caret", "caret", "^"),
diff --git a/pkg/types/types.go b/pkg/types/types.go
index 1f6989d1..0c824429 100644
--- a/pkg/types/types.go
+++ b/pkg/types/types.go
@@ -551,7 +551,7 @@ func NewDocumentHeader(title []interface{}, authors interface{}, revision interf
// those attributes can be used in attribute substitutions in the document
func expandAuthors(authors []DocumentAuthor) Attributes {
result := make(map[string]interface{}, 1+6*len(authors)) // each author may add up to 6 fields in the result map
- sanitized := make([]DocumentAuthor, 0, len(authors))
+ s := make([]DocumentAuthor, 0, len(authors))
for i, author := range authors {
var part1, part2, part3, email string
author.FullName = strings.ReplaceAll(author.FullName, " ", " ")
@@ -608,13 +608,13 @@ func expandAuthors(authors []DocumentAuthor) Attributes {
if email != "" {
result[key("email", i)] = email
}
- // also include a "sanitized" version of the given author
- sanitized = append(sanitized, DocumentAuthor{
+ // also include a "string" version of the given author
+ s = append(s, DocumentAuthor{
FullName: result[key("author", i)].(string),
Email: email,
})
}
- result[AttrAuthors] = sanitized
+ result[AttrAuthors] = s
log.Debugf("authors: %v", result)
return result
}
@@ -2325,3 +2325,18 @@ func NewInlineAttribute(name string, value interface{}) (interface{}, error) {
return nil, fmt.Errorf("invalid type for attribute %q: %T", name, value)
}
}
+
+// ------------------------------------------------------------------------------------
+// Special Characters
+// They need to be identified as they may have a special treatment during the rendering
+// ------------------------------------------------------------------------------------
+
+// SpecialCharacter a special character, which may get a special treatment later during rendering
+type SpecialCharacter StringElement
+
+// NewSpecialCharacter return a new SpecialCharacter
+func NewSpecialCharacter(content string) (SpecialCharacter, error) {
+ return SpecialCharacter{
+ Content: content,
+ }, nil
+}
diff --git a/testsupport/parse_document_block.go b/testsupport/parse_document_block.go
index ea1f7ea5..95996b28 100644
--- a/testsupport/parse_document_block.go
+++ b/testsupport/parse_document_block.go
@@ -13,10 +13,8 @@ import (
func ParseDocumentBlock(actual string, opts ...parser.Option) (interface{}, error) {
r := strings.NewReader(actual)
result, err := parser.ParseReader("", r, append(opts, parser.Entrypoint("DocumentRawBlock"))...)
- if err == nil {
- if log.IsLevelEnabled(log.DebugLevel) {
- spew.Dump(result)
- }
+ if err == nil && log.IsLevelEnabled(log.DebugLevel) {
+ spew.Fdump(log.StandardLogger().Out, result)
}
return result, err
}
diff --git a/testsupport/parse_inline_elements.go b/testsupport/parse_inline_elements.go
index a4a80f08..ea07bdc9 100644
--- a/testsupport/parse_inline_elements.go
+++ b/testsupport/parse_inline_elements.go
@@ -4,10 +4,16 @@ import (
"strings"
"github.com/bytesparadise/libasciidoc/pkg/parser"
+ "github.com/davecgh/go-spew/spew"
+ log "github.com/sirupsen/logrus"
)
// ParseInlineElements parses the actual source with the options
func ParseInlineElements(actual string, options ...parser.Option) (interface{}, error) {
r := strings.NewReader(actual)
- return parser.ParseReader("", r, append(options, parser.Entrypoint("InlineElements"))...)
+ result, err := parser.ParseReader("", r, append(options, parser.Entrypoint("InlineElements"))...)
+ if err == nil && log.IsLevelEnabled(log.DebugLevel) {
+ spew.Fdump(log.StandardLogger().Out, result)
+ }
+ return result, err
}