goldmark-highlighting icon indicating copy to clipboard operation
goldmark-highlighting copied to clipboard

Concurrent use of goldmark-highlighting ?

Open chmike opened this issue 1 year ago • 1 comments

Apparently, according to this goldmark issue, the goldmark instance created with New can be used concurrently with multiple go routines rendering different Mardown text.

I may have misunderstood it's usage, but it seam that this property is not preserved by the use of WithCSSWriter as the same writer is shared by different concurrent Rendering operations.

It's correct or intended usage may need a clarification.

If we want to inline the css as a style in the head of the web page, we would need to support concurrent css writing. To do that it seam the the CSS writer should be passed as a context variable.

Will this option ensure that the css is written only once ?

chmike avatar May 25 '24 07:05 chmike

This option does not ensure that the css is written only once. Currently, we have choices...

  • Make a CSS writer goroutine-safe yourself
  • Use 1 goldmark per goroutine

Another thoughts: Add an interface for writing CSS

type CSSWriter interface {
   WriteCSS(p []byte) (n int, err error)
}

If a writer implements a CSSWriter, goldmark-highlighting will wirte CSS using this method. I feel more straightforward for the purpose.

yuin avatar May 28 '24 18:05 yuin