diff --git a/.gitignore b/.gitignore index be39ad33..b73fcb21 100644 --- a/.gitignore +++ b/.gitignore @@ -58,3 +58,4 @@ tmp # exclude code coverage merged results coverage.txt *.html +.DS_Store diff --git a/README.adoc b/README.adoc index cc42a29f..7dfbcbdd 100644 --- a/README.adoc +++ b/README.adoc @@ -21,6 +21,7 @@ It is is available under the terms of the https://raw.githubusercontent.com/byte * Inline images in paragraphs (`image://`) * Block images (`image:://`) * Element attributes (`ID`, `link` and `title`, where applicable) on block images, paragraphs, lists and sections +* Labeled, ordered and unordered lists (with nesting and attributes) See the http://LIMITATIONS.adoc[known limitations] page for differences between Asciidoc/Asciidoctor and Libasciidoc. @@ -33,18 +34,30 @@ Further elements will be supported in the future. Feel free to open issues https == Usage +=== Command Line + +The libasciidoc library includes a minimalist command line interface to generate the HTML content from a given file: + +``` +$ libasciidoc -s content.adoc +``` + +=== Code integration + Libasciidoc provides 2 functions to convert an Asciidoc content into HTML: -1. Converting to a complete HTML document: +1. Converting an `io.Reader` into an HTML document: - func ConvertToHTML(context.Context, io.Reader, io.Writer, renderer.Option...) (map[string]interface{}, error) + func ConvertToHTML(ctx context.Context, source io.Reader, output io.Writer, options renderer.Option...) (map[string]interface{}, error) -2. Converting to a `body` element only: +2. Converting a file (giving its name) into an HTML document: - func ConvertToHTMLBody(context.Context, io.Reader, io.Writer) (map[string]interface{}, error) + func ConvertFileToHTML(ctx context.Context, filename string, output io.Writer, options renderer.Option...) (map[string]interface{}, error) where the returned `map[string]interface{}` object contains the document's title (which is not rendered in the HTML's body) and its other attributes. +The currently available option to pass as a last argument is `renderer.IncludeHeaderFooter(false)` to limit the generation to the body of the HTML document. + == How to contribute Please refer to the http://CONTRIBUTE.adoc[Contribute] page. diff --git a/cmd/libasciidoc/main.go b/cmd/libasciidoc/main.go index 99c16ecd..f1052210 100644 --- a/cmd/libasciidoc/main.go +++ b/cmd/libasciidoc/main.go @@ -1,18 +1,13 @@ package main import ( - "bytes" "context" "fmt" - "io/ioutil" "os" "strings" + "github.com/bytesparadise/libasciidoc" "github.com/bytesparadise/libasciidoc/renderer" - "github.com/bytesparadise/libasciidoc/renderer/html5" - "github.com/bytesparadise/libasciidoc/types" - - "github.com/bytesparadise/libasciidoc/parser" "github.com/pkg/errors" "github.com/spf13/cobra" @@ -48,21 +43,10 @@ func newRootCmd() *cobra.Command { os.Exit(1) } source := cmd.Flag("source").Value.String() - b, err := ioutil.ReadFile(source) + _, err := libasciidoc.ConvertFileToHTML(context.Background(), source, os.Stdout, renderer.IncludeHeaderFooter(true)) //renderer.IncludeHeaderFooter(true) if err != nil { - fmt.Printf("failed to read the source file: %v\n", err) - os.Exit(1) - } - doc, err := parser.Parse(source, b) - if err != nil { - fmt.Printf("failed to parse the source file: %v\n", err) - os.Exit(1) + return err } - buff := bytes.NewBuffer(nil) - actualDocument := doc.(types.Document) - rendererCtx := renderer.Wrap(context.Background(), actualDocument) - _, err = html5.Render(rendererCtx, buff) - fmt.Printf("%s\n", buff.String()) return nil }, } diff --git a/libasciidoc.go b/libasciidoc.go index 103ee67c..c9b75ef8 100644 --- a/libasciidoc.go +++ b/libasciidoc.go @@ -12,33 +12,29 @@ import ( log "github.com/sirupsen/logrus" ) -// ConvertToHTMLBody converts the content of the given reader `r` into an set of