Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support nested code blocks and blockquotes in lists #40

Closed
4 tasks done
weiQuill opened this issue Nov 21, 2024 · 8 comments
Closed
4 tasks done

Support nested code blocks and blockquotes in lists #40

weiQuill opened this issue Nov 21, 2024 · 8 comments
Labels
🤷 no/invalid This cannot be acted upon 👎 phase/no Post cannot or will not be acted on

Comments

@weiQuill
Copy link

weiQuill commented Nov 21, 2024

Initial checklist

Problem

Hi team,
Is it possible to support such structural conversion?

1. milk
	> banana
2. cheese

Expect

[
	{
		type: "list",
		children: [
			{ type: "list item", ... },
			{ type: "blockquote", ... },
			{ type: "list item", ... },
		]
 	}
]

Actual

[
	{
		type: "list",
		children: [
			{ type: "list item", ... },
		]
 	},
	{ type: "blockquote", ... },
	{
		type: "list",
		children: [
			{ type: "list item", ... },
		]
 	}
]

The markdown works fine in GitHub

  1. milk

    banana

  2. cheese

  1. milk
    banana
    
  2. cheese

Solution

None

Alternatives

None

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Nov 21, 2024
@wooorm
Copy link
Member

wooorm commented Nov 21, 2024

What you want is not possible, and it is not needed.

Lists have list items. On GH too. You cannot remove the list items. And you do not need to.

The block quote is inside the item. On GH too.

import {fromMarkdown} from 'mdast-util-from-markdown'
import {removePosition} from 'unist-util-remove-position'

const document = `1. milk
	> banana
2. cheese`
const tree = fromMarkdown(document)
removePosition(tree, {force: true})

console.dir(tree, {depth: null})
{
  type: 'root',
  children: [
    {
      type: 'list',
      ordered: true,
      start: 1,
      spread: false,
      children: [
        {
          type: 'listItem',
          spread: false,
          checked: null,
          children: [
            {
              type: 'paragraph',
              children: [ { type: 'text', value: 'milk' } ]
            },
            {
              type: 'blockquote',
              children: [
                {
                  type: 'paragraph',
                  children: [ { type: 'text', value: 'banana' } ]
                }
              ]
            }
          ]
        },
        {
          type: 'listItem',
          spread: false,
          checked: null,
          children: [
            {
              type: 'paragraph',
              children: [ { type: 'text', value: 'cheese' } ]
            }
          ]
        }
      ]
    }
  ]
}

@wooorm wooorm closed this as not planned Won't fix, can't repro, duplicate, stale Nov 21, 2024
@wooorm wooorm added the 🤷 no/invalid This cannot be acted upon label Nov 21, 2024

This comment has been minimized.

@github-actions github-actions bot added 👎 phase/no Post cannot or will not be acted on and removed 🤞 phase/open Post is being triaged manually labels Nov 21, 2024
@weiQuill
Copy link
Author

weiQuill commented Nov 21, 2024

Thanks you @wooorm , that construction you got works for me!
I am using mdast-util-from-markdown 2.0.0, and called fromMarkdown like this:

const tree: Parent = fromMarkdown(text, {
	extensions: [gfmStrikethrough(), gfmTable(), gfmTaskListItem()],
	mdastExtensions: [gfmTableFromMarkdown(), gfmStrikethroughFromMarkdown(), gfmTaskListItemFromMarkdown()],
}) as Parent;

But got the tree different from yours:

tree {
	type: 'root',
	children: [
		{
			type: 'list',
			ordered: true,
			start: 1,
			spread: false,
			children: [Array],
			position: [Object]
		},
		{ type: 'blockquote', children: [Array], position: [Object] },
		{
			type: 'list',
			ordered: true,
			start: 2,
			spread: false,
			children: [Array],
			position: [Object]
		}
	],
	position: {
        start: { line: 1, column: 1, offset: 0 },
        end: { line: 4, column: 1, offset: 29 }
	}
}

Do you know how this happened? Huge thanks!

@wooorm
Copy link
Member

wooorm commented Nov 21, 2024

Can you show the actual code and versions? I am quite sure text is different from what you post here

@wooorm
Copy link
Member

wooorm commented Nov 21, 2024

And make your reproduction smaller: remove everything that is not needed. Remove every extension that’s not needed.

@weiQuill
Copy link
Author

weird, If I pass in the string you used directly, I can get the same result as yours. If I read the markdown from another md file, I will get the incorrect result.
10-quote-in-list.md

@wooorm
Copy link
Member

wooorm commented Nov 21, 2024

It’s not weird, it’s well specified! ;) It’s the difference between 2 spaces and a tab. In markdown, that tab there is worth 4 spaces.

You do not use enough spaces.
Take this: the block quote is not in the list item.

1. milk
> banana

Same with this, 1 is not enough:

1. milk
 > banana

Same, 2 is not enough:

1. milk
  > banana

Because 1 and . and are 3, you need 3 spaces:

1. milk
   > banana

@weiQuill
Copy link
Author

Thank you very much! It works now:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤷 no/invalid This cannot be acted upon 👎 phase/no Post cannot or will not be acted on
Development

No branches or pull requests

2 participants