Debian Codegraph @

markup/asciidocext/convert.go

raw
1 // Copyright 2020 The Hugo Authors. All rights reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 // http://www.apache.org/licenses/LICENSE-2.0
7 //
8 // Unless required by applicable law or agreed to in writing, software
9 // distributed under the License is distributed on an "AS IS" BASIS,
10 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 // See the License for the specific language governing permissions and
12 // limitations under the License.
13
14 // Package asciidocext converts AsciiDoc to HTML using Asciidoctor
15 // external binary. The `asciidoc` module is reserved for a future golang
16 // implementation.
17 package asciidocext
18
19 import (
20 "github.com/gohugoio/hugo/htesting"
21 "github.com/gohugoio/hugo/markup/asciidocext/internal"
22 "github.com/gohugoio/hugo/markup/converter"
23 )
24
25 // Provider is the package entry point.
26 var Provider converter.ProviderProvider = provider{}
27
28 type provider struct{}
29
30 func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
31 return converter.NewProvider("asciidocext", func(ctx converter.DocumentContext) (converter.Converter, error) {
32 return &internal.AsciiDocConverter{
33 Ctx: ctx,
34 Cfg: cfg,
35 }, nil
36 }), nil
37 }
38
39 // Supports reports whether the AsciiDoc converter is installed. Only used in
40 // tests.
41 func Supports() (bool, error) {
42 hasAsciiDoc, err := internal.HasAsciiDoc()
43 if htesting.SupportsAll() {
44 if !hasAsciiDoc {
45 panic(err)
46 }
47 return true, nil
48
49 }
50
51 return hasAsciiDoc, err
52 }
53
54 // SupportsGoATDiagrams reports whether the AsciiDoc converter can render GoAT
55 // diagrams. Only used in tests.
56 func SupportsGoATDiagrams() (bool, error) {
57 supportsGoATDiagrams, err := internal.CanRenderGoATDiagrams()
58 if htesting.SupportsAll() {
59 if !supportsGoATDiagrams {
60 panic(err)
61 }
62 return true, nil
63 }
64
65 return supportsGoATDiagrams, err
66 }