Community
    • Login

    Create hyperlinks in Exsisting Table

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    8 Posts 3 Posters 508 Views
    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.
    • MusoCityM
      MusoCity
      last edited by MusoCity

      I converted a TSV to HTLM and I want to add some hyperlinks to each song name and there are too many to do manually.
      So =POPSONG will link to
      httXX://mysongs.com/songs/=POPSONG.mp3

      This is one of many:

      	<tr>
      		<td>=POPSONG</td>
      		<td>R</td>
      		<td>4/4</td>
      		<td>ev8</td>
      		<td>140</td>
      		<td>Pop Piano Lite Solo Piano</td>
      		<td>Ballad</td>
      		<td>Pop 20</td>
      		<td>2009/12</td>
      		<td>RT 70</td>
      		<td>2</td>
      		<td>2</td>
      		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
      	</tr>
      
      1 Reply Last reply Reply Quote 0
      • guy038G
        guy038
        last edited by guy038

        Hello, @musocity and All,

        From your INPUT file, below :

        	<tr>
        		<td>=POPSONG</td>
        		<td>R</td>
        		<td>4/4</td>
        		<td>ev8</td>
        		<td>140</td>
        		<td>Pop Piano Lite Solo Piano</td>
        		<td>Ballad</td>
        		<td>Pop 20</td>
        		<td>2009/12</td>
        		<td>RT 70</td>
        		<td>2</td>
        		<td>2</td>
        		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
        	</tr>
        

        Use the following regex search :

        • SEARCH (?-s)^(\h+)<td>(=.+)</td>

        • REPLACE ${0}\r\n${1}httXX://mysons\.com/songs/${2}\.mp3

        And you should get this OUTPUT text :

        	<tr>
        		<td>=POPSONG</td>
        		httXX://mysons.com/songs/=POPSONG.mp3
        		<td>R</td>
        		<td>4/4</td>
        		<td>ev8</td>
        		<td>140</td>
        		<td>Pop Piano Lite Solo Piano</td>
        		<td>Ballad</td>
        		<td>Pop 20</td>
        		<td>2009/12</td>
        		<td>RT 70</td>
        		<td>2</td>
        		<td>2</td>
        		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
        	</tr>
        

        Best Regards,

        guy038

        1 Reply Last reply Reply Quote 0
        • guy038G
          guy038
          last edited by guy038

          Hi, @musocity and All,

          Ouuuups ! Sorry I misunderstood your need ! May be you prefer this OUTPUT :

          	<tr>
          		<td>httXX://mysons.com/songs/=POPSONG.mp3</td>
          		<td>R</td>
          		<td>4/4</td>
          		<td>ev8</td>
          		<td>140</td>
          		<td>Pop Piano Lite Solo Piano</td>
          		<td>Ballad</td>
          		<td>Pop 20</td>
          		<td>2009/12</td>
          		<td>RT 70</td>
          		<td>2</td>
          		<td>2</td>
          		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
          	</tr>
          

          If so , juste modify the previous S/R as :

          • SEARCH (?-s)=.+(?=</td>)

          • REPLACE httXX://mysons\.com/songs/${1}\.mp3

          BR

          guy038

          1 Reply Last reply Reply Quote 1
          • MusoCityM
            MusoCity
            last edited by

            I need

            d><a href="https://mysongs.com/songs/=POPSONG.mp3" title="">=POPSONG</a></td>
            

            the above SR gives me (using RegEx)

            <td>https://mysongs.com/songs/.mp3</td>
            
            CoisesC 1 Reply Last reply Reply Quote 0
            • CoisesC
              Coises @MusoCity
              last edited by Coises

              @MusoCity Try:
              Find what: (<tr>\s*\R\s*<td>)(.+)</td>
              Replace with: $1<a href="https://mysongs.com/songs/$2.mp3" title="">$2</a></td>

              However, this will still be problematic if your song titles include blanks or other characters that should be encoded in URLs. I would have to think a while longer if there is any reasonable way to fix that.

              CoisesC 1 Reply Last reply Reply Quote 0
              • CoisesC
                Coises @Coises
                last edited by

                I said in Create hyperlinks in Exsisting Table:

                However, this will still be problematic if your song titles include blanks or other characters that should be encoded in URLs. I would have to think a while longer if there is any reasonable way to fix that.

                This is a little slow and clumsy, but after doing the first replacement, you could clean up URLs with something like:

                Find what:("https://mysongs.com/songs/[^"]*) ([^"]*")
                Replace with:$1%20$2

                (note the space between first close parenthesis and the following open parenthesis in the find string); Replace All repeatedly until it doesn’t find anything else.

                Then repeat with any other special characters, such as “/” replaced with “%2F”; “:” with “%3A”; and “?” with “%3F”; there might be a faster way, but I don’t know what it is.

                1 Reply Last reply Reply Quote 0
                • MusoCityM
                  MusoCity
                  last edited by

                  Thanks ! I think that should do the job
                  example here:
                  Xttps://reatrak.com/downloads/biab/style-player/
                  I set target=“_blank” to open in new tab.
                  “You need 1 reputation to post links” so change the X to h :(

                  1 Reply Last reply Reply Quote 0
                  • guy038G
                    guy038
                    last edited by guy038

                    Hello, @musocity, @coises and All,

                    @musocity, I must admit that I shoud have remembered that an HTML link is always defined by a <a> tag, whose the href attribute specifies the link’s destination :-(

                    But, in your first post, you textually said :

                    So =POPSONG will link to
                    httXX://mysongs.com/songs/=POPSONG.mp3

                    Which is exactly what I did, in my second reply to you !!


                    Now, if you had posted something like :

                    I have a lot of <tr> blocks which, each, defines a song’s name, after the <td>/= chars

                    For instance, I have this INPUT text :

                    	<tr>
                    		<td>=POPSONG</td>
                    		<td>R</td>
                    		<td>4/4</td>
                    		<td>ev8</td>
                    		<td>140</td>
                    		<td>Pop Piano Lite Solo Piano</td>
                    		<td>Ballad</td>
                    		<td>Pop 20</td>
                    		<td>2009/12</td>
                    		<td>RT 70</td>
                    		<td>2</td>
                    		<td>2</td>
                    		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
                    	</tr>
                    

                    and I would like to get this OUTPUT :

                    	<tr>
                    		<td><a href="https://mysongs.com/songs/=POPSONG.mp3" title="">=POPSONG</a></td>
                    		<td>R</td>
                    		<td>4/4</td>
                    		<td>ev8</td>
                    		<td>140</td>
                    		<td>Pop Piano Lite Solo Piano</td>
                    		<td>Ballad</td>
                    		<td>Pop 20</td>
                    		<td>2009/12</td>
                    		<td>RT 70</td>
                    		<td>2</td>
                    		<td>2</td>
                    		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
                    	</tr>
                    

                    I could have given you the exact answer, straight away !


                    Now, regarding the replacement of some punctuation chars by their %encoded equivalent :

                    • I did not consider the -, ~, _ chars and the . dot if followed with mp3, which are non-reserved chars, as well as word chars

                    • I did not consider, either, the " double-quotes as well as the < and > chars, extensively used in HTML files

                    Thus, the remaining characters to test are this list :

                    !#$ %&'()*+,/:;=?@[]^`{|}
                    

                    Then, I chose this odd name’s song :

                    !#$ Name%&of'()*+,/:;the=?@[]song^`{|}
                    

                    Followed by .mp3

                    I found out a regex S/R which treats all these characters and replace them by their %encoded equivalent, in one go :

                    - SEARCH (?:/=|>=|(?<!\A)\G)(?:(?s-i)(?!\.mp3|</a>).)*?\K(?:(\x20)|(!)|(#)|(\$)|(%)|(&)|(')|(\()|(\))|(\*)|(\+)|(,)|(/)|(:)|(;)|(=)|(\?)|(@)|([)|(\\)|(])|(\^)|(`)|(\{)|(\|)|(\})|(\.(?!mp3)))
                    
                    - REPLACE (?{1}%20)(?{2}%21)(?{3}%23)(?{4}%24)(?{5}%25)(?{6}%26)(?{7}%27)(?{8}%28)(?{9}%29)(?{10}%2A)(?{11}%2B)(?{12}%2C)(?{13}%2F)(?{14}%3A)(?{15}%3B)(?{16}%3D)(?{17}%3F)(?{18}%40)(?{19}%5B)(?{20}%5C)(?{21}%5D)(?{22}%5E)(?{23}%60)(?{24}%7B)(?{25}%7C)(?{26}%7D)(?{27}%2E)
                    

                    I took inspiration from this post :

                    https://community.notepad-plus-plus.org/topic/22690/generic-regex-replacing-in-a-specific-zone-of-text


                    To test this regex :

                    • First, copy the following text in a new tab
                    	<tr>
                    		<td><a href="https://mysongs.com/songs/=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}.mp3" title="">=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}</a></td>
                    		<td>R</td>
                    		<td>4/4</td>
                    		<td>ev8</td>
                    		<td>140</td>
                    		<td>Pop Piano Lite Solo Piano</td>
                    		<td>Ballad</td>
                    		<td>Pop 20</td>
                    		<td>2009/12</td>
                    		<td>RT 70</td>
                    		<td>2</td>
                    		<td>2</td>
                    		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
                    	</tr>
                    
                    	<tr>
                    		<td><a href="https://mysongs.com/songs/=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}.mp3" title="">=!#$ Name%&of'()*+,/:;the=?@[]song^`{|}</a></td>
                    		<td>R</td>
                    		<td>4/4</td>
                    		<td>ev8</td>
                    		<td>140</td>
                    		<td>Pop Piano Lite Solo Piano</td>
                    		<td>Ballad</td>
                    		<td>Pop 20</td>
                    		<td>2009/12</td>
                    		<td>RT 70</td>
                    		<td>2</td>
                    		<td>2</td>
                    		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
                    	</tr>
                    
                    • Move to the very beginning of the file ( IMPORTANT )

                    • Open the Replace dialog ( Ctrl + H )

                    • Un-tick all box options

                    - SEARCH (?:/=|>=|(?<!\A)\G)(?:(?s-i)(?!\.mp3|</a>).)*?\K(?:(\x20)|(!)|(#)|(\$)|(%)|(&)|(')|(\()|(\))|(\*)|(\+)|(,)|(/)|(:)|(;)|(=)|(\?)|(@)|([)|(\\)|(])|(\^)|(`)|(\{)|(\|)|(\})|(\.(?!mp3)))
                    
                    - REPLACE (?{1}%20)(?{2}%21)(?{3}%23)(?{4}%24)(?{5}%25)(?{6}%26)(?{7}%27)(?{8}%28)(?{9}%29)(?{10}%2A)(?{11}%2B)(?{12}%2C)(?{13}%2F)(?{14}%3A)(?{15}%3B)(?{16}%3D)(?{17}%3F)(?{18}%40)(?{19}%5B)(?{20}%5C)(?{21}%5D)(?{22}%5E)(?{23}%60)(?{24}%7B)(?{25}%7C)(?{26}%7D)(?{27}%2E)
                    
                    • Select the Regular expression search mode

                    • Click once, on the Replace All button ( Do not use the Replace button )

                    Important :

                    • Due to the presence of the \K syntax, in the search regex, you CANNOT use the Replace button and must trigger a global replacement !

                    • If you just want to know the different occurrences, which will be replaced later, simply use the Find Next or Find Previous button ( or F3 / Shift + F3 )

                    And you should get this OUTPUT :

                    	<tr>
                    		<td><a href="https://mysongs.com/songs/=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D.mp3" title="">=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D</a></td>
                    		<td>R</td>
                    		<td>4/4</td>
                    		<td>ev8</td>
                    		<td>140</td>
                    		<td>Pop Piano Lite Solo Piano</td>
                    		<td>Ballad</td>
                    		<td>Pop 20</td>
                    		<td>2009/12</td>
                    		<td>RT 70</td>
                    		<td>2</td>
                    		<td>2</td>
                    		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
                    	</tr>
                    
                    	<tr>
                    		<td><a href="https://mysongs.com/songs/=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D.mp3" title="">=%21%23%24%20Name%25%26of%27%28%29%2A%2B%2C%2F%3A%3Bthe%3D%3F%40%5B%5C%5Dsong%5E%60%7B%7C%7D</a></td>
                    		<td>R</td>
                    		<td>4/4</td>
                    		<td>ev8</td>
                    		<td>140</td>
                    		<td>Pop Piano Lite Solo Piano</td>
                    		<td>Ballad</td>
                    		<td>Pop 20</td>
                    		<td>2009/12</td>
                    		<td>RT 70</td>
                    		<td>2</td>
                    		<td>2</td>
                    		<td>Piano Ballad,Air,Celtic,Country Ballad,Worship</td>
                    	</tr>
                    

                    Final clarification :

                    • Do not run this S/R twice ! Indeed, any % char of the encoded chars would be encoded as %25 again !

                    Best Regards,

                    guy038

                    1 Reply Last reply Reply Quote 2
                    • First post
                      Last post
                    The Community of users of the Notepad++ text editor.
                    Powered by NodeBB | Contributors