diff options
| author | Shulhan <ms@kilabit.info> | 2023-05-28 02:38:52 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-05-28 02:38:52 +0700 |
| commit | 5d485c22755334728dea72d7ce434814021e3aaa (patch) | |
| tree | 1ed6be8e02c464bd7379900267bb577686686a2f | |
| parent | c66c685ff3d33028811e972811c85be8534760d0 (diff) | |
| download | asciidoctor-go-5d485c22755334728dea72d7ce434814021e3aaa.tar.xz | |
all: fix rendering blockquote without attribution
Previously, in the htmlWriteBlockQuoteEnd, if attribution is set
we add HTML tag <div> and close it later after we add citation.
The issue is we did not check if attribution is true again when we
add closing tag for div, which make the div above of blockquote get
closed.
| -rw-r--r-- | html_backend.go | 22 | ||||
| -rw-r--r-- | testdata/blockquote_test.txt | 91 |
2 files changed, 104 insertions, 9 deletions
diff --git a/html_backend.go b/html_backend.go index ff51447..f3a285d 100644 --- a/html_backend.go +++ b/html_backend.go @@ -731,21 +731,25 @@ func htmlWriteBlockQuoteEnd(el *element, out io.Writer) { fmt.Fprint(out, "\n</blockquote>") var ( - v string - ok bool + v string + withAttribution bool + withCitation bool ) - v, ok = el.Attrs[attrNameAttribution] - if ok { - fmt.Fprintf(out, "\n<div class=%q>\n— %s", - attrNameAttribution, v) + v, withAttribution = el.Attrs[attrNameAttribution] + if withAttribution { + fmt.Fprintf(out, "\n<div class=%q>\n— %s", attrNameAttribution, v) } - v, ok = el.Attrs[attrNameCitation] - if ok { + v, withCitation = el.Attrs[attrNameCitation] + if withCitation { fmt.Fprintf(out, "<br>\n<cite>%s</cite>", v) } - fmt.Fprint(out, "\n</div>\n</div>") + + if withAttribution { + fmt.Fprint(out, "\n</div>") + } + fmt.Fprint(out, "\n</div>") } func htmlWriteBlockSidebar(el *element, out io.Writer) { diff --git a/testdata/blockquote_test.txt b/testdata/blockquote_test.txt new file mode 100644 index 0000000..9fd90ab --- /dev/null +++ b/testdata/blockquote_test.txt @@ -0,0 +1,91 @@ +Test [quote] and ____. + +>>> blockquote += Title + +== Section 1 + +[quote] +Quote in +section 1. + +== Section 2 + +[quote, John Doe] +Quote from +Section 2. + +== Section 3 + +____ +Quote from +section 3. +____ + +== Section 4 + +[quote, John Doe, Section 4] +____ +Quote from +section 4. +____ + +<<< blockquote + +<div class="sect1"> +<h2 id="section_1">Section 1</h2> +<div class="sectionbody"> +<div class="quoteblock"> +<blockquote> +Quote in +section 1. +</blockquote> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="section_2">Section 2</h2> +<div class="sectionbody"> +<div class="quoteblock"> +<blockquote> +Quote from +Section 2. +</blockquote> +<div class="attribution"> +— John Doe +</div> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="section_3">Section 3</h2> +<div class="sectionbody"> +<div class="quoteblock"> +<blockquote> + +<div class="paragraph"> +<p>Quote from +section 3.</p> +</div> +</blockquote> +</div> +</div> +</div> +<div class="sect1"> +<h2 id="section_4">Section 4</h2> +<div class="sectionbody"> +<div class="quoteblock"> +<blockquote> + +<div class="paragraph"> +<p>Quote from +section 4.</p> +</div> +</blockquote> +<div class="attribution"> +— John Doe<br> +<cite>Section 4</cite> +</div> +</div> +</div> +</div> |
