Navigation

    The Onewheel Forum

    Onewheel Forum

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Users
    • Groups
    • Rules
    • Archive

    Improvements to the forum

    Suggestions & Feedback
    6
    42
    1922
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Lia
      Lia GT XR Pint Plus V1 DIY @biell last edited by

      @biell Nail on the head, currently it will always start at 0 and ignore everything else including playlists. In turn making it so you couldn't share a playlist. For text links that had a video it meant the text goes missing, buried in the embed code that we don't see.

      That is indeed the plugin. I think it will be best to have it only embed on links without anything on the end of the ID. That way it doesn't embed a timecode link, playlist or text links where youtube is linked.

      1 Reply Last reply Reply Quote 1
      • B
        biell Plus GT DIY @Lia last edited by biell

        @lia The reason you are having trouble is because the {6,11} is a variable width greedy construct. So, if you put something around it, then the greedy match will just shrink to accommodate it. What we need is a zero width negative lookahead assertion, but the key to its success is to ensure it includes the previous expression, to ensure the {6,11} doesn't just match 10 to keep from failing our negative assertion. Ironically, in this case, the greedy RE match isn't greedy enough and we must force it to gobble up the whole string. With the inclusion of the original character class as a subset of our additional negative assertion character class, the RE will now match URLs without any options (time or otherwise) but will still match simple URLs.

        (?:<a.*?)?(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?!user|channel)\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)([\w-]{6,11})(?![\w?&-])(?:.*?\/a>)?
        

        Two things here. First, I replace a-zA-Z0-9_ with \w because it means the same thing (at least for a URL, \w accepts more in UTF-8, but we can ignore that). So, now that we have that cleaned up, we have between 6 and 11 (inclusive) of [\w-] but, critically, not followed by [\w?&-] which adds two characters to the character class ?& We exclude these because they start variable assignments in an HTTP GET statement, with ? starting the first variable and signifying to the HTTP server that variable arguments are starting, and & separating all subsequent variables. Because we include both ? and &, we can match www.youtube.com /watch?v=f0i-KnPu4Rw but not www.youtube.com /watch?v=f0i-KnPu4Rw&t=12 and we can match youtu.be /f0i-KnPu4Rw without matching youtu.be /f0i-KnPu4Rw?t=12

        Lia NotSure 2 Replies Last reply Reply Quote 2
        • Lia
          Lia GT XR Pint Plus V1 DIY @biell last edited by Lia

          @biell That works! Thank you so much :)

          I've added a close bracket to the [\w?&-] so it looks like [\w?)&-]in hopes to also have it not embed when in a link text like [Link text](Youtube link) which works in https://regex101.com/ but not here so wonder if it reads that differently.

          B 1 Reply Last reply Reply Quote 2
          • B
            biell Plus GT DIY @Lia last edited by

            @lia I cannot envision why that wouldn't work. You could try putting a backslash \ in front of the paren ) but that should be completely unnecessary. I ran this in node, and it matches as expected

            $ node
            Welcome to Node.js v17.6.0.
            Type ".help" for more information.
            > var link=/(?:<a.*?)?(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/(?!user|channel)\S*(?:(?:\/e(?:mbed))?\/|watch\?(?:\S*?&?v\=))|youtu\.be\/)([\w-]{6,11})(?![\w?)&-])(?:.*?\/a>)?/;
            undefined
            > link.exec("https://youtube.com/watch?v=f0i-KnPu4Rw");
            [
              'https://youtube.com /watch?v=f0i-KnPu4Rw',
              'f0i-KnPu4Rw',
              index: 0,
              input: 'https://youtube.com /watch?v=f0i-KnPu4Rw',
              groups: undefined
            ]
            > link.exec("https://youtube.com/watch?v=f0i-KnPu4Rw)");
            null
            > link.exec("https://youtu.be/f0i-KnPu4Rw");
            [
              'https://youtu.be /f0i-KnPu4Rw',
              'f0i-KnPu4Rw',
              index: 0,
              input: 'https://youtu.be /f0i-KnPu4Rw',
              groups: undefined
            ]
            > link.exec("https://youtu.be/f0i-KnPu4Rw)");
            null
            > 
            

            Also, this plugin is broken, in my opinion, because it should not attempt to run in a code block.

            Lia 1 Reply Last reply Reply Quote 2
            • NotSure
              NotSure XR Pint @biell last edited by

              @biell said in Improvements to the forum:

              What we need is a zero width negative lookahead assertion

              blech... glad that's over!

              regex was designed by lizard ppl.

              XR's got what plants crave!

              B 1 Reply Last reply Reply Quote 1
              • B
                biell Plus GT DIY @NotSure last edited by

                @notsure I love regular expressions. But, I do agree that it is a hammer, and not all problems are nails.

                In this case, there is no reason for youtube.com and youtu.be URLs to be configured from within the same stanza.

                    {
                      "name": "youtube",
                      "displayName": "Youtube",
                      "icon": "fa-youtube",
                      "regex": "(?:<a.*?)?(?:https?:\\/\\/)?(?:www\\.)?(?:youtube\\.com\\/(?!user|channel)\\S*(?:(?:\\/e(?:mbed))?\\/|watch\\?(?:\\S*?&?v\\=))|youtu\\.be\\/)([a-zA-Z0-9_-]{6,11})(?:.*?\\/a>)?",
                      "replacement": "<div class='embed-wrapper'><div class='embed-container'><iframe src='https://www.youtube.com/embed/$1' frameborder='0' allowfullscreen></iframe></div></div>"
                    },
                

                Should be two different configurations, and this idea that they support using them within anchor <a> HTML tags was just unnecessary.

                NotSure 1 Reply Last reply Reply Quote 2
                • NotSure
                  NotSure XR Pint @biell last edited by

                  @biell said in Improvements to the forum:

                  @notsure I love regular expressions.

                  interesting... on a totally unrelated subject, what color is ur blood lizard man?

                  XR's got what plants crave!

                  B 1 Reply Last reply Reply Quote 1
                  • Lia
                    Lia GT XR Pint Plus V1 DIY @biell last edited by

                    @biell said in Improvements to the forum:

                    Also, this plugin is broken, in my opinion, because it should not attempt to run in a code block.

                    Agreed, I even have the embed plugin after all the others.Markdown occurs before the embed plugin yet still wants to poke at it.

                    Did wonder if \W instead of \w would work but no joy. What you gave should just work so I think whatever is running it on the back is bugged. At least it doesn't generate embeds for timestamps anymore though so thank you for solving that one :)

                    Timestamp example: https://www.youtube.com/watch?v=f0i-KnPu4Rw?t=10
                    Playlist example: https://www.youtube.com/watch?v=gidOwEmVq5w&list=PLinsBwlGP89HoLf9d1VwmLIqjBikA38d3

                    B 1 Reply Last reply Reply Quote 1
                    • B
                      biell Plus GT DIY @Lia last edited by

                      @lia said in Improvements to the forum:

                      if \W instead of \w would work but no joy.

                      \W is actually the inverse of \w, so it matches every character except [a-zA-Z0-9_].

                      1 Reply Last reply Reply Quote 2
                      • B
                        biell Plus GT DIY @NotSure last edited by

                        @notsure 😛

                        1 Reply Last reply Reply Quote 2
                        • First post
                          Last post