Skip to content

Commit

Permalink
refactor(renderer): simplify rendering of special characters (#1070)
Browse files Browse the repository at this point in the history
Signed-off-by: Xavier Coulon <[email protected]>
  • Loading branch information
xcoulon authored Jul 25, 2022
1 parent d941be1 commit 25aad00
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 5 additions & 5 deletions libasciidoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ func Convert(source io.Reader, output io.Writer, config *configuration.Configura
var start, endOfPreprocess, emdOfParse, endOfValidate, endOfRender time.Time
start = time.Now()
defer func() {
log.Debugf("time to preprocess %d microseconds", endOfPreprocess.Sub(start).Microseconds())
log.Debugf("time to parse %d microseconds", emdOfParse.Sub(endOfPreprocess).Microseconds())
log.Debugf("time to validate %d microseconds", endOfValidate.Sub(emdOfParse).Microseconds())
log.Debugf("time to render %d microseconds", endOfRender.Sub(endOfValidate).Microseconds())
log.Debugf("total time %d microseconds", endOfRender.Sub(start).Microseconds())
log.Infof("time to preprocess %d microseconds", endOfPreprocess.Sub(start).Microseconds())
log.Infof("time to parse %d microseconds", emdOfParse.Sub(endOfPreprocess).Microseconds())
log.Infof("time to validate %d microseconds", endOfValidate.Sub(emdOfParse).Microseconds())
log.Infof("time to render %d microseconds", endOfRender.Sub(endOfValidate).Microseconds())
log.Infof("total time %d microseconds", endOfRender.Sub(start).Microseconds())
}()
p, err := parser.Preprocess(source, config)
if err != nil {
Expand Down
14 changes: 12 additions & 2 deletions pkg/renderer/sgml/special_character.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package sgml

import (
"fmt"

"github.com/bytesparadise/libasciidoc/pkg/types"
)

func (r *sgmlRenderer) renderSpecialCharacter(s *types.SpecialCharacter) (string, error) {
// log.Debugf("rendering special character '%s'", s.Name)
return escapeString(s.Name), nil
switch s.Name {
case `&`:
return "&amp;", nil
case `<`:
return "&lt;", nil
case `>`:
return "&gt;", nil
default:
return "", fmt.Errorf("unknown special character: '%s'", s.Name)
}
}

0 comments on commit 25aad00

Please sign in to comment.