We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14050
    • 788 Posts
    Let’s say I have the following raw text:

    
    <p>
    This is a demonstration of the plugin "Context Links."  This demonstration is set to work on two parents with IDs of 110 and 111. Parent 110 has children "Concord" and "Riesling."  Parent 111 has children "Chambourcin," "Chambourcin Reserve" and "Villard Blanc."  The paragraph below, as it existed before the plugin converted it, only had the word "Chambourcin" linked.  The others are all plain text, and were dynamically converted to point to the correct document.  
    </p>
    <p>
    Please try our wonderful <a href="[~112~]" title="Chambourcin">Chambourcin</a>, Chambourcin Reserve, Villard Blanc, Concord, and  Riesling. 
    </p>
    


    If I want to replace every instance of "Chambourcin" unless it is inside an anchor or is an attribute for html. Original I had:

    \bChambourcin\b
    


    However, the replaces "Chambourcin" even when it is part of the title attribute and inside the anchor element. So then I tried:

    [^<?>]\bchambourcin\b
    


    This eliminates it from finding "Chambourcin" when it is the title attribute and inside the anchor tag, but has the undesired effect of matching ";Chambourcin" and " Chambourcin". How can I eliminate what I am trying to eliminate, while still having it only match "Chambourcin" and respecting its word boundaries?
      Jesse R.
      Consider trying something new and extraordinary.
      Illinois Wine

      Have you considered donating to MODx lately?
      Donate now. Every contribution helps.
      • 14050
      • 788 Posts
      Is there anyway with regular expressions to do something like this:

      Do not match "<a ... keyword ... >keyword</a>" but match "keyword" where ever else it may appear? I can match anything between the anchor tags with:

      <a\b[^>]*>.*?</a>
      


      Basically, I want my match to exclude anything matching that pattern, while matching another pattern.

      I am sure I am still not making any sense smiley
        Jesse R.
        Consider trying something new and extraordinary.
        Illinois Wine

        Have you considered donating to MODx lately?
        Donate now. Every contribution helps.
        • 3749
        • 24,544 Posts
        Great snippet!

        A third option (in addition to the TV for the keywords) could be a chunk with content like the following:

        KEYWORD: blah

        REPLACEMENT:blah, blah, blah

        KEYWORD: blah2

        REPLACEMENT:blah2, blah2, blah2


        I think it might be easier to work with if you had a lot of keywords to replace on each page and wanted to edit them often. You could name the chunk with the pageTitle or (probably safter) after the DocID.


        You could cannibalize the code from the EZfaq snippet to parse the chunk.

        Bob
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 14050
          • 788 Posts
          Quote from: BobRay at Feb 16, 2008, 08:02 PM

          Great snippet!

          A third option (in addition to the TV for the keywords) could be a chunk with content like the following:

          KEYWORD: blah

          REPLACEMENT:blah, blah, blah

          KEYWORD: blah2

          REPLACEMENT:blah2, blah2, blah2


          I think it might be easier to work with if you had a lot of keywords to replace on each page and wanted to edit them often. You could name the chunk with the pageTitle or (probably safter) after the DocID.


          You could cannibalize the code from the EZfaq snippet to parse the chunk.

          Bob


          The problem with this and the TV method is what document ID would you use when replacing the keyword with a hyperlink? Would they have something like this?

          Keyword: blah
          Replacement: <a href="[~5~]>blah</a>

          When I determine the keywords based on one of the fields from a document, then I can generate this link automatically because I can grab the document ID at the same time.
            Jesse R.
            Consider trying something new and extraordinary.
            Illinois Wine

            Have you considered donating to MODx lately?
            Donate now. Every contribution helps.
            • 3749
            • 24,544 Posts
            Quote from: Jesse at Feb 16, 2008, 11:24 PM

            The problem with this and the TV method is what document ID would you use when replacing the keyword with a hyperlink? Would they have something like this?

            Keyword: blah
            Replacement: <a href="[~5~]">blah</a>

            When I determine the keywords based on one of the fields from a document, then I can generate this link automatically because I can grab the document ID at the same time.

            It depends on the order that the parser handles things, but I *think* that would work. You’re right, though, about being able to get the ID directly. The only way around that would be to user the Doc ID in the chunk name and parse that but I’m not sure it’s worth the effort to do it the way I suggested.

            Bob
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 14050
              • 788 Posts
              If it was in a chunk or TV, the parser would not parse that. I would parse that, but use that notation for consistencies sake.
                Jesse R.
                Consider trying something new and extraordinary.
                Illinois Wine

                Have you considered donating to MODx lately?
                Donate now. Every contribution helps.
                • 18862
                • 70 Posts
                Ahhh, -Light goes on-

                Thanks Jesse, that makes sense. (You answered my post a couple of weeks back. Been a while since I’ve checked back on the forum)

                  • 19083
                  • 15 Posts
                  I ran into a problem with Context Link replacing text inside of hyperlinks and in my document’s header even with the search type set to 2. When I picked OnLoadWebDocument, Context link doesn’t recognize my TVs only content, introtext, etc.

                  As an alternative, I’ve been working with Auto Link. Auto Link uses tags to determine what part of a document will be parsed for link replacement. To have only the content of your site reviewed, encapsulate it in <autolink>asdfasdfasdf</autolink>.

                  You may want to consider something similar for Context link. I would suggest comments instead of custom tags i.e., <!-- start_context_link -->asdfasdfasdfasdfasdf <!-- end_context_link>. This might be an easy way to limit where Context Link will look for replacements.