Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7488883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T15:06:14+00:00 2026-05-29T15:06:14+00:00

I forked the excellent zen-coding project, with an idea to implement DOM ascension using

  • 0

I forked the excellent zen-coding project, with an idea to implement DOM ascension using a ^ – so you can do:

html>head>title^body>h1 rather than html>(head>title)+body>h1

Initially I implemented with rather shoddy regex methods. I have now implemented using @Jordan’s excellent answer. My fork is here

What I still want to know

Are there any scenarios where my function returns the wrong value?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T15:06:14+00:00Added an answer on May 29, 2026 at 3:06 pm

    Disclaimer: I have never used zen-coding and this is only my second time hearing about it, so I have no idea what the likely gotchas are. That said, this seems to be a working solution, or at least very close to one.

    I am using Zen Coding for textarea v0.7.1 for this. If you are using a different version of the codebase you will need to adapt these instructions accordingly.

    A couple of commenters have suggested that this is not a job for regular expressions, and I agree. Fortunately, zen-coding has its own parser implementation, and it’s really easy to build on! There are two places where you need to add code to make this work:

    1. Add the ^ character to the special_chars variable in the isAllowedChar function (starts circa line 1694):

      function isAllowedChar(ch) {
          ...
          special_chars = '#.>+*:$-_!@[]()|^'; // Added ascension operator "^"
      
    2. Handle the new operator in the switch statement of the parse function (starts circa line 1541):

      parse: function(abbr) {
          ...
          while (i < il) {
              ch = abbr.charAt(i);
              prev_ch = i ? abbr.charAt(i - 1) : '';
              switch (ch) {
                  ...
                  // YOUR CODE BELOW
                  case '^': // Ascension operator
                      if (!text_lvl && !attr_lvl) {
                          dumpToken();
                          context = context.parent.parent.addChild();
                      } else {
                          token += ch;
                      }
                      break;
      

      Here’s a line-by-line breakdown of what the new code does:

      case '^':                         // Current character is ascension operator.
          if (!text_lvl && !attr_lvl) { // Don't apply in text/attributes.
              dumpToken();              // Operator signifies end of current token.
      
                                        // Shift context up two levels.
              context = context.parent.parent.addChild();
      
          } else {
              token += ch;              // Add char to token in text/attribute.
          }
          break;
      

    The implementation above works as expected for e.g.:

    html>head>title^body
    html:5>div#first>div.inner^div#second>div.inner
    html:5>div>(div>div>div^div)^div*2
    html:5>div>div>div^^div
    

    You will doubtless want to try some more advanced, real-world test cases. Here’s my modified source if you want a kick-start; replace your zen_textarea.min.js with this for some quick-and-dirty testing.

    Note that this merely ascends the DOM by two levels and does not treat the preceding elements as a group, so e.g. div>div^*3 will not work like (div>div)*3. If this is something you want then look at the logic for the closing parenthesis character, which uses a lookahead to check for multiplication. (Personally, I suggest not doing this, since even for an abbreviated syntax it is horribly unreadable.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have forked an SVN project using Git because I needed to add features
Possible Duplicate: Can I update a forked project, on git, to the original/master copy?
Someone forked a Github project of mine and made some changes. How can I
I've never forked a project before so I'm a little stumped as to how
I forked a project on github, since then the original owner made changes to
I have forked the git repository of a project on Github and made my
I'm wanting to fork a github project that other's have forked and one of
I forked some project and cloned it locally. Changed files, commited changes, pushed changes
I forked a project on github, made some changes, so far so good. In
I've forked a project. I've also added handle 'upstream' that points to the original

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.