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

Break link definitions onto multiple lines when needed #3531

Merged
merged 13 commits into from
May 14, 2018

Conversation

j-f1
Copy link
Member

@j-f1 j-f1 commented Dec 19, 2017

Ref #3481.

Prettier 1.9.2
Playground link

--parser markdown

Input:

[just-url]: https://example.com
[url-with-short-title]: https://example.com "title"
[url-with-long-title]: https://example.com "a long, long title. It's really really long. Here have words."

[long]: https://example.com/a-long-url/another-segment/yet-another-segment/a-really-long-file-name.php.aspx 
[long-with-title]: https://example.com/a-long-url/another-segment/yet-another-segment/a-really-long-file-name.php.aspx "look a title!"

Output:

[just-url]: https://example.com
[url-with-short-title]: https://example.com "title"
[url-with-long-title]: https://example.com "a long, long title. It's really really long. Here have words."
[long]: https://example.com/a-long-url/another-segment/yet-another-segment/a-really-long-file-name.php.aspx
[long-with-title]: https://example.com/a-long-url/another-segment/yet-another-segment/a-really-long-file-name.php.aspx "look a title!"

Output after this PR:
Preview playground link

[just-url]: https://example.com
[url-with-short-title]: https://example.com "title"
[url-with-long-title]:
  https://example.com
  "a long, long title. It's really really long. Here have words."
[long]:
  https://example.com/a-long-url/another-segment/yet-another-segment/a-really-long-file-name.php.aspx
[long-with-title]:
  https://example.com/a-long-url/another-segment/yet-another-segment/a-really-long-file-name.php.aspx
  "look a title!"

printUrl(node.url),
node.title ? line : null,
node.title ? printTitle(node.title) : null
].filter(x => x)
Copy link
Member

@ikatyang ikatyang Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be better this way as it's more intuitive:

concat([
  line,
  printUrl(node.url),
  node.title === null
    ? ""
    : concat([line, printTitle(node.title)])
])

And also we should add a test case for empty title:

[something]: http://prettier.io ""

Copy link
Member Author

@j-f1 j-f1 Dec 19, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the "" can be removed when the title is blank. Markdown (at least CommonMark) doesn’t render links with empty titles differently from links without titles.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll change the AST (at least remark's), we shouldn't touch it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...sorry, I thought node.title was "" in that case, it seems they're all parsed as null. But results are the same anyway.

Copy link
Member

@ikatyang ikatyang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

concat([
line,
printUrl(node.url),
node.title === null
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

@azz
Copy link
Member

azz commented Dec 24, 2017

I worry that this will break some renderers (specifically BitBucket Server). Maybe we could make it respect proseWrap: "preserve"?

@ikatyang
Copy link
Member

from BitBucket Support - Markdown syntax guide:

Bitbucket Server uses Markdown for formatting text, as specified in CommonMark (with a few extensions)

It seems they should render it correctly, but they actually didn't follow the CommonMark Spec. I'm not sure what should we do here since the link definition does not look like a prose.

@j-f1
Copy link
Member Author

j-f1 commented Jan 1, 2018

Rebased to fix the merge conflicts.

@j-f1
Copy link
Member Author

j-f1 commented Jan 4, 2018

👍/👎?

@j-f1
Copy link
Member Author

j-f1 commented Feb 18, 2018

Should we merge this or should I 🗑 it?

@lipis
Copy link
Member

lipis commented Feb 19, 2018

screen shot 2018-02-19 at 11 01 26

Even GitHub is not rendering them correctly (link is not purple).. I would leave them in a single line.. links are links :)

@j-f1
Copy link
Member Author

j-f1 commented Feb 19, 2018

@lipis GitHub renders them correctly:

just-url url-with-short-title url-with-long-title long long-with-title

@lipis
Copy link
Member

lipis commented Feb 19, 2018

the result is correct.. but when they are fenced?

Either case I would prefer to not break them or at least respect the proseWrap option

@j-f1
Copy link
Member Author

j-f1 commented Feb 19, 2018

Respecting proseWrap is a good idea 👍

@lipis
Copy link
Member

lipis commented May 11, 2018

What's the status with this one?

@j-f1
Copy link
Member Author

j-f1 commented May 11, 2018

I’m not sure — should this get merged as-is or should it be modified to respect proseWrap?

@lipis
Copy link
Member

lipis commented May 11, 2018

I would respect the proseWrap.. WDYT?

@lipis
Copy link
Member

lipis commented May 11, 2018

So shall we add the 1.13 tag for a friendly pressure?

@j-f1
Copy link
Member Author

j-f1 commented May 11, 2018

Sure 😀

@j-f1 j-f1 added this to the 1.13 milestone May 11, 2018
@j-f1 j-f1 requested review from lipis and ikatyang May 13, 2018 22:12
@j-f1 j-f1 merged commit dc68a3d into prettier:master May 14, 2018
@j-f1 j-f1 deleted the break-link-definitions branch June 3, 2018 11:10
@lock lock bot added the locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting. label Sep 1, 2018
@lock lock bot locked as resolved and limited conversation to collaborators Sep 1, 2018
JavierJF added a commit to JavierJF/prettier that referenced this pull request Apr 12, 2024
Allows to select if Markdown definitions should be broken when
'proseWrap' is set to 'always'. Single line reference links helps
preventing potential rendering issues.
JavierJF added a commit to JavierJF/prettier that referenced this pull request Apr 12, 2024
Allows to select if Markdown definitions should be broken when
'proseWrap' is set to 'always'. This enables, for example, single line
reference links, which can prevent potential rendering issues.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
locked-due-to-inactivity Please open a new issue and fill out the template instead of commenting.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants