From 79c454cb8080b3b4172c1575f3e01ac4d0931b73 Mon Sep 17 00:00:00 2001 From: Xavier Coulon Date: Sat, 7 Mar 2020 18:07:02 +0100 Subject: [PATCH] feat(cli): support attributes set/reset in CLI (#495) API break: using a new 'configuration.Configuration' parameter to wrap all the settings at the `libasciidoc.ConvertToHTML` level Fixes #484 Signed-off-by: Xavier Coulon --- README.adoc | 14 +- cmd/libasciidoc/root_cmd.go | 40 +++- cmd/libasciidoc/root_cmd_test.go | 34 +++- cmd/libasciidoc/test/doc_with_attributes.adoc | 5 + go.sum | 10 +- libasciidoc.go | 23 ++- libasciidoc_test.go | 14 +- pkg/configuration/configuration.go | 98 +++++++++ pkg/configuration/macro_template.go | 8 + pkg/parser/document_preprocessing.go | 28 +-- pkg/parser/document_processing.go | 35 ++-- ...document_processing_apply_substitutions.go | 8 +- ...ent_processing_apply_substitutions_test.go | 147 +++++++++++--- pkg/parser/file_inclusion.go | 27 ++- pkg/parser/file_inclusion_test.go | 83 +++++++- pkg/renderer/context.go | 188 ++++++++++-------- pkg/renderer/html5/article_adoc_test.go | 6 +- pkg/renderer/html5/document_details.go | 3 +- pkg/renderer/html5/document_details_test.go | 8 +- pkg/renderer/html5/elements.go | 2 +- pkg/renderer/html5/file_inclusion_test.go | 24 +-- pkg/renderer/html5/html5.go | 9 +- pkg/renderer/html5/html5_test.go | 8 +- pkg/renderer/html5/inline_elements.go | 6 +- pkg/renderer/html5/paragraph.go | 8 +- pkg/renderer/html5/user_macro.go | 2 +- pkg/renderer/html5/user_macro_test.go | 18 +- pkg/renderer/options.go | 86 -------- pkg/types/document_attributes.go | 89 ++++++--- pkg/types/document_attributes_test.go | 79 ++++++-- pkg/types/element_attributes.go | 16 +- pkg/types/types.go | 12 +- pkg/types/types_test.go | 49 +++-- test/supported_fixtures_test.go | 4 +- testsupport/document_attributes.go | 3 +- testsupport/document_metadata.go | 7 +- testsupport/document_metadata_test.go | 4 +- testsupport/html5_template_matcher.go | 4 +- testsupport/include_preamble.go | 3 +- .../include_table_of_contents_placeholder.go | 3 +- testsupport/parse_document.go | 3 +- testsupport/parse_draft_document.go | 4 +- testsupport/render_html5.go | 62 ++---- testsupport/table_of_contents.go | 3 +- 44 files changed, 820 insertions(+), 467 deletions(-) create mode 100644 cmd/libasciidoc/test/doc_with_attributes.adoc create mode 100644 pkg/configuration/configuration.go create mode 100644 pkg/configuration/macro_template.go delete mode 100644 pkg/renderer/options.go diff --git a/README.adoc b/README.adoc index c453e797..4788b9a4 100644 --- a/README.adoc +++ b/README.adoc @@ -58,21 +58,21 @@ Libasciidoc provides 2 functions to convert an Asciidoc content into HTML: 1. Converting an `io.Reader` into an HTML document: - func ConvertToHTML(ctx context.Context, source io.Reader, output io.Writer, options renderer.Option...) (map[string]interface{}, error) + ConvertToHTML(r io.Reader, output io.Writer, config configuration.Configuration) (types.Metadata, error) 2. Converting a file (given its name) into an HTML document: - func ConvertFileToHTML(ctx context.Context, filename string, output io.Writer, options renderer.Option...) (map[string]interface{}, error) + ConvertFileToHTML(output io.Writer, config configuration.Configuration) (types.Metadata, error) -where the returned `map[string]interface{}` object contains the document's title which is not part of the generated HTML `` part, as well as the other attributes of the source document. +where the returned `types.Metadata` object contains the document's title which is not part of the generated HTML `` part, as well as the other attributes of the source document. -For now, the sole option to pass as a last argument is `renderer.IncludeHeaderFooter` to include the `
` and `