Skip to content

Commit

Permalink
refactor(renderer): rename files (#1065)
Browse files Browse the repository at this point in the history
also, update comments
follow-up of #1064

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Jul 7, 2022
1 parent e12e660 commit 348d3bc
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 65 deletions.
3 changes: 1 addition & 2 deletions pkg/renderer/sgml/html5/html5.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import (
"github.com/bytesparadise/libasciidoc/pkg/types"
)

// Render renders the document to the output, using a default instance
// of the renderer, with default templates.
// Render renders the document to the output, using the SGML renderer configured with the HTML5 templates
func Render(doc *types.Document, config *configuration.Configuration, output io.Writer) (types.Metadata, error) {
return sgml.Render(doc, config, output, templates)
}
4 changes: 2 additions & 2 deletions pkg/renderer/sgml/html5/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"github.com/bytesparadise/libasciidoc/pkg/renderer/sgml"
)

// Templates returns the default Templates use for HTML5. It may be useful
// for derived implementations.
// Templates returns the default Templates use for HTML5.
func Templates() sgml.Templates {
return templates
}

// the Templates used for HTML5.
var templates = sgml.Templates{
AdmonitionBlock: admonitionBlockTmpl,
AdmonitionParagraph: admonitionParagraphTmpl,
Expand Down
30 changes: 30 additions & 0 deletions pkg/renderer/sgml/xhtml5/article.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package xhtml5

const (
articleTmpl = "<!DOCTYPE html>\n" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">\n" +
"<head>\n" +
"<meta charset=\"UTF-8\"/>\n" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>\n" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>\n" +
"{{ if .Generator }}<meta name=\"generator\" content=\"{{ .Generator }}\"/>\n{{ end }}" +
"{{ if .Authors }}<meta name=\"author\" content=\"{{ .Authors }}\"/>\n{{ end }}" +
"{{ range $css := .CSS }}<link type=\"text/css\" rel=\"stylesheet\" href=\"{{ $css }}\"/>\n{{ end }}" +
"<title>{{ .Title }}</title>\n" +
"</head>\n" +
"<body" +
"{{ if .ID }} id=\"{{ .ID }}\"{{ end }}" +
" class=\"{{ .Doctype }}{{ if .Roles }} {{ .Roles }}{{ end }}\">\n" +
"{{ if .IncludeHTMLBodyHeader }}{{ .Header }}{{ end }}" +
"<div id=\"content\">\n" +
"{{ .Content }}" +
"</div>\n" +
"{{ if .IncludeHTMLBodyFooter }}<div id=\"footer\">\n" +
"<div id=\"footer-text\">\n" +
"{{ if .RevNumber }}Version {{ .RevNumber }}<br/>\n{{ end }}" +
"Last updated {{ .LastUpdated }}\n" +
"</div>\n" +
"</div>\n{{ end }}" +
"</body>\n" +
"</html>\n"
)
34 changes: 0 additions & 34 deletions pkg/renderer/sgml/xhtml5/templates.go

This file was deleted.

57 changes: 30 additions & 27 deletions pkg/renderer/sgml/xhtml5/xhtml5.go
Original file line number Diff line number Diff line change
@@ -1,30 +1,33 @@
package xhtml5

const (
articleTmpl = "<!DOCTYPE html>\n" +
"<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\">\n" +
"<head>\n" +
"<meta charset=\"UTF-8\"/>\n" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\"/>\n" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"/>\n" +
"{{ if .Generator }}<meta name=\"generator\" content=\"{{ .Generator }}\"/>\n{{ end }}" +
"{{ if .Authors }}<meta name=\"author\" content=\"{{ .Authors }}\"/>\n{{ end }}" +
"{{ range $css := .CSS }}<link type=\"text/css\" rel=\"stylesheet\" href=\"{{ $css }}\"/>\n{{ end }}" +
"<title>{{ .Title }}</title>\n" +
"</head>\n" +
"<body" +
"{{ if .ID }} id=\"{{ .ID }}\"{{ end }}" +
" class=\"{{ .Doctype }}{{ if .Roles }} {{ .Roles }}{{ end }}\">\n" +
"{{ if .IncludeHTMLBodyHeader }}{{ .Header }}{{ end }}" +
"<div id=\"content\">\n" +
"{{ .Content }}" +
"</div>\n" +
"{{ if .IncludeHTMLBodyFooter }}<div id=\"footer\">\n" +
"<div id=\"footer-text\">\n" +
"{{ if .RevNumber }}Version {{ .RevNumber }}<br/>\n{{ end }}" +
"Last updated {{ .LastUpdated }}\n" +
"</div>\n" +
"</div>\n{{ end }}" +
"</body>\n" +
"</html>\n"
import (
"io"

"github.com/bytesparadise/libasciidoc/pkg/configuration"
"github.com/bytesparadise/libasciidoc/pkg/renderer/sgml"
"github.com/bytesparadise/libasciidoc/pkg/renderer/sgml/html5"
"github.com/bytesparadise/libasciidoc/pkg/types"
)

// Render renders the document to the output, using the SGML renderer configured with the XHTML5 templates
func Render(doc *types.Document, config *configuration.Configuration, output io.Writer) (types.Metadata, error) {
templates := html5.Templates()
// XHTML5 overrides of HTML5.
templates.Article = articleTmpl
templates.BlockImage = blockImageTmpl
templates.LineBreak = lineBreakTmpl
templates.DocumentAuthorDetails = documentAuthorDetailsTmpl
templates.DocumentDetails = documentDetailsTmpl
templates.Footnotes = footnotesTmpl
templates.IconImage = iconImageTmpl
templates.InlineImage = inlineImageTmpl
templates.LabeledListHorizontalElement = labeledListHorizontalItemTmpl
templates.Table = tableTmpl
templates.ThematicBreak = thematicBreakTmpl
templates.QuoteBlock = quoteBlockTmpl
templates.QuoteParagraph = quoteParagraphTmpl
templates.VerseBlock = verseBlockTmpl
templates.VerseParagraph = verseParagraphTmpl

return sgml.Render(doc, config, output, templates)
}

0 comments on commit 348d3bc

Please sign in to comment.