Skip to content

Commit

Permalink
Add real context to HTML parser context struct
Browse files Browse the repository at this point in the history
  • Loading branch information
tulir committed Apr 13, 2024
1 parent 640086d commit 423d32d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions format/htmlparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package format

import (
"context"
"fmt"
"math"
"strconv"
Expand All @@ -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),
}
Expand Down Expand Up @@ -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.
Expand All @@ -429,5 +432,5 @@ func HTMLToMarkdown(html string) string {
}
return fmt.Sprintf("[%s](%s)", text, href)
},
}).Parse(html, NewContext())
}).Parse(html, NewContext(context.TODO()))
}

0 comments on commit 423d32d

Please sign in to comment.