Skip to content

Commit

Permalink
feat(validator): validate manpage document
Browse files Browse the repository at this point in the history
Add a new `pkg/validator` package which validates
the given document, reports problems and in the case
of a `manpage` document, changes the doctype to `article`
if a problem was found.

Fixes bytesparadise#529

Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon committed Apr 19, 2020
1 parent 6bdca28 commit c62a594
Show file tree
Hide file tree
Showing 11 changed files with 977 additions and 120 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
run:
skip-dirs:
- pkg/parser/includes
- pkg/renderer/html5/includes
- test/includes
skip-files:
- pkg/parser/parser.go # generated

Expand All @@ -10,6 +9,7 @@ linters:
- megacheck
- govet
- gocyclo
- unused
enable-all: false
disable:
- maligned
Expand Down
16 changes: 14 additions & 2 deletions libasciidoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/bytesparadise/libasciidoc/pkg/renderer"
htmlrenderer "github.com/bytesparadise/libasciidoc/pkg/renderer/html5"
"github.com/bytesparadise/libasciidoc/pkg/types"
"github.com/bytesparadise/libasciidoc/pkg/validator"
"github.com/pkg/errors"

log "github.com/sirupsen/logrus"
Expand Down Expand Up @@ -57,8 +58,19 @@ func ConvertToHTML(r io.Reader, output io.Writer, config configuration.Configura
if err != nil {
return types.Metadata{}, err
}
rendererCtx := renderer.NewContext(doc, config)
metadata, err := htmlrenderer.Render(rendererCtx, doc, output)
// validate the document
problems := validator.Validate(&doc)
for _, problem := range problems {
switch problem.Severity {
case validator.Error:
log.Error(problem.Message)
case validator.Warning:
log.Warn(problem.Message)
}
}
// render
ctx := renderer.NewContext(doc, config)
metadata, err := htmlrenderer.Render(ctx, doc, output)
if err != nil {
return types.Metadata{}, err
}
Expand Down
Loading

0 comments on commit c62a594

Please sign in to comment.