markdown icon indicating copy to clipboard operation
markdown copied to clipboard

Make default syntaxes public

Open matthew-carroll opened this issue 10 months ago • 2 comments

Is there a reason that the default inline syntaxes are private?

https://github.com/dart-lang/markdown/blob/782b1803a29aa964410d93b4437d5d1efa47f6b4/lib/src/inline_parser.dart#L26

Imagine that I want the defaults, but I want to add my own syntax either as top priority, or bottom priority. With public defaults, that's as easy as:

inlineSyntaxes: [
  myTopPrioritySyntax,
  ...defaultInlineSyntaxes,
  myBottomPrioritySyntax,
]

But if the defaults are private then the developer has to dig through the source code to fine them, and then has to copy them over. There will be cases where that's still necessary, because sometimes a new syntax needs to be placed at a specific location in the priority list, but the most common case probably doesn't require that level of intervention.

matthew-carroll avatar Apr 09 '24 21:04 matthew-carroll

Because the order matters, for example, if you put SoftLineBreakSyntax() before LineBreakSyntax(), some syntax might not work as expected, or it might lower the performance if you move them around freely.

But perhaps that shouldn't be the reason for making it private

chenzhiguang avatar Apr 10 '24 08:04 chenzhiguang

I understand order matters - that's why I describe three cases in my original post:

  1. Add a syntax as top priority
  2. Add a syntax as bottom priority
  3. Add a syntax somewhere in the middle

Situation 3 will always require copying the list. But situation 1 and 2 wouldn't, and I would guess those two are the average.

matthew-carroll avatar Apr 10 '24 09:04 matthew-carroll