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

Links in a list are not parsed #31

Closed
Jaspur opened this issue Nov 17, 2019 · 9 comments
Closed

Links in a list are not parsed #31

Jaspur opened this issue Nov 17, 2019 · 9 comments
Assignees
Labels
good first issue Good for newcomers

Comments

@Jaspur
Copy link

Jaspur commented Nov 17, 2019

Hey,
I have a unsorted list with text on each line, all beginning with a link at the first word. But the links aren't parsed when generating HtmlOutput.. Also not in the show-modus in Nova.

@roelofr
Copy link
Collaborator

roelofr commented Nov 17, 2019

Hey @Jaspur,

Thanks for bringing this to our attention! 🎉

I looked into it, by making a list on the Editor.js website, but the behaviour there seems identical.

When you add a link to the list, it isn't automatically converted to an <a>-tag, which is why it doesn't become clickable.

The JSON also represents this, as I made the first item a link via the Editor.js config menu.

{
    "type" : "list",
    "data" : {
        "style" : "ordered",
        "items" : [
            "<a href=\"https://google.com\">https://google.com</a>",
            "https://bing.com",
            "https://cake.co.uk"
        ]
    }
}

There are three ways to solve this:

  1. Add a custom block (LinkList or something) that supports it. But this is blocked by how to add new tools? #19.
  2. Hook into the Editor.js API and listen for links, and convert them on the fly, but this also seems blocked by how to add new tools? #19
  3. Export the views and modify the list view to replace URLs with links.

Something like this might work:

 <div class="editor-js-block">
     {{ ($style == 'unordered') ? '<ul>' : '<ol>' }}
     @foreach ($items as $item)
         <li>
-            {{ $item }}
+            @if (filter_var($item, FILTER_VALIDATE_URL))
+                <a href="{{ $item }}" rel="noopener" target="_blank">{{ $item }}</a>
+            @else
+                {{ $item }}
+            @endif
         </li>
     @endforeach
     {{ ($style == 'unordered') ? '</ul>' : '</ol>' }}
 </div>

TL;DR: It's not supported out-of-the-box by Editor.js, but a custom view might work.

@roelofr roelofr self-assigned this Nov 17, 2019
@roelofr roelofr added enhancement New feature or request good first issue Good for newcomers labels Nov 17, 2019
@Jaspur
Copy link
Author

Jaspur commented Nov 17, 2019

Hi, thanks, but why isn't this supported out of the box then? ;-) Looks pretty normal behavior.

@roelofr
Copy link
Collaborator

roelofr commented Nov 17, 2019

I really don't know. You'd think that when you type https://example.com and press Enter or Space, it'd convert it to a link, but alas, it doesn't.


Edit: I do believe that this should be client-side behaviour. Turning every link in an anchor might be a security issue.

@roelofr
Copy link
Collaborator

roelofr commented Nov 17, 2019

Since we can't really do anything about this, I'm closing this issue. I'll try to fit in some time to get those custom blocks working, and then add a helper for the linked-list block.

@roelofr roelofr closed this as completed Nov 17, 2019
@roelofr roelofr removed the enhancement New feature or request label Nov 17, 2019
@Jaspur
Copy link
Author

Jaspur commented Nov 17, 2019

But it is different by the way, because my list-items are not just url's: https://www.dropbox.com/s/tuucryikeh9vx1y/Schermafdruk%202019-11-17%2020.50.56.png?dl=1

@roelofr
Copy link
Collaborator

roelofr commented Nov 17, 2019

Screenshot

Can't you just use the inline tools then? I don't see the issue with the screenshot you sent.

@Jaspur
Copy link
Author

Jaspur commented Nov 29, 2019

Same issue is for using links in Tables..

@roelofr
Copy link
Collaborator

roelofr commented Nov 29, 2019

Again, this is because automatic link recognition is not built into Editor.js.

@desaintflorent
Copy link

Hello,

I have the same problem, links are not parsed on list elements.
When I create a link on a list element in edit mode It's working, I can see it. But when I leave the edit mode links are not displayed.
I looked in the database and I can see those links.
And It's working well for text element.

Is this still a bug ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants