-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(renderer): render external links (#48)
Signed-off-by: Xavier Coulon <xcoulon@redhat.com>
- Loading branch information
Showing
3 changed files
with
56 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package html5 | ||
|
||
import ( | ||
"bytes" | ||
"html/template" | ||
|
||
"github.com/bytesparadise/libasciidoc/renderer" | ||
"github.com/bytesparadise/libasciidoc/types" | ||
"github.com/pkg/errors" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
var externalLinkTmpl *template.Template | ||
|
||
// initializes the templates | ||
func init() { | ||
externalLinkTmpl = newHTMLTemplate("external link", `<a href="{{ .URL }}">{{ .Text }}</a>`) | ||
} | ||
|
||
func renderExternalLink(ctx *renderer.Context, l *types.ExternalLink) ([]byte, error) { | ||
result := bytes.NewBuffer(nil) | ||
err := externalLinkTmpl.Execute(result, l) | ||
if err != nil { | ||
return nil, errors.Wrapf(err, "unable to render external link") | ||
} | ||
log.Debugf("rendered external link: %s", result.Bytes()) | ||
return result.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package html5_test | ||
|
||
import . "github.com/onsi/ginkgo" | ||
|
||
var _ = Describe("Links", func() { | ||
Context("External links", func() { | ||
|
||
It("External link alone", func() { | ||
|
||
actualContent := "https://foo.com[the website]" | ||
expected := `<div class="paragraph"> | ||
<p><a href="https://foo.com">the website</a></p> | ||
</div>` | ||
verify(GinkgoT(), expected, actualContent) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters