From f9d7f5a462ef3ba6d07f0f13af6816badcea09e1 Mon Sep 17 00:00:00 2001 From: Shulhan Date: Mon, 30 Mar 2026 21:30:00 +0700 Subject: all: move the sect anchor element to the right Previously, we try to fix the anchor position by using "flex-direction: row-reverse". This cause the formatted text inside title also become reversed. For example, == With `mono` Will rendered as mono With $ This is not as expected. This changes fix this by rendering the anchor on the right after title. --- default.css | 1 - html_backend.go | 20 +++---- testdata/test.got.html | 143 ++++++++++++++++++++++++------------------------- 3 files changed, 79 insertions(+), 85 deletions(-) diff --git a/default.css b/default.css index 8138b84..e103647 100644 --- a/default.css +++ b/default.css @@ -373,7 +373,6 @@ h4, h5, h6 { display: flex; - flex-direction: row-reverse; justify-content: start; padding-bottom: 0.5em; } diff --git a/html_backend.go b/html_backend.go index 323b60b..32973e0 100644 --- a/html_backend.go +++ b/html_backend.go @@ -1160,18 +1160,7 @@ func htmlWriteSection(doc *Document, el *element, out io.Writer) { fmt.Fprintf(out, "\n
\n<%s id=%q>", class, tag, el.ID) - var ( - withSectAnchors bool - withSectlinks bool - ) - - _, withSectAnchors = doc.Attributes.Entry[docAttrSectAnchors] - if withSectAnchors { - fmt.Fprintf(out, - ``, - el.ID, el.ID) - } - _, withSectlinks = doc.Attributes.Entry[docAttrSectLinks] + _, withSectlinks := doc.Attributes.Entry[docAttrSectLinks] if withSectlinks { fmt.Fprintf(out, ``, el.ID) } @@ -1185,6 +1174,13 @@ func htmlWriteSection(doc *Document, el *element, out io.Writer) { if withSectlinks { fmt.Fprint(out, "") } + + _, withSectAnchors := doc.Attributes.Entry[docAttrSectAnchors] + if withSectAnchors { + fmt.Fprintf(out, + ``, + el.ID, el.ID) + } fmt.Fprintf(out, "", tag) if el.kind == elKindSectionL1 { diff --git a/testdata/test.got.html b/testdata/test.got.html index 49751a9..6e8c276 100644 --- a/testdata/test.got.html +++ b/testdata/test.got.html @@ -384,7 +384,6 @@ h4, h5, h6 { display: flex; - flex-direction: row-reverse; justify-content: start; padding-bottom: 0.5em; } @@ -2611,7 +2610,7 @@ p.tableblock {
-

1. Metadata references

+

1. Metadata references

First author: Author A Author A a@a.com @@ -2631,7 +2630,7 @@ AA.

-

2. Inline formatting on section

+

2. Inline formatting on section

Test inline formatting on section title.

@@ -2639,16 +2638,16 @@ AA.

-

3. Level 1

+

3. Level 1

-

5. Comment

+

5. Comment

@@ -2678,7 +2677,7 @@ Indented block comment
-

6. Paragraph

+

6. Paragraph

A Title
@@ -2736,7 +2735,7 @@ This is next line in paragraph.

-

6.1. Alignment

+

6.1. Alignment

This text is left aligned.

@@ -2751,7 +2750,7 @@ This is next line in paragraph.

-

6.2. Line break

+

6.2. Line break

Rubies are red,
Topazes are blue.

@@ -2774,7 +2773,7 @@ line break

-

7. Unconstrained text formatting

+

7. Unconstrained text formatting

__A *B*__: A B

@@ -2809,7 +2808,7 @@ line break

-

8. Single quote

+

8. Single quote

'` A single quote without end.

@@ -2826,7 +2825,7 @@ line break

-

9. Subscript and superscript

+

9. Subscript and superscript

H20 H~ 3 ~0 H~4 ~0 H ~ 5~0 H~6 7~0.

@@ -2837,7 +2836,7 @@ line break

-

10. Constrained text formatting

+

10. Constrained text formatting

_A_B: _A_B

@@ -2889,10 +2888,10 @@ paragraph.

-

11. Blocks

+

11. Blocks

-

11.1. Title

+

11.1. Title

TODO list
    @@ -2911,7 +2910,7 @@ paragraph.

-

12. Block listing

+

12. Block listing

@@ -2930,7 +2929,7 @@ This is not listing.

-

13. Block literal

+

13. Block literal

@@ -2955,7 +2954,7 @@ A literal named and trailing characters will become paragraph.

-

14. Ordered Lists

+

14. Ordered Lists

    @@ -3178,7 +3177,7 @@ This line separated by comment.

-

15. Unordered Lists

+

15. Unordered Lists

    @@ -3404,7 +3403,7 @@ This line separated by comment.

    * Two

-

15.1. Custom markers

+

15.1. Custom markers

  • @@ -3553,7 +3552,7 @@ This line separated by comment.

-

15.2. Checklist

+

15.2. Checklist

  • @@ -3574,7 +3573,7 @@ This line separated by comment.

-

16. Mixed list

+

16. Mixed list

    @@ -3650,7 +3649,7 @@ This line separated by comment.

-

17. Description list

+

17. Description list

@@ -3977,7 +3976,7 @@ Hard drive
-

18. Question and Answers

+

18. Question and Answers

    @@ -3997,7 +3996,7 @@ Hard drive
-

19. Table

+

19. Table

@@ -4063,7 +4062,7 @@ D

-

19.2. Cell formatting

+

19.2. Cell formatting

Cell duplicated across three columns,

@@ -4206,7 +4205,7 @@ D

-

19.3. Header row

+

19.3. Header row

@@ -4243,7 +4242,7 @@ D

- + @@ -4276,7 +4275,7 @@ D

-

19.5. Table width

+

19.5. Table width

@@ -4353,9 +4352,9 @@ D

-

19.6. Table borders

+

19.6. Table borders

-

19.6.1. Frame

+

19.6.1. Frame

@@ -4421,7 +4420,7 @@ D

-

19.6.2. Grids

+

19.6.2. Grids

@@ -4488,7 +4487,7 @@ D

@@ -4595,7 +4594,7 @@ D

-

19.8. Orientation

+

19.8. Orientation

@@ -4630,7 +4629,7 @@ D

-

19.9. Table caption

+

19.9. Table caption

@@ -4690,7 +4689,7 @@ D

Table 1. A formal table
-

19.10. Escaping the Cell separator

+

19.10. Escaping the Cell separator

@@ -4719,7 +4718,7 @@ D

-

20. Horizontal rules

+

20. Horizontal rules


@@ -4741,7 +4740,7 @@ D

-

21. Page break

+

21. Page break

Before page break.

@@ -4753,7 +4752,7 @@ D

-

22. URLs

+

22. URLs

https://asciidoctor.org.

@@ -4782,7 +4781,7 @@ D

-

23. Anchors

+

23. Anchors

This paragraph gets a lot of attention.

@@ -4810,21 +4809,21 @@ D

-

23.2. Version 4.10

+

23.2. Version 4.10

-

24. Cross references

+

24. Cross references

-

24.1. Internal

+

24.1. Internal

Cross reference with ID _anchors.

@@ -4841,7 +4840,7 @@ D

-

25. Include

+

25. Include

This is inside the fragment1.adoc.

@@ -4907,10 +4906,10 @@ type anchor struct {
-

26. Images

+

26. Images

-

26.1. Block images

+

26.1. Block images

sunset @@ -4990,7 +4989,7 @@ This is become paragraph.

-

26.2. Float group

+

26.2. Float group

@@ -5012,7 +5011,7 @@ This is become paragraph.

-

26.3. Inline image

+

26.3. Inline image

Linux

@@ -5030,7 +5029,7 @@ You can find Linux everywhere these days!

-

27. Block open

+

27. Block open

Section inside
@@ -5043,7 +5042,7 @@ You can find Linux everywhere these days!

-

28. Video

+

28. Video

Video without options
@@ -5090,7 +5089,7 @@ Your browser does not support the video tag.
-

29. Audio

+

29. Audio

@@ -5102,10 +5101,10 @@ Your browser does not support the audio tag.
-

30. Admonition

+

30. Admonition

-

30.1. Line admonition

+

30.1. Line admonition

Admonition between a paragraph. WARNING: Wolpertingers are known to nest in server racks. @@ -5192,7 +5191,7 @@ admonition followed by list

@@ -5278,7 +5277,7 @@ Literal paragraph with admonition.
@@ -5296,7 +5295,7 @@ Enter at your own risk.
- +
@@ -5326,7 +5325,7 @@ for producing professional documents like DocBook and LaTeX.

-

32. Example

+

32. Example

Example 1. Sample document
@@ -5351,7 +5350,7 @@ This guide provides...
-

33. Quote

+

33. Quote

@@ -5390,7 +5389,7 @@ Everybody remember where we parked.
-

33.1. Quoted paragraph

+

33.1. Quoted paragraph

I hold it that a little rebellion now and then is a good thing, @@ -5451,7 +5450,7 @@ a quote
-

34. Verse

+

34. Verse

The fog comes
@@ -5477,13 +5476,13 @@ and then moves on.
-

35. Passthrough

+

35. Passthrough

A B+

-

35.1. Block passthrough

+

35.1. Block passthrough

@@ -5491,14 +5490,14 @@ and then moves on.
-

36. Section Discrete

+

36. Section Discrete

Discrete

This is content of discrete section.