ProseMirror / prosemirror-markdown

ProseMirror Markdown integration
https://prosemirror.net
MIT License
345 stars 81 forks source link

Update method signature for getAttrs #53

Closed stevenle closed 3 years ago

stevenle commented 3 years ago

Per the code usage, the getAttrs() method actually accepts 3 arguments. Without the correct method signature, typescript complains about the usage.

There is a similar PR created to update the typescript @types definition for this package: https://github.com/DefinitelyTyped/DefinitelyTyped/pull/52752

marijnh commented 3 years ago

I think those additional arguments were intended to be internal. What are you using them for?

stevenle commented 3 years ago

I had copied out the defaultMarkdownParser to a custom parser, so that I could add support for additional tags on top of it (e.g. strikethrough). I'm realizing now that I can just do something like:

const myParser = new MarkdownParser(
  schema, 
  markdownit('default', {html: false}), 
  Object.assign({}, defaultMarkdownParser.tokens , {
    s: {mark: 's'}
  ));

It does seem odd for the defaultMarkdownParser to be able to use internal variables that are inaccessible to anyone else. Any chance this could be revisited or potentially refactored so anything available to the default parser would be accessible to all?

marijnh commented 3 years ago

Any chance this could be revisited or potentially refactored so anything available to the default parser would be accessible to all?

Only if there's a specific credible use case for this—expanding the public interface is easy, but all that stuff has to be supported forever.

stevenle commented 3 years ago

I'm gonna close this since I have a workaround for my issue. I would generally recommend, if possible, to refactor the listIsTight function to somehow not require the extra args passed to it so that defaultMarkdownParser can use the public API. Otherwise, anyone looking at the code for defaultMarkdownParser will think that that API is available (as I did) and would assume that the documentation is just out-of-date.