Lists, default tight

I’ve successfully been able to insert tight lists with something like

wrapInList(schema.nodes.bullet_list, { tight: true });

But I’ve not been able to set this as default… I’m using the markdown spec, so I’m trying something like the following:

import { schema } from 'prosemirror-markdown';
schema.nodes.ordered_list.attrs.tight.default = true;
export { schema };

It just inserts non-tight lists.

Don’t mutate schemas, that’s bound to break in various ways. You can create a new one, though, replacing the bullet_list node type with your own variant that defaults to tight.

Out of curiosity, what is a “tight” list? Is this something you use for styling/css?

It’s for markdown schema, renders as

* item 1
* item 2

Instead of:

* item 1

* item 2

Which is the default

How I’m supposed to extend an existing schema?

const newSchema = new Schema(schema.spec);

breaks functionality of my lists

@marijn about schema.spec being an OrderedMap, I think it’s always easier to work with natives, so would be good it you allow to access spec as a plain js object too.

@marijn the problem is actually not with my implementation, tried with the same prosemirror-markdown/master/src/schema.js and the behavior is the same as shown in the GIF. Will investigate further and probably fill an issue.

@marijn the problem can also be noticed importing from node_modules/prosemirror-markdown/src/schema.js {schema} instead of ‘prosemirror-markdown’ {schema}, probably it has to do with versions used by the prosemirror-markdown project on compiling time that differ from my local copy?

I’ve not been able to reproduce it on the internet, if you can please check it out, else I’ll check how to reproduce the problem on the cloud it in a few hours,

Are you maybe using two different schema objects in your code? All code interacting with a given editor should use the same schema instance, since node types are compared by identity, and different instances of the (conceptually) same node will be considered different.

Nope, even copied the entire prosemirror-markdown/src directory into an ‘schema’ folder, made the proper linking, and behavior is the same :frowning:

Edit: this is not the issue

@marijn I’ve found the issue, prosemirror-markdown is not compatible with version 1.0.1 of prosemirror-schema-list but only 1.0.0, please check that, I’d fill an issue but now I’m in a hurry.

prosemirror-markdown doesn’t seem to interact with prosemirror-schema-list at all. Are you using the schema from prosemirror-markdown as basis for your schema?

@marijn you’re right… IDK what I’ve changed exactly to make it work, but it’s working with lists v1.0.1… looks like it has to do with using a custom MarkdownParser, with the new schema I created, just as you suggested, just coincidentally I’ve been messing with dependencies, sorry about that.

About “extending a schema”, I’m doing this:

const newOrderedList = schema.spec.nodes.get('ordered_list');
const newBulletList = schema.spec.nodes.get('bullet_list');
newOrderedList.attrs.tight.default = true;
newBulletList.attrs.tight.default = true;
schema.spec.nodes.update('ordered_list', newOrderedList);
schema.spec.nodes.update('bullet_list', newBulletList);
const customSchema = new Schema(schema.spec);

And really don’t like it much, for instance if I could do something like schema.spec.nodes.update('ordered_list.attrs.tight.default', true); that would be more straightforward (or allowing me to access the schema through an standard object). Is there other way to edit this OrderedMap properties directly?

You’re still mutating shared objects—though I guess the chance of another piece of code depending on the original markdown schema in your setup is pretty slim. Something like this is cleaner:

const customSchema = new Schema({
  nodes: schema.spec.nodes
    .update("ordered_list", Object.assign({}, schema.spec.nodes.get("ordered_list"),
      {attrs: {order: {default: 1}, tight: {default: true}}}))
    .update("bullet_list", Object.assign({}, schema.spec.nodes.get("bullet_list"),
      {attrs: {tight: {default: true}}}))
  marks: schema.spec.marks