Add real context to HTML parser context struct

pull/206/head
Tulir Asokan 2024-04-13 13:56:26 +03:00
parent 640086dbf9
commit 423d32ddf6
1 changed files with 6 additions and 3 deletions

View File

@ -7,6 +7,7 @@
package format
import (
"context"
"fmt"
"math"
"strconv"
@ -33,14 +34,16 @@ func (ts TagStack) Has(tag string) bool {
}
type Context struct {
Ctx context.Context
ReturnData map[string]any
TagStack TagStack
PreserveWhitespace bool
}
func NewContext() Context {
func NewContext(ctx context.Context) Context {
return Context{
Ctx: ctx,
ReturnData: map[string]any{},
TagStack: make(TagStack, 0, 4),
}
@ -411,7 +414,7 @@ func HTMLToText(html string) string {
Newline: "\n",
HorizontalLine: "\n---\n",
PillConverter: DefaultPillConverter,
}).Parse(html, NewContext())
}).Parse(html, NewContext(context.TODO()))
}
// HTMLToMarkdown converts Matrix HTML into markdown with the default settings.
@ -429,5 +432,5 @@ func HTMLToMarkdown(html string) string {
}
return fmt.Sprintf("[%s](%s)", text, href)
},
}).Parse(html, NewContext())
}).Parse(html, NewContext(context.TODO()))
}