1
0

test html

This commit is contained in:
Arpad Ryszka 2025-10-29 22:48:38 +01:00
parent ecb46a4b09
commit e4dd3ca0df
4 changed files with 1574 additions and 6 deletions

2
go.mod
View File

@ -4,4 +4,4 @@ go 1.25.0
require code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2
require code.squareroundforest.org/arpio/html v0.0.0-20251011102613-70f77954001f // indirect
require code.squareroundforest.org/arpio/html v0.0.0-20251029200407-effffeadf9f8 // indirect

2
go.sum
View File

@ -1,4 +1,6 @@
code.squareroundforest.org/arpio/html v0.0.0-20251011102613-70f77954001f h1:Ep/POhkmvOfSkQklPIpeA4n2FTD2SoFxthjF0SJbsCU=
code.squareroundforest.org/arpio/html v0.0.0-20251011102613-70f77954001f/go.mod h1:LX+Fwqu/a7nDayuDNhXA56cVb+BNrkz4M/WCqvw9YFQ=
code.squareroundforest.org/arpio/html v0.0.0-20251029200407-effffeadf9f8 h1:6OwHDturRjOeIxoc2Zlfkhf4InnMnNKKDb3LtrbIJjg=
code.squareroundforest.org/arpio/html v0.0.0-20251029200407-effffeadf9f8/go.mod h1:LX+Fwqu/a7nDayuDNhXA56cVb+BNrkz4M/WCqvw9YFQ=
code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2 h1:S4mjQHL70CuzFg1AGkr0o0d+4M+ZWM0sbnlYq6f0b3I=
code.squareroundforest.org/arpio/notation v0.0.0-20250826181910-5140794b16b2/go.mod h1:ait4Fvg9o0+bq5hlxi9dAcPL5a+/sr33qsZPNpToMLY=

36
html.go
View File

@ -19,11 +19,20 @@ func htmlText(t Txt) []any {
return c
}
var text any = t.text
if t.link != "" {
return []any{tag.A(html.Attr("href", t.link), t.text)}
text = tag.A(html.Attr("href", t.link), text)
}
return []any{t.text}
if t.bold {
text = tag.B(text)
}
if t.italic {
text = tag.I(text)
}
return []any{text}
}
func htmlTitle(e Entry) html.Tag {
@ -92,6 +101,7 @@ func htmlNumberedDefinitions(e Entry) html.Tag {
func htmlTable(e Entry) html.Tag {
table := tag.Table
e.rows = normalizeTable(e.rows)
for _, r := range e.rows {
row := tag.Tr
cell := tag.Td
@ -143,7 +153,7 @@ func htmlSequence(s SyntaxItem) string {
}
func htmlChoice(s SyntaxItem) string {
ss := htmlSyntaxItems(s.sequence)
ss := htmlSyntaxItems(s.choice)
if s.topLevel {
return strings.Join(ss, "\n")
}
@ -251,6 +261,10 @@ func renderHTMLFragment(out io.Writer, doc Document) error {
return err
}
if len(tags) == 0 {
return nil
}
for i, tag := range tags {
indent := html.Indentation{
Indent: "\t",
@ -267,11 +281,15 @@ func renderHTMLFragment(out io.Writer, doc Document) error {
indent.Indent = timesn(" ", doc.entries[i].indent)
}
if err := html.RenderIndent(out, indent, tag); err != nil {
if err := html.WriteIndent(out, indent, tag); err != nil {
return err
}
}
if _, err := fmt.Fprintln(out); err != nil {
return err
}
return nil
}
@ -302,5 +320,13 @@ func renderHTML(out io.Writer, doc Document, lang string) error {
MinPWidth: 60,
}
return html.RenderIndent(out, indent, tag.Doctype("html"), htmlDoc)
if err := html.WriteIndent(out, indent, tag.Doctype("html"), htmlDoc); err != nil {
return err
}
if _, err := fmt.Fprintln(out); err != nil {
return err
}
return nil
}

File diff suppressed because it is too large Load Diff